Skip to content
Browse files

add auth capabilities to browser shim of request module

  • Loading branch information...
1 parent 50fbc18 commit 9eaa21b4bfc598b0ec39a47c3115c0630d7ea6bc @basti1302 committed Nov 28, 2013
View
47 browser/dist/traverson.external.js
@@ -77,57 +77,76 @@ Request.prototype.defaults = function(options) {
}
Request.prototype.get = function(uri, callback) {
- setupRequest(superagent.get(uri), this.options)
+ mapRequest(superagent.get(uri), this.options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
Request.prototype.post = function(uri, options, callback) {
- setupRequest(superagent.post(uri), this.options, options)
+ mapRequest(superagent.post(uri), this.options, options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
Request.prototype.put = function(uri, options, callback) {
- setupRequest(superagent.put(uri), this.options, options)
+ mapRequest(superagent.put(uri), this.options, options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
Request.prototype.patch = function(uri, options, callback) {
- setupRequest(superagent.patch(uri), this.options, options)
+ mapRequest(superagent.patch(uri), this.options, options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
Request.prototype.del = function(uri, options, callback) {
- setupRequest(superagent.del(uri), this.options)
+ mapRequest(superagent.del(uri), this.options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
-function setupRequest(superagentRequest, options, bodyOptions) {
+function mapRequest(superagentRequest, options, bodyOptions) {
+ mapHeaders(superagentRequest, options)
+ mapAuth(superagentRequest, options)
+ mapBody(superagentRequest, options, bodyOptions)
+ return superagentRequest
+}
+
+function mapHeaders(superagentRequest, options) {
var headers = options.headers
if (headers != null) {
- superagentRequest = superagentRequest.set(options.headers)
+ superagentRequest = superagentRequest.set(headers)
}
+}
+
+function mapAuth(superagentRequest, options) {
+ var auth = options.auth
+ if (auth != null) {
+ superagentRequest = superagentRequest.auth(
+ auth.user || auth.username,
+ auth.pass || auth.password
+ )
+ }
+}
+
+function mapBody(superagentRequest, options, bodyOptions) {
if (bodyOptions != null) {
var body = bodyOptions.body
if (body != null) {
superagentRequest = superagentRequest.send(body)
}
}
- return superagentRequest
}
// map XHR response object properties to Node.js request lib's response object
// properties
-function map(response) {
+function mapResponse(response) {
response.body = response.text
response.statusCode = response.status
return response
View
2 browser/dist/traverson.external.min.js
@@ -1,2 +1,2 @@
-require=function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){"use strict";function c(a){null==a&&(a=""),this.id=a}function d(a){return new c(a)}var e=!1;c.prototype.enable=function(){this.enabled=!0},c.prototype.debug=function(a){e&&console.log(this.id+"/debug: "+a)},c.prototype.info=function(a){e&&console.log(this.id+"/info: "+a)},c.prototype.warn=function(a){e&&console.log(this.id+"/warn: "+a)},c.prototype.error=function(a){e&&console.log(this.id+"/error: "+a)},d.enable=function(){e=!0},b.exports=d},{}],2:[function(a,b){"use strict";b.exports={isArray:function(a){return null==a?!1:"[object Array]"===Object.prototype.toString.call(a)}}},{}],3:[function(a,b){"use strict";function c(){this.options={}}function d(a,b,c){var d=b.headers;if(null!=d&&(a=a.set(b.headers)),null!=c){var e=c.body;null!=e&&(a=a.send(e))}return a}function e(a){return a.body=a.text,a.statusCode=a.status,a}var f=a("../third-party/superagent");c.prototype.defaults=function(a){var b=new c;return b.options=a,b},c.prototype.get=function(a,b){d(f.get(a),this.options).end(function(a){b(null,e(a))})},c.prototype.post=function(a,b,c){d(f.post(a),this.options,b).end(function(a){c(null,e(a))})},c.prototype.put=function(a,b,c){d(f.put(a),this.options,b).end(function(a){c(null,e(a))})},c.prototype.patch=function(a,b,c){d(f.patch(a),this.options,b).end(function(a){c(null,e(a))})},c.prototype.del=function(a,b,c){d(f.del(a),this.options).end(function(a){c(null,e(a))})},b.exports=new c},{"../third-party/superagent":5}],4:[function(a,b){"use strict";var c={startsWith:function(a,b){return""===b?!0:null==a||null==b?!1:(a=String(a),b=String(b),a.length>=b.length&&a.slice(0,b.length)===b)},endsWith:function(a,b){return""===b?!0:null==a||null==b?!1:(a=String(a),b=String(b),a.length>=b.length&&a.slice(a.length-b.length)===b)},splice:function(a,b,d,e){var f=c.chars(a);return f.splice(~~b,~~d,e),f.join("")},contains:function(a,b){return""===b?!0:null==a?!1:-1!==String(a).indexOf(b)},chars:function(a){return null==a?[]:String(a).split("")}};b.exports=c},{}],5:[function(a,b,c){!function(){function a(b,c,d){var e=a.resolve(b);if(null==e){d=d||b,c=c||"root";var f=new Error('Failed to require "'+d+'" from "'+c+'"');throw f.path=d,f.parent=c,f.require=!0,f}var g=a.modules[e];return g.exports||(g.exports={},g.client=g.component=!0,g.call(this,g.exports,a.relative(e),g)),g.exports}a.modules={},a.aliases={},a.resolve=function(b){"/"===b.charAt(0)&&(b=b.slice(1));for(var c=b+"/index.js",d=[b,b+".js",b+".json",b+"/index.js",b+"/index.json"],e=0;e<d.length;e++){var b=d[e];if(a.modules.hasOwnProperty(b))return b}return a.aliases.hasOwnProperty(c)?a.aliases[c]:void 0},a.normalize=function(a,b){var c=[];if("."!=b.charAt(0))return b;a=a.split("/"),b=b.split("/");for(var d=0;d<b.length;++d)".."==b[d]?a.pop():"."!=b[d]&&""!=b[d]&&c.push(b[d]);return a.concat(c).join("/")},a.register=function(b,c){a.modules[b]=c},a.alias=function(b,c){if(!a.modules.hasOwnProperty(b))throw new Error('Failed to alias "'+b+'", it does not exist');a.aliases[c]=b},a.relative=function(b){function c(a,b){for(var c=a.length;c--;)if(a[c]===b)return c;return-1}function d(c){var e=d.resolve(c);return a(e,b,c)}var e=a.normalize(b,"..");return d.resolve=function(d){var f=d.charAt(0);if("/"==f)return d.slice(1);if("."==f)return a.normalize(e,d);var g=b.split("/"),h=c(g,"deps")+1;return h||(h=0),d=g.slice(0,h+1).join("/")+"/deps/"+d},d.exists=function(b){return a.modules.hasOwnProperty(d.resolve(b))},d},a.register("component-indexof/index.js",function(a,b,c){var d=[].indexOf;c.exports=function(a,b){if(d)return a.indexOf(b);for(var c=0;c<a.length;++c)if(a[c]===b)return c;return-1}}),a.register("component-emitter/index.js",function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}var f=b("indexof");c.exports=d,d.prototype.on=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},b._off=c,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;var d=f(c,b._off||b);return~d&&c.splice(d,1),this},d.prototype.emit=function(a){this._callbacks=this._callbacks||{};var b=[].slice.call(arguments,1),c=this._callbacks[a];if(c){c=c.slice(0);for(var d=0,e=c.length;e>d;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}}),a.register("RedVentures-reduce/index.js",function(a,b,c){c.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}}),a.register("superagent/lib/client.js",function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(){if(r.XMLHttpRequest&&("file:"!=r.location.protocol||!r.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1}function g(a){return a===Object(a)}function h(a){if(!g(a))return a;var b=[];for(var c in a)b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function i(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function j(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=s(c.slice(b+1)),g[d]=e;return g}function k(a){return a.split(/ *; */).shift()}function l(a){return q(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function m(a,b){b=b||{},this.xhr=a,this.text=a.responseText,this.setStatusProperties(a.status),this.header=this.headers=j(a.getAllResponseHeaders()),this.header["content-type"]=a.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body=this.parseBody(this.text)}function n(a,b){var c=this;p.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.set("X-Requested-With","XMLHttpRequest"),this.on("end",function(){var b=new m(c.xhr);"HEAD"==a&&(b.text=null),c.callback(null,b)})}function o(a,b){return"function"==typeof b?new n("GET",a).end(b):1==arguments.length?new n("GET",a):new n(a,b)}var p=b("emitter"),q=b("reduce"),r="undefined"==typeof window?this:window,s="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};o.serializeObject=h,o.parseString=i,o.types={html:"text/html",json:"application/json",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},o.serialize={"application/x-www-form-urlencoded":h,"application/json":JSON.stringify},o.parse={"application/x-www-form-urlencoded":i,"application/json":JSON.parse},m.prototype.get=function(a){return this.header[a.toLowerCase()]},m.prototype.setHeaderProperties=function(){var a=this.header["content-type"]||"";this.type=k(a);var b=l(a);for(var c in b)this[c]=b[c]},m.prototype.parseBody=function(a){var b=o.parse[this.type];return b?b(a):null},m.prototype.setStatusProperties=function(a){var b=a/100|0;this.status=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a||1223==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},m.prototype.toError=function(){var a="got "+this.status+" response",b=new Error(a);return b.status=this.status,b},o.Response=m,n.prototype=new p,n.prototype.constructor=n,n.prototype.timeout=function(a){return this._timeout=a,this},n.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},n.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},n.prototype.set=function(a,b){if(g(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},n.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},n.prototype.type=function(a){return this.set("Content-Type",o.types[a]||a),this},n.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},n.prototype.query=function(a){return"string"!=typeof a&&(a=h(a)),a&&this._query.push(a),this},n.prototype.send=function(a){var b=g(a),c=this.getHeader("Content-Type");if(b&&g(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),this._data="application/x-www-form-urlencoded"==c?this._data?this._data+"&"+a:a:(this._data||"")+a):this._data=a;return b?(c||this.type("json"),this):this},n.prototype.callback=function(a,b){var c=this._callback;return 2==c.length?c(a,b):a?this.emit("error",a):(c(b),void 0)},n.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},n.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},n.prototype.withCredentials=function(){return this._withCredentials=!0,this},n.prototype.end=function(a){var b=this,c=this.xhr=f(),g=this._query.join("&"),h=this._timeout,i=this._data;if(this._callback=a||d,this._withCredentials&&(c.withCredentials=!0),c.onreadystatechange=function(){return 4==c.readyState?0==c.status?b.aborted?b.timeoutError():b.crossDomainError():(b.emit("end"),void 0):void 0},c.upload&&(c.upload.onprogress=function(a){a.percent=a.loaded/a.total*100,b.emit("progress",a)}),h&&!this._timer&&(this._timer=setTimeout(function(){b.abort()},h)),g&&(g=o.serializeObject(g),this.url+=~this.url.indexOf("?")?"&"+g:"?"+g),c.open(this.method,this.url,!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof i&&!e(i)){var j=o.serialize[this.getHeader("Content-Type")];j&&(i=j(i))}for(var k in this.header)null!=this.header[k]&&c.setRequestHeader(k,this.header[k]);return c.send(i),this},o.Request=n,o.get=function(a,b,c){var d=o("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},o.head=function(a,b,c){var d=o("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},o.del=function(a,b){var c=o("DELETE",a);return b&&c.end(b),c},o.patch=function(a,b,c){var d=o("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},o.post=function(a,b,c){var d=o("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},o.put=function(a,b,c){var d=o("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},c.exports=o}),a.alias("component-emitter/index.js","superagent/deps/emitter/index.js"),a.alias("component-emitter/index.js","emitter/index.js"),a.alias("component-indexof/index.js","component-emitter/deps/indexof/index.js"),a.alias("RedVentures-reduce/index.js","superagent/deps/reduce/index.js"),a.alias("RedVentures-reduce/index.js","reduce/index.js"),a.alias("superagent/lib/client.js","superagent/index.js"),"object"==typeof c?b.exports=a("superagent"):"function"==typeof define&&define.amd?define(function(){return a("superagent")}):this.superagent=a("superagent")}()},{emitter:15,indexof:15,reduce:15,superagent:15}],6:[function(a,b){"use strict";function c(a,b){this.walker=this.createWalker(a),this.walker.startUri=b,this.walker.request=this.request=e,this.finalAction=new g(this.walker)}var d=a("minilog"),e=a("request"),f=a("util"),g=a("./final_action"),h=a("./json_walker"),i=a("./json_hal_walker"),j=a("./media_types"),k=d("traverson");c.prototype.createWalker=function(a){switch(a){case j.JSON:return k.debug("creating new JsonWalker"),new h;case j.JSON_HAL:return k.debug("creating new JsonHalWalker"),new i;default:throw new Error("Unknown or unsupported media type: "+a)}},c.prototype.follow=function(){return this.walker.links=1===arguments.length&&f.isArray(arguments[0])?arguments[0]:Array.prototype.slice.apply(arguments),this},c.prototype.walk=c.prototype.follow,c.prototype.withTemplateParameters=function(a){return this.walker.templateParameters=a,this},c.prototype.withRequestOptions=function(a){return this.walker.request=this.request=e.defaults(a),this},c.prototype.get=function(a){var b=this;this.walker.walk(function(c,d,e){return k.debug("walker.walk returned"),c?a(c,e.response,e.uri):(b.finalAction.get(d,a),void 0)})},c.prototype.getResource=function(a){var b=this;this.walker.walk(function(c,d,e){return k.debug("walker.walk returned"),c?a(c,e.response,e.uri):(b.finalAction.getResource(d,a),void 0)})},c.prototype.getUri=function(a){var b=this;this.walker.walk(function(c,d,e){return k.debug("walker.walk returned"),c?a(c,e.response,e.uri):(b.finalAction.getUri(d,a),void 0)})},c.prototype.post=function(a,b){this.finalAction.walkAndExecute(a,this.request,this.request.post,b)},c.prototype.put=function(a,b){this.finalAction.walkAndExecute(a,this.request,this.request.put,b)},c.prototype.patch=function(a,b){this.finalAction.walkAndExecute(a,this.request,this.request.patch,b)},c.prototype.del=function(a){this.finalAction.walkAndExecute(null,this.request,this.request.del,a)},b.exports=c},{"./final_action":7,"./json_hal_walker":8,"./json_walker":9,"./media_types":10,minilog:1,request:3,util:2}],7:[function(a,b){"use strict";function c(a){this.walker=a}var d=a("minilog"),e=d("traverson");c.prototype.get=function(a,b){e.debug("next step: "+JSON.stringify(a,null,2)),this.walker.process(a,function(a,c){return e.debug("walker.process returned"),a?b(a,c.response,c.uri):(!c.response&&c.doc&&(e.debug("faking HTTP response for embedded resource"),c.response={statusCode:200,body:JSON.stringify(c.doc),remark:"This is not an actual HTTP response. The resource you requested was an embedded resource, so no HTTP request was made to acquire it."}),b(null,c.response),void 0)})},c.prototype.getResource=function(a,b){var c=this;e.debug("next step: "+JSON.stringify(a)),this.walker.process(a,function(a,d){if(e.debug("walker.process returned"),a)return b(a,d.response,d.uri);if(d.doc)return b(null,d.doc);var f;try{return c.walker.checkHttpStatus(d),f=c.walker.parse(d),b(null,f)}catch(g){return b(g,g.doc)}})},c.prototype.getUri=function(a,b){var c=this;return e.debug("returning uri"),a.uri?b(null,a.uri):a.doc&&a.doc._links&&a.doc._links.self&&a.doc._links.self.href?b(null,c.walker.startUri+a.doc._links.self.href):b(new Error('You requested an URI but the last resource is an embedded resource and has no URI of its own (that is, it has no link with rel="self"'))},c.prototype.walkAndExecute=function(a,b,c,d){var f=this;this.walker.walk(function(g,h,i){return e.debug("walker.walk returned"),g?d(g,i.response,i.uri):(e.debug("executing final request with step: "+JSON.stringify(h)),f.executeRequest(h.uri,b,c,a,d),void 0)})},c.prototype.executeRequest=function(a,b,c,d,f){var g;g=d?{body:JSON.stringify(d)}:{},e.debug("request to "+a+" with options "+JSON.stringify(g)),c.call(b,a,g,function(b,c){return e.debug("request to "+a+" succeeded"),b?f(b,c,a):f(null,c,a)})},b.exports=c},{minilog:1}],8:[function(a,b){"use strict";function c(){}function d(a,b,c){var d=a.linkArray(b);if(!d||0===d.length)return null;var g=e(d,b,c);return g||(g=f(d,b)),g}function e(a,b,c){if(c){if(!a[c])throw new Error(b+"["+c+"] requested, but link array "+b+" had no element at index "+c);if(!a[c].href)throw new Error(b+"["+c+"] requested, but this link had no href attribute.");return p.debug("found hal link: "+a[c].href),{uri:a[c].href}}return null}function f(a,b){for(var c,d=0;d<a.length;d++)if(a[d].href){c=a[d];break}return c?(a.length>1&&p.warn("Found HAL link array with more than one element for key "+b+", arbitrarily choosing index "+d+", because it was the first that had a href attribute."),p.debug("found hal link: "+c.href),{uri:c.href}):null}function g(a,b,c,d){p.debug("checking for embedded: "+c+(d?d:""));var e=a.embeddedArray(c);if(!e||0===e.length)return null;p.debug("Found an array of embedded resource for: "+c);var f=h(e,c,d);return f||(f=i(e,c)),f}function h(a,b,c){if(c){if(!a[c])throw new Error(b+"["+c+"] requested, but there is no such link. However, there is an embedded resource array named "+b+" but it does not have an element at index "+c);return p.debug("Found an embedded resource for: "+b+"["+c+"]"),{doc:a[c].original()}}return null}function i(a,b){return a.length>1&&p.warn("Found HAL embedded resource array with more than one element for key "+b+", arbitrarily choosing first element."),{doc:a[0].original()}}function j(a){var b=a.match(/.*\[(\d+)\]/);return b?b[1]:null}function k(a){var b=a.match(/(.*)\[\d+\]/);return b?b[1]:a}var l=a("halfred"),m=a("minilog"),n=a("underscore.string"),o=a("./walker"),p=m("traverson");c.prototype=new o,c.prototype.findNextStep=function(a,b){p.debug("parsing hal");var c=l.parse(a),e=j(b);b=k(b);var f=d(c,b,e);if(f)return f;if(f=g(c,a,b,e))return f;throw new Error("Could not find a link nor an embedded object for "+b+" in document:\n"+JSON.stringify(a))},c.prototype.postProcessStep=function(a){a.uri&&(n.endsWith(this.startUri,"/")&&n.startsWith(a.uri,"/")&&(a.uri=n.splice(a.uri,0,1)),a.uri=this.startUri+a.uri)},b.exports=c},{"./walker":11,halfred:16,minilog:1,"underscore.string":4}],9:[function(a,b){"use strict";function c(){}var d=a("./walker");c.prototype=new d,b.exports=c},{"./walker":11}],10:[function(a,b){"use strict";b.exports={JSON:"application/json",JSON_HAL:"application/hal+json"}},{}],11:[function(a,b){"use strict";function c(){}function d(a,b,c){var d=new Error("HTTP GET for "+a+" resulted in HTTP status code "+b+".");d.name="HTTPError",d.uri=a,d.httpStatus=b,d.body=c;try{d.doc=JSON.parse(c)}catch(e){}return d}function e(a,b){var c=new Error("The document at "+a+" could not be parsed as JSON: "+b);return c.name="JSONError",c.uri=a,c.body=b,c}var f=a("JSONPath"),g=a("minilog"),h=a("underscore.string"),i=a("uri-template"),j=a("util"),k=f.eval,l=g("traverson");c.prototype.walk=function(a){function b(){return e<c.links.length?(c.process(d,function(g,h){if(f=h,g)return l.debug("error while processing step "+JSON.stringify(d)),l.error(g),a(g,d,h);l.debug("successully processed step");try{c.checkHttpStatus(h)}catch(i){return l.error("unexpected http status code"),l.error(i),a(i,d,h)}var j;try{j=c.parse(h)}catch(i){return l.error("parsing failed"),l.error(i),a(i,d,h)}var k=c.links[e++];l.debug("next link: "+k);try{d=c.findNextStep(j,k)}catch(i){return l.error("could not find next step"),l.error(i),a(i,d,h)}c.postProcessStep(d),l.debug("next step: "+JSON.stringify(d,null,2)),d.uri&&(d.uri=c.resolveUriTemplate(d.uri,c.templateParameters,e)),b()}),void 0):(l.debug("link array exhausted, calling callback"),a(null,d,f))}var c=this,d={uri:this.resolveUriTemplate(this.startUri,this.templateParameters,0)},e=0,f=d;l.debug("starting to follow links"),b()},c.prototype.process=function(a,b){if(l.debug("processing next step: "+JSON.stringify(a,null,2)),a.uri)this.get(a,b);else{if(!a.doc)throw new Error("Can not process next step: "+JSON.stringify(a));l.debug("document for next step has already been fetched"),b(null,a)}},c.prototype.get=function(a,b){l.debug("request to "+a.uri),this.request.get(a.uri,function(c,d){return l.debug("request.get returned"),c?b(c,a):(l.debug("request to "+a.uri+" finished ("+d.statusCode+")"),a.response=d,b(null,a))})},c.prototype.checkHttpStatus=function(a){if(a.response||!a.doc){var b=a.response.statusCode;if(200>b||b>=300)throw d(a.uri,b,a.response.body)}},c.prototype.parse=function(a){if(a.doc)return a.doc;try{return JSON.parse(a.response.body)}catch(b){if("SyntaxError"===b.name)throw e(a.uri,a.response.body);throw b}},c.prototype.findNextStep=function(a,b){l.debug("extracting link "+b+" from "+JSON.stringify(a));if(this.testJSONPath(b))return{uri:this.resolveJSONPath(b,a)};if(a[b])return{uri:a[b]};throw new Error("Could not find property "+b+" in document:\n"+JSON.stringify(a))},c.prototype.postProcessStep=function(){},c.prototype.testJSONPath=function(a){return h.startsWith(a,"$.")||h.startsWith(a,"$[")},c.prototype.resolveJSONPath=function(a,b){var c=k(b,a);if(1===c.length){var d=c[0];if(!d)throw new Error("JSONPath expression "+a+" was resolved but the result was null, undefined or an empty string in document:\n"+JSON.stringify(b));return d}throw c.length>1?new Error("JSONPath expression "+a+" returned more than one match in document:\n"+JSON.stringify(b)):new Error("JSONPath expression "+a+" returned no match in document:\n"+JSON.stringify(b))},c.prototype.resolveUriTemplate=function(a,b,c){if(j.isArray(b)&&(b=b[c]),!b)return a;if(h.contains(a,"{")){var d=i.parse(a);return d.expand(b)}return a},b.exports=c},{JSONPath:13,minilog:1,"underscore.string":4,"uri-template":20,util:2}],12:[function(a,b,c){var d=Array.isArray;c.isArray=d||function(a){return"[object Array]"==Object.prototype.toString.call(a)}},{}],13:[function(a,b,c){function d(a,b,c){var d={resultType:c&&c.resultType||"VALUE",flatten:c&&c.flatten||!1,wrap:c&&c.hasOwnProperty("wrap")?c.wrap:!0,sandbox:c&&c.sandbox?c.sandbox:{},normalize:function(a){if(g[a])return g[a];var b=[],c=a.replace(/[\['](\??\(.*?\))[\]']/g,function(a,c){return"[#"+(b.push(c)-1)+"]"}).replace(/'?\.'?|\['?/g,";").replace(/;;;|;;/g,";..;").replace(/;$|'?\]|'$/g,"").replace(/#([0-9]+)/g,function(a,c){return b[c]});return g[a]=c,c},asPath:function(a){for(var b=a.split(";"),c="$",d=1,e=b.length;e>d;d++)c+=/^[0-9*]+$/.test(b[d])?"["+b[d]+"]":"['"+b[d]+"']";return c},store:function(a,b){return a&&("PATH"==d.resultType?d.result[d.result.length]=d.asPath(a):f.isArray(b)&&d.flatten?(d.result||(d.result=[]),f.isArray(d.result)||(d.result=[d.result]),d.result=d.result.concat(b)):d.result?(f.isArray(d.result)||(d.result=[d.result]),f.isArray(b)&&d.flatten?d.result=d.result.concat(b):d.result[d.result.length]=b):d.result=b),!!a},trace:function(a,b,c){if(a){var e=a.split(";"),f=e.shift();if(e=e.join(";"),b&&b.hasOwnProperty(f))d.trace(e,b[f],c+";"+f);else if("*"===f)d.walk(f,e,b,c,function(a,b,c,e,f){d.trace(a+";"+c,e,f)});else if(".."===f)d.trace(e,b,c),d.walk(f,e,b,c,function(a,b,c,e,f){"object"==typeof e[a]&&d.trace("..;"+c,e[a],f+";"+a)});else if(/,/.test(f))for(var g=f.split(/'?,'?/),h=0,i=g.length;i>h;h++)d.trace(g[h]+";"+e,b,c);else/^\(.*?\)$/.test(f)?d.trace(d.eval(f,b,c.substr(c.lastIndexOf(";")+1))+";"+e,b,c):/^\?\(.*?\)$/.test(f)?d.walk(f,e,b,c,function(a,b,c,e,f){d.eval(b.replace(/^\?\((.*?)\)$/,"$1"),e[a],a)&&d.trace(a+";"+c,e,f)}):/^(-?[0-9]*):(-?[0-9]*):?([0-9]*)$/.test(f)&&d.slice(f,e,b,c)}else d.store(c,b)},walk:function(a,b,c,d,e){if(c instanceof Array)for(var f=0,g=c.length;g>f;f++)f in c&&e(f,a,b,c,d);else if("object"==typeof c)for(var h in c)c.hasOwnProperty(h)&&e(h,a,b,c,d)},slice:function(a,b,c,e){if(c instanceof Array){var f=c.length,g=0,h=f,i=1;a.replace(/^(-?[0-9]*):(-?[0-9]*):?(-?[0-9]*)$/g,function(a,b,c,d){g=parseInt(b||g),h=parseInt(c||h),i=parseInt(d||i)}),g=0>g?Math.max(0,g+f):Math.min(f,g),h=0>h?Math.max(0,h+f):Math.min(f,h);for(var j=g;h>j;j+=i)d.trace(j+";"+b,c,e)}},eval:function(a,b){d.sandbox._v=b;try{return h&&b&&e.runInNewContext(a.replace(/@/g,"_v"),d.sandbox)}catch(c){throw console.log(c),new SyntaxError("jsonPath: "+c.message+": "+a.replace(/@/g,"_v").replace(/\^/g,"_a"))}}};d.result=d.wrap===!0?[]:void 0;var h=a;return b&&a&&("VALUE"==d.resultType||"PATH"==d.resultType)?(d.trace(d.normalize(b).replace(/^\$;/,""),a,"$"),!f.isArray(d.result)&&d.wrap&&(d.result=[d.result]),d.result?d.result:!1):void 0}var e=a("vm"),f=a("underscore");c.eval=d;var g={}},{underscore:12,vm:14}],14:[function(require,module,exports){var Object_keys=function(a){if(Object.keys)return Object.keys(a);var b=[];for(var c in a)b.push(c);return b},forEach=function(a,b){if(a.forEach)return a.forEach(b);for(var c=0;c<a.length;c++)b(a[c],c,a)},Script=exports.Script=function(a){return this instanceof Script?(this.code=a,void 0):new Script(a)};Script.prototype.runInNewContext=function(a){a||(a={});var b=document.createElement("iframe");b.style||(b.style={}),b.style.display="none",document.body.appendChild(b);var c=b.contentWindow;forEach(Object_keys(a),function(b){c[b]=a[b]}),!c.eval&&c.execScript&&c.execScript("null");var d=c.eval(this.code);return forEach(Object_keys(c),function(b){a[b]=c[b]}),document.body.removeChild(b),d},Script.prototype.runInThisContext=function(){return eval(this.code)},Script.prototype.runInContext=function(a){return this.runInNewContext(a)},forEach(Object_keys(Script.prototype),function(a){exports[a]=Script[a]=function(b){var c=Script(b);return c[a].apply(c,[].slice.call(arguments,1))}}),exports.createScript=function(a){return exports.Script(a)},exports.createContext=Script.createContext=function(a){var b={};return"object"==typeof a&&forEach(Object_keys(a),function(c){b[c]=a[c]}),b}},{}],15:[function(){},{}],16:[function(a,b){var c=a("./lib/parser"),d=!1;b.exports={parse:function(a){return(new c).parse(a,d)},enableValidation:function(a){d=null!=a?a:!0},disableValidation:function(){d=!1}}},{"./lib/parser":18}],17:[function(a,b){"use strict";function c(){this._array=arguments.length>=1?arguments[0]:[]}c.prototype.array=function(){return this._array},c.prototype.isEmpty=function(){return 0===this._array.length},c.prototype.push=function(a){var b=this._array.slice(0);return b.push(a),new c(b)},c.prototype.pop=function(){var a=this._array.slice(0,this._array.length-1);return new c(a)},c.prototype.peek=function(){if(this.isEmpty())throw new Error("can't peek on empty stack");return this._array[this._array.length-1]},b.exports=c},{}],18:[function(a,b){"use strict";function c(){}function d(a,b,c){if(null==a)return a;var d=e(a._links,b,c.push("_links")),h=f(a._embedded,b,c.push("_embedded")),i=new q(d,h,b);return g(a,i),i._original=a,i}function e(a,b,c){return a=h(a,j,b,c),(null==a||null==a.self)&&m("Resource does not have a self link",b,c),a}function f(a,b,c){var e=h(a,l,b,c);return null==e?e:(Object.keys(e).forEach(function(a){e[a]=e[a].map(function(e){var f=null!=b?[]:null,g=d(e,f,c.push(a));return g._original=e,g})}),e)}function g(a,b){Object.keys(a).forEach(function(c){"_links"!==c&&"_embedded"!==c&&(b[c]=a[c])})}function h(a,b,c,d){if(null==a)return a;var e={};return Object.keys(a).forEach(function(f){e[f]=i(f,a[f],b,c,d)}),e}function i(a,b,c,d,e){return k(b)?b.map(function(b){return c(a,b,d,e)}):[c(a,b,d,e)]}function j(a,b,c,d){var e=o(b);return Object.keys(s).forEach(function(b){null==e[b]&&(s[b].required&&m("Link misses required property "+b+".",c,d.push(a)),null!=s[b].defaultValue&&(e[b]=s[b].defaultValue))}),e.deprecation&&n("Warning: Link "+p(d.push(a))+" is deprecated, see "+e.deprecation),e.templated!==!0&&e.templated!==!1&&(e.templated=!1),c?(e.href&&e.href.indexOf("{")>=0&&!e.templated&&m('Link seems to be an URI template but its "templated" property is not set to true.',c,d.push(a)),e):e}function k(a){return"[object Array]"===Object.prototype.toString.call(a)}function l(a,b){return b}function m(a,b,c){b&&b.push({path:p(c),message:a})}function n(a){"undefined"!=typeof console&&"function"==typeof console.log&&console.log(a)}function o(a){var b={};return Object.keys(a).forEach(function(c){b[c]=a[c]}),b}function p(a){for(var b="$.",c=0;c<a.array().length;c++)b+=a.array()[c]+".";return b=b.substring(0,b.length-1)}var q=a("./resource"),r=a("./immutable_stack"),s={href:{required:!0,defaultValue:null},templated:{required:!1,defaultValue:!1},type:{required:!1,defaultValue:null},deprecation:{required:!1,defaultValue:null},name:{required:!1,defaultValue:null},profile:{required:!1,defaultValue:null},title:{required:!1,defaultValue:null},hreflang:{required:!1,defaultValue:null}};c.prototype.parse=function(a,b){var c=b?[]:null;return d(a,c,new r)},b.exports=c},{"./immutable_stack":17,"./resource":19}],19:[function(a,b){"use strict";function c(a,b,c){this._links=a||{},this._embedded=b||{},this._validation=c||[]}function d(a,b){return null!=a?a[b]:null}function e(a,b,c){c=c||0;var e=d(a,b);return null!=e&&e.length>=1?e[c]:null}c.prototype.allLinkArrays=function(){return this._links},c.prototype.linkArray=function(a){return d(this._links,a)},c.prototype.link=function(a,b){return e(this._links,a,b)},c.prototype.allEmbeddedResourceArrays=function(){return this._embedded},c.prototype.embeddedResourceArray=function(a){return d(this._embedded,a)},c.prototype.embeddedResource=function(a,b){return e(this._embedded,a,b)},c.prototype.original=function(){return this._original},c.prototype.validationIssues=function(){return this._validation},c.prototype.allLinks=c.prototype.allLinkArrays,c.prototype.allEmbeddedArrays=c.prototype.allEmbeddedResources=c.prototype.allEmbeddedResourceArrays,c.prototype.embeddedArray=c.prototype.embeddedResourceArray,c.prototype.embedded=c.prototype.embeddedResource,c.prototype.validation=c.prototype.validationIssues,b.exports=c},{}],20:[function(a,b){b.exports=function(){function b(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var c={parse:function(c,d){function e(a){v>t||(t>v&&(v=t,w=[]),w.push(a))}function f(){var a,b,c;for(c=t,a=[],b=o(),null===b&&(b=g());null!==b;)a.push(b),b=o(),null===b&&(b=g());return null!==a&&(a=function(a,b){return new y(b)}(c,a)),null===a&&(t=c),a}function g(){var a,b,d,f,g,i;return g=t,i=t,123===c.charCodeAt(t)?(a="{",t++):(a=null,0===u&&e('"{"')),null!==a?(b=h(),null!==b?(d=j(),null!==d?(125===c.charCodeAt(t)?(f="}",t++):(f=null,0===u&&e('"}"')),null!==f?a=[a,b,d,f]:(a=null,t=i)):(a=null,t=i)):(a=null,t=i)):(a=null,t=i),null!==a&&(a=function(a,b,c){return z(b,c)}(g,a[1],a[2])),null===a&&(t=g),a}function h(){var a;return/^[\/;:.?&+#]/.test(c.charAt(t))?(a=c.charAt(t),t++):(a=null,0===u&&e("[\\/;:.?&+#]")),null===a&&(a=""),a}function i(){var a;return"{/"===c.substr(t,2)?(a="{/",t+=2):(a=null,0===u&&e('"{/"')),a}function j(){var a,b,d,f,g,h,i,j;if(g=t,h=t,a=k(),null!==a){for(b=[],i=t,j=t,44===c.charCodeAt(t)?(d=",",t++):(d=null,0===u&&e('","')),null!==d?(f=k(),null!==f?d=[d,f]:(d=null,t=j)):(d=null,t=j),null!==d&&(d=function(a,b){return b}(i,d[1])),null===d&&(t=i);null!==d;)b.push(d),i=t,j=t,44===c.charCodeAt(t)?(d=",",t++):(d=null,0===u&&e('","')),null!==d?(f=k(),null!==f?d=[d,f]:(d=null,t=j)):(d=null,t=j),null!==d&&(d=function(a,b){return b}(i,d[1])),null===d&&(t=i);null!==b?a=[a,b]:(a=null,t=h)}else a=null,t=h;return null!==a&&(a=function(a,b,c){return c.unshift(b),c}(g,a[0],a[1])),null===a&&(t=g),a}function k(){var a,b,d,f,g;for(f=t,g=t,a=[],/^[a-zA-Z0-9_.%]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[a-zA-Z0-9_.%]"));null!==b;)a.push(b),/^[a-zA-Z0-9_.%]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[a-zA-Z0-9_.%]"));return null!==a?(b=l(),null===b&&(b=m()),b=null!==b?b:"",null!==b?(d=p(),d=null!==d?d:"",null!==d?a=[a,b,d]:(a=null,t=g)):(a=null,t=g)):(a=null,t=g),null!==a&&(a=function(a,b,c,d){return c=c||{},{name:b.join(""),explode:c.listMarker,cut:c.cut,extended:d}
+require=function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){"use strict";function c(a){null==a&&(a=""),this.id=a}function d(a){return new c(a)}var e=!1;c.prototype.enable=function(){this.enabled=!0},c.prototype.debug=function(a){e&&console.log(this.id+"/debug: "+a)},c.prototype.info=function(a){e&&console.log(this.id+"/info: "+a)},c.prototype.warn=function(a){e&&console.log(this.id+"/warn: "+a)},c.prototype.error=function(a){e&&console.log(this.id+"/error: "+a)},d.enable=function(){e=!0},b.exports=d},{}],2:[function(a,b){"use strict";b.exports={isArray:function(a){return null==a?!1:"[object Array]"===Object.prototype.toString.call(a)}}},{}],3:[function(a,b){"use strict";function c(){this.options={}}function d(a,b,c){return e(a,b),f(a,b),g(a,b,c),a}function e(a,b){var c=b.headers;null!=c&&(a=a.set(c))}function f(a,b){var c=b.auth;null!=c&&(a=a.auth(c.user||c.username,c.pass||c.password))}function g(a,b,c){if(null!=c){var d=c.body;null!=d&&(a=a.send(d))}}function h(a){return a.body=a.text,a.statusCode=a.status,a}var i=a("../third-party/superagent");c.prototype.defaults=function(a){var b=new c;return b.options=a,b},c.prototype.get=function(a,b){d(i.get(a),this.options).end(function(a){b(null,h(a))})},c.prototype.post=function(a,b,c){d(i.post(a),this.options,b).end(function(a){c(null,h(a))})},c.prototype.put=function(a,b,c){d(i.put(a),this.options,b).end(function(a){c(null,h(a))})},c.prototype.patch=function(a,b,c){d(i.patch(a),this.options,b).end(function(a){c(null,h(a))})},c.prototype.del=function(a,b,c){d(i.del(a),this.options).end(function(a){c(null,h(a))})},b.exports=new c},{"../third-party/superagent":5}],4:[function(a,b){"use strict";var c={startsWith:function(a,b){return""===b?!0:null==a||null==b?!1:(a=String(a),b=String(b),a.length>=b.length&&a.slice(0,b.length)===b)},endsWith:function(a,b){return""===b?!0:null==a||null==b?!1:(a=String(a),b=String(b),a.length>=b.length&&a.slice(a.length-b.length)===b)},splice:function(a,b,d,e){var f=c.chars(a);return f.splice(~~b,~~d,e),f.join("")},contains:function(a,b){return""===b?!0:null==a?!1:-1!==String(a).indexOf(b)},chars:function(a){return null==a?[]:String(a).split("")}};b.exports=c},{}],5:[function(a,b,c){!function(){function a(b,c,d){var e=a.resolve(b);if(null==e){d=d||b,c=c||"root";var f=new Error('Failed to require "'+d+'" from "'+c+'"');throw f.path=d,f.parent=c,f.require=!0,f}var g=a.modules[e];return g.exports||(g.exports={},g.client=g.component=!0,g.call(this,g.exports,a.relative(e),g)),g.exports}a.modules={},a.aliases={},a.resolve=function(b){"/"===b.charAt(0)&&(b=b.slice(1));for(var c=b+"/index.js",d=[b,b+".js",b+".json",b+"/index.js",b+"/index.json"],e=0;e<d.length;e++){var b=d[e];if(a.modules.hasOwnProperty(b))return b}return a.aliases.hasOwnProperty(c)?a.aliases[c]:void 0},a.normalize=function(a,b){var c=[];if("."!=b.charAt(0))return b;a=a.split("/"),b=b.split("/");for(var d=0;d<b.length;++d)".."==b[d]?a.pop():"."!=b[d]&&""!=b[d]&&c.push(b[d]);return a.concat(c).join("/")},a.register=function(b,c){a.modules[b]=c},a.alias=function(b,c){if(!a.modules.hasOwnProperty(b))throw new Error('Failed to alias "'+b+'", it does not exist');a.aliases[c]=b},a.relative=function(b){function c(a,b){for(var c=a.length;c--;)if(a[c]===b)return c;return-1}function d(c){var e=d.resolve(c);return a(e,b,c)}var e=a.normalize(b,"..");return d.resolve=function(d){var f=d.charAt(0);if("/"==f)return d.slice(1);if("."==f)return a.normalize(e,d);var g=b.split("/"),h=c(g,"deps")+1;return h||(h=0),d=g.slice(0,h+1).join("/")+"/deps/"+d},d.exists=function(b){return a.modules.hasOwnProperty(d.resolve(b))},d},a.register("component-indexof/index.js",function(a,b,c){var d=[].indexOf;c.exports=function(a,b){if(d)return a.indexOf(b);for(var c=0;c<a.length;++c)if(a[c]===b)return c;return-1}}),a.register("component-emitter/index.js",function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}var f=b("indexof");c.exports=d,d.prototype.on=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},b._off=c,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;var d=f(c,b._off||b);return~d&&c.splice(d,1),this},d.prototype.emit=function(a){this._callbacks=this._callbacks||{};var b=[].slice.call(arguments,1),c=this._callbacks[a];if(c){c=c.slice(0);for(var d=0,e=c.length;e>d;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}}),a.register("RedVentures-reduce/index.js",function(a,b,c){c.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}}),a.register("superagent/lib/client.js",function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(){if(r.XMLHttpRequest&&("file:"!=r.location.protocol||!r.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1}function g(a){return a===Object(a)}function h(a){if(!g(a))return a;var b=[];for(var c in a)b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function i(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function j(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=s(c.slice(b+1)),g[d]=e;return g}function k(a){return a.split(/ *; */).shift()}function l(a){return q(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function m(a,b){b=b||{},this.xhr=a,this.text=a.responseText,this.setStatusProperties(a.status),this.header=this.headers=j(a.getAllResponseHeaders()),this.header["content-type"]=a.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body=this.parseBody(this.text)}function n(a,b){var c=this;p.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.set("X-Requested-With","XMLHttpRequest"),this.on("end",function(){var b=new m(c.xhr);"HEAD"==a&&(b.text=null),c.callback(null,b)})}function o(a,b){return"function"==typeof b?new n("GET",a).end(b):1==arguments.length?new n("GET",a):new n(a,b)}var p=b("emitter"),q=b("reduce"),r="undefined"==typeof window?this:window,s="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};o.serializeObject=h,o.parseString=i,o.types={html:"text/html",json:"application/json",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},o.serialize={"application/x-www-form-urlencoded":h,"application/json":JSON.stringify},o.parse={"application/x-www-form-urlencoded":i,"application/json":JSON.parse},m.prototype.get=function(a){return this.header[a.toLowerCase()]},m.prototype.setHeaderProperties=function(){var a=this.header["content-type"]||"";this.type=k(a);var b=l(a);for(var c in b)this[c]=b[c]},m.prototype.parseBody=function(a){var b=o.parse[this.type];return b?b(a):null},m.prototype.setStatusProperties=function(a){var b=a/100|0;this.status=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a||1223==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},m.prototype.toError=function(){var a="got "+this.status+" response",b=new Error(a);return b.status=this.status,b},o.Response=m,n.prototype=new p,n.prototype.constructor=n,n.prototype.timeout=function(a){return this._timeout=a,this},n.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},n.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},n.prototype.set=function(a,b){if(g(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},n.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},n.prototype.type=function(a){return this.set("Content-Type",o.types[a]||a),this},n.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},n.prototype.query=function(a){return"string"!=typeof a&&(a=h(a)),a&&this._query.push(a),this},n.prototype.send=function(a){var b=g(a),c=this.getHeader("Content-Type");if(b&&g(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),this._data="application/x-www-form-urlencoded"==c?this._data?this._data+"&"+a:a:(this._data||"")+a):this._data=a;return b?(c||this.type("json"),this):this},n.prototype.callback=function(a,b){var c=this._callback;return 2==c.length?c(a,b):a?this.emit("error",a):(c(b),void 0)},n.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},n.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},n.prototype.withCredentials=function(){return this._withCredentials=!0,this},n.prototype.end=function(a){var b=this,c=this.xhr=f(),g=this._query.join("&"),h=this._timeout,i=this._data;if(this._callback=a||d,this._withCredentials&&(c.withCredentials=!0),c.onreadystatechange=function(){return 4==c.readyState?0==c.status?b.aborted?b.timeoutError():b.crossDomainError():(b.emit("end"),void 0):void 0},c.upload&&(c.upload.onprogress=function(a){a.percent=a.loaded/a.total*100,b.emit("progress",a)}),h&&!this._timer&&(this._timer=setTimeout(function(){b.abort()},h)),g&&(g=o.serializeObject(g),this.url+=~this.url.indexOf("?")?"&"+g:"?"+g),c.open(this.method,this.url,!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof i&&!e(i)){var j=o.serialize[this.getHeader("Content-Type")];j&&(i=j(i))}for(var k in this.header)null!=this.header[k]&&c.setRequestHeader(k,this.header[k]);return c.send(i),this},o.Request=n,o.get=function(a,b,c){var d=o("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},o.head=function(a,b,c){var d=o("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},o.del=function(a,b){var c=o("DELETE",a);return b&&c.end(b),c},o.patch=function(a,b,c){var d=o("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},o.post=function(a,b,c){var d=o("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},o.put=function(a,b,c){var d=o("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},c.exports=o}),a.alias("component-emitter/index.js","superagent/deps/emitter/index.js"),a.alias("component-emitter/index.js","emitter/index.js"),a.alias("component-indexof/index.js","component-emitter/deps/indexof/index.js"),a.alias("RedVentures-reduce/index.js","superagent/deps/reduce/index.js"),a.alias("RedVentures-reduce/index.js","reduce/index.js"),a.alias("superagent/lib/client.js","superagent/index.js"),"object"==typeof c?b.exports=a("superagent"):"function"==typeof define&&define.amd?define(function(){return a("superagent")}):this.superagent=a("superagent")}()},{emitter:15,indexof:15,reduce:15,superagent:15}],6:[function(a,b){"use strict";function c(a,b){this.walker=this.createWalker(a),this.walker.startUri=b,this.walker.request=this.request=e,this.finalAction=new g(this.walker)}var d=a("minilog"),e=a("request"),f=a("util"),g=a("./final_action"),h=a("./json_walker"),i=a("./json_hal_walker"),j=a("./media_types"),k=d("traverson");c.prototype.createWalker=function(a){switch(a){case j.JSON:return k.debug("creating new JsonWalker"),new h;case j.JSON_HAL:return k.debug("creating new JsonHalWalker"),new i;default:throw new Error("Unknown or unsupported media type: "+a)}},c.prototype.follow=function(){return this.walker.links=1===arguments.length&&f.isArray(arguments[0])?arguments[0]:Array.prototype.slice.apply(arguments),this},c.prototype.walk=c.prototype.follow,c.prototype.withTemplateParameters=function(a){return this.walker.templateParameters=a,this},c.prototype.withRequestOptions=function(a){return this.walker.request=this.request=e.defaults(a),this},c.prototype.get=function(a){var b=this;this.walker.walk(function(c,d,e){return k.debug("walker.walk returned"),c?a(c,e.response,e.uri):(b.finalAction.get(d,a),void 0)})},c.prototype.getResource=function(a){var b=this;this.walker.walk(function(c,d,e){return k.debug("walker.walk returned"),c?a(c,e.response,e.uri):(b.finalAction.getResource(d,a),void 0)})},c.prototype.getUri=function(a){var b=this;this.walker.walk(function(c,d,e){return k.debug("walker.walk returned"),c?a(c,e.response,e.uri):(b.finalAction.getUri(d,a),void 0)})},c.prototype.post=function(a,b){this.finalAction.walkAndExecute(a,this.request,this.request.post,b)},c.prototype.put=function(a,b){this.finalAction.walkAndExecute(a,this.request,this.request.put,b)},c.prototype.patch=function(a,b){this.finalAction.walkAndExecute(a,this.request,this.request.patch,b)},c.prototype.del=function(a){this.finalAction.walkAndExecute(null,this.request,this.request.del,a)},b.exports=c},{"./final_action":7,"./json_hal_walker":8,"./json_walker":9,"./media_types":10,minilog:1,request:3,util:2}],7:[function(a,b){"use strict";function c(a){this.walker=a}var d=a("minilog"),e=d("traverson");c.prototype.get=function(a,b){e.debug("next step: "+JSON.stringify(a,null,2)),this.walker.process(a,function(a,c){return e.debug("walker.process returned"),a?b(a,c.response,c.uri):(!c.response&&c.doc&&(e.debug("faking HTTP response for embedded resource"),c.response={statusCode:200,body:JSON.stringify(c.doc),remark:"This is not an actual HTTP response. The resource you requested was an embedded resource, so no HTTP request was made to acquire it."}),b(null,c.response),void 0)})},c.prototype.getResource=function(a,b){var c=this;e.debug("next step: "+JSON.stringify(a)),this.walker.process(a,function(a,d){if(e.debug("walker.process returned"),a)return b(a,d.response,d.uri);if(d.doc)return b(null,d.doc);var f;try{return c.walker.checkHttpStatus(d),f=c.walker.parse(d),b(null,f)}catch(g){return b(g,g.doc)}})},c.prototype.getUri=function(a,b){var c=this;return e.debug("returning uri"),a.uri?b(null,a.uri):a.doc&&a.doc._links&&a.doc._links.self&&a.doc._links.self.href?b(null,c.walker.startUri+a.doc._links.self.href):b(new Error('You requested an URI but the last resource is an embedded resource and has no URI of its own (that is, it has no link with rel="self"'))},c.prototype.walkAndExecute=function(a,b,c,d){var f=this;this.walker.walk(function(g,h,i){return e.debug("walker.walk returned"),g?d(g,i.response,i.uri):(e.debug("executing final request with step: "+JSON.stringify(h)),f.executeRequest(h.uri,b,c,a,d),void 0)})},c.prototype.executeRequest=function(a,b,c,d,f){var g;g=d?{body:JSON.stringify(d)}:{},e.debug("request to "+a+" with options "+JSON.stringify(g)),c.call(b,a,g,function(b,c){return e.debug("request to "+a+" succeeded"),b?f(b,c,a):f(null,c,a)})},b.exports=c},{minilog:1}],8:[function(a,b){"use strict";function c(){}function d(a,b,c){var d=a.linkArray(b);if(!d||0===d.length)return null;var g=e(d,b,c);return g||(g=f(d,b)),g}function e(a,b,c){if(c){if(!a[c])throw new Error(b+"["+c+"] requested, but link array "+b+" had no element at index "+c);if(!a[c].href)throw new Error(b+"["+c+"] requested, but this link had no href attribute.");return p.debug("found hal link: "+a[c].href),{uri:a[c].href}}return null}function f(a,b){for(var c,d=0;d<a.length;d++)if(a[d].href){c=a[d];break}return c?(a.length>1&&p.warn("Found HAL link array with more than one element for key "+b+", arbitrarily choosing index "+d+", because it was the first that had a href attribute."),p.debug("found hal link: "+c.href),{uri:c.href}):null}function g(a,b,c,d){p.debug("checking for embedded: "+c+(d?d:""));var e=a.embeddedArray(c);if(!e||0===e.length)return null;p.debug("Found an array of embedded resource for: "+c);var f=h(e,c,d);return f||(f=i(e,c)),f}function h(a,b,c){if(c){if(!a[c])throw new Error(b+"["+c+"] requested, but there is no such link. However, there is an embedded resource array named "+b+" but it does not have an element at index "+c);return p.debug("Found an embedded resource for: "+b+"["+c+"]"),{doc:a[c].original()}}return null}function i(a,b){return a.length>1&&p.warn("Found HAL embedded resource array with more than one element for key "+b+", arbitrarily choosing first element."),{doc:a[0].original()}}function j(a){var b=a.match(/.*\[(\d+)\]/);return b?b[1]:null}function k(a){var b=a.match(/(.*)\[\d+\]/);return b?b[1]:a}var l=a("halfred"),m=a("minilog"),n=a("underscore.string"),o=a("./walker"),p=m("traverson");c.prototype=new o,c.prototype.findNextStep=function(a,b){p.debug("parsing hal");var c=l.parse(a),e=j(b);b=k(b);var f=d(c,b,e);if(f)return f;if(f=g(c,a,b,e))return f;throw new Error("Could not find a link nor an embedded object for "+b+" in document:\n"+JSON.stringify(a))},c.prototype.postProcessStep=function(a){a.uri&&(n.endsWith(this.startUri,"/")&&n.startsWith(a.uri,"/")&&(a.uri=n.splice(a.uri,0,1)),a.uri=this.startUri+a.uri)},b.exports=c},{"./walker":11,halfred:16,minilog:1,"underscore.string":4}],9:[function(a,b){"use strict";function c(){}var d=a("./walker");c.prototype=new d,b.exports=c},{"./walker":11}],10:[function(a,b){"use strict";b.exports={JSON:"application/json",JSON_HAL:"application/hal+json"}},{}],11:[function(a,b){"use strict";function c(){}function d(a,b,c){var d=new Error("HTTP GET for "+a+" resulted in HTTP status code "+b+".");d.name="HTTPError",d.uri=a,d.httpStatus=b,d.body=c;try{d.doc=JSON.parse(c)}catch(e){}return d}function e(a,b){var c=new Error("The document at "+a+" could not be parsed as JSON: "+b);return c.name="JSONError",c.uri=a,c.body=b,c}var f=a("JSONPath"),g=a("minilog"),h=a("underscore.string"),i=a("uri-template"),j=a("util"),k=f.eval,l=g("traverson");c.prototype.walk=function(a){function b(){return e<c.links.length?(c.process(d,function(g,h){if(f=h,g)return l.debug("error while processing step "+JSON.stringify(d)),l.error(g),a(g,d,h);l.debug("successully processed step");try{c.checkHttpStatus(h)}catch(i){return l.error("unexpected http status code"),l.error(i),a(i,d,h)}var j;try{j=c.parse(h)}catch(i){return l.error("parsing failed"),l.error(i),a(i,d,h)}var k=c.links[e++];l.debug("next link: "+k);try{d=c.findNextStep(j,k)}catch(i){return l.error("could not find next step"),l.error(i),a(i,d,h)}c.postProcessStep(d),l.debug("next step: "+JSON.stringify(d,null,2)),d.uri&&(d.uri=c.resolveUriTemplate(d.uri,c.templateParameters,e)),b()}),void 0):(l.debug("link array exhausted, calling callback"),a(null,d,f))}var c=this,d={uri:this.resolveUriTemplate(this.startUri,this.templateParameters,0)},e=0,f=d;l.debug("starting to follow links"),b()},c.prototype.process=function(a,b){if(l.debug("processing next step: "+JSON.stringify(a,null,2)),a.uri)this.get(a,b);else{if(!a.doc)throw new Error("Can not process next step: "+JSON.stringify(a));l.debug("document for next step has already been fetched"),b(null,a)}},c.prototype.get=function(a,b){l.debug("request to "+a.uri),this.request.get(a.uri,function(c,d){return l.debug("request.get returned"),c?b(c,a):(l.debug("request to "+a.uri+" finished ("+d.statusCode+")"),a.response=d,b(null,a))})},c.prototype.checkHttpStatus=function(a){if(a.response||!a.doc){var b=a.response.statusCode;if(200>b||b>=300)throw d(a.uri,b,a.response.body)}},c.prototype.parse=function(a){if(a.doc)return a.doc;try{return JSON.parse(a.response.body)}catch(b){if("SyntaxError"===b.name)throw e(a.uri,a.response.body);throw b}},c.prototype.findNextStep=function(a,b){l.debug("extracting link "+b+" from "+JSON.stringify(a));if(this.testJSONPath(b))return{uri:this.resolveJSONPath(b,a)};if(a[b])return{uri:a[b]};throw new Error("Could not find property "+b+" in document:\n"+JSON.stringify(a))},c.prototype.postProcessStep=function(){},c.prototype.testJSONPath=function(a){return h.startsWith(a,"$.")||h.startsWith(a,"$[")},c.prototype.resolveJSONPath=function(a,b){var c=k(b,a);if(1===c.length){var d=c[0];if(!d)throw new Error("JSONPath expression "+a+" was resolved but the result was null, undefined or an empty string in document:\n"+JSON.stringify(b));return d}throw c.length>1?new Error("JSONPath expression "+a+" returned more than one match in document:\n"+JSON.stringify(b)):new Error("JSONPath expression "+a+" returned no match in document:\n"+JSON.stringify(b))},c.prototype.resolveUriTemplate=function(a,b,c){if(j.isArray(b)&&(b=b[c]),!b)return a;if(h.contains(a,"{")){var d=i.parse(a);return d.expand(b)}return a},b.exports=c},{JSONPath:13,minilog:1,"underscore.string":4,"uri-template":20,util:2}],12:[function(a,b,c){var d=Array.isArray;c.isArray=d||function(a){return"[object Array]"==Object.prototype.toString.call(a)}},{}],13:[function(a,b,c){function d(a,b,c){var d={resultType:c&&c.resultType||"VALUE",flatten:c&&c.flatten||!1,wrap:c&&c.hasOwnProperty("wrap")?c.wrap:!0,sandbox:c&&c.sandbox?c.sandbox:{},normalize:function(a){if(g[a])return g[a];var b=[],c=a.replace(/[\['](\??\(.*?\))[\]']/g,function(a,c){return"[#"+(b.push(c)-1)+"]"}).replace(/'?\.'?|\['?/g,";").replace(/;;;|;;/g,";..;").replace(/;$|'?\]|'$/g,"").replace(/#([0-9]+)/g,function(a,c){return b[c]});return g[a]=c,c},asPath:function(a){for(var b=a.split(";"),c="$",d=1,e=b.length;e>d;d++)c+=/^[0-9*]+$/.test(b[d])?"["+b[d]+"]":"['"+b[d]+"']";return c},store:function(a,b){return a&&("PATH"==d.resultType?d.result[d.result.length]=d.asPath(a):f.isArray(b)&&d.flatten?(d.result||(d.result=[]),f.isArray(d.result)||(d.result=[d.result]),d.result=d.result.concat(b)):d.result?(f.isArray(d.result)||(d.result=[d.result]),f.isArray(b)&&d.flatten?d.result=d.result.concat(b):d.result[d.result.length]=b):d.result=b),!!a},trace:function(a,b,c){if(a){var e=a.split(";"),f=e.shift();if(e=e.join(";"),b&&b.hasOwnProperty(f))d.trace(e,b[f],c+";"+f);else if("*"===f)d.walk(f,e,b,c,function(a,b,c,e,f){d.trace(a+";"+c,e,f)});else if(".."===f)d.trace(e,b,c),d.walk(f,e,b,c,function(a,b,c,e,f){"object"==typeof e[a]&&d.trace("..;"+c,e[a],f+";"+a)});else if(/,/.test(f))for(var g=f.split(/'?,'?/),h=0,i=g.length;i>h;h++)d.trace(g[h]+";"+e,b,c);else/^\(.*?\)$/.test(f)?d.trace(d.eval(f,b,c.substr(c.lastIndexOf(";")+1))+";"+e,b,c):/^\?\(.*?\)$/.test(f)?d.walk(f,e,b,c,function(a,b,c,e,f){d.eval(b.replace(/^\?\((.*?)\)$/,"$1"),e[a],a)&&d.trace(a+";"+c,e,f)}):/^(-?[0-9]*):(-?[0-9]*):?([0-9]*)$/.test(f)&&d.slice(f,e,b,c)}else d.store(c,b)},walk:function(a,b,c,d,e){if(c instanceof Array)for(var f=0,g=c.length;g>f;f++)f in c&&e(f,a,b,c,d);else if("object"==typeof c)for(var h in c)c.hasOwnProperty(h)&&e(h,a,b,c,d)},slice:function(a,b,c,e){if(c instanceof Array){var f=c.length,g=0,h=f,i=1;a.replace(/^(-?[0-9]*):(-?[0-9]*):?(-?[0-9]*)$/g,function(a,b,c,d){g=parseInt(b||g),h=parseInt(c||h),i=parseInt(d||i)}),g=0>g?Math.max(0,g+f):Math.min(f,g),h=0>h?Math.max(0,h+f):Math.min(f,h);for(var j=g;h>j;j+=i)d.trace(j+";"+b,c,e)}},eval:function(a,b){d.sandbox._v=b;try{return h&&b&&e.runInNewContext(a.replace(/@/g,"_v"),d.sandbox)}catch(c){throw console.log(c),new SyntaxError("jsonPath: "+c.message+": "+a.replace(/@/g,"_v").replace(/\^/g,"_a"))}}};d.result=d.wrap===!0?[]:void 0;var h=a;return b&&a&&("VALUE"==d.resultType||"PATH"==d.resultType)?(d.trace(d.normalize(b).replace(/^\$;/,""),a,"$"),!f.isArray(d.result)&&d.wrap&&(d.result=[d.result]),d.result?d.result:!1):void 0}var e=a("vm"),f=a("underscore");c.eval=d;var g={}},{underscore:12,vm:14}],14:[function(require,module,exports){var Object_keys=function(a){if(Object.keys)return Object.keys(a);var b=[];for(var c in a)b.push(c);return b},forEach=function(a,b){if(a.forEach)return a.forEach(b);for(var c=0;c<a.length;c++)b(a[c],c,a)},Script=exports.Script=function(a){return this instanceof Script?(this.code=a,void 0):new Script(a)};Script.prototype.runInNewContext=function(a){a||(a={});var b=document.createElement("iframe");b.style||(b.style={}),b.style.display="none",document.body.appendChild(b);var c=b.contentWindow;forEach(Object_keys(a),function(b){c[b]=a[b]}),!c.eval&&c.execScript&&c.execScript("null");var d=c.eval(this.code);return forEach(Object_keys(c),function(b){a[b]=c[b]}),document.body.removeChild(b),d},Script.prototype.runInThisContext=function(){return eval(this.code)},Script.prototype.runInContext=function(a){return this.runInNewContext(a)},forEach(Object_keys(Script.prototype),function(a){exports[a]=Script[a]=function(b){var c=Script(b);return c[a].apply(c,[].slice.call(arguments,1))}}),exports.createScript=function(a){return exports.Script(a)},exports.createContext=Script.createContext=function(a){var b={};return"object"==typeof a&&forEach(Object_keys(a),function(c){b[c]=a[c]}),b}},{}],15:[function(){},{}],16:[function(a,b){var c=a("./lib/parser"),d=!1;b.exports={parse:function(a){return(new c).parse(a,d)},enableValidation:function(a){d=null!=a?a:!0},disableValidation:function(){d=!1}}},{"./lib/parser":18}],17:[function(a,b){"use strict";function c(){this._array=arguments.length>=1?arguments[0]:[]}c.prototype.array=function(){return this._array},c.prototype.isEmpty=function(){return 0===this._array.length},c.prototype.push=function(a){var b=this._array.slice(0);return b.push(a),new c(b)},c.prototype.pop=function(){var a=this._array.slice(0,this._array.length-1);return new c(a)},c.prototype.peek=function(){if(this.isEmpty())throw new Error("can't peek on empty stack");return this._array[this._array.length-1]},b.exports=c},{}],18:[function(a,b){"use strict";function c(){}function d(a,b,c){if(null==a)return a;var d=e(a._links,b,c.push("_links")),h=f(a._embedded,b,c.push("_embedded")),i=new q(d,h,b);return g(a,i),i._original=a,i}function e(a,b,c){return a=h(a,j,b,c),(null==a||null==a.self)&&m("Resource does not have a self link",b,c),a}function f(a,b,c){var e=h(a,l,b,c);return null==e?e:(Object.keys(e).forEach(function(a){e[a]=e[a].map(function(e){var f=null!=b?[]:null,g=d(e,f,c.push(a));return g._original=e,g})}),e)}function g(a,b){Object.keys(a).forEach(function(c){"_links"!==c&&"_embedded"!==c&&(b[c]=a[c])})}function h(a,b,c,d){if(null==a)return a;var e={};return Object.keys(a).forEach(function(f){e[f]=i(f,a[f],b,c,d)}),e}function i(a,b,c,d,e){return k(b)?b.map(function(b){return c(a,b,d,e)}):[c(a,b,d,e)]}function j(a,b,c,d){var e=o(b);return Object.keys(s).forEach(function(b){null==e[b]&&(s[b].required&&m("Link misses required property "+b+".",c,d.push(a)),null!=s[b].defaultValue&&(e[b]=s[b].defaultValue))}),e.deprecation&&n("Warning: Link "+p(d.push(a))+" is deprecated, see "+e.deprecation),e.templated!==!0&&e.templated!==!1&&(e.templated=!1),c?(e.href&&e.href.indexOf("{")>=0&&!e.templated&&m('Link seems to be an URI template but its "templated" property is not set to true.',c,d.push(a)),e):e}function k(a){return"[object Array]"===Object.prototype.toString.call(a)}function l(a,b){return b}function m(a,b,c){b&&b.push({path:p(c),message:a})}function n(a){"undefined"!=typeof console&&"function"==typeof console.log&&console.log(a)}function o(a){var b={};return Object.keys(a).forEach(function(c){b[c]=a[c]}),b}function p(a){for(var b="$.",c=0;c<a.array().length;c++)b+=a.array()[c]+".";return b=b.substring(0,b.length-1)}var q=a("./resource"),r=a("./immutable_stack"),s={href:{required:!0,defaultValue:null},templated:{required:!1,defaultValue:!1},type:{required:!1,defaultValue:null},deprecation:{required:!1,defaultValue:null},name:{required:!1,defaultValue:null},profile:{required:!1,defaultValue:null},title:{required:!1,defaultValue:null},hreflang:{required:!1,defaultValue:null}};c.prototype.parse=function(a,b){var c=b?[]:null;return d(a,c,new r)},b.exports=c},{"./immutable_stack":17,"./resource":19}],19:[function(a,b){"use strict";function c(a,b,c){this._links=a||{},this._embedded=b||{},this._validation=c||[]}function d(a,b){return null!=a?a[b]:null}function e(a,b,c){c=c||0;var e=d(a,b);return null!=e&&e.length>=1?e[c]:null}c.prototype.allLinkArrays=function(){return this._links},c.prototype.linkArray=function(a){return d(this._links,a)},c.prototype.link=function(a,b){return e(this._links,a,b)},c.prototype.allEmbeddedResourceArrays=function(){return this._embedded},c.prototype.embeddedResourceArray=function(a){return d(this._embedded,a)},c.prototype.embeddedResource=function(a,b){return e(this._embedded,a,b)},c.prototype.original=function(){return this._original},c.prototype.validationIssues=function(){return this._validation},c.prototype.allLinks=c.prototype.allLinkArrays,c.prototype.allEmbeddedArrays=c.prototype.allEmbeddedResources=c.prototype.allEmbeddedResourceArrays,c.prototype.embeddedArray=c.prototype.embeddedResourceArray,c.prototype.embedded=c.prototype.embeddedResource,c.prototype.validation=c.prototype.validationIssues,b.exports=c},{}],20:[function(a,b){b.exports=function(){function b(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var c={parse:function(c,d){function e(a){v>t||(t>v&&(v=t,w=[]),w.push(a))}function f(){var a,b,c;for(c=t,a=[],b=o(),null===b&&(b=g());null!==b;)a.push(b),b=o(),null===b&&(b=g());return null!==a&&(a=function(a,b){return new y(b)}(c,a)),null===a&&(t=c),a}function g(){var a,b,d,f,g,i;return g=t,i=t,123===c.charCodeAt(t)?(a="{",t++):(a=null,0===u&&e('"{"')),null!==a?(b=h(),null!==b?(d=j(),null!==d?(125===c.charCodeAt(t)?(f="}",t++):(f=null,0===u&&e('"}"')),null!==f?a=[a,b,d,f]:(a=null,t=i)):(a=null,t=i)):(a=null,t=i)):(a=null,t=i),null!==a&&(a=function(a,b,c){return z(b,c)}(g,a[1],a[2])),null===a&&(t=g),a}function h(){var a;return/^[\/;:.?&+#]/.test(c.charAt(t))?(a=c.charAt(t),t++):(a=null,0===u&&e("[\\/;:.?&+#]")),null===a&&(a=""),a}function i(){var a;return"{/"===c.substr(t,2)?(a="{/",t+=2):(a=null,0===u&&e('"{/"')),a}function j(){var a,b,d,f,g,h,i,j;if(g=t,h=t,a=k(),null!==a){for(b=[],i=t,j=t,44===c.charCodeAt(t)?(d=",",t++):(d=null,0===u&&e('","')),null!==d?(f=k(),null!==f?d=[d,f]:(d=null,t=j)):(d=null,t=j),null!==d&&(d=function(a,b){return b}(i,d[1])),null===d&&(t=i);null!==d;)b.push(d),i=t,j=t,44===c.charCodeAt(t)?(d=",",t++):(d=null,0===u&&e('","')),null!==d?(f=k(),null!==f?d=[d,f]:(d=null,t=j)):(d=null,t=j),null!==d&&(d=function(a,b){return b}(i,d[1])),null===d&&(t=i);null!==b?a=[a,b]:(a=null,t=h)}else a=null,t=h;return null!==a&&(a=function(a,b,c){return c.unshift(b),c}(g,a[0],a[1])),null===a&&(t=g),a}function k(){var a,b,d,f,g;for(f=t,g=t,a=[],/^[a-zA-Z0-9_.%]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[a-zA-Z0-9_.%]"));null!==b;)a.push(b),/^[a-zA-Z0-9_.%]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[a-zA-Z0-9_.%]"));return null!==a?(b=l(),null===b&&(b=m()),b=null!==b?b:"",null!==b?(d=p(),d=null!==d?d:"",null!==d?a=[a,b,d]:(a=null,t=g)):(a=null,t=g)):(a=null,t=g),null!==a&&(a=function(a,b,c,d){return c=c||{},{name:b.join(""),explode:c.listMarker,cut:c.cut,extended:d}
}(f,a[0],a[1],a[2])),null===a&&(t=f),a}function l(){var a,b;return b=t,a=n(),null!==a&&(a=function(a,b){return{cut:b}}(b,a)),null===a&&(t=b),a}function m(){var a,b;return b=t,42===c.charCodeAt(t)?(a="*",t++):(a=null,0===u&&e('"*"')),null!==a&&(a=function(a,b){return{listMarker:b}}(b,a)),null===a&&(t=b),a}function n(){var a,b,d,f,g;if(f=t,g=t,58===c.charCodeAt(t)?(a=":",t++):(a=null,0===u&&e('":"')),null!==a){if(/^[0-9]/.test(c.charAt(t))?(d=c.charAt(t),t++):(d=null,0===u&&e("[0-9]")),null!==d)for(b=[];null!==d;)b.push(d),/^[0-9]/.test(c.charAt(t))?(d=c.charAt(t),t++):(d=null,0===u&&e("[0-9]"));else b=null;null!==b?a=[a,b]:(a=null,t=g)}else a=null,t=g;return null!==a&&(a=function(a,b){return parseInt(b.join(""))}(f,a[1])),null===a&&(t=f),a}function o(){var a,b,d;if(d=t,/^[^{]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[^{]")),null!==b)for(a=[];null!==b;)a.push(b),/^[^{]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[^{]"));else a=null;return null!==a&&(a=function(a,b){return b.join("")}(d,a)),null===a&&(t=d),a}function p(){var a,b,d,f,g;if(f=t,g=t,40===c.charCodeAt(t)?(a="(",t++):(a=null,0===u&&e('"("')),null!==a){if(/^[^)]/.test(c.charAt(t))?(d=c.charAt(t),t++):(d=null,0===u&&e("[^)]")),null!==d)for(b=[];null!==d;)b.push(d),/^[^)]/.test(c.charAt(t))?(d=c.charAt(t),t++):(d=null,0===u&&e("[^)]"));else b=null;null!==b?(41===c.charCodeAt(t)?(d=")",t++):(d=null,0===u&&e('")"')),null!==d?a=[a,b,d]:(a=null,t=g)):(a=null,t=g)}else a=null,t=g;return null!==a&&(a=function(a,b){return b.join("")}(f,a[1])),null===a&&(t=f),a}function q(a){a.sort();for(var b=null,c=[],d=0;d<a.length;d++)a[d]!==b&&(c.push(a[d]),b=a[d]);return c}function r(){for(var a=1,b=1,d=!1,e=0;e<Math.max(t,v);e++){var f=c.charAt(e);"\n"===f?(d||a++,b=1,d=!1):"\r"===f||"\u2028"===f||"\u2029"===f?(a++,b=1,d=!0):(b++,d=!1)}return{line:a,column:b}}var s={uriTemplate:f,expression:g,op:h,pathExpression:i,paramList:j,param:k,cut:l,listMarker:m,substr:n,nonexpression:o,extension:p};if(void 0!==d){if(void 0===s[d])throw new Error("Invalid rule name: "+b(d)+".")}else d="uriTemplate";var t=0,u=0,v=0,w=[],x=a("./lib/classes"),y=x.Template,z=x.expression,A=s[d]();if(null===A||t!==c.length){var B=Math.max(t,v),C=B<c.length?c.charAt(B):null,D=r();throw new this.SyntaxError(q(w),C,B,D.line,D.column)}return A},toSource:function(){return this._source}};return c.SyntaxError=function(a,c,d,e,f){function g(a,c){var d,e;switch(a.length){case 0:d="end of input";break;case 1:d=a[0];break;default:d=a.slice(0,a.length-1).join(", ")+" or "+a[a.length-1]}return e=c?b(c):"end of input","Expected "+d+" but "+e+" found."}this.name="SyntaxError",this.expected=a,this.found=c,this.message=g(a,c),this.offset=d,this.line=e,this.column=f},c.SyntaxError.prototype=Error.prototype,c}()},{"./lib/classes":21}],21:[function(a,b){(function(){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v=function(a,b){return function(){return a.apply(b,arguments)}},w={}.hasOwnProperty,x=function(a,b){function c(){this.constructor=a}for(var d in b)w.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};m=a("./encoders"),l=l=function(){function a(a){var b,c=this;this.expressions=[],this.prefix="string"==typeof a[0]?a.shift():"",b=0,a.forEach(function(a){switch(typeof a){case"object":return c.expressions[b++]=a;case"string":return c.expressions[b-1].suffix=a}})}return a.prototype.expand=function(a){return this.prefix+this.expressions.map(function(b){return b.expand(a)}).join("")},a.prototype.toString=function(){return this.prefix+this.expressions.join("")},a.prototype.toJSON=function(){return this.toString()},a}(),k=function(){function a(a){var b;this.params=a,this.explodeObject=v(this.explodeObject,this),this.explodeArray=v(this.explodeArray,this),this._expandPair=v(this._expandPair,this),this.stringifySingle=v(this.stringifySingle,this),this.encode=v(this.encode,this),null==(b=this.params)&&(this.params=[]),this.suffix=""}var b;return a.prototype.first="",a.prototype.sep=",",a.prototype.named=!1,a.prototype.empty="",a.prototype.allow="U",a.prototype.encode=function(a){return m[this.allow](a)},a.prototype.stringifySingle=function(a,b){var c,d,e;if(d=typeof b,"string"===d||"boolean"===d||"number"===d)return b=b.toString(),this.encode(b.substring(0,a.cut||b.length));if(Array.isArray(b)){if(a.cut)throw new Error("Prefixed Values do not support lists. Check "+a.name);return b.map(this.encode).join(",")}if(a.cut)throw new Error("Prefixed Values do not support maps. Check "+a.name);return function(){var a;a=[];for(c in b)e=b[c],a.push([c,e].map(this.encode).join(","));return a}.call(this).join(",")},a.prototype.expand=function(a){var c,d,e=this;return c=b(this.params,a),d=c.map(function(a){return e._expandPair.apply(e,a)}).join(this.sep),d?this.first+d+this.suffix:this.empty&&c.length?this.empty+this.suffix:this.suffix},b=function(a,b){return a.map(function(a){return[a,b[a.name]]}).filter(function(a){var b,c,d;switch(c=a[1],typeof c){case"undefined":return!1;case"object":Array.isArray(c)&&c.length>0;for(b in c)if(d=c[b])return!0;return!1;default:return!0}})},a.prototype._expandPair=function(a,b){var c;return c=a.name,a.explode?Array.isArray(b)?this.explodeArray(a,b):"string"==typeof b?this.stringifySingle(a,b):this.explodeObject(b):this.stringifySingle(a,b)},a.prototype.explodeArray=function(a,b){return b.map(this.encode).join(this.sep)},a.prototype.explodeObject=function(a){var b,c,d,e,f,g;c=[];for(b in a)if(d=a[b],b=this.encode(b),Array.isArray(d))for(f=0,g=d.length;g>f;f++)e=d[f],c.push([b,this.encode(e)]);else c.push([b,this.encode(d)]);return c.map(function(a){return a.join("=")}).join(this.sep)},a.prototype.toString=function(){var a;return a=this.params.map(function(a){return a.name+a.explode}).join(","),"{"+this.first+a+"}"+this.suffix},a.prototype.toJSON=function(){return this.toString()},a}(),g=function(a){function b(){return this.explodeArray=v(this.explodeArray,this),this.stringifySingle=v(this.stringifySingle,this),n=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.stringifySingle=function(a,c){return c=(c=b.__super__.stringifySingle.apply(this,arguments))?"="+c:this.empty,""+a.name+c},b.prototype.explodeArray=function(a,b){var c=this;return b.map(function(b){return""+a.name+"="+c.encode(b)}).join(this.sep)},b}(k),j=function(a){function b(){return o=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.encode=function(a){return m["U+R"](a)},b.prototype.toString=function(){return"{+"+b.__super__.toString.apply(this,arguments).substring(1)},b}(k),e=function(a){function b(){return p=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first="#",b.prototype.empty="#",b.prototype.encode=function(a){return m["U+R"](a)},b}(k),f=function(a){function b(){return q=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first=".",b.prototype.sep=".",b.prototype.empty=".",b}(k),i=function(a){function b(){return r=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first="/",b.prototype.sep="/",b}(k),h=function(a){function b(){return s=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first=";",b.prototype.sep=";",b}(g),d=function(a){function b(){return t=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first="?",b.prototype.sep="&",b.prototype.empty="=",b}(g),c=function(a){function b(){return u=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first="&",b}(d),b.exports={Template:l,SimpleExpression:k,NamedExpression:g,ReservedExpression:j,FragmentExpression:e,LabelExpression:f,PathSegmentExpression:i,PathParamExpression:h,FormStartExpression:d,FormContinuationExpression:c,expression:function(a,b){var g;return g=function(){switch(a){case"":return k;case"+":return j;case"#":return e;case".":return f;case"/":return i;case";":return h;case"?":return d;case"&":return c}}(),new g(b)}}}).call(this)},{"./encoders":22}],22:[function(a,b,c){(function(){var b;b=a("pct-encode"),c.U=b(/[^\w~.-]/g),c["U+R"]=b(/[^\w.~:\/\?#\[\]@!\$&'()*+,;=-]/g)}).call(this)},{"pct-encode":23}],23:[function(a,b){b.exports=function(a){return a=a||/\W/g,function(b){return b=String(b),b.replace(a,function(a){var b=a[0].charCodeAt(0),c=[];return 128>b?c.push(b):b>=128&&2048>b?(c.push(b>>6|192),c.push(63&b|128)):(c.push(b>>12|224),c.push(b>>6&63|128),c.push(63&b|128)),c.map(function(a){return"%"+a.toString(16).toUpperCase()}).join("")})}}},{}],"/home/bastian/projekte/traverson/traverson.js":[function(a,b){b.exports=a("5u5bvt")},{}],"5u5bvt":[function(a,b){"use strict";var c=(a("minilog"),a("./lib/media_types")),d=a("./lib/builder");b.exports={json:{from:function(a){return{newRequest:function(){return new d(c.JSON,a)}}}},jsonHal:{from:function(a){return{newRequest:function(){return new d(c.JSON_HAL,a)}}}}}},{"./lib/builder":6,"./lib/media_types":10,minilog:1}]},{},["5u5bvt"]);
View
47 browser/dist/traverson.js
@@ -77,57 +77,76 @@ Request.prototype.defaults = function(options) {
}
Request.prototype.get = function(uri, callback) {
- setupRequest(superagent.get(uri), this.options)
+ mapRequest(superagent.get(uri), this.options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
Request.prototype.post = function(uri, options, callback) {
- setupRequest(superagent.post(uri), this.options, options)
+ mapRequest(superagent.post(uri), this.options, options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
Request.prototype.put = function(uri, options, callback) {
- setupRequest(superagent.put(uri), this.options, options)
+ mapRequest(superagent.put(uri), this.options, options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
Request.prototype.patch = function(uri, options, callback) {
- setupRequest(superagent.patch(uri), this.options, options)
+ mapRequest(superagent.patch(uri), this.options, options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
Request.prototype.del = function(uri, options, callback) {
- setupRequest(superagent.del(uri), this.options)
+ mapRequest(superagent.del(uri), this.options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
-function setupRequest(superagentRequest, options, bodyOptions) {
+function mapRequest(superagentRequest, options, bodyOptions) {
+ mapHeaders(superagentRequest, options)
+ mapAuth(superagentRequest, options)
+ mapBody(superagentRequest, options, bodyOptions)
+ return superagentRequest
+}
+
+function mapHeaders(superagentRequest, options) {
var headers = options.headers
if (headers != null) {
- superagentRequest = superagentRequest.set(options.headers)
+ superagentRequest = superagentRequest.set(headers)
}
+}
+
+function mapAuth(superagentRequest, options) {
+ var auth = options.auth
+ if (auth != null) {
+ superagentRequest = superagentRequest.auth(
+ auth.user || auth.username,
+ auth.pass || auth.password
+ )
+ }
+}
+
+function mapBody(superagentRequest, options, bodyOptions) {
if (bodyOptions != null) {
var body = bodyOptions.body
if (body != null) {
superagentRequest = superagentRequest.send(body)
}
}
- return superagentRequest
}
// map XHR response object properties to Node.js request lib's response object
// properties
-function map(response) {
+function mapResponse(response) {
response.body = response.text
response.statusCode = response.status
return response
View
4 browser/dist/traverson.min.js
@@ -1,2 +1,2 @@
-!function(a){"object"==typeof exports?module.exports=a():"function"==typeof define&&define.amd?define(a):"undefined"!=typeof window?window.traverson=a():"undefined"!=typeof global?global.traverson=a():"undefined"!=typeof self&&(self.traverson=a())}(function(){var define,module,exports;return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){"use strict";function c(a){null==a&&(a=""),this.id=a}function d(a){return new c(a)}var e=!1;c.prototype.enable=function(){this.enabled=!0},c.prototype.debug=function(a){e&&console.log(this.id+"/debug: "+a)},c.prototype.info=function(a){e&&console.log(this.id+"/info: "+a)},c.prototype.warn=function(a){e&&console.log(this.id+"/warn: "+a)},c.prototype.error=function(a){e&&console.log(this.id+"/error: "+a)},d.enable=function(){e=!0},b.exports=d},{}],2:[function(a,b){"use strict";b.exports={isArray:function(a){return null==a?!1:"[object Array]"===Object.prototype.toString.call(a)}}},{}],3:[function(a,b){"use strict";function c(){this.options={}}function d(a,b,c){var d=b.headers;if(null!=d&&(a=a.set(b.headers)),null!=c){var e=c.body;null!=e&&(a=a.send(e))}return a}function e(a){return a.body=a.text,a.statusCode=a.status,a}var f=a("../third-party/superagent");c.prototype.defaults=function(a){var b=new c;return b.options=a,b},c.prototype.get=function(a,b){d(f.get(a),this.options).end(function(a){b(null,e(a))})},c.prototype.post=function(a,b,c){d(f.post(a),this.options,b).end(function(a){c(null,e(a))})},c.prototype.put=function(a,b,c){d(f.put(a),this.options,b).end(function(a){c(null,e(a))})},c.prototype.patch=function(a,b,c){d(f.patch(a),this.options,b).end(function(a){c(null,e(a))})},c.prototype.del=function(a,b,c){d(f.del(a),this.options).end(function(a){c(null,e(a))})},b.exports=new c},{"../third-party/superagent":5}],4:[function(a,b){"use strict";var c={startsWith:function(a,b){return""===b?!0:null==a||null==b?!1:(a=String(a),b=String(b),a.length>=b.length&&a.slice(0,b.length)===b)},endsWith:function(a,b){return""===b?!0:null==a||null==b?!1:(a=String(a),b=String(b),a.length>=b.length&&a.slice(a.length-b.length)===b)},splice:function(a,b,d,e){var f=c.chars(a);return f.splice(~~b,~~d,e),f.join("")},contains:function(a,b){return""===b?!0:null==a?!1:-1!==String(a).indexOf(b)},chars:function(a){return null==a?[]:String(a).split("")}};b.exports=c},{}],5:[function(a,b,c){!function(){function a(b,c,d){var e=a.resolve(b);if(null==e){d=d||b,c=c||"root";var f=new Error('Failed to require "'+d+'" from "'+c+'"');throw f.path=d,f.parent=c,f.require=!0,f}var g=a.modules[e];return g.exports||(g.exports={},g.client=g.component=!0,g.call(this,g.exports,a.relative(e),g)),g.exports}a.modules={},a.aliases={},a.resolve=function(b){"/"===b.charAt(0)&&(b=b.slice(1));for(var c=b+"/index.js",d=[b,b+".js",b+".json",b+"/index.js",b+"/index.json"],e=0;e<d.length;e++){var b=d[e];if(a.modules.hasOwnProperty(b))return b}return a.aliases.hasOwnProperty(c)?a.aliases[c]:void 0},a.normalize=function(a,b){var c=[];if("."!=b.charAt(0))return b;a=a.split("/"),b=b.split("/");for(var d=0;d<b.length;++d)".."==b[d]?a.pop():"."!=b[d]&&""!=b[d]&&c.push(b[d]);return a.concat(c).join("/")},a.register=function(b,c){a.modules[b]=c},a.alias=function(b,c){if(!a.modules.hasOwnProperty(b))throw new Error('Failed to alias "'+b+'", it does not exist');a.aliases[c]=b},a.relative=function(b){function c(a,b){for(var c=a.length;c--;)if(a[c]===b)return c;return-1}function d(c){var e=d.resolve(c);return a(e,b,c)}var e=a.normalize(b,"..");return d.resolve=function(d){var f=d.charAt(0);if("/"==f)return d.slice(1);if("."==f)return a.normalize(e,d);var g=b.split("/"),h=c(g,"deps")+1;return h||(h=0),d=g.slice(0,h+1).join("/")+"/deps/"+d},d.exists=function(b){return a.modules.hasOwnProperty(d.resolve(b))},d},a.register("component-indexof/index.js",function(a,b,c){var d=[].indexOf;c.exports=function(a,b){if(d)return a.indexOf(b);for(var c=0;c<a.length;++c)if(a[c]===b)return c;return-1}}),a.register("component-emitter/index.js",function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}var f=b("indexof");c.exports=d,d.prototype.on=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},b._off=c,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;var d=f(c,b._off||b);return~d&&c.splice(d,1),this},d.prototype.emit=function(a){this._callbacks=this._callbacks||{};var b=[].slice.call(arguments,1),c=this._callbacks[a];if(c){c=c.slice(0);for(var d=0,e=c.length;e>d;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}}),a.register("RedVentures-reduce/index.js",function(a,b,c){c.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}}),a.register("superagent/lib/client.js",function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(){if(r.XMLHttpRequest&&("file:"!=r.location.protocol||!r.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1}function g(a){return a===Object(a)}function h(a){if(!g(a))return a;var b=[];for(var c in a)b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function i(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function j(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=s(c.slice(b+1)),g[d]=e;return g}function k(a){return a.split(/ *; */).shift()}function l(a){return q(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function m(a,b){b=b||{},this.xhr=a,this.text=a.responseText,this.setStatusProperties(a.status),this.header=this.headers=j(a.getAllResponseHeaders()),this.header["content-type"]=a.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body=this.parseBody(this.text)}function n(a,b){var c=this;p.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.set("X-Requested-With","XMLHttpRequest"),this.on("end",function(){var b=new m(c.xhr);"HEAD"==a&&(b.text=null),c.callback(null,b)})}function o(a,b){return"function"==typeof b?new n("GET",a).end(b):1==arguments.length?new n("GET",a):new n(a,b)}var p=b("emitter"),q=b("reduce"),r="undefined"==typeof window?this:window,s="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};o.serializeObject=h,o.parseString=i,o.types={html:"text/html",json:"application/json",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},o.serialize={"application/x-www-form-urlencoded":h,"application/json":JSON.stringify},o.parse={"application/x-www-form-urlencoded":i,"application/json":JSON.parse},m.prototype.get=function(a){return this.header[a.toLowerCase()]},m.prototype.setHeaderProperties=function(){var a=this.header["content-type"]||"";this.type=k(a);var b=l(a);for(var c in b)this[c]=b[c]},m.prototype.parseBody=function(a){var b=o.parse[this.type];return b?b(a):null},m.prototype.setStatusProperties=function(a){var b=a/100|0;this.status=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a||1223==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},m.prototype.toError=function(){var a="got "+this.status+" response",b=new Error(a);return b.status=this.status,b},o.Response=m,n.prototype=new p,n.prototype.constructor=n,n.prototype.timeout=function(a){return this._timeout=a,this},n.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},n.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},n.prototype.set=function(a,b){if(g(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},n.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},n.prototype.type=function(a){return this.set("Content-Type",o.types[a]||a),this},n.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},n.prototype.query=function(a){return"string"!=typeof a&&(a=h(a)),a&&this._query.push(a),this},n.prototype.send=function(a){var b=g(a),c=this.getHeader("Content-Type");if(b&&g(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),this._data="application/x-www-form-urlencoded"==c?this._data?this._data+"&"+a:a:(this._data||"")+a):this._data=a;return b?(c||this.type("json"),this):this},n.prototype.callback=function(a,b){var c=this._callback;return 2==c.length?c(a,b):a?this.emit("error",a):(c(b),void 0)},n.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},n.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},n.prototype.withCredentials=function(){return this._withCredentials=!0,this},n.prototype.end=function(a){var b=this,c=this.xhr=f(),g=this._query.join("&"),h=this._timeout,i=this._data;if(this._callback=a||d,this._withCredentials&&(c.withCredentials=!0),c.onreadystatechange=function(){return 4==c.readyState?0==c.status?b.aborted?b.timeoutError():b.crossDomainError():(b.emit("end"),void 0):void 0},c.upload&&(c.upload.onprogress=function(a){a.percent=a.loaded/a.total*100,b.emit("progress",a)}),h&&!this._timer&&(this._timer=setTimeout(function(){b.abort()},h)),g&&(g=o.serializeObject(g),this.url+=~this.url.indexOf("?")?"&"+g:"?"+g),c.open(this.method,this.url,!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof i&&!e(i)){var j=o.serialize[this.getHeader("Content-Type")];j&&(i=j(i))}for(var k in this.header)null!=this.header[k]&&c.setRequestHeader(k,this.header[k]);return c.send(i),this},o.Request=n,o.get=function(a,b,c){var d=o("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},o.head=function(a,b,c){var d=o("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},o.del=function(a,b){var c=o("DELETE",a);return b&&c.end(b),c},o.patch=function(a,b,c){var d=o("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},o.post=function(a,b,c){var d=o("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},o.put=function(a,b,c){var d=o("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},c.exports=o}),a.alias("component-emitter/index.js","superagent/deps/emitter/index.js"),a.alias("component-emitter/index.js","emitter/index.js"),a.alias("component-indexof/index.js","component-emitter/deps/indexof/index.js"),a.alias("RedVentures-reduce/index.js","superagent/deps/reduce/index.js"),a.alias("RedVentures-reduce/index.js","reduce/index.js"),a.alias("superagent/lib/client.js","superagent/index.js"),"object"==typeof c?b.exports=a("superagent"):"function"==typeof define&&define.amd?define(function(){return a("superagent")}):this.superagent=a("superagent")}()},{emitter:15,indexof:15,reduce:15,superagent:15}],6:[function(a,b){"use strict";function c(a,b){this.walker=this.createWalker(a),this.walker.startUri=b,this.walker.request=this.request=e,this.finalAction=new g(this.walker)}var d=a("minilog"),e=a("request"),f=a("util"),g=a("./final_action"),h=a("./json_walker"),i=a("./json_hal_walker"),j=a("./media_types"),k=d("traverson");c.prototype.createWalker=function(a){switch(a){case j.JSON:return k.debug("creating new JsonWalker"),new h;case j.JSON_HAL:return k.debug("creating new JsonHalWalker"),new i;default:throw new Error("Unknown or unsupported media type: "+a)}},c.prototype.follow=function(){return this.walker.links=1===arguments.length&&f.isArray(arguments[0])?arguments[0]:Array.prototype.slice.apply(arguments),this},c.prototype.walk=c.prototype.follow,c.prototype.withTemplateParameters=function(a){return this.walker.templateParameters=a,this},c.prototype.withRequestOptions=function(a){return this.walker.request=this.request=e.defaults(a),this},c.prototype.get=function(a){var b=this;this.walker.walk(function(c,d,e){return k.debug("walker.walk returned"),c?a(c,e.response,e.uri):(b.finalAction.get(d,a),void 0)})},c.prototype.getResource=function(a){var b=this;this.walker.walk(function(c,d,e){return k.debug("walker.walk returned"),c?a(c,e.response,e.uri):(b.finalAction.getResource(d,a),void 0)})},c.prototype.getUri=function(a){var b=this;this.walker.walk(function(c,d,e){return k.debug("walker.walk returned"),c?a(c,e.response,e.uri):(b.finalAction.getUri(d,a),void 0)})},c.prototype.post=function(a,b){this.finalAction.walkAndExecute(a,this.request,this.request.post,b)},c.prototype.put=function(a,b){this.finalAction.walkAndExecute(a,this.request,this.request.put,b)},c.prototype.patch=function(a,b){this.finalAction.walkAndExecute(a,this.request,this.request.patch,b)},c.prototype.del=function(a){this.finalAction.walkAndExecute(null,this.request,this.request.del,a)},b.exports=c},{"./final_action":7,"./json_hal_walker":8,"./json_walker":9,"./media_types":10,minilog:1,request:3,util:2}],7:[function(a,b){"use strict";function c(a){this.walker=a}var d=a("minilog"),e=d("traverson");c.prototype.get=function(a,b){e.debug("next step: "+JSON.stringify(a,null,2)),this.walker.process(a,function(a,c){return e.debug("walker.process returned"),a?b(a,c.response,c.uri):(!c.response&&c.doc&&(e.debug("faking HTTP response for embedded resource"),c.response={statusCode:200,body:JSON.stringify(c.doc),remark:"This is not an actual HTTP response. The resource you requested was an embedded resource, so no HTTP request was made to acquire it."}),b(null,c.response),void 0)})},c.prototype.getResource=function(a,b){var c=this;e.debug("next step: "+JSON.stringify(a)),this.walker.process(a,function(a,d){if(e.debug("walker.process returned"),a)return b(a,d.response,d.uri);if(d.doc)return b(null,d.doc);var f;try{return c.walker.checkHttpStatus(d),f=c.walker.parse(d),b(null,f)}catch(g){return b(g,g.doc)}})},c.prototype.getUri=function(a,b){var c=this;return e.debug("returning uri"),a.uri?b(null,a.uri):a.doc&&a.doc._links&&a.doc._links.self&&a.doc._links.self.href?b(null,c.walker.startUri+a.doc._links.self.href):b(new Error('You requested an URI but the last resource is an embedded resource and has no URI of its own (that is, it has no link with rel="self"'))},c.prototype.walkAndExecute=function(a,b,c,d){var f=this;this.walker.walk(function(g,h,i){return e.debug("walker.walk returned"),g?d(g,i.response,i.uri):(e.debug("executing final request with step: "+JSON.stringify(h)),f.executeRequest(h.uri,b,c,a,d),void 0)})},c.prototype.executeRequest=function(a,b,c,d,f){var g;g=d?{body:JSON.stringify(d)}:{},e.debug("request to "+a+" with options "+JSON.stringify(g)),c.call(b,a,g,function(b,c){return e.debug("request to "+a+" succeeded"),b?f(b,c,a):f(null,c,a)})},b.exports=c},{minilog:1}],8:[function(a,b){"use strict";function c(){}function d(a,b,c){var d=a.linkArray(b);if(!d||0===d.length)return null;var g=e(d,b,c);return g||(g=f(d,b)),g}function e(a,b,c){if(c){if(!a[c])throw new Error(b+"["+c+"] requested, but link array "+b+" had no element at index "+c);if(!a[c].href)throw new Error(b+"["+c+"] requested, but this link had no href attribute.");return p.debug("found hal link: "+a[c].href),{uri:a[c].href}}return null}function f(a,b){for(var c,d=0;d<a.length;d++)if(a[d].href){c=a[d];break}return c?(a.length>1&&p.warn("Found HAL link array with more than one element for key "+b+", arbitrarily choosing index "+d+", because it was the first that had a href attribute."),p.debug("found hal link: "+c.href),{uri:c.href}):null}function g(a,b,c,d){p.debug("checking for embedded: "+c+(d?d:""));var e=a.embeddedArray(c);if(!e||0===e.length)return null;p.debug("Found an array of embedded resource for: "+c);var f=h(e,c,d);return f||(f=i(e,c)),f}function h(a,b,c){if(c){if(!a[c])throw new Error(b+"["+c+"] requested, but there is no such link. However, there is an embedded resource array named "+b+" but it does not have an element at index "+c);return p.debug("Found an embedded resource for: "+b+"["+c+"]"),{doc:a[c].original()}}return null}function i(a,b){return a.length>1&&p.warn("Found HAL embedded resource array with more than one element for key "+b+", arbitrarily choosing first element."),{doc:a[0].original()}}function j(a){var b=a.match(/.*\[(\d+)\]/);return b?b[1]:null}function k(a){var b=a.match(/(.*)\[\d+\]/);return b?b[1]:a}var l=a("halfred"),m=a("minilog"),n=a("underscore.string"),o=a("./walker"),p=m("traverson");c.prototype=new o,c.prototype.findNextStep=function(a,b){p.debug("parsing hal");var c=l.parse(a),e=j(b);b=k(b);var f=d(c,b,e);if(f)return f;if(f=g(c,a,b,e))return f;throw new Error("Could not find a link nor an embedded object for "+b+" in document:\n"+JSON.stringify(a))},c.prototype.postProcessStep=function(a){a.uri&&(n.endsWith(this.startUri,"/")&&n.startsWith(a.uri,"/")&&(a.uri=n.splice(a.uri,0,1)),a.uri=this.startUri+a.uri)},b.exports=c},{"./walker":11,halfred:16,minilog:1,"underscore.string":4}],9:[function(a,b){"use strict";function c(){}var d=a("./walker");c.prototype=new d,b.exports=c},{"./walker":11}],10:[function(a,b){"use strict";b.exports={JSON:"application/json",JSON_HAL:"application/hal+json"}},{}],11:[function(a,b){"use strict";function c(){}function d(a,b,c){var d=new Error("HTTP GET for "+a+" resulted in HTTP status code "+b+".");d.name="HTTPError",d.uri=a,d.httpStatus=b,d.body=c;try{d.doc=JSON.parse(c)}catch(e){}return d}function e(a,b){var c=new Error("The document at "+a+" could not be parsed as JSON: "+b);return c.name="JSONError",c.uri=a,c.body=b,c}var f=a("JSONPath"),g=a("minilog"),h=a("underscore.string"),i=a("uri-template"),j=a("util"),k=f.eval,l=g("traverson");c.prototype.walk=function(a){function b(){return e<c.links.length?(c.process(d,function(g,h){if(f=h,g)return l.debug("error while processing step "+JSON.stringify(d)),l.error(g),a(g,d,h);l.debug("successully processed step");try{c.checkHttpStatus(h)}catch(i){return l.error("unexpected http status code"),l.error(i),a(i,d,h)}var j;try{j=c.parse(h)}catch(i){return l.error("parsing failed"),l.error(i),a(i,d,h)}var k=c.links[e++];l.debug("next link: "+k);try{d=c.findNextStep(j,k)}catch(i){return l.error("could not find next step"),l.error(i),a(i,d,h)}c.postProcessStep(d),l.debug("next step: "+JSON.stringify(d,null,2)),d.uri&&(d.uri=c.resolveUriTemplate(d.uri,c.templateParameters,e)),b()}),void 0):(l.debug("link array exhausted, calling callback"),a(null,d,f))}var c=this,d={uri:this.resolveUriTemplate(this.startUri,this.templateParameters,0)},e=0,f=d;l.debug("starting to follow links"),b()},c.prototype.process=function(a,b){if(l.debug("processing next step: "+JSON.stringify(a,null,2)),a.uri)this.get(a,b);else{if(!a.doc)throw new Error("Can not process next step: "+JSON.stringify(a));l.debug("document for next step has already been fetched"),b(null,a)}},c.prototype.get=function(a,b){l.debug("request to "+a.uri),this.request.get(a.uri,function(c,d){return l.debug("request.get returned"),c?b(c,a):(l.debug("request to "+a.uri+" finished ("+d.statusCode+")"),a.response=d,b(null,a))})},c.prototype.checkHttpStatus=function(a){if(a.response||!a.doc){var b=a.response.statusCode;if(200>b||b>=300)throw d(a.uri,b,a.response.body)}},c.prototype.parse=function(a){if(a.doc)return a.doc;try{return JSON.parse(a.response.body)}catch(b){if("SyntaxError"===b.name)throw e(a.uri,a.response.body);throw b}},c.prototype.findNextStep=function(a,b){l.debug("extracting link "+b+" from "+JSON.stringify(a));if(this.testJSONPath(b))return{uri:this.resolveJSONPath(b,a)};if(a[b])return{uri:a[b]};throw new Error("Could not find property "+b+" in document:\n"+JSON.stringify(a))},c.prototype.postProcessStep=function(){},c.prototype.testJSONPath=function(a){return h.startsWith(a,"$.")||h.startsWith(a,"$[")},c.prototype.resolveJSONPath=function(a,b){var c=k(b,a);if(1===c.length){var d=c[0];if(!d)throw new Error("JSONPath expression "+a+" was resolved but the result was null, undefined or an empty string in document:\n"+JSON.stringify(b));return d}throw c.length>1?new Error("JSONPath expression "+a+" returned more than one match in document:\n"+JSON.stringify(b)):new Error("JSONPath expression "+a+" returned no match in document:\n"+JSON.stringify(b))},c.prototype.resolveUriTemplate=function(a,b,c){if(j.isArray(b)&&(b=b[c]),!b)return a;if(h.contains(a,"{")){var d=i.parse(a);return d.expand(b)}return a},b.exports=c},{JSONPath:13,minilog:1,"underscore.string":4,"uri-template":20,util:2}],12:[function(a,b,c){var d=Array.isArray;c.isArray=d||function(a){return"[object Array]"==Object.prototype.toString.call(a)}},{}],13:[function(a,b,c){function d(a,b,c){var d={resultType:c&&c.resultType||"VALUE",flatten:c&&c.flatten||!1,wrap:c&&c.hasOwnProperty("wrap")?c.wrap:!0,sandbox:c&&c.sandbox?c.sandbox:{},normalize:function(a){if(g[a])return g[a];var b=[],c=a.replace(/[\['](\??\(.*?\))[\]']/g,function(a,c){return"[#"+(b.push(c)-1)+"]"}).replace(/'?\.'?|\['?/g,";").replace(/;;;|;;/g,";..;").replace(/;$|'?\]|'$/g,"").replace(/#([0-9]+)/g,function(a,c){return b[c]});return g[a]=c,c},asPath:function(a){for(var b=a.split(";"),c="$",d=1,e=b.length;e>d;d++)c+=/^[0-9*]+$/.test(b[d])?"["+b[d]+"]":"['"+b[d]+"']";return c},store:function(a,b){return a&&("PATH"==d.resultType?d.result[d.result.length]=d.asPath(a):f.isArray(b)&&d.flatten?(d.result||(d.result=[]),f.isArray(d.result)||(d.result=[d.result]),d.result=d.result.concat(b)):d.result?(f.isArray(d.result)||(d.result=[d.result]),f.isArray(b)&&d.flatten?d.result=d.result.concat(b):d.result[d.result.length]=b):d.result=b),!!a},trace:function(a,b,c){if(a){var e=a.split(";"),f=e.shift();if(e=e.join(";"),b&&b.hasOwnProperty(f))d.trace(e,b[f],c+";"+f);else if("*"===f)d.walk(f,e,b,c,function(a,b,c,e,f){d.trace(a+";"+c,e,f)});else if(".."===f)d.trace(e,b,c),d.walk(f,e,b,c,function(a,b,c,e,f){"object"==typeof e[a]&&d.trace("..;"+c,e[a],f+";"+a)});else if(/,/.test(f))for(var g=f.split(/'?,'?/),h=0,i=g.length;i>h;h++)d.trace(g[h]+";"+e,b,c);else/^\(.*?\)$/.test(f)?d.trace(d.eval(f,b,c.substr(c.lastIndexOf(";")+1))+";"+e,b,c):/^\?\(.*?\)$/.test(f)?d.walk(f,e,b,c,function(a,b,c,e,f){d.eval(b.replace(/^\?\((.*?)\)$/,"$1"),e[a],a)&&d.trace(a+";"+c,e,f)}):/^(-?[0-9]*):(-?[0-9]*):?([0-9]*)$/.test(f)&&d.slice(f,e,b,c)}else d.store(c,b)},walk:function(a,b,c,d,e){if(c instanceof Array)for(var f=0,g=c.length;g>f;f++)f in c&&e(f,a,b,c,d);else if("object"==typeof c)for(var h in c)c.hasOwnProperty(h)&&e(h,a,b,c,d)},slice:function(a,b,c,e){if(c instanceof Array){var f=c.length,g=0,h=f,i=1;a.replace(/^(-?[0-9]*):(-?[0-9]*):?(-?[0-9]*)$/g,function(a,b,c,d){g=parseInt(b||g),h=parseInt(c||h),i=parseInt(d||i)}),g=0>g?Math.max(0,g+f):Math.min(f,g),h=0>h?Math.max(0,h+f):Math.min(f,h);for(var j=g;h>j;j+=i)d.trace(j+";"+b,c,e)}},eval:function(a,b){d.sandbox._v=b;try{return h&&b&&e.runInNewContext(a.replace(/@/g,"_v"),d.sandbox)}catch(c){throw console.log(c),new SyntaxError("jsonPath: "+c.message+": "+a.replace(/@/g,"_v").replace(/\^/g,"_a"))}}};d.result=d.wrap===!0?[]:void 0;var h=a;return b&&a&&("VALUE"==d.resultType||"PATH"==d.resultType)?(d.trace(d.normalize(b).replace(/^\$;/,""),a,"$"),!f.isArray(d.result)&&d.wrap&&(d.result=[d.result]),d.result?d.result:!1):void 0}var e=a("vm"),f=a("underscore");c.eval=d;var g={}},{underscore:12,vm:14}],14:[function(require,module,exports){var Object_keys=function(a){if(Object.keys)return Object.keys(a);var b=[];for(var c in a)b.push(c);return b},forEach=function(a,b){if(a.forEach)return a.forEach(b);for(var c=0;c<a.length;c++)b(a[c],c,a)},Script=exports.Script=function(a){return this instanceof Script?(this.code=a,void 0):new Script(a)};Script.prototype.runInNewContext=function(a){a||(a={});var b=document.createElement("iframe");b.style||(b.style={}),b.style.display="none",document.body.appendChild(b);var c=b.contentWindow;forEach(Object_keys(a),function(b){c[b]=a[b]}),!c.eval&&c.execScript&&c.execScript("null");var d=c.eval(this.code);return forEach(Object_keys(c),function(b){a[b]=c[b]}),document.body.removeChild(b),d},Script.prototype.runInThisContext=function(){return eval(this.code)},Script.prototype.runInContext=function(a){return this.runInNewContext(a)},forEach(Object_keys(Script.prototype),function(a){exports[a]=Script[a]=function(b){var c=Script(b);return c[a].apply(c,[].slice.call(arguments,1))}}),exports.createScript=function(a){return exports.Script(a)},exports.createContext=Script.createContext=function(a){var b={};return"object"==typeof a&&forEach(Object_keys(a),function(c){b[c]=a[c]}),b}},{}],15:[function(){},{}],16:[function(a,b){var c=a("./lib/parser"),d=!1;b.exports={parse:function(a){return(new c).parse(a,d)},enableValidation:function(a){d=null!=a?a:!0},disableValidation:function(){d=!1}}},{"./lib/parser":18}],17:[function(a,b){"use strict";function c(){this._array=arguments.length>=1?arguments[0]:[]}c.prototype.array=function(){return this._array},c.prototype.isEmpty=function(){return 0===this._array.length},c.prototype.push=function(a){var b=this._array.slice(0);return b.push(a),new c(b)},c.prototype.pop=function(){var a=this._array.slice(0,this._array.length-1);return new c(a)},c.prototype.peek=function(){if(this.isEmpty())throw new Error("can't peek on empty stack");return this._array[this._array.length-1]},b.exports=c},{}],18:[function(a,b){"use strict";function c(){}function d(a,b,c){if(null==a)return a;var d=e(a._links,b,c.push("_links")),h=f(a._embedded,b,c.push("_embedded")),i=new q(d,h,b);return g(a,i),i._original=a,i}function e(a,b,c){return a=h(a,j,b,c),(null==a||null==a.self)&&m("Resource does not have a self link",b,c),a}function f(a,b,c){var e=h(a,l,b,c);return null==e?e:(Object.keys(e).forEach(function(a){e[a]=e[a].map(function(e){var f=null!=b?[]:null,g=d(e,f,c.push(a));return g._original=e,g})}),e)}function g(a,b){Object.keys(a).forEach(function(c){"_links"!==c&&"_embedded"!==c&&(b[c]=a[c])})}function h(a,b,c,d){if(null==a)return a;var e={};return Object.keys(a).forEach(function(f){e[f]=i(f,a[f],b,c,d)}),e}function i(a,b,c,d,e){return k(b)?b.map(function(b){return c(a,b,d,e)}):[c(a,b,d,e)]}function j(a,b,c,d){var e=o(b);return Object.keys(s).forEach(function(b){null==e[b]&&(s[b].required&&m("Link misses required property "+b+".",c,d.push(a)),null!=s[b].defaultValue&&(e[b]=s[b].defaultValue))}),e.deprecation&&n("Warning: Link "+p(d.push(a))+" is deprecated, see "+e.deprecation),e.templated!==!0&&e.templated!==!1&&(e.templated=!1),c?(e.href&&e.href.indexOf("{")>=0&&!e.templated&&m('Link seems to be an URI template but its "templated" property is not set to true.',c,d.push(a)),e):e}function k(a){return"[object Array]"===Object.prototype.toString.call(a)}function l(a,b){return b}function m(a,b,c){b&&b.push({path:p(c),message:a})}function n(a){"undefined"!=typeof console&&"function"==typeof console.log&&console.log(a)}function o(a){var b={};return Object.keys(a).forEach(function(c){b[c]=a[c]}),b}function p(a){for(var b="$.",c=0;c<a.array().length;c++)b+=a.array()[c]+".";return b=b.substring(0,b.length-1)}var q=a("./resource"),r=a("./immutable_stack"),s={href:{required:!0,defaultValue:null},templated:{required:!1,defaultValue:!1},type:{required:!1,defaultValue:null},deprecation:{required:!1,defaultValue:null},name:{required:!1,defaultValue:null},profile:{required:!1,defaultValue:null},title:{required:!1,defaultValue:null},hreflang:{required:!1,defaultValue:null}};c.prototype.parse=function(a,b){var c=b?[]:null;return d(a,c,new r)},b.exports=c},{"./immutable_stack":17,"./resource":19}],19:[function(a,b){"use strict";function c(a,b,c){this._links=a||{},this._embedded=b||{},this._validation=c||[]}function d(a,b){return null!=a?a[b]:null}function e(a,b,c){c=c||0;var e=d(a,b);return null!=e&&e.length>=1?e[c]:null}c.prototype.allLinkArrays=function(){return this._links},c.prototype.linkArray=function(a){return d(this._links,a)},c.prototype.link=function(a,b){return e(this._links,a,b)},c.prototype.allEmbeddedResourceArrays=function(){return this._embedded},c.prototype.embeddedResourceArray=function(a){return d(this._embedded,a)},c.prototype.embeddedResource=function(a,b){return e(this._embedded,a,b)},c.prototype.original=function(){return this._original},c.prototype.validationIssues=function(){return this._validation},c.prototype.allLinks=c.prototype.allLinkArrays,c.prototype.allEmbeddedArrays=c.prototype.allEmbeddedResources=c.prototype.allEmbeddedResourceArrays,c.prototype.embeddedArray=c.prototype.embeddedResourceArray,c.prototype.embedded=c.prototype.embeddedResource,c.prototype.validation=c.prototype.validationIssues,b.exports=c},{}],20:[function(a,b){b.exports=function(){function b(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var c={parse:function(c,d){function e(a){v>t||(t>v&&(v=t,w=[]),w.push(a))}function f(){var a,b,c;for(c=t,a=[],b=o(),null===b&&(b=g());null!==b;)a.push(b),b=o(),null===b&&(b=g());return null!==a&&(a=function(a,b){return new y(b)}(c,a)),null===a&&(t=c),a}function g(){var a,b,d,f,g,i;return g=t,i=t,123===c.charCodeAt(t)?(a="{",t++):(a=null,0===u&&e('"{"')),null!==a?(b=h(),null!==b?(d=j(),null!==d?(125===c.charCodeAt(t)?(f="}",t++):(f=null,0===u&&e('"}"')),null!==f?a=[a,b,d,f]:(a=null,t=i)):(a=null,t=i)):(a=null,t=i)):(a=null,t=i),null!==a&&(a=function(a,b,c){return z(b,c)}(g,a[1],a[2])),null===a&&(t=g),a}function h(){var a;return/^[\/;:.?&+#]/.test(c.charAt(t))?(a=c.charAt(t),t++):(a=null,0===u&&e("[\\/;:.?&+#]")),null===a&&(a=""),a}function i(){var a;return"{/"===c.substr(t,2)?(a="{/",t+=2):(a=null,0===u&&e('"{/"')),a}function j(){var a,b,d,f,g,h,i,j;if(g=t,h=t,a=k(),null!==a){for(b=[],i=t,j=t,44===c.charCodeAt(t)?(d=",",t++):(d=null,0===u&&e('","')),null!==d?(f=k(),null!==f?d=[d,f]:(d=null,t=j)):(d=null,t=j),null!==d&&(d=function(a,b){return b}(i,d[1])),null===d&&(t=i);null!==d;)b.push(d),i=t,j=t,44===c.charCodeAt(t)?(d=",",t++):(d=null,0===u&&e('","')),null!==d?(f=k(),null!==f?d=[d,f]:(d=null,t=j)):(d=null,t=j),null!==d&&(d=function(a,b){return b}(i,d[1])),null===d&&(t=i);null!==b?a=[a,b]:(a=null,t=h)}else a=null,t=h;return null!==a&&(a=function(a,b,c){return c.unshift(b),c}(g,a[0],a[1])),null===a&&(t=g),a}function k(){var a,b,d,f,g;for(f=t,g=t,a=[],/^[a-zA-Z0-9_.%]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[a-zA-Z0-9_.%]"));null!==b;)a.push(b),/^[a-zA-Z0-9_.%]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[a-zA-Z0-9_.%]"));
-return null!==a?(b=l(),null===b&&(b=m()),b=null!==b?b:"",null!==b?(d=p(),d=null!==d?d:"",null!==d?a=[a,b,d]:(a=null,t=g)):(a=null,t=g)):(a=null,t=g),null!==a&&(a=function(a,b,c,d){return c=c||{},{name:b.join(""),explode:c.listMarker,cut:c.cut,extended:d}}(f,a[0],a[1],a[2])),null===a&&(t=f),a}function l(){var a,b;return b=t,a=n(),null!==a&&(a=function(a,b){return{cut:b}}(b,a)),null===a&&(t=b),a}function m(){var a,b;return b=t,42===c.charCodeAt(t)?(a="*",t++):(a=null,0===u&&e('"*"')),null!==a&&(a=function(a,b){return{listMarker:b}}(b,a)),null===a&&(t=b),a}function n(){var a,b,d,f,g;if(f=t,g=t,58===c.charCodeAt(t)?(a=":",t++):(a=null,0===u&&e('":"')),null!==a){if(/^[0-9]/.test(c.charAt(t))?(d=c.charAt(t),t++):(d=null,0===u&&e("[0-9]")),null!==d)for(b=[];null!==d;)b.push(d),/^[0-9]/.test(c.charAt(t))?(d=c.charAt(t),t++):(d=null,0===u&&e("[0-9]"));else b=null;null!==b?a=[a,b]:(a=null,t=g)}else a=null,t=g;return null!==a&&(a=function(a,b){return parseInt(b.join(""))}(f,a[1])),null===a&&(t=f),a}function o(){var a,b,d;if(d=t,/^[^{]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[^{]")),null!==b)for(a=[];null!==b;)a.push(b),/^[^{]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[^{]"));else a=null;return null!==a&&(a=function(a,b){return b.join("")}(d,a)),null===a&&(t=d),a}function p(){var a,b,d,f,g;if(f=t,g=t,40===c.charCodeAt(t)?(a="(",t++):(a=null,0===u&&e('"("')),null!==a){if(/^[^)]/.test(c.charAt(t))?(d=c.charAt(t),t++):(d=null,0===u&&e("[^)]")),null!==d)for(b=[];null!==d;)b.push(d),/^[^)]/.test(c.charAt(t))?(d=c.charAt(t),t++):(d=null,0===u&&e("[^)]"));else b=null;null!==b?(41===c.charCodeAt(t)?(d=")",t++):(d=null,0===u&&e('")"')),null!==d?a=[a,b,d]:(a=null,t=g)):(a=null,t=g)}else a=null,t=g;return null!==a&&(a=function(a,b){return b.join("")}(f,a[1])),null===a&&(t=f),a}function q(a){a.sort();for(var b=null,c=[],d=0;d<a.length;d++)a[d]!==b&&(c.push(a[d]),b=a[d]);return c}function r(){for(var a=1,b=1,d=!1,e=0;e<Math.max(t,v);e++){var f=c.charAt(e);"\n"===f?(d||a++,b=1,d=!1):"\r"===f||"\u2028"===f||"\u2029"===f?(a++,b=1,d=!0):(b++,d=!1)}return{line:a,column:b}}var s={uriTemplate:f,expression:g,op:h,pathExpression:i,paramList:j,param:k,cut:l,listMarker:m,substr:n,nonexpression:o,extension:p};if(void 0!==d){if(void 0===s[d])throw new Error("Invalid rule name: "+b(d)+".")}else d="uriTemplate";var t=0,u=0,v=0,w=[],x=a("./lib/classes"),y=x.Template,z=x.expression,A=s[d]();if(null===A||t!==c.length){var B=Math.max(t,v),C=B<c.length?c.charAt(B):null,D=r();throw new this.SyntaxError(q(w),C,B,D.line,D.column)}return A},toSource:function(){return this._source}};return c.SyntaxError=function(a,c,d,e,f){function g(a,c){var d,e;switch(a.length){case 0:d="end of input";break;case 1:d=a[0];break;default:d=a.slice(0,a.length-1).join(", ")+" or "+a[a.length-1]}return e=c?b(c):"end of input","Expected "+d+" but "+e+" found."}this.name="SyntaxError",this.expected=a,this.found=c,this.message=g(a,c),this.offset=d,this.line=e,this.column=f},c.SyntaxError.prototype=Error.prototype,c}()},{"./lib/classes":21}],21:[function(a,b){(function(){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v=function(a,b){return function(){return a.apply(b,arguments)}},w={}.hasOwnProperty,x=function(a,b){function c(){this.constructor=a}for(var d in b)w.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};m=a("./encoders"),l=l=function(){function a(a){var b,c=this;this.expressions=[],this.prefix="string"==typeof a[0]?a.shift():"",b=0,a.forEach(function(a){switch(typeof a){case"object":return c.expressions[b++]=a;case"string":return c.expressions[b-1].suffix=a}})}return a.prototype.expand=function(a){return this.prefix+this.expressions.map(function(b){return b.expand(a)}).join("")},a.prototype.toString=function(){return this.prefix+this.expressions.join("")},a.prototype.toJSON=function(){return this.toString()},a}(),k=function(){function a(a){var b;this.params=a,this.explodeObject=v(this.explodeObject,this),this.explodeArray=v(this.explodeArray,this),this._expandPair=v(this._expandPair,this),this.stringifySingle=v(this.stringifySingle,this),this.encode=v(this.encode,this),null==(b=this.params)&&(this.params=[]),this.suffix=""}var b;return a.prototype.first="",a.prototype.sep=",",a.prototype.named=!1,a.prototype.empty="",a.prototype.allow="U",a.prototype.encode=function(a){return m[this.allow](a)},a.prototype.stringifySingle=function(a,b){var c,d,e;if(d=typeof b,"string"===d||"boolean"===d||"number"===d)return b=b.toString(),this.encode(b.substring(0,a.cut||b.length));if(Array.isArray(b)){if(a.cut)throw new Error("Prefixed Values do not support lists. Check "+a.name);return b.map(this.encode).join(",")}if(a.cut)throw new Error("Prefixed Values do not support maps. Check "+a.name);return function(){var a;a=[];for(c in b)e=b[c],a.push([c,e].map(this.encode).join(","));return a}.call(this).join(",")},a.prototype.expand=function(a){var c,d,e=this;return c=b(this.params,a),d=c.map(function(a){return e._expandPair.apply(e,a)}).join(this.sep),d?this.first+d+this.suffix:this.empty&&c.length?this.empty+this.suffix:this.suffix},b=function(a,b){return a.map(function(a){return[a,b[a.name]]}).filter(function(a){var b,c,d;switch(c=a[1],typeof c){case"undefined":return!1;case"object":Array.isArray(c)&&c.length>0;for(b in c)if(d=c[b])return!0;return!1;default:return!0}})},a.prototype._expandPair=function(a,b){var c;return c=a.name,a.explode?Array.isArray(b)?this.explodeArray(a,b):"string"==typeof b?this.stringifySingle(a,b):this.explodeObject(b):this.stringifySingle(a,b)},a.prototype.explodeArray=function(a,b){return b.map(this.encode).join(this.sep)},a.prototype.explodeObject=function(a){var b,c,d,e,f,g;c=[];for(b in a)if(d=a[b],b=this.encode(b),Array.isArray(d))for(f=0,g=d.length;g>f;f++)e=d[f],c.push([b,this.encode(e)]);else c.push([b,this.encode(d)]);return c.map(function(a){return a.join("=")}).join(this.sep)},a.prototype.toString=function(){var a;return a=this.params.map(function(a){return a.name+a.explode}).join(","),"{"+this.first+a+"}"+this.suffix},a.prototype.toJSON=function(){return this.toString()},a}(),g=function(a){function b(){return this.explodeArray=v(this.explodeArray,this),this.stringifySingle=v(this.stringifySingle,this),n=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.stringifySingle=function(a,c){return c=(c=b.__super__.stringifySingle.apply(this,arguments))?"="+c:this.empty,""+a.name+c},b.prototype.explodeArray=function(a,b){var c=this;return b.map(function(b){return""+a.name+"="+c.encode(b)}).join(this.sep)},b}(k),j=function(a){function b(){return o=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.encode=function(a){return m["U+R"](a)},b.prototype.toString=function(){return"{+"+b.__super__.toString.apply(this,arguments).substring(1)},b}(k),e=function(a){function b(){return p=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first="#",b.prototype.empty="#",b.prototype.encode=function(a){return m["U+R"](a)},b}(k),f=function(a){function b(){return q=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first=".",b.prototype.sep=".",b.prototype.empty=".",b}(k),i=function(a){function b(){return r=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first="/",b.prototype.sep="/",b}(k),h=function(a){function b(){return s=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first=";",b.prototype.sep=";",b}(g),d=function(a){function b(){return t=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first="?",b.prototype.sep="&",b.prototype.empty="=",b}(g),c=function(a){function b(){return u=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first="&",b}(d),b.exports={Template:l,SimpleExpression:k,NamedExpression:g,ReservedExpression:j,FragmentExpression:e,LabelExpression:f,PathSegmentExpression:i,PathParamExpression:h,FormStartExpression:d,FormContinuationExpression:c,expression:function(a,b){var g;return g=function(){switch(a){case"":return k;case"+":return j;case"#":return e;case".":return f;case"/":return i;case";":return h;case"?":return d;case"&":return c}}(),new g(b)}}}).call(this)},{"./encoders":22}],22:[function(a,b,c){(function(){var b;b=a("pct-encode"),c.U=b(/[^\w~.-]/g),c["U+R"]=b(/[^\w.~:\/\?#\[\]@!\$&'()*+,;=-]/g)}).call(this)},{"pct-encode":23}],23:[function(a,b){b.exports=function(a){return a=a||/\W/g,function(b){return b=String(b),b.replace(a,function(a){var b=a[0].charCodeAt(0),c=[];return 128>b?c.push(b):b>=128&&2048>b?(c.push(b>>6|192),c.push(63&b|128)):(c.push(b>>12|224),c.push(b>>6&63|128),c.push(63&b|128)),c.map(function(a){return"%"+a.toString(16).toUpperCase()}).join("")})}}},{}],24:[function(a,b){"use strict";var c=(a("minilog"),a("./lib/media_types")),d=a("./lib/builder");b.exports={json:{from:function(a){return{newRequest:function(){return new d(c.JSON,a)}}}},jsonHal:{from:function(a){return{newRequest:function(){return new d(c.JSON_HAL,a)}}}}}},{"./lib/builder":6,"./lib/media_types":10,minilog:1}]},{},[24])(24)});
+!function(a){"object"==typeof exports?module.exports=a():"function"==typeof define&&define.amd?define(a):"undefined"!=typeof window?window.traverson=a():"undefined"!=typeof global?global.traverson=a():"undefined"!=typeof self&&(self.traverson=a())}(function(){var define,module,exports;return function a(b,c,d){function e(g,h){if(!c[g]){if(!b[g]){var i="function"==typeof require&&require;if(!h&&i)return i(g,!0);if(f)return f(g,!0);throw new Error("Cannot find module '"+g+"'")}var j=c[g]={exports:{}};b[g][0].call(j.exports,function(a){var c=b[g][1][a];return e(c?c:a)},j,j.exports,a,b,c,d)}return c[g].exports}for(var f="function"==typeof require&&require,g=0;g<d.length;g++)e(d[g]);return e}({1:[function(a,b){"use strict";function c(a){null==a&&(a=""),this.id=a}function d(a){return new c(a)}var e=!1;c.prototype.enable=function(){this.enabled=!0},c.prototype.debug=function(a){e&&console.log(this.id+"/debug: "+a)},c.prototype.info=function(a){e&&console.log(this.id+"/info: "+a)},c.prototype.warn=function(a){e&&console.log(this.id+"/warn: "+a)},c.prototype.error=function(a){e&&console.log(this.id+"/error: "+a)},d.enable=function(){e=!0},b.exports=d},{}],2:[function(a,b){"use strict";b.exports={isArray:function(a){return null==a?!1:"[object Array]"===Object.prototype.toString.call(a)}}},{}],3:[function(a,b){"use strict";function c(){this.options={}}function d(a,b,c){return e(a,b),f(a,b),g(a,b,c),a}function e(a,b){var c=b.headers;null!=c&&(a=a.set(c))}function f(a,b){var c=b.auth;null!=c&&(a=a.auth(c.user||c.username,c.pass||c.password))}function g(a,b,c){if(null!=c){var d=c.body;null!=d&&(a=a.send(d))}}function h(a){return a.body=a.text,a.statusCode=a.status,a}var i=a("../third-party/superagent");c.prototype.defaults=function(a){var b=new c;return b.options=a,b},c.prototype.get=function(a,b){d(i.get(a),this.options).end(function(a){b(null,h(a))})},c.prototype.post=function(a,b,c){d(i.post(a),this.options,b).end(function(a){c(null,h(a))})},c.prototype.put=function(a,b,c){d(i.put(a),this.options,b).end(function(a){c(null,h(a))})},c.prototype.patch=function(a,b,c){d(i.patch(a),this.options,b).end(function(a){c(null,h(a))})},c.prototype.del=function(a,b,c){d(i.del(a),this.options).end(function(a){c(null,h(a))})},b.exports=new c},{"../third-party/superagent":5}],4:[function(a,b){"use strict";var c={startsWith:function(a,b){return""===b?!0:null==a||null==b?!1:(a=String(a),b=String(b),a.length>=b.length&&a.slice(0,b.length)===b)},endsWith:function(a,b){return""===b?!0:null==a||null==b?!1:(a=String(a),b=String(b),a.length>=b.length&&a.slice(a.length-b.length)===b)},splice:function(a,b,d,e){var f=c.chars(a);return f.splice(~~b,~~d,e),f.join("")},contains:function(a,b){return""===b?!0:null==a?!1:-1!==String(a).indexOf(b)},chars:function(a){return null==a?[]:String(a).split("")}};b.exports=c},{}],5:[function(a,b,c){!function(){function a(b,c,d){var e=a.resolve(b);if(null==e){d=d||b,c=c||"root";var f=new Error('Failed to require "'+d+'" from "'+c+'"');throw f.path=d,f.parent=c,f.require=!0,f}var g=a.modules[e];return g.exports||(g.exports={},g.client=g.component=!0,g.call(this,g.exports,a.relative(e),g)),g.exports}a.modules={},a.aliases={},a.resolve=function(b){"/"===b.charAt(0)&&(b=b.slice(1));for(var c=b+"/index.js",d=[b,b+".js",b+".json",b+"/index.js",b+"/index.json"],e=0;e<d.length;e++){var b=d[e];if(a.modules.hasOwnProperty(b))return b}return a.aliases.hasOwnProperty(c)?a.aliases[c]:void 0},a.normalize=function(a,b){var c=[];if("."!=b.charAt(0))return b;a=a.split("/"),b=b.split("/");for(var d=0;d<b.length;++d)".."==b[d]?a.pop():"."!=b[d]&&""!=b[d]&&c.push(b[d]);return a.concat(c).join("/")},a.register=function(b,c){a.modules[b]=c},a.alias=function(b,c){if(!a.modules.hasOwnProperty(b))throw new Error('Failed to alias "'+b+'", it does not exist');a.aliases[c]=b},a.relative=function(b){function c(a,b){for(var c=a.length;c--;)if(a[c]===b)return c;return-1}function d(c){var e=d.resolve(c);return a(e,b,c)}var e=a.normalize(b,"..");return d.resolve=function(d){var f=d.charAt(0);if("/"==f)return d.slice(1);if("."==f)return a.normalize(e,d);var g=b.split("/"),h=c(g,"deps")+1;return h||(h=0),d=g.slice(0,h+1).join("/")+"/deps/"+d},d.exists=function(b){return a.modules.hasOwnProperty(d.resolve(b))},d},a.register("component-indexof/index.js",function(a,b,c){var d=[].indexOf;c.exports=function(a,b){if(d)return a.indexOf(b);for(var c=0;c<a.length;++c)if(a[c]===b)return c;return-1}}),a.register("component-emitter/index.js",function(a,b,c){function d(a){return a?e(a):void 0}function e(a){for(var b in d.prototype)a[b]=d.prototype[b];return a}var f=b("indexof");c.exports=d,d.prototype.on=function(a,b){return this._callbacks=this._callbacks||{},(this._callbacks[a]=this._callbacks[a]||[]).push(b),this},d.prototype.once=function(a,b){function c(){d.off(a,c),b.apply(this,arguments)}var d=this;return this._callbacks=this._callbacks||{},b._off=c,this.on(a,c),this},d.prototype.off=d.prototype.removeListener=d.prototype.removeAllListeners=function(a,b){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var c=this._callbacks[a];if(!c)return this;if(1==arguments.length)return delete this._callbacks[a],this;var d=f(c,b._off||b);return~d&&c.splice(d,1),this},d.prototype.emit=function(a){this._callbacks=this._callbacks||{};var b=[].slice.call(arguments,1),c=this._callbacks[a];if(c){c=c.slice(0);for(var d=0,e=c.length;e>d;++d)c[d].apply(this,b)}return this},d.prototype.listeners=function(a){return this._callbacks=this._callbacks||{},this._callbacks[a]||[]},d.prototype.hasListeners=function(a){return!!this.listeners(a).length}}),a.register("RedVentures-reduce/index.js",function(a,b,c){c.exports=function(a,b,c){for(var d=0,e=a.length,f=3==arguments.length?c:a[d++];e>d;)f=b.call(null,f,a[d],++d,a);return f}}),a.register("superagent/lib/client.js",function(a,b,c){function d(){}function e(a){var b={}.toString.call(a);switch(b){case"[object File]":case"[object Blob]":case"[object FormData]":return!0;default:return!1}}function f(){if(r.XMLHttpRequest&&("file:"!=r.location.protocol||!r.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(a){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(a){}return!1}function g(a){return a===Object(a)}function h(a){if(!g(a))return a;var b=[];for(var c in a)b.push(encodeURIComponent(c)+"="+encodeURIComponent(a[c]));return b.join("&")}function i(a){for(var b,c,d={},e=a.split("&"),f=0,g=e.length;g>f;++f)c=e[f],b=c.split("="),d[decodeURIComponent(b[0])]=decodeURIComponent(b[1]);return d}function j(a){var b,c,d,e,f=a.split(/\r?\n/),g={};f.pop();for(var h=0,i=f.length;i>h;++h)c=f[h],b=c.indexOf(":"),d=c.slice(0,b).toLowerCase(),e=s(c.slice(b+1)),g[d]=e;return g}function k(a){return a.split(/ *; */).shift()}function l(a){return q(a.split(/ *; */),function(a,b){var c=b.split(/ *= */),d=c.shift(),e=c.shift();return d&&e&&(a[d]=e),a},{})}function m(a,b){b=b||{},this.xhr=a,this.text=a.responseText,this.setStatusProperties(a.status),this.header=this.headers=j(a.getAllResponseHeaders()),this.header["content-type"]=a.getResponseHeader("content-type"),this.setHeaderProperties(this.header),this.body=this.parseBody(this.text)}function n(a,b){var c=this;p.call(this),this._query=this._query||[],this.method=a,this.url=b,this.header={},this._header={},this.set("X-Requested-With","XMLHttpRequest"),this.on("end",function(){var b=new m(c.xhr);"HEAD"==a&&(b.text=null),c.callback(null,b)})}function o(a,b){return"function"==typeof b?new n("GET",a).end(b):1==arguments.length?new n("GET",a):new n(a,b)}var p=b("emitter"),q=b("reduce"),r="undefined"==typeof window?this:window,s="".trim?function(a){return a.trim()}:function(a){return a.replace(/(^\s*|\s*$)/g,"")};o.serializeObject=h,o.parseString=i,o.types={html:"text/html",json:"application/json",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},o.serialize={"application/x-www-form-urlencoded":h,"application/json":JSON.stringify},o.parse={"application/x-www-form-urlencoded":i,"application/json":JSON.parse},m.prototype.get=function(a){return this.header[a.toLowerCase()]},m.prototype.setHeaderProperties=function(){var a=this.header["content-type"]||"";this.type=k(a);var b=l(a);for(var c in b)this[c]=b[c]},m.prototype.parseBody=function(a){var b=o.parse[this.type];return b?b(a):null},m.prototype.setStatusProperties=function(a){var b=a/100|0;this.status=a,this.statusType=b,this.info=1==b,this.ok=2==b,this.clientError=4==b,this.serverError=5==b,this.error=4==b||5==b?this.toError():!1,this.accepted=202==a,this.noContent=204==a||1223==a,this.badRequest=400==a,this.unauthorized=401==a,this.notAcceptable=406==a,this.notFound=404==a,this.forbidden=403==a},m.prototype.toError=function(){var a="got "+this.status+" response",b=new Error(a);return b.status=this.status,b},o.Response=m,n.prototype=new p,n.prototype.constructor=n,n.prototype.timeout=function(a){return this._timeout=a,this},n.prototype.clearTimeout=function(){return this._timeout=0,clearTimeout(this._timer),this},n.prototype.abort=function(){return this.aborted?void 0:(this.aborted=!0,this.xhr.abort(),this.clearTimeout(),this.emit("abort"),this)},n.prototype.set=function(a,b){if(g(a)){for(var c in a)this.set(c,a[c]);return this}return this._header[a.toLowerCase()]=b,this.header[a]=b,this},n.prototype.getHeader=function(a){return this._header[a.toLowerCase()]},n.prototype.type=function(a){return this.set("Content-Type",o.types[a]||a),this},n.prototype.auth=function(a,b){var c=btoa(a+":"+b);return this.set("Authorization","Basic "+c),this},n.prototype.query=function(a){return"string"!=typeof a&&(a=h(a)),a&&this._query.push(a),this},n.prototype.send=function(a){var b=g(a),c=this.getHeader("Content-Type");if(b&&g(this._data))for(var d in a)this._data[d]=a[d];else"string"==typeof a?(c||this.type("form"),c=this.getHeader("Content-Type"),this._data="application/x-www-form-urlencoded"==c?this._data?this._data+"&"+a:a:(this._data||"")+a):this._data=a;return b?(c||this.type("json"),this):this},n.prototype.callback=function(a,b){var c=this._callback;return 2==c.length?c(a,b):a?this.emit("error",a):(c(b),void 0)},n.prototype.crossDomainError=function(){var a=new Error("Origin is not allowed by Access-Control-Allow-Origin");a.crossDomain=!0,this.callback(a)},n.prototype.timeoutError=function(){var a=this._timeout,b=new Error("timeout of "+a+"ms exceeded");b.timeout=a,this.callback(b)},n.prototype.withCredentials=function(){return this._withCredentials=!0,this},n.prototype.end=function(a){var b=this,c=this.xhr=f(),g=this._query.join("&"),h=this._timeout,i=this._data;if(this._callback=a||d,this._withCredentials&&(c.withCredentials=!0),c.onreadystatechange=function(){return 4==c.readyState?0==c.status?b.aborted?b.timeoutError():b.crossDomainError():(b.emit("end"),void 0):void 0},c.upload&&(c.upload.onprogress=function(a){a.percent=a.loaded/a.total*100,b.emit("progress",a)}),h&&!this._timer&&(this._timer=setTimeout(function(){b.abort()},h)),g&&(g=o.serializeObject(g),this.url+=~this.url.indexOf("?")?"&"+g:"?"+g),c.open(this.method,this.url,!0),"GET"!=this.method&&"HEAD"!=this.method&&"string"!=typeof i&&!e(i)){var j=o.serialize[this.getHeader("Content-Type")];j&&(i=j(i))}for(var k in this.header)null!=this.header[k]&&c.setRequestHeader(k,this.header[k]);return c.send(i),this},o.Request=n,o.get=function(a,b,c){var d=o("GET",a);return"function"==typeof b&&(c=b,b=null),b&&d.query(b),c&&d.end(c),d},o.head=function(a,b,c){var d=o("HEAD",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},o.del=function(a,b){var c=o("DELETE",a);return b&&c.end(b),c},o.patch=function(a,b,c){var d=o("PATCH",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},o.post=function(a,b,c){var d=o("POST",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},o.put=function(a,b,c){var d=o("PUT",a);return"function"==typeof b&&(c=b,b=null),b&&d.send(b),c&&d.end(c),d},c.exports=o}),a.alias("component-emitter/index.js","superagent/deps/emitter/index.js"),a.alias("component-emitter/index.js","emitter/index.js"),a.alias("component-indexof/index.js","component-emitter/deps/indexof/index.js"),a.alias("RedVentures-reduce/index.js","superagent/deps/reduce/index.js"),a.alias("RedVentures-reduce/index.js","reduce/index.js"),a.alias("superagent/lib/client.js","superagent/index.js"),"object"==typeof c?b.exports=a("superagent"):"function"==typeof define&&define.amd?define(function(){return a("superagent")}):this.superagent=a("superagent")}()},{emitter:15,indexof:15,reduce:15,superagent:15}],6:[function(a,b){"use strict";function c(a,b){this.walker=this.createWalker(a),this.walker.startUri=b,this.walker.request=this.request=e,this.finalAction=new g(this.walker)}var d=a("minilog"),e=a("request"),f=a("util"),g=a("./final_action"),h=a("./json_walker"),i=a("./json_hal_walker"),j=a("./media_types"),k=d("traverson");c.prototype.createWalker=function(a){switch(a){case j.JSON:return k.debug("creating new JsonWalker"),new h;case j.JSON_HAL:return k.debug("creating new JsonHalWalker"),new i;default:throw new Error("Unknown or unsupported media type: "+a)}},c.prototype.follow=function(){return this.walker.links=1===arguments.length&&f.isArray(arguments[0])?arguments[0]:Array.prototype.slice.apply(arguments),this},c.prototype.walk=c.prototype.follow,c.prototype.withTemplateParameters=function(a){return this.walker.templateParameters=a,this},c.prototype.withRequestOptions=function(a){return this.walker.request=this.request=e.defaults(a),this},c.prototype.get=function(a){var b=this;this.walker.walk(function(c,d,e){return k.debug("walker.walk returned"),c?a(c,e.response,e.uri):(b.finalAction.get(d,a),void 0)})},c.prototype.getResource=function(a){var b=this;this.walker.walk(function(c,d,e){return k.debug("walker.walk returned"),c?a(c,e.response,e.uri):(b.finalAction.getResource(d,a),void 0)})},c.prototype.getUri=function(a){var b=this;this.walker.walk(function(c,d,e){return k.debug("walker.walk returned"),c?a(c,e.response,e.uri):(b.finalAction.getUri(d,a),void 0)})},c.prototype.post=function(a,b){this.finalAction.walkAndExecute(a,this.request,this.request.post,b)},c.prototype.put=function(a,b){this.finalAction.walkAndExecute(a,this.request,this.request.put,b)},c.prototype.patch=function(a,b){this.finalAction.walkAndExecute(a,this.request,this.request.patch,b)},c.prototype.del=function(a){this.finalAction.walkAndExecute(null,this.request,this.request.del,a)},b.exports=c},{"./final_action":7,"./json_hal_walker":8,"./json_walker":9,"./media_types":10,minilog:1,request:3,util:2}],7:[function(a,b){"use strict";function c(a){this.walker=a}var d=a("minilog"),e=d("traverson");c.prototype.get=function(a,b){e.debug("next step: "+JSON.stringify(a,null,2)),this.walker.process(a,function(a,c){return e.debug("walker.process returned"),a?b(a,c.response,c.uri):(!c.response&&c.doc&&(e.debug("faking HTTP response for embedded resource"),c.response={statusCode:200,body:JSON.stringify(c.doc),remark:"This is not an actual HTTP response. The resource you requested was an embedded resource, so no HTTP request was made to acquire it."}),b(null,c.response),void 0)})},c.prototype.getResource=function(a,b){var c=this;e.debug("next step: "+JSON.stringify(a)),this.walker.process(a,function(a,d){if(e.debug("walker.process returned"),a)return b(a,d.response,d.uri);if(d.doc)return b(null,d.doc);var f;try{return c.walker.checkHttpStatus(d),f=c.walker.parse(d),b(null,f)}catch(g){return b(g,g.doc)}})},c.prototype.getUri=function(a,b){var c=this;return e.debug("returning uri"),a.uri?b(null,a.uri):a.doc&&a.doc._links&&a.doc._links.self&&a.doc._links.self.href?b(null,c.walker.startUri+a.doc._links.self.href):b(new Error('You requested an URI but the last resource is an embedded resource and has no URI of its own (that is, it has no link with rel="self"'))},c.prototype.walkAndExecute=function(a,b,c,d){var f=this;this.walker.walk(function(g,h,i){return e.debug("walker.walk returned"),g?d(g,i.response,i.uri):(e.debug("executing final request with step: "+JSON.stringify(h)),f.executeRequest(h.uri,b,c,a,d),void 0)})},c.prototype.executeRequest=function(a,b,c,d,f){var g;g=d?{body:JSON.stringify(d)}:{},e.debug("request to "+a+" with options "+JSON.stringify(g)),c.call(b,a,g,function(b,c){return e.debug("request to "+a+" succeeded"),b?f(b,c,a):f(null,c,a)})},b.exports=c},{minilog:1}],8:[function(a,b){"use strict";function c(){}function d(a,b,c){var d=a.linkArray(b);if(!d||0===d.length)return null;var g=e(d,b,c);return g||(g=f(d,b)),g}function e(a,b,c){if(c){if(!a[c])throw new Error(b+"["+c+"] requested, but link array "+b+" had no element at index "+c);if(!a[c].href)throw new Error(b+"["+c+"] requested, but this link had no href attribute.");return p.debug("found hal link: "+a[c].href),{uri:a[c].href}}return null}function f(a,b){for(var c,d=0;d<a.length;d++)if(a[d].href){c=a[d];break}return c?(a.length>1&&p.warn("Found HAL link array with more than one element for key "+b+", arbitrarily choosing index "+d+", because it was the first that had a href attribute."),p.debug("found hal link: "+c.href),{uri:c.href}):null}function g(a,b,c,d){p.debug("checking for embedded: "+c+(d?d:""));var e=a.embeddedArray(c);if(!e||0===e.length)return null;p.debug("Found an array of embedded resource for: "+c);var f=h(e,c,d);return f||(f=i(e,c)),f}function h(a,b,c){if(c){if(!a[c])throw new Error(b+"["+c+"] requested, but there is no such link. However, there is an embedded resource array named "+b+" but it does not have an element at index "+c);return p.debug("Found an embedded resource for: "+b+"["+c+"]"),{doc:a[c].original()}}return null}function i(a,b){return a.length>1&&p.warn("Found HAL embedded resource array with more than one element for key "+b+", arbitrarily choosing first element."),{doc:a[0].original()}}function j(a){var b=a.match(/.*\[(\d+)\]/);return b?b[1]:null}function k(a){var b=a.match(/(.*)\[\d+\]/);return b?b[1]:a}var l=a("halfred"),m=a("minilog"),n=a("underscore.string"),o=a("./walker"),p=m("traverson");c.prototype=new o,c.prototype.findNextStep=function(a,b){p.debug("parsing hal");var c=l.parse(a),e=j(b);b=k(b);var f=d(c,b,e);if(f)return f;if(f=g(c,a,b,e))return f;throw new Error("Could not find a link nor an embedded object for "+b+" in document:\n"+JSON.stringify(a))},c.prototype.postProcessStep=function(a){a.uri&&(n.endsWith(this.startUri,"/")&&n.startsWith(a.uri,"/")&&(a.uri=n.splice(a.uri,0,1)),a.uri=this.startUri+a.uri)},b.exports=c},{"./walker":11,halfred:16,minilog:1,"underscore.string":4}],9:[function(a,b){"use strict";function c(){}var d=a("./walker");c.prototype=new d,b.exports=c},{"./walker":11}],10:[function(a,b){"use strict";b.exports={JSON:"application/json",JSON_HAL:"application/hal+json"}},{}],11:[function(a,b){"use strict";function c(){}function d(a,b,c){var d=new Error("HTTP GET for "+a+" resulted in HTTP status code "+b+".");d.name="HTTPError",d.uri=a,d.httpStatus=b,d.body=c;try{d.doc=JSON.parse(c)}catch(e){}return d}function e(a,b){var c=new Error("The document at "+a+" could not be parsed as JSON: "+b);return c.name="JSONError",c.uri=a,c.body=b,c}var f=a("JSONPath"),g=a("minilog"),h=a("underscore.string"),i=a("uri-template"),j=a("util"),k=f.eval,l=g("traverson");c.prototype.walk=function(a){function b(){return e<c.links.length?(c.process(d,function(g,h){if(f=h,g)return l.debug("error while processing step "+JSON.stringify(d)),l.error(g),a(g,d,h);l.debug("successully processed step");try{c.checkHttpStatus(h)}catch(i){return l.error("unexpected http status code"),l.error(i),a(i,d,h)}var j;try{j=c.parse(h)}catch(i){return l.error("parsing failed"),l.error(i),a(i,d,h)}var k=c.links[e++];l.debug("next link: "+k);try{d=c.findNextStep(j,k)}catch(i){return l.error("could not find next step"),l.error(i),a(i,d,h)}c.postProcessStep(d),l.debug("next step: "+JSON.stringify(d,null,2)),d.uri&&(d.uri=c.resolveUriTemplate(d.uri,c.templateParameters,e)),b()}),void 0):(l.debug("link array exhausted, calling callback"),a(null,d,f))}var c=this,d={uri:this.resolveUriTemplate(this.startUri,this.templateParameters,0)},e=0,f=d;l.debug("starting to follow links"),b()},c.prototype.process=function(a,b){if(l.debug("processing next step: "+JSON.stringify(a,null,2)),a.uri)this.get(a,b);else{if(!a.doc)throw new Error("Can not process next step: "+JSON.stringify(a));l.debug("document for next step has already been fetched"),b(null,a)}},c.prototype.get=function(a,b){l.debug("request to "+a.uri),this.request.get(a.uri,function(c,d){return l.debug("request.get returned"),c?b(c,a):(l.debug("request to "+a.uri+" finished ("+d.statusCode+")"),a.response=d,b(null,a))})},c.prototype.checkHttpStatus=function(a){if(a.response||!a.doc){var b=a.response.statusCode;if(200>b||b>=300)throw d(a.uri,b,a.response.body)}},c.prototype.parse=function(a){if(a.doc)return a.doc;try{return JSON.parse(a.response.body)}catch(b){if("SyntaxError"===b.name)throw e(a.uri,a.response.body);throw b}},c.prototype.findNextStep=function(a,b){l.debug("extracting link "+b+" from "+JSON.stringify(a));if(this.testJSONPath(b))return{uri:this.resolveJSONPath(b,a)};if(a[b])return{uri:a[b]};throw new Error("Could not find property "+b+" in document:\n"+JSON.stringify(a))},c.prototype.postProcessStep=function(){},c.prototype.testJSONPath=function(a){return h.startsWith(a,"$.")||h.startsWith(a,"$[")},c.prototype.resolveJSONPath=function(a,b){var c=k(b,a);if(1===c.length){var d=c[0];if(!d)throw new Error("JSONPath expression "+a+" was resolved but the result was null, undefined or an empty string in document:\n"+JSON.stringify(b));return d}throw c.length>1?new Error("JSONPath expression "+a+" returned more than one match in document:\n"+JSON.stringify(b)):new Error("JSONPath expression "+a+" returned no match in document:\n"+JSON.stringify(b))},c.prototype.resolveUriTemplate=function(a,b,c){if(j.isArray(b)&&(b=b[c]),!b)return a;if(h.contains(a,"{")){var d=i.parse(a);return d.expand(b)}return a},b.exports=c},{JSONPath:13,minilog:1,"underscore.string":4,"uri-template":20,util:2}],12:[function(a,b,c){var d=Array.isArray;c.isArray=d||function(a){return"[object Array]"==Object.prototype.toString.call(a)}},{}],13:[function(a,b,c){function d(a,b,c){var d={resultType:c&&c.resultType||"VALUE",flatten:c&&c.flatten||!1,wrap:c&&c.hasOwnProperty("wrap")?c.wrap:!0,sandbox:c&&c.sandbox?c.sandbox:{},normalize:function(a){if(g[a])return g[a];var b=[],c=a.replace(/[\['](\??\(.*?\))[\]']/g,function(a,c){return"[#"+(b.push(c)-1)+"]"}).replace(/'?\.'?|\['?/g,";").replace(/;;;|;;/g,";..;").replace(/;$|'?\]|'$/g,"").replace(/#([0-9]+)/g,function(a,c){return b[c]});return g[a]=c,c},asPath:function(a){for(var b=a.split(";"),c="$",d=1,e=b.length;e>d;d++)c+=/^[0-9*]+$/.test(b[d])?"["+b[d]+"]":"['"+b[d]+"']";return c},store:function(a,b){return a&&("PATH"==d.resultType?d.result[d.result.length]=d.asPath(a):f.isArray(b)&&d.flatten?(d.result||(d.result=[]),f.isArray(d.result)||(d.result=[d.result]),d.result=d.result.concat(b)):d.result?(f.isArray(d.result)||(d.result=[d.result]),f.isArray(b)&&d.flatten?d.result=d.result.concat(b):d.result[d.result.length]=b):d.result=b),!!a},trace:function(a,b,c){if(a){var e=a.split(";"),f=e.shift();if(e=e.join(";"),b&&b.hasOwnProperty(f))d.trace(e,b[f],c+";"+f);else if("*"===f)d.walk(f,e,b,c,function(a,b,c,e,f){d.trace(a+";"+c,e,f)});else if(".."===f)d.trace(e,b,c),d.walk(f,e,b,c,function(a,b,c,e,f){"object"==typeof e[a]&&d.trace("..;"+c,e[a],f+";"+a)});else if(/,/.test(f))for(var g=f.split(/'?,'?/),h=0,i=g.length;i>h;h++)d.trace(g[h]+";"+e,b,c);else/^\(.*?\)$/.test(f)?d.trace(d.eval(f,b,c.substr(c.lastIndexOf(";")+1))+";"+e,b,c):/^\?\(.*?\)$/.test(f)?d.walk(f,e,b,c,function(a,b,c,e,f){d.eval(b.replace(/^\?\((.*?)\)$/,"$1"),e[a],a)&&d.trace(a+";"+c,e,f)}):/^(-?[0-9]*):(-?[0-9]*):?([0-9]*)$/.test(f)&&d.slice(f,e,b,c)}else d.store(c,b)},walk:function(a,b,c,d,e){if(c instanceof Array)for(var f=0,g=c.length;g>f;f++)f in c&&e(f,a,b,c,d);else if("object"==typeof c)for(var h in c)c.hasOwnProperty(h)&&e(h,a,b,c,d)},slice:function(a,b,c,e){if(c instanceof Array){var f=c.length,g=0,h=f,i=1;a.replace(/^(-?[0-9]*):(-?[0-9]*):?(-?[0-9]*)$/g,function(a,b,c,d){g=parseInt(b||g),h=parseInt(c||h),i=parseInt(d||i)}),g=0>g?Math.max(0,g+f):Math.min(f,g),h=0>h?Math.max(0,h+f):Math.min(f,h);for(var j=g;h>j;j+=i)d.trace(j+";"+b,c,e)}},eval:function(a,b){d.sandbox._v=b;try{return h&&b&&e.runInNewContext(a.replace(/@/g,"_v"),d.sandbox)}catch(c){throw console.log(c),new SyntaxError("jsonPath: "+c.message+": "+a.replace(/@/g,"_v").replace(/\^/g,"_a"))}}};d.result=d.wrap===!0?[]:void 0;var h=a;return b&&a&&("VALUE"==d.resultType||"PATH"==d.resultType)?(d.trace(d.normalize(b).replace(/^\$;/,""),a,"$"),!f.isArray(d.result)&&d.wrap&&(d.result=[d.result]),d.result?d.result:!1):void 0}var e=a("vm"),f=a("underscore");c.eval=d;var g={}},{underscore:12,vm:14}],14:[function(require,module,exports){var Object_keys=function(a){if(Object.keys)return Object.keys(a);var b=[];for(var c in a)b.push(c);return b},forEach=function(a,b){if(a.forEach)return a.forEach(b);for(var c=0;c<a.length;c++)b(a[c],c,a)},Script=exports.Script=function(a){return this instanceof Script?(this.code=a,void 0):new Script(a)};Script.prototype.runInNewContext=function(a){a||(a={});var b=document.createElement("iframe");b.style||(b.style={}),b.style.display="none",document.body.appendChild(b);var c=b.contentWindow;forEach(Object_keys(a),function(b){c[b]=a[b]}),!c.eval&&c.execScript&&c.execScript("null");var d=c.eval(this.code);return forEach(Object_keys(c),function(b){a[b]=c[b]}),document.body.removeChild(b),d},Script.prototype.runInThisContext=function(){return eval(this.code)},Script.prototype.runInContext=function(a){return this.runInNewContext(a)},forEach(Object_keys(Script.prototype),function(a){exports[a]=Script[a]=function(b){var c=Script(b);return c[a].apply(c,[].slice.call(arguments,1))}}),exports.createScript=function(a){return exports.Script(a)},exports.createContext=Script.createContext=function(a){var b={};return"object"==typeof a&&forEach(Object_keys(a),function(c){b[c]=a[c]}),b}},{}],15:[function(){},{}],16:[function(a,b){var c=a("./lib/parser"),d=!1;b.exports={parse:function(a){return(new c).parse(a,d)},enableValidation:function(a){d=null!=a?a:!0},disableValidation:function(){d=!1}}},{"./lib/parser":18}],17:[function(a,b){"use strict";function c(){this._array=arguments.length>=1?arguments[0]:[]}c.prototype.array=function(){return this._array},c.prototype.isEmpty=function(){return 0===this._array.length},c.prototype.push=function(a){var b=this._array.slice(0);return b.push(a),new c(b)},c.prototype.pop=function(){var a=this._array.slice(0,this._array.length-1);return new c(a)},c.prototype.peek=function(){if(this.isEmpty())throw new Error("can't peek on empty stack");return this._array[this._array.length-1]},b.exports=c},{}],18:[function(a,b){"use strict";function c(){}function d(a,b,c){if(null==a)return a;var d=e(a._links,b,c.push("_links")),h=f(a._embedded,b,c.push("_embedded")),i=new q(d,h,b);return g(a,i),i._original=a,i}function e(a,b,c){return a=h(a,j,b,c),(null==a||null==a.self)&&m("Resource does not have a self link",b,c),a}function f(a,b,c){var e=h(a,l,b,c);return null==e?e:(Object.keys(e).forEach(function(a){e[a]=e[a].map(function(e){var f=null!=b?[]:null,g=d(e,f,c.push(a));return g._original=e,g})}),e)}function g(a,b){Object.keys(a).forEach(function(c){"_links"!==c&&"_embedded"!==c&&(b[c]=a[c])})}function h(a,b,c,d){if(null==a)return a;var e={};return Object.keys(a).forEach(function(f){e[f]=i(f,a[f],b,c,d)}),e}function i(a,b,c,d,e){return k(b)?b.map(function(b){return c(a,b,d,e)}):[c(a,b,d,e)]}function j(a,b,c,d){var e=o(b);return Object.keys(s).forEach(function(b){null==e[b]&&(s[b].required&&m("Link misses required property "+b+".",c,d.push(a)),null!=s[b].defaultValue&&(e[b]=s[b].defaultValue))}),e.deprecation&&n("Warning: Link "+p(d.push(a))+" is deprecated, see "+e.deprecation),e.templated!==!0&&e.templated!==!1&&(e.templated=!1),c?(e.href&&e.href.indexOf("{")>=0&&!e.templated&&m('Link seems to be an URI template but its "templated" property is not set to true.',c,d.push(a)),e):e}function k(a){return"[object Array]"===Object.prototype.toString.call(a)}function l(a,b){return b}function m(a,b,c){b&&b.push({path:p(c),message:a})}function n(a){"undefined"!=typeof console&&"function"==typeof console.log&&console.log(a)}function o(a){var b={};return Object.keys(a).forEach(function(c){b[c]=a[c]}),b}function p(a){for(var b="$.",c=0;c<a.array().length;c++)b+=a.array()[c]+".";return b=b.substring(0,b.length-1)}var q=a("./resource"),r=a("./immutable_stack"),s={href:{required:!0,defaultValue:null},templated:{required:!1,defaultValue:!1},type:{required:!1,defaultValue:null},deprecation:{required:!1,defaultValue:null},name:{required:!1,defaultValue:null},profile:{required:!1,defaultValue:null},title:{required:!1,defaultValue:null},hreflang:{required:!1,defaultValue:null}};c.prototype.parse=function(a,b){var c=b?[]:null;return d(a,c,new r)},b.exports=c},{"./immutable_stack":17,"./resource":19}],19:[function(a,b){"use strict";function c(a,b,c){this._links=a||{},this._embedded=b||{},this._validation=c||[]}function d(a,b){return null!=a?a[b]:null}function e(a,b,c){c=c||0;var e=d(a,b);return null!=e&&e.length>=1?e[c]:null}c.prototype.allLinkArrays=function(){return this._links},c.prototype.linkArray=function(a){return d(this._links,a)},c.prototype.link=function(a,b){return e(this._links,a,b)},c.prototype.allEmbeddedResourceArrays=function(){return this._embedded},c.prototype.embeddedResourceArray=function(a){return d(this._embedded,a)},c.prototype.embeddedResource=function(a,b){return e(this._embedded,a,b)},c.prototype.original=function(){return this._original},c.prototype.validationIssues=function(){return this._validation},c.prototype.allLinks=c.prototype.allLinkArrays,c.prototype.allEmbeddedArrays=c.prototype.allEmbeddedResources=c.prototype.allEmbeddedResourceArrays,c.prototype.embeddedArray=c.prototype.embeddedResourceArray,c.prototype.embedded=c.prototype.embeddedResource,c.prototype.validation=c.prototype.validationIssues,b.exports=c},{}],20:[function(a,b){b.exports=function(){function b(a){return'"'+a.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\x08/g,"\\b").replace(/\t/g,"\\t").replace(/\n/g,"\\n").replace(/\f/g,"\\f").replace(/\r/g,"\\r").replace(/[\x00-\x07\x0B\x0E-\x1F\x80-\uFFFF]/g,escape)+'"'}var c={parse:function(c,d){function e(a){v>t||(t>v&&(v=t,w=[]),w.push(a))}function f(){var a,b,c;for(c=t,a=[],b=o(),null===b&&(b=g());null!==b;)a.push(b),b=o(),null===b&&(b=g());return null!==a&&(a=function(a,b){return new y(b)}(c,a)),null===a&&(t=c),a}function g(){var a,b,d,f,g,i;return g=t,i=t,123===c.charCodeAt(t)?(a="{",t++):(a=null,0===u&&e('"{"')),null!==a?(b=h(),null!==b?(d=j(),null!==d?(125===c.charCodeAt(t)?(f="}",t++):(f=null,0===u&&e('"}"')),null!==f?a=[a,b,d,f]:(a=null,t=i)):(a=null,t=i)):(a=null,t=i)):(a=null,t=i),null!==a&&(a=function(a,b,c){return z(b,c)}(g,a[1],a[2])),null===a&&(t=g),a}function h(){var a;return/^[\/;:.?&+#]/.test(c.charAt(t))?(a=c.charAt(t),t++):(a=null,0===u&&e("[\\/;:.?&+#]")),null===a&&(a=""),a}function i(){var a;return"{/"===c.substr(t,2)?(a="{/",t+=2):(a=null,0===u&&e('"{/"')),a}function j(){var a,b,d,f,g,h,i,j;if(g=t,h=t,a=k(),null!==a){for(b=[],i=t,j=t,44===c.charCodeAt(t)?(d=",",t++):(d=null,0===u&&e('","')),null!==d?(f=k(),null!==f?d=[d,f]:(d=null,t=j)):(d=null,t=j),null!==d&&(d=function(a,b){return b}(i,d[1])),null===d&&(t=i);null!==d;)b.push(d),i=t,j=t,44===c.charCodeAt(t)?(d=",",t++):(d=null,0===u&&e('","')),null!==d?(f=k(),null!==f?d=[d,f]:(d=null,t=j)):(d=null,t=j),null!==d&&(d=function(a,b){return b}(i,d[1])),null===d&&(t=i);null!==b?a=[a,b]:(a=null,t=h)}else a=null,t=h;return null!==a&&(a=function(a,b,c){return c.unshift(b),c}(g,a[0],a[1])),null===a&&(t=g),a}function k(){var a,b,d,f,g;
+for(f=t,g=t,a=[],/^[a-zA-Z0-9_.%]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[a-zA-Z0-9_.%]"));null!==b;)a.push(b),/^[a-zA-Z0-9_.%]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[a-zA-Z0-9_.%]"));return null!==a?(b=l(),null===b&&(b=m()),b=null!==b?b:"",null!==b?(d=p(),d=null!==d?d:"",null!==d?a=[a,b,d]:(a=null,t=g)):(a=null,t=g)):(a=null,t=g),null!==a&&(a=function(a,b,c,d){return c=c||{},{name:b.join(""),explode:c.listMarker,cut:c.cut,extended:d}}(f,a[0],a[1],a[2])),null===a&&(t=f),a}function l(){var a,b;return b=t,a=n(),null!==a&&(a=function(a,b){return{cut:b}}(b,a)),null===a&&(t=b),a}function m(){var a,b;return b=t,42===c.charCodeAt(t)?(a="*",t++):(a=null,0===u&&e('"*"')),null!==a&&(a=function(a,b){return{listMarker:b}}(b,a)),null===a&&(t=b),a}function n(){var a,b,d,f,g;if(f=t,g=t,58===c.charCodeAt(t)?(a=":",t++):(a=null,0===u&&e('":"')),null!==a){if(/^[0-9]/.test(c.charAt(t))?(d=c.charAt(t),t++):(d=null,0===u&&e("[0-9]")),null!==d)for(b=[];null!==d;)b.push(d),/^[0-9]/.test(c.charAt(t))?(d=c.charAt(t),t++):(d=null,0===u&&e("[0-9]"));else b=null;null!==b?a=[a,b]:(a=null,t=g)}else a=null,t=g;return null!==a&&(a=function(a,b){return parseInt(b.join(""))}(f,a[1])),null===a&&(t=f),a}function o(){var a,b,d;if(d=t,/^[^{]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[^{]")),null!==b)for(a=[];null!==b;)a.push(b),/^[^{]/.test(c.charAt(t))?(b=c.charAt(t),t++):(b=null,0===u&&e("[^{]"));else a=null;return null!==a&&(a=function(a,b){return b.join("")}(d,a)),null===a&&(t=d),a}function p(){var a,b,d,f,g;if(f=t,g=t,40===c.charCodeAt(t)?(a="(",t++):(a=null,0===u&&e('"("')),null!==a){if(/^[^)]/.test(c.charAt(t))?(d=c.charAt(t),t++):(d=null,0===u&&e("[^)]")),null!==d)for(b=[];null!==d;)b.push(d),/^[^)]/.test(c.charAt(t))?(d=c.charAt(t),t++):(d=null,0===u&&e("[^)]"));else b=null;null!==b?(41===c.charCodeAt(t)?(d=")",t++):(d=null,0===u&&e('")"')),null!==d?a=[a,b,d]:(a=null,t=g)):(a=null,t=g)}else a=null,t=g;return null!==a&&(a=function(a,b){return b.join("")}(f,a[1])),null===a&&(t=f),a}function q(a){a.sort();for(var b=null,c=[],d=0;d<a.length;d++)a[d]!==b&&(c.push(a[d]),b=a[d]);return c}function r(){for(var a=1,b=1,d=!1,e=0;e<Math.max(t,v);e++){var f=c.charAt(e);"\n"===f?(d||a++,b=1,d=!1):"\r"===f||"\u2028"===f||"\u2029"===f?(a++,b=1,d=!0):(b++,d=!1)}return{line:a,column:b}}var s={uriTemplate:f,expression:g,op:h,pathExpression:i,paramList:j,param:k,cut:l,listMarker:m,substr:n,nonexpression:o,extension:p};if(void 0!==d){if(void 0===s[d])throw new Error("Invalid rule name: "+b(d)+".")}else d="uriTemplate";var t=0,u=0,v=0,w=[],x=a("./lib/classes"),y=x.Template,z=x.expression,A=s[d]();if(null===A||t!==c.length){var B=Math.max(t,v),C=B<c.length?c.charAt(B):null,D=r();throw new this.SyntaxError(q(w),C,B,D.line,D.column)}return A},toSource:function(){return this._source}};return c.SyntaxError=function(a,c,d,e,f){function g(a,c){var d,e;switch(a.length){case 0:d="end of input";break;case 1:d=a[0];break;default:d=a.slice(0,a.length-1).join(", ")+" or "+a[a.length-1]}return e=c?b(c):"end of input","Expected "+d+" but "+e+" found."}this.name="SyntaxError",this.expected=a,this.found=c,this.message=g(a,c),this.offset=d,this.line=e,this.column=f},c.SyntaxError.prototype=Error.prototype,c}()},{"./lib/classes":21}],21:[function(a,b){(function(){var c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v=function(a,b){return function(){return a.apply(b,arguments)}},w={}.hasOwnProperty,x=function(a,b){function c(){this.constructor=a}for(var d in b)w.call(b,d)&&(a[d]=b[d]);return c.prototype=b.prototype,a.prototype=new c,a.__super__=b.prototype,a};m=a("./encoders"),l=l=function(){function a(a){var b,c=this;this.expressions=[],this.prefix="string"==typeof a[0]?a.shift():"",b=0,a.forEach(function(a){switch(typeof a){case"object":return c.expressions[b++]=a;case"string":return c.expressions[b-1].suffix=a}})}return a.prototype.expand=function(a){return this.prefix+this.expressions.map(function(b){return b.expand(a)}).join("")},a.prototype.toString=function(){return this.prefix+this.expressions.join("")},a.prototype.toJSON=function(){return this.toString()},a}(),k=function(){function a(a){var b;this.params=a,this.explodeObject=v(this.explodeObject,this),this.explodeArray=v(this.explodeArray,this),this._expandPair=v(this._expandPair,this),this.stringifySingle=v(this.stringifySingle,this),this.encode=v(this.encode,this),null==(b=this.params)&&(this.params=[]),this.suffix=""}var b;return a.prototype.first="",a.prototype.sep=",",a.prototype.named=!1,a.prototype.empty="",a.prototype.allow="U",a.prototype.encode=function(a){return m[this.allow](a)},a.prototype.stringifySingle=function(a,b){var c,d,e;if(d=typeof b,"string"===d||"boolean"===d||"number"===d)return b=b.toString(),this.encode(b.substring(0,a.cut||b.length));if(Array.isArray(b)){if(a.cut)throw new Error("Prefixed Values do not support lists. Check "+a.name);return b.map(this.encode).join(",")}if(a.cut)throw new Error("Prefixed Values do not support maps. Check "+a.name);return function(){var a;a=[];for(c in b)e=b[c],a.push([c,e].map(this.encode).join(","));return a}.call(this).join(",")},a.prototype.expand=function(a){var c,d,e=this;return c=b(this.params,a),d=c.map(function(a){return e._expandPair.apply(e,a)}).join(this.sep),d?this.first+d+this.suffix:this.empty&&c.length?this.empty+this.suffix:this.suffix},b=function(a,b){return a.map(function(a){return[a,b[a.name]]}).filter(function(a){var b,c,d;switch(c=a[1],typeof c){case"undefined":return!1;case"object":Array.isArray(c)&&c.length>0;for(b in c)if(d=c[b])return!0;return!1;default:return!0}})},a.prototype._expandPair=function(a,b){var c;return c=a.name,a.explode?Array.isArray(b)?this.explodeArray(a,b):"string"==typeof b?this.stringifySingle(a,b):this.explodeObject(b):this.stringifySingle(a,b)},a.prototype.explodeArray=function(a,b){return b.map(this.encode).join(this.sep)},a.prototype.explodeObject=function(a){var b,c,d,e,f,g;c=[];for(b in a)if(d=a[b],b=this.encode(b),Array.isArray(d))for(f=0,g=d.length;g>f;f++)e=d[f],c.push([b,this.encode(e)]);else c.push([b,this.encode(d)]);return c.map(function(a){return a.join("=")}).join(this.sep)},a.prototype.toString=function(){var a;return a=this.params.map(function(a){return a.name+a.explode}).join(","),"{"+this.first+a+"}"+this.suffix},a.prototype.toJSON=function(){return this.toString()},a}(),g=function(a){function b(){return this.explodeArray=v(this.explodeArray,this),this.stringifySingle=v(this.stringifySingle,this),n=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.stringifySingle=function(a,c){return c=(c=b.__super__.stringifySingle.apply(this,arguments))?"="+c:this.empty,""+a.name+c},b.prototype.explodeArray=function(a,b){var c=this;return b.map(function(b){return""+a.name+"="+c.encode(b)}).join(this.sep)},b}(k),j=function(a){function b(){return o=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.encode=function(a){return m["U+R"](a)},b.prototype.toString=function(){return"{+"+b.__super__.toString.apply(this,arguments).substring(1)},b}(k),e=function(a){function b(){return p=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first="#",b.prototype.empty="#",b.prototype.encode=function(a){return m["U+R"](a)},b}(k),f=function(a){function b(){return q=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first=".",b.prototype.sep=".",b.prototype.empty=".",b}(k),i=function(a){function b(){return r=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first="/",b.prototype.sep="/",b}(k),h=function(a){function b(){return s=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first=";",b.prototype.sep=";",b}(g),d=function(a){function b(){return t=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first="?",b.prototype.sep="&",b.prototype.empty="=",b}(g),c=function(a){function b(){return u=b.__super__.constructor.apply(this,arguments)}return x(b,a),b.prototype.first="&",b}(d),b.exports={Template:l,SimpleExpression:k,NamedExpression:g,ReservedExpression:j,FragmentExpression:e,LabelExpression:f,PathSegmentExpression:i,PathParamExpression:h,FormStartExpression:d,FormContinuationExpression:c,expression:function(a,b){var g;return g=function(){switch(a){case"":return k;case"+":return j;case"#":return e;case".":return f;case"/":return i;case";":return h;case"?":return d;case"&":return c}}(),new g(b)}}}).call(this)},{"./encoders":22}],22:[function(a,b,c){(function(){var b;b=a("pct-encode"),c.U=b(/[^\w~.-]/g),c["U+R"]=b(/[^\w.~:\/\?#\[\]@!\$&'()*+,;=-]/g)}).call(this)},{"pct-encode":23}],23:[function(a,b){b.exports=function(a){return a=a||/\W/g,function(b){return b=String(b),b.replace(a,function(a){var b=a[0].charCodeAt(0),c=[];return 128>b?c.push(b):b>=128&&2048>b?(c.push(b>>6|192),c.push(63&b|128)):(c.push(b>>12|224),c.push(b>>6&63|128),c.push(63&b|128)),c.map(function(a){return"%"+a.toString(16).toUpperCase()}).join("")})}}},{}],24:[function(a,b){"use strict";var c=(a("minilog"),a("./lib/media_types")),d=a("./lib/builder");b.exports={json:{from:function(a){return{newRequest:function(){return new d(c.JSON,a)}}}},jsonHal:{from:function(a){return{newRequest:function(){return new d(c.JSON_HAL,a)}}}}}},{"./lib/builder":6,"./lib/media_types":10,minilog:1}]},{},[24])(24)});
View
47 browser/lib/shim/request.js
@@ -13,57 +13,76 @@ Request.prototype.defaults = function(options) {
}
Request.prototype.get = function(uri, callback) {
- setupRequest(superagent.get(uri), this.options)
+ mapRequest(superagent.get(uri), this.options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
Request.prototype.post = function(uri, options, callback) {
- setupRequest(superagent.post(uri), this.options, options)
+ mapRequest(superagent.post(uri), this.options, options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
Request.prototype.put = function(uri, options, callback) {
- setupRequest(superagent.put(uri), this.options, options)
+ mapRequest(superagent.put(uri), this.options, options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
Request.prototype.patch = function(uri, options, callback) {
- setupRequest(superagent.patch(uri), this.options, options)
+ mapRequest(superagent.patch(uri), this.options, options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
Request.prototype.del = function(uri, options, callback) {
- setupRequest(superagent.del(uri), this.options)
+ mapRequest(superagent.del(uri), this.options)
.end(function(response) {
- callback(null, map(response))
+ callback(null, mapResponse(response))
})
}
-function setupRequest(superagentRequest, options, bodyOptions) {
+function mapRequest(superagentRequest, options, bodyOptions) {
+ mapHeaders(superagentRequest, options)
+ mapAuth(superagentRequest, options)
+ mapBody(superagentRequest, options, bodyOptions)
+ return superagentRequest
+}
+
+function mapHeaders(superagentRequest, options) {
var headers = options.headers
if (headers != null) {
- superagentRequest = superagentRequest.set(options.headers)
+ superagentRequest = superagentRequest.set(headers)
}
+}
+
+function mapAuth(superagentRequest, options) {
+ var auth = options.auth
+ if (auth != null) {
+ superagentRequest = superagentRequest.auth(
+ auth.user || auth.username,
+ auth.pass || auth.password
+ )
+ }
+}
+
+function mapBody(superagentRequest, options, bodyOptions) {
if (bodyOptions != null) {
var body = bodyOptions.body
if (body != null) {
superagentRequest = superagentRequest.send(body)
}
}
- return superagentRequest
}
// map XHR response object properties to Node.js request lib's response object
// properties
-function map(response) {
+function mapResponse(response) {
response.body = response.text
response.statusCode = response.status
return response
View
23 browser/test/browserified_tests.js
22 additions, 1 deletion not shown because the diff is too large. Please use a local Git client to view these changes.
View
9 server/app.js
@@ -10,12 +10,6 @@ var app = express()
var server
var json = require('./routes')
-/*
-var root = require('./routes/root')
-var shop = require('./routes/shop')
-var customerCare = require('./routes/cc')
-var billing = require('./routes/billing')
-*/
exports.start = function() {
// all environments
@@ -50,11 +44,14 @@ exports.start = function() {
app.use(express.errorHandler())
}
+ var auth = express.basicAuth('traverson', 'verysecretpassword');
+
app.get('/', json.root.get)
app.get('/first', json.first.get)
app.get('/second', json.second.get)
app.get('/second/document', json.second.document.get)
app.get('/third', json.third.get)
+ app.get('/basic/auth', auth, json.auth.get)
app.get(/^\/(\w+)\/fixed\/(\w+)?$/, json.uriTemplate.get)
app.post('/postings', json.postings.post)
app.put('/puttings/42', json.puttings.put)
View
9 server/routes/index.js
@@ -16,6 +16,7 @@ module.exports = {
'jsonpath': {
'nested': { 'key': root + '/third' }
},
+ 'auth': root + '/basic/auth',
'uri_template': root + '/{param}/fixed{/id}',
'post_link': root + '/postings',
'put_link': root + '/puttings/42',
@@ -103,6 +104,14 @@ module.exports = {
}
},
+ auth: {
+ get: function(req, res) {
+ res.json({
+ 'user': 'authenticated'
+ })
+ }
+ },
+
uriTemplate: {
get: function(req, res) {
res.json({
View
21 test/localhost.js
@@ -167,6 +167,27 @@ describe('Traverson (when tested against a local server)', function() {
)
})
+ it('should authenticate', function(done) {
+ jsonApi
+ .withRequestOptions({
+ auth: {
+ user: 'traverson',
+ pass: 'verysecretpassword',
+ sendImmediately: false
+ }
+ }).follow('auth')
+ .getResource(callback)
+ waitFor(
+ function() { return callback.called },
+ function() {
+ var resultDoc = checkResultDoc()
+ expect(resultDoc.user).to.exist
+ expect(resultDoc.user).to.equal('authenticated')
+ done()
+ }
+ )
+ })
+
it('should leverage JSONPath', function(done) {
jsonApi.follow('$.jsonpath.nested.key').getResource(callback)
waitFor(

0 comments on commit 9eaa21b

Please sign in to comment.
Something went wrong with that request. Please try again.