!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.StratumnAgentClient=e.StratumnAgentClient||{})}(this,function(e){"use strict";function t(e,t){t?console.warn("WARNING: "+e+" is deprecated. Please use "+t+" instead."):console.warn("WARNING: "+e+" is deprecated.")}function n(e){var t=Object.keys(e).reduce(function(t,n){var r=Array.isArray(e[n])?e[n].join("+"):e[n];return t.push(encodeURIComponent(n)+"="+encodeURIComponent(r)),t},[]);return t.length?"?"+t.join("&"):""}function r(e){return e&&"object"==typeof e&&"default"in e?e.default:e}function o(e,t){return t={exports:{}},e(t,t.exports),t.exports}function s(e,t){return new Promise(function(n,r){function o(){t().then(function(){e()?o():n()}).catch(r)}setImmediate(o)})}function a(e,t,n){return new Promise(function(r,o){fe({method:e,url:t,body:n},function(e,t){if(e){var n=e&&e.body&&e.body.meta&&e.body.meta.errorMessage?new Error(e.body.meta.errorMessage):e;n.status=e.status,o(n)}else r(t)})})}function i(e){return a("GET",e)}function u(e,t){return a("POST",e,t)}function c(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},r=Object.assign({},t);if(t.limit===-1){r.limit=r.batchSize||pe,delete r.batchSize,r.offset=0;var o=[];return s(function(){return o.length===r.limit},function(){return c(e,r).then(function(e){o.push.apply(o,le(e)),r.offset+=r.limit})}).then(function(){return o})}return i(e.url+"/segments"+n(t)).then(function(t){return t.body.map(function(t){return l(e,t)})})}function f(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return t("Agent#getBranches(agent, prevLinkHash, tags = [])","Agent#findSegments(agent, filter)"),c(e,{prevLinkHash:n,tags:r})}function l(e,n){return Object.keys(e.agentInfo.actions).filter(function(e){return["init"].indexOf(e)<0}).forEach(function(t){n[t]=function(){for(var r=arguments.length,o=Array(r),s=0;s1?t-1:0),r=1;r1&&void 0!==arguments[1]?arguments[1]:{};return i(e.url+"/maps"+n(t)).then(function(e){return e.body})}function g(e,n){return t("Agent#getLink(agent, hash)","Agent#getSegment(agent, hash)"),d(e,n)}function m(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:[];return t("getMap(agent, mapId, tags = [])","findSegments(agent, filter)"),c(e,{mapId:n,tags:r})}function y(e){return i(e).then(function(t){var n=t.body;return n.url=e,n.createMap=p.bind(null,n),n.getSegment=d.bind(null,n),n.findSegments=c.bind(null,n),n.getMapIds=h.bind(null,n),n.getBranches=f.bind(null,n),n.getLink=g.bind(null,n),n.getMap=m.bind(null,n),n})}function v(e){return y(e.meta.agentUrl||e.meta.applicationLocation).then(function(t){var n=l(t,e);return{agent:t,segment:n}})}function b(e,n){return t("getApplication(name, url)","getAgent(url)"),y(n||de.applicationUrl.replace("%s",e))}function R(e){return t("loadLink(obj)","fromSegment(obj)"),v(e).then(function(e){var t=e.segment;return t})}var x="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{},w=o(function(e){!function(e,t){function n(e){"function"!=typeof e&&(e=new Function(""+e));for(var t=new Array(arguments.length-1),n=0;n=400}var n=r(W),o=r(Y);t.prototype.header=n.prototype.header,t.fromRequest=function(e){return new t(o(e))},e.exports=t}),ee=r(Z),te=Object.freeze({default:ee}),ne=o(function(e){function t(e,t){var n=new Error(e);n.name="RequestError",this.name=n.name,this.message=n.message,n.stack&&(this.stack=n.stack),this.toString=function(){return this.message};for(var r in t)t.hasOwnProperty(r)&&(this[r]=t[r])}var n=r(te),o=r(Y),s=r(K);t.prototype=s(Error.prototype),t.prototype.constructor=t,t.create=function(e,r,s){var a=new t(e,s);return n.call(a,o(r)),a},e.exports=t}),re=r(ne),oe=Object.freeze({default:re}),se=o(function(e){e.exports=function(e){var t,n=!1;return function(){return n||(n=!0,t=e.apply(this,arguments)),t}}}),ae=r(se),ie=Object.freeze({default:ae}),ue=o(function(e){function t(e,r){function s(t,s){var u,d,h,g,m,y;for(t=new f(l(e,t)),o=0;o