UNPKG

leopard-tie-client

Version:

Extended TIE Client that accepts additional custom request headers

2 lines (1 loc) 39.2 kB
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t=t||self,t.leopardTieClient=e())}(this,function(){"use strict";function t(t,e){return e={exports:{}},t(e,e.exports),e.exports}function e(t,e,o){r(t,"",[],void 0);var n;for(n=0===P.length?JSON.stringify(t,e,o):JSON.stringify(t,s(e),o);0!==A.length;){var i=A.pop();4===i.length?Object.defineProperty(i[0],i[1],i[3]):i[0][i[1]]=i[2]}return n}function r(t,e,o,n){var i;if("object"==typeof t&&null!==t){for(i=0;i<o.length;i++)if(o[i]===t){var s=Object.getOwnPropertyDescriptor(n,e);return void(void 0!==s.get?s.configurable?(Object.defineProperty(n,e,{value:"[Circular]"}),A.push([n,e,t,s])):P.push([t,e]):(n[e]="[Circular]",A.push([n,e,t])))}if(o.push(t),Array.isArray(t))for(i=0;i<t.length;i++)r(t[i],i,o,t);else{var a=Object.keys(t);for(i=0;i<a.length;i++){var u=a[i];r(t[u],u,o,t)}}o.pop()}}function o(t,e){return t<e?-1:t>e?1:0}function n(t,e,r){var o,n=i(t,"",[],void 0)||t;for(o=0===P.length?JSON.stringify(n,e,r):JSON.stringify(n,s(e),r);0!==A.length;){var a=A.pop();4===a.length?Object.defineProperty(a[0],a[1],a[3]):a[0][a[1]]=a[2]}return o}function i(t,e,r,n){var s;if("object"==typeof t&&null!==t){for(s=0;s<r.length;s++)if(r[s]===t){var a=Object.getOwnPropertyDescriptor(n,e);return void(void 0!==a.get?a.configurable?(Object.defineProperty(n,e,{value:"[Circular]"}),A.push([n,e,t,a])):P.push([t,e]):(n[e]="[Circular]",A.push([n,e,t])))}if("function"==typeof t.toJSON)return;if(r.push(t),Array.isArray(t))for(s=0;s<t.length;s++)i(t[s],s,r,t);else{var u={},c=Object.keys(t).sort(o);for(s=0;s<c.length;s++){var l=c[s];i(t[l],l,r,t),u[l]=t[l]}if(void 0===n)return u;A.push([n,e,t]),n[e]=u}r.pop()}}function s(t){return t=void 0!==t?t:function(t,e){return e},function(e,r){if(P.length>0)for(var o=0;o<P.length;o++){var n=P[o];if(n[1]===e&&n[0]===r){r="[Circular]",P.splice(o,1);break}}return t.call(this,e,r)}}function a(t){"@babel/helpers - typeof";return(a="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function u(t){return null!==t&&"object"===a(t)}function c(t){"@babel/helpers - typeof";return(c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function l(t){if(t)return p(t)}function p(t){for(var e in l.prototype)Object.prototype.hasOwnProperty.call(l.prototype,e)&&(t[e]=l.prototype[e]);return t}function f(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=h(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var o=0,n=function(){};return{s:n,n:function(){return o>=t.length?{done:!0}:{done:!1,value:t[o++]}},e:function(t){throw t},f:n}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}var i,s=!0,a=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return s=t.done,t},e:function(t){a=!0,i=t},f:function(){try{s||null==r.return||r.return()}finally{if(a)throw i}}}}function h(t,e){if(t){if("string"==typeof t)return d(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?d(t,e):void 0}}function d(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,o=new Array(e);r<e;r++)o[r]=t[r];return o}function y(t){if(t)return m(t)}function m(t){for(var e in y.prototype)Object.prototype.hasOwnProperty.call(y.prototype,e)&&(t[e]=y.prototype[e]);return t}function b(t){return _(t)||w(t)||g(t)||v()}function v(){throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function g(t,e){if(t){if("string"==typeof t)return O(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);return"Object"===r&&t.constructor&&(r=t.constructor.name),"Map"===r||"Set"===r?Array.from(t):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?O(t,e):void 0}}function w(t){if("undefined"!=typeof Symbol&&Symbol.iterator in Object(t))return Array.from(t)}function _(t){if(Array.isArray(t))return O(t)}function O(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,o=new Array(e);r<e;r++)o[r]=t[r];return o}function j(){this._defaults=[]}function T(t,e,r){void 0===r&&(r=20);var o=Pt(At(t)+"endsession",e),n=e&&Et?{Cookie:"JSESSIONID="+e}:{};return Ot.post(o,Ct(),n,r)}function E(t,e,r,o){void 0===o&&(o=20),Rt(r);var n=St(e,r),i=kt(r),s=Ct(Object.assign({userinput:r.text},i)),a=Pt(At(t),e);return Ot.post(a,s,n,o)}function x(t){return new jt(t)}void 0!==typeof self&&self;var S=t(function(t){function e(t){if(t)return r(t)}function r(t){for(var r in e.prototype)t[r]=e.prototype[r];return t}t.exports=e,e.prototype.on=e.prototype.addEventListener=function(t,e){return this._callbacks=this._callbacks||{},(this._callbacks["$"+t]=this._callbacks["$"+t]||[]).push(e),this},e.prototype.once=function(t,e){function r(){this.off(t,r),e.apply(this,arguments)}return r.fn=e,this.on(t,r),this},e.prototype.off=e.prototype.removeListener=e.prototype.removeAllListeners=e.prototype.removeEventListener=function(t,e){if(this._callbacks=this._callbacks||{},0==arguments.length)return this._callbacks={},this;var r=this._callbacks["$"+t];if(!r)return this;if(1==arguments.length)return delete this._callbacks["$"+t],this;for(var o,n=0;n<r.length;n++)if((o=r[n])===e||o.fn===e){r.splice(n,1);break}return 0===r.length&&delete this._callbacks["$"+t],this},e.prototype.emit=function(t){this._callbacks=this._callbacks||{};for(var e=new Array(arguments.length-1),r=this._callbacks["$"+t],o=1;o<arguments.length;o++)e[o-1]=arguments[o];if(r)for(var o=0,n=(r=r.slice(0)).length;o<n;++o)r[o].apply(this,e);return this},e.prototype.listeners=function(t){return this._callbacks=this._callbacks||{},this._callbacks["$"+t]||[]},e.prototype.hasListeners=function(t){return!!this.listeners(t).length}}),k=e;e.default=e,e.stable=n,e.stableStringify=n;var A=[],P=[],C=Object.prototype.hasOwnProperty,R=Array.isArray,N=function(){for(var t=[],e=0;e<256;++e)t.push("%"+((e<16?"0":"")+e.toString(16)).toUpperCase());return t}(),D=function(t){for(;t.length>1;){var e=t.pop(),r=e.obj[e.prop];if(R(r)){for(var o=[],n=0;n<r.length;++n)void 0!==r[n]&&o.push(r[n]);e.obj[e.prop]=o}}},L=function(t,e){for(var r=e&&e.plainObjects?Object.create(null):{},o=0;o<t.length;++o)void 0!==t[o]&&(r[o]=t[o]);return r},H={arrayToObject:L,assign:function(t,e){return Object.keys(e).reduce(function(t,r){return t[r]=e[r],t},t)},combine:function(t,e){return[].concat(t,e)},compact:function(t){for(var e=[{obj:{o:t},prop:"o"}],r=[],o=0;o<e.length;++o)for(var n=e[o],i=n.obj[n.prop],s=Object.keys(i),a=0;a<s.length;++a){var u=s[a],c=i[u];"object"==typeof c&&null!==c&&-1===r.indexOf(c)&&(e.push({obj:i,prop:u}),r.push(c))}return D(e),t},decode:function(t,e,r){var o=t.replace(/\+/g," ");if("iso-8859-1"===r)return o.replace(/%[0-9a-f]{2}/gi,unescape);try{return decodeURIComponent(o)}catch(t){return o}},encode:function(t,e,r){if(0===t.length)return t;var o=t;if("symbol"==typeof t?o=Symbol.prototype.toString.call(t):"string"!=typeof t&&(o=String(t)),"iso-8859-1"===r)return escape(o).replace(/%u[0-9a-f]{4}/gi,function(t){return"%26%23"+parseInt(t.slice(2),16)+"%3B"});for(var n="",i=0;i<o.length;++i){var s=o.charCodeAt(i);45===s||46===s||95===s||126===s||s>=48&&s<=57||s>=65&&s<=90||s>=97&&s<=122?n+=o.charAt(i):s<128?n+=N[s]:s<2048?n+=N[192|s>>6]+N[128|63&s]:s<55296||s>=57344?n+=N[224|s>>12]+N[128|s>>6&63]+N[128|63&s]:(i+=1,s=65536+((1023&s)<<10|1023&o.charCodeAt(i)),n+=N[240|s>>18]+N[128|s>>12&63]+N[128|s>>6&63]+N[128|63&s])}return n},isBuffer:function(t){return!(!t||"object"!=typeof t)&&!!(t.constructor&&t.constructor.isBuffer&&t.constructor.isBuffer(t))},isRegExp:function(t){return"[object RegExp]"===Object.prototype.toString.call(t)},maybeMap:function(t,e){if(R(t)){for(var r=[],o=0;o<t.length;o+=1)r.push(e(t[o]));return r}return e(t)},merge:function t(e,r,o){if(!r)return e;if("object"!=typeof r){if(R(e))e.push(r);else{if(!e||"object"!=typeof e)return[e,r];(o&&(o.plainObjects||o.allowPrototypes)||!C.call(Object.prototype,r))&&(e[r]=!0)}return e}if(!e||"object"!=typeof e)return[e].concat(r);var n=e;return R(e)&&!R(r)&&(n=L(e,o)),R(e)&&R(r)?(r.forEach(function(r,n){if(C.call(e,n)){var i=e[n];i&&"object"==typeof i&&r&&"object"==typeof r?e[n]=t(i,r,o):e.push(r)}else e[n]=r}),e):Object.keys(r).reduce(function(e,n){var i=r[n];return C.call(e,n)?e[n]=t(e[n],i,o):e[n]=i,e},n)}},I=String.prototype.replace,q={RFC1738:"RFC1738",RFC3986:"RFC3986"},U=H.assign({default:q.RFC3986,formatters:{RFC1738:function(t){return I.call(t,/%20/g,"+")},RFC3986:function(t){return String(t)}}},q),z=Object.prototype.hasOwnProperty,M={brackets:function(t){return t+"[]"},comma:"comma",indices:function(t,e){return t+"["+e+"]"},repeat:function(t){return t}},B=Array.isArray,F=Array.prototype.push,J=function(t,e){F.apply(t,B(e)?e:[e])},Q=Date.prototype.toISOString,$=U.default,X={addQueryPrefix:!1,allowDots:!1,charset:"utf-8",charsetSentinel:!1,delimiter:"&",encode:!0,encoder:H.encode,encodeValuesOnly:!1,format:$,formatter:U.formatters[$],indices:!1,serializeDate:function(t){return Q.call(t)},skipNulls:!1,strictNullHandling:!1},W=function(t){return"string"==typeof t||"number"==typeof t||"boolean"==typeof t||"symbol"==typeof t||"bigint"==typeof t},G=function t(e,r,o,n,i,s,a,u,c,l,p,f,h){var d=e;if("function"==typeof a?d=a(r,d):d instanceof Date?d=l(d):"comma"===o&&B(d)&&(d=H.maybeMap(d,function(t){return t instanceof Date?l(t):t}).join(",")),null===d){if(n)return s&&!f?s(r,X.encoder,h,"key"):r;d=""}if(W(d)||H.isBuffer(d))return s?[p(f?r:s(r,X.encoder,h,"key"))+"="+p(s(d,X.encoder,h,"value"))]:[p(r)+"="+p(String(d))];var y=[];if(void 0===d)return y;var m;if(B(a))m=a;else{var b=Object.keys(d);m=u?b.sort(u):b}for(var v=0;v<m.length;++v){var g=m[v],w=d[g];if(!i||null!==w){var _=B(d)?"function"==typeof o?o(r,g):r:r+(c?"."+g:"["+g+"]");J(y,t(w,_,o,n,i,s,a,u,c,l,p,f,h))}}return y},V=function(t){if(!t)return X;if(null!==t.encoder&&void 0!==t.encoder&&"function"!=typeof t.encoder)throw new TypeError("Encoder has to be a function.");var e=t.charset||X.charset;if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var r=U.default;if(void 0!==t.format){if(!z.call(U.formatters,t.format))throw new TypeError("Unknown format option provided.");r=t.format}var o=U.formatters[r],n=X.filter;return("function"==typeof t.filter||B(t.filter))&&(n=t.filter),{addQueryPrefix:"boolean"==typeof t.addQueryPrefix?t.addQueryPrefix:X.addQueryPrefix,allowDots:void 0===t.allowDots?X.allowDots:!!t.allowDots,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:X.charsetSentinel,delimiter:void 0===t.delimiter?X.delimiter:t.delimiter,encode:"boolean"==typeof t.encode?t.encode:X.encode,encoder:"function"==typeof t.encoder?t.encoder:X.encoder,encodeValuesOnly:"boolean"==typeof t.encodeValuesOnly?t.encodeValuesOnly:X.encodeValuesOnly,filter:n,formatter:o,serializeDate:"function"==typeof t.serializeDate?t.serializeDate:X.serializeDate,skipNulls:"boolean"==typeof t.skipNulls?t.skipNulls:X.skipNulls,sort:"function"==typeof t.sort?t.sort:null,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:X.strictNullHandling}},K=function(t,e){var r,o=t,n=V(e);"function"==typeof n.filter?o=(0,n.filter)("",o):B(n.filter)&&(r=n.filter);var i=[];if("object"!=typeof o||null===o)return"";var s;s=e&&e.arrayFormat in M?e.arrayFormat:e&&"indices"in e?e.indices?"indices":"repeat":"indices";var a=M[s];r||(r=Object.keys(o)),n.sort&&r.sort(n.sort);for(var u=0;u<r.length;++u){var c=r[u];n.skipNulls&&null===o[c]||J(i,G(o[c],c,a,n.strictNullHandling,n.skipNulls,n.encode?n.encoder:null,n.filter,n.sort,n.allowDots,n.serializeDate,n.formatter,n.encodeValuesOnly,n.charset))}var l=i.join(n.delimiter),p=!0===n.addQueryPrefix?"?":"";return n.charsetSentinel&&("iso-8859-1"===n.charset?p+="utf8=%26%2310003%3B&":p+="utf8=%E2%9C%93&"),l.length>0?p+l:""},Y=Object.prototype.hasOwnProperty,Z=Array.isArray,tt={allowDots:!1,allowPrototypes:!1,arrayLimit:20,charset:"utf-8",charsetSentinel:!1,comma:!1,decoder:H.decode,delimiter:"&",depth:5,ignoreQueryPrefix:!1,interpretNumericEntities:!1,parameterLimit:1e3,parseArrays:!0,plainObjects:!1,strictNullHandling:!1},et=function(t){return t.replace(/&#(\d+);/g,function(t,e){return String.fromCharCode(parseInt(e,10))})},rt=function(t,e){return t&&"string"==typeof t&&e.comma&&t.indexOf(",")>-1?t.split(","):t},ot=function(t,e){var r,o={},n=e.ignoreQueryPrefix?t.replace(/^\?/,""):t,i=e.parameterLimit===1/0?void 0:e.parameterLimit,s=n.split(e.delimiter,i),a=-1,u=e.charset;if(e.charsetSentinel)for(r=0;r<s.length;++r)0===s[r].indexOf("utf8=")&&("utf8=%E2%9C%93"===s[r]?u="utf-8":"utf8=%26%2310003%3B"===s[r]&&(u="iso-8859-1"),a=r,r=s.length);for(r=0;r<s.length;++r)if(r!==a){var c,l,p=s[r],f=p.indexOf("]="),h=-1===f?p.indexOf("="):f+1;-1===h?(c=e.decoder(p,tt.decoder,u,"key"),l=e.strictNullHandling?null:""):(c=e.decoder(p.slice(0,h),tt.decoder,u,"key"),l=H.maybeMap(rt(p.slice(h+1),e),function(t){return e.decoder(t,tt.decoder,u,"value")})),l&&e.interpretNumericEntities&&"iso-8859-1"===u&&(l=et(l)),p.indexOf("[]=")>-1&&(l=Z(l)?[l]:l),Y.call(o,c)?o[c]=H.combine(o[c],l):o[c]=l}return o},nt=function(t,e,r,o){for(var n=o?e:rt(e,r),i=t.length-1;i>=0;--i){var s,a=t[i];if("[]"===a&&r.parseArrays)s=[].concat(n);else{s=r.plainObjects?Object.create(null):{};var u="["===a.charAt(0)&&"]"===a.charAt(a.length-1)?a.slice(1,-1):a,c=parseInt(u,10);r.parseArrays||""!==u?!isNaN(c)&&a!==u&&String(c)===u&&c>=0&&r.parseArrays&&c<=r.arrayLimit?(s=[])[c]=n:s[u]=n:s={0:n}}n=s}return n},it=function(t,e,r,o){if(t){var n=r.allowDots?t.replace(/\.([^.[]+)/g,"[$1]"):t,i=/(\[[^[\]]*])/,s=/(\[[^[\]]*])/g,a=r.depth>0&&i.exec(n),u=a?n.slice(0,a.index):n,c=[];if(u){if(!r.plainObjects&&Y.call(Object.prototype,u)&&!r.allowPrototypes)return;c.push(u)}for(var l=0;r.depth>0&&null!==(a=s.exec(n))&&l<r.depth;){if(l+=1,!r.plainObjects&&Y.call(Object.prototype,a[1].slice(1,-1))&&!r.allowPrototypes)return;c.push(a[1])}return a&&c.push("["+n.slice(a.index)+"]"),nt(c,e,r,o)}},st=function(t){if(!t)return tt;if(null!==t.decoder&&void 0!==t.decoder&&"function"!=typeof t.decoder)throw new TypeError("Decoder has to be a function.");if(void 0!==t.charset&&"utf-8"!==t.charset&&"iso-8859-1"!==t.charset)throw new TypeError("The charset option must be either utf-8, iso-8859-1, or undefined");var e=void 0===t.charset?tt.charset:t.charset;return{allowDots:void 0===t.allowDots?tt.allowDots:!!t.allowDots,allowPrototypes:"boolean"==typeof t.allowPrototypes?t.allowPrototypes:tt.allowPrototypes,arrayLimit:"number"==typeof t.arrayLimit?t.arrayLimit:tt.arrayLimit,charset:e,charsetSentinel:"boolean"==typeof t.charsetSentinel?t.charsetSentinel:tt.charsetSentinel,comma:"boolean"==typeof t.comma?t.comma:tt.comma,decoder:"function"==typeof t.decoder?t.decoder:tt.decoder,delimiter:"string"==typeof t.delimiter||H.isRegExp(t.delimiter)?t.delimiter:tt.delimiter,depth:"number"==typeof t.depth||!1===t.depth?+t.depth:tt.depth,ignoreQueryPrefix:!0===t.ignoreQueryPrefix,interpretNumericEntities:"boolean"==typeof t.interpretNumericEntities?t.interpretNumericEntities:tt.interpretNumericEntities,parameterLimit:"number"==typeof t.parameterLimit?t.parameterLimit:tt.parameterLimit,parseArrays:!1!==t.parseArrays,plainObjects:"boolean"==typeof t.plainObjects?t.plainObjects:tt.plainObjects,strictNullHandling:"boolean"==typeof t.strictNullHandling?t.strictNullHandling:tt.strictNullHandling}},at={formats:U,parse:function(t,e){var r=st(e);if(""===t||null===t||void 0===t)return r.plainObjects?Object.create(null):{};for(var o="string"==typeof t?ot(t,r):t,n=r.plainObjects?Object.create(null):{},i=Object.keys(o),s=0;s<i.length;++s){var a=i[s],u=it(a,o[a],r,"string"==typeof t);n=H.merge(n,u,r)}return H.compact(n)},stringify:K},ut=u,ct=l;l.prototype.clearTimeout=function(){return clearTimeout(this._timer),clearTimeout(this._responseTimeoutTimer),clearTimeout(this._uploadTimeoutTimer),delete this._timer,delete this._responseTimeoutTimer,delete this._uploadTimeoutTimer,this},l.prototype.parse=function(t){return this._parser=t,this},l.prototype.responseType=function(t){return this._responseType=t,this},l.prototype.serialize=function(t){return this._serializer=t,this},l.prototype.timeout=function(t){if(!t||"object"!==c(t))return this._timeout=t,this._responseTimeout=0,this._uploadTimeout=0,this;for(var e in t)if(Object.prototype.hasOwnProperty.call(t,e))switch(e){case"deadline":this._timeout=t.deadline;break;case"response":this._responseTimeout=t.response;break;case"upload":this._uploadTimeout=t.upload;break;default:console.warn("Unknown timeout option",e)}return this},l.prototype.retry=function(t,e){return 0!==arguments.length&&!0!==t||(t=1),t<=0&&(t=0),this._maxRetries=t,this._retries=0,this._retryCallback=e,this};var lt=new Set(["ETIMEDOUT","ECONNRESET","EADDRINUSE","ECONNREFUSED","EPIPE","ENOTFOUND","ENETUNREACH","EAI_AGAIN"]),pt=new Set([408,413,429,500,502,503,504,521,522,524]);l.prototype._shouldRetry=function(t,e){if(!this._maxRetries||this._retries++>=this._maxRetries)return!1;if(this._retryCallback)try{var r=this._retryCallback(t,e);if(!0===r)return!0;if(!1===r)return!1}catch(t){console.error(t)}if(e&&e.status&&pt.has(e.status))return!0;if(t){if(t.code&&lt.has(t.code))return!0;if(t.timeout&&"ECONNABORTED"===t.code)return!0;if(t.crossDomain)return!0}return!1},l.prototype._retry=function(){return this.clearTimeout(),this.req&&(this.req=null,this.req=this.request()),this._aborted=!1,this.timedout=!1,this.timedoutError=null,this._end()},l.prototype.then=function(t,e){var r=this;if(!this._fullfilledPromise){var o=this;this._endCalled&&console.warn("Warning: superagent request was sent twice, because both .end() and .then() were called. Never call .end() if you use promises"),this._fullfilledPromise=new Promise(function(t,e){o.on("abort",function(){if(!(r._maxRetries&&r._maxRetries>r._retries)){if(r.timedout&&r.timedoutError)return void e(r.timedoutError);var t=new Error("Aborted");t.code="ABORTED",t.status=r.status,t.method=r.method,t.url=r.url,e(t)}}),o.end(function(r,o){r?e(r):t(o)})})}return this._fullfilledPromise.then(t,e)},l.prototype.catch=function(t){return this.then(void 0,t)},l.prototype.use=function(t){return t(this),this},l.prototype.ok=function(t){if("function"!=typeof t)throw new Error("Callback required");return this._okCallback=t,this},l.prototype._isResponseOK=function(t){return!!t&&(this._okCallback?this._okCallback(t):t.status>=200&&t.status<300)},l.prototype.get=function(t){return this._header[t.toLowerCase()]},l.prototype.getHeader=l.prototype.get,l.prototype.set=function(t,e){if(ut(t)){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&this.set(r,t[r]);return this}return this._header[t.toLowerCase()]=e,this.header[t]=e,this},l.prototype.unset=function(t){return delete this._header[t.toLowerCase()],delete this.header[t],this},l.prototype.field=function(t,e){if(null===t||void 0===t)throw new Error(".field(name, val) name can not be empty");if(this._data)throw new Error(".field() can't be used if .send() is used. Please use only .send() or only .field() & .attach()");if(ut(t)){for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&this.field(r,t[r]);return this}if(Array.isArray(e)){for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&this.field(t,e[o]);return this}if(null===e||void 0===e)throw new Error(".field(name, val) val can not be empty");return"boolean"==typeof e&&(e=String(e)),this._getFormData().append(t,e),this},l.prototype.abort=function(){return this._aborted?this:(this._aborted=!0,this.xhr&&this.xhr.abort(),this.req&&this.req.abort(),this.clearTimeout(),this.emit("abort"),this)},l.prototype._auth=function(t,e,r,o){switch(r.type){case"basic":this.set("Authorization","Basic ".concat(o("".concat(t,":").concat(e))));break;case"auto":this.username=t,this.password=e;break;case"bearer":this.set("Authorization","Bearer ".concat(t))}return this},l.prototype.withCredentials=function(t){return void 0===t&&(t=!0),this._withCredentials=t,this},l.prototype.redirects=function(t){return this._maxRedirects=t,this},l.prototype.maxResponseSize=function(t){if("number"!=typeof t)throw new TypeError("Invalid argument");return this._maxResponseSize=t,this},l.prototype.toJSON=function(){return{method:this.method,url:this.url,data:this._data,headers:this._header}},l.prototype.send=function(t){var e=ut(t),r=this._header["content-type"];if(this._formData)throw new Error(".send() can't be used if .attach() or .field() is used. Please use only .send() or only .field() & .attach()");if(e&&!this._data)Array.isArray(t)?this._data=[]:this._isHost(t)||(this._data={});else if(t&&this._data&&this._isHost(this._data))throw new Error("Can't merge these send calls");if(e&&ut(this._data))for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(this._data[o]=t[o]);else"string"==typeof t?(r||this.type("form"),(r=this._header["content-type"])&&(r=r.toLowerCase().trim()),this._data="application/x-www-form-urlencoded"===r?this._data?"".concat(this._data,"&").concat(t):t:(this._data||"")+t):this._data=t;return!e||this._isHost(t)?this:(r||this.type("json"),this)},l.prototype.sortQuery=function(t){return this._sort=void 0===t||t,this},l.prototype._finalizeQueryString=function(){var t=this._query.join("&");if(t&&(this.url+=(this.url.includes("?")?"&":"?")+t),this._query.length=0,this._sort){var e=this.url.indexOf("?");if(e>=0){var r=this.url.slice(e+1).split("&");"function"==typeof this._sort?r.sort(this._sort):r.sort(),this.url=this.url.slice(0,e)+"?"+r.join("&")}}},l.prototype._appendQueryString=function(){console.warn("Unsupported")},l.prototype._timeoutError=function(t,e,r){if(!this._aborted){var o=new Error("".concat(t+e,"ms exceeded"));o.timeout=e,o.code="ECONNABORTED",o.errno=r,this.timedout=!0,this.timedoutError=o,this.abort(),this.callback(o)}},l.prototype._setTimeouts=function(){var t=this;this._timeout&&!this._timer&&(this._timer=setTimeout(function(){t._timeoutError("Timeout of ",t._timeout,"ETIME")},this._timeout)),this._responseTimeout&&!this._responseTimeoutTimer&&(this._responseTimeoutTimer=setTimeout(function(){t._timeoutError("Response timeout of ",t._responseTimeout,"ETIMEDOUT")},this._responseTimeout))};var ft={type:function(t){return t.split(/ *; */).shift()},params:function(t){var e,r={},o=f(t.split(/ *; */));try{for(o.s();!(e=o.n()).done;){var n=e.value.split(/ *= */),i=n.shift(),s=n.shift();i&&s&&(r[i]=s)}}catch(t){o.e(t)}finally{o.f()}return r},parseLinks:function(t){var e,r={},o=f(t.split(/ *, */));try{for(o.s();!(e=o.n()).done;){var n=e.value.split(/ *; */),i=n[0].slice(1,-1);r[n[1].split(/ *= */)[1].slice(1,-1)]=i}}catch(t){o.e(t)}finally{o.f()}return r},cleanHeader:function(t,e){return delete t["content-type"],delete t["content-length"],delete t["transfer-encoding"],delete t.host,e&&(delete t.authorization,delete t.cookie),t}},ht=y;y.prototype.get=function(t){return this.header[t.toLowerCase()]},y.prototype._setHeaderProperties=function(t){var e=t["content-type"]||"";this.type=ft.type(e);var r=ft.params(e);for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&(this[o]=r[o]);this.links={};try{t.link&&(this.links=ft.parseLinks(t.link))}catch(t){}},y.prototype._setStatusProperties=function(t){var e=t/100|0;this.statusCode=t,this.status=this.statusCode,this.statusType=e,this.info=1===e,this.ok=2===e,this.redirect=3===e,this.clientError=4===e,this.serverError=5===e,this.error=(4===e||5===e)&&this.toError(),this.created=201===t,this.accepted=202===t,this.noContent=204===t,this.badRequest=400===t,this.unauthorized=401===t,this.notAcceptable=406===t,this.forbidden=403===t,this.notFound=404===t,this.unprocessableEntity=422===t},["use","on","once","set","query","type","accept","auth","withCredentials","sortQuery","retry","ok","redirects","timeout","buffer","serialize","parse","ca","key","pfx","cert","disableTLSCerts"].forEach(function(t){j.prototype[t]=function(){for(var e=arguments.length,r=new Array(e),o=0;o<e;o++)r[o]=arguments[o];return this._defaults.push({fn:t,args:r}),this}}),j.prototype._setDefaults=function(t){this._defaults.forEach(function(e){t[e.fn].apply(t,b(e.args))})};var dt=j,yt=t(function(t,e){function r(t){"@babel/helpers - typeof";return(r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function o(){}function n(t){if(!ut(t))return t;var e=[];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&i(e,r,t[r]);return e.join("&")}function i(t,e,r){if(void 0!==r){if(null===r)return void t.push(encodeURI(e));if(Array.isArray(r))r.forEach(function(r){i(t,e,r)});else if(ut(r))for(var o in r)Object.prototype.hasOwnProperty.call(r,o)&&i(t,"".concat(e,"[").concat(o,"]"),r[o]);else t.push(encodeURI(e)+"="+encodeURIComponent(r))}}function s(t){for(var e,r,o={},n=t.split("&"),i=0,s=n.length;i<s;++i)-1===(r=(e=n[i]).indexOf("="))?o[decodeURIComponent(e)]="":o[decodeURIComponent(e.slice(0,r))]=decodeURIComponent(e.slice(r+1));return o}function a(t){for(var e,r,o,n,i=t.split(/\r?\n/),s={},a=0,u=i.length;a<u;++a)-1!==(e=(r=i[a]).indexOf(":"))&&(o=r.slice(0,e).toLowerCase(),n=d(r.slice(e+1)),s[o]=n);return s}function u(t){return/[/+]json($|[^-\w])/i.test(t)}function c(t){this.req=t,this.xhr=this.req.xhr,this.text="HEAD"!==this.req.method&&(""===this.xhr.responseType||"text"===this.xhr.responseType)||void 0===this.xhr.responseType?this.xhr.responseText:null,this.statusText=this.req.xhr.statusText;var e=this.xhr.status;1223===e&&(e=204),this._setStatusProperties(e),this.headers=a(this.xhr.getAllResponseHeaders()),this.header=this.headers,this.header["content-type"]=this.xhr.getResponseHeader("content-type"),this._setHeaderProperties(this.header),null===this.text&&t._responseType?this.body=this.xhr.response:this.body="HEAD"===this.req.method?null:this._parseBody(this.text?this.text:this.xhr.response)}function l(t,e){var r=this;this._query=this._query||[],this.method=t,this.url=e,this.header={},this._header={},this.on("end",function(){var t=null,e=null;try{e=new c(r)}catch(e){return t=new Error("Parser is unable to parse the response"),t.parse=!0,t.original=e,r.xhr?(t.rawResponse=void 0===r.xhr.responseType?r.xhr.responseText:r.xhr.response,t.status=r.xhr.status?r.xhr.status:null,t.statusCode=t.status):(t.rawResponse=null,t.status=null),r.callback(t)}r.emit("response",e);var o;try{r._isResponseOK(e)||(o=new Error(e.statusText||e.text||"Unsuccessful HTTP response"))}catch(t){o=t}o?(o.original=t,o.response=e,o.status=e.status,r.callback(o,e)):r.callback(null,e)})}function p(t,e,r){var o=h("DELETE",t);return"function"==typeof e&&(r=e,e=null),e&&o.send(e),r&&o.end(r),o}var f;"undefined"!=typeof window?f=window:"undefined"==typeof self?(console.warn("Using browser-only version of superagent in non-browser environment"),f=void 0):f=self,t.exports=function(t,r){return"function"==typeof r?new e.Request("GET",t).end(r):1===arguments.length?new e.Request("GET",t):new e.Request(t,r)};var h=e=t.exports;e.Request=l,h.getXHR=function(){if(f.XMLHttpRequest&&(!f.location||"file:"!==f.location.protocol||!f.ActiveXObject))return new XMLHttpRequest;try{return new ActiveXObject("Microsoft.XMLHTTP")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.6.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP.3.0")}catch(t){}try{return new ActiveXObject("Msxml2.XMLHTTP")}catch(t){}throw new Error("Browser-only version of superagent could not find XHR")};var d="".trim?function(t){return t.trim()}:function(t){return t.replace(/(^\s*|\s*$)/g,"")};h.serializeObject=n,h.parseString=s,h.types={html:"text/html",json:"application/json",xml:"text/xml",urlencoded:"application/x-www-form-urlencoded",form:"application/x-www-form-urlencoded","form-data":"application/x-www-form-urlencoded"},h.serialize={"application/x-www-form-urlencoded":at.stringify,"application/json":k},h.parse={"application/x-www-form-urlencoded":s,"application/json":JSON.parse},ht(c.prototype),c.prototype._parseBody=function(t){var e=h.parse[this.type];return this.req._parser?this.req._parser(this,t):(!e&&u(this.type)&&(e=h.parse["application/json"]),e&&t&&(t.length>0||t instanceof Object)?e(t):null)},c.prototype.toError=function(){var t=this.req,e=t.method,r=t.url,o="cannot ".concat(e," ").concat(r," (").concat(this.status,")"),n=new Error(o);return n.status=this.status,n.method=e,n.url=r,n},h.Response=c,S(l.prototype),ct(l.prototype),l.prototype.type=function(t){return this.set("Content-Type",h.types[t]||t),this},l.prototype.accept=function(t){return this.set("Accept",h.types[t]||t),this},l.prototype.auth=function(t,e,o){1===arguments.length&&(e=""),"object"===r(e)&&null!==e&&(o=e,e=""),o||(o={type:"function"==typeof btoa?"basic":"auto"});var n=function(t){if("function"==typeof btoa)return btoa(t);throw new Error("Cannot use basic auth, btoa is not a function")};return this._auth(t,e,o,n)},l.prototype.query=function(t){return"string"!=typeof t&&(t=n(t)),t&&this._query.push(t),this},l.prototype.attach=function(t,e,r){if(e){if(this._data)throw new Error("superagent can't mix .send() and .attach()");this._getFormData().append(t,e,r||e.name)}return this},l.prototype._getFormData=function(){return this._formData||(this._formData=new f.FormData),this._formData},l.prototype.callback=function(t,e){if(this._shouldRetry(t,e))return this._retry();var r=this._callback;this.clearTimeout(),t&&(this._maxRetries&&(t.retries=this._retries-1),this.emit("error",t)),r(t,e)},l.prototype.crossDomainError=function(){var t=new Error("Request has been terminated\nPossible causes: the network is offline, Origin is not allowed by Access-Control-Allow-Origin, the page is being unloaded, etc.");t.crossDomain=!0,t.status=this.status,t.method=this.method,t.url=this.url,this.callback(t)},l.prototype.agent=function(){return console.warn("This is not supported in browser version of superagent"),this},l.prototype.ca=l.prototype.agent,l.prototype.buffer=l.prototype.ca,l.prototype.write=function(){throw new Error("Streaming is not supported in browser version of superagent")},l.prototype.pipe=l.prototype.write,l.prototype._isHost=function(t){return t&&"object"===r(t)&&!Array.isArray(t)&&"[object Object]"!==Object.prototype.toString.call(t)},l.prototype.end=function(t){this._endCalled&&console.warn("Warning: .end() was called twice. This is not supported in superagent"),this._endCalled=!0,this._callback=t||o,this._finalizeQueryString(),this._end()},l.prototype._setUploadTimeout=function(){var t=this;this._uploadTimeout&&!this._uploadTimeoutTimer&&(this._uploadTimeoutTimer=setTimeout(function(){t._timeoutError("Upload timeout of ",t._uploadTimeout,"ETIMEDOUT")},this._uploadTimeout))},l.prototype._end=function(){if(this._aborted)return this.callback(new Error("The request has been aborted even before .end() was called"));var t=this;this.xhr=h.getXHR();var e=this.xhr,r=this._formData||this._data;this._setTimeouts(),e.onreadystatechange=function(){var r=e.readyState;if(r>=2&&t._responseTimeoutTimer&&clearTimeout(t._responseTimeoutTimer),4===r){var o;try{o=e.status}catch(t){o=0}if(!o){if(t.timedout||t._aborted)return;return t.crossDomainError()}t.emit("end")}};var o=function(e,r){r.total>0&&(r.percent=r.loaded/r.total*100,100===r.percent&&clearTimeout(t._uploadTimeoutTimer)),r.direction=e,t.emit("progress",r)};if(this.hasListeners("progress"))try{e.addEventListener("progress",o.bind(null,"download")),e.upload&&e.upload.addEventListener("progress",o.bind(null,"upload"))}catch(t){}e.upload&&this._setUploadTimeout();try{this.username&&this.password?e.open(this.method,this.url,!0,this.username,this.password):e.open(this.method,this.url,!0)}catch(t){return this.callback(t)}if(this._withCredentials&&(e.withCredentials=!0),!this._formData&&"GET"!==this.method&&"HEAD"!==this.method&&"string"!=typeof r&&!this._isHost(r)){var n=this._header["content-type"],i=this._serializer||h.serialize[n?n.split(";")[0]:""];!i&&u(n)&&(i=h.serialize["application/json"]),i&&(r=i(r))}for(var s in this.header)null!==this.header[s]&&Object.prototype.hasOwnProperty.call(this.header,s)&&e.setRequestHeader(s,this.header[s]);this._responseType&&(e.responseType=this._responseType),this.emit("request",this),e.send(void 0===r?null:r)},h.agent=function(){return new dt},["GET","POST","OPTIONS","PATCH","PUT","DELETE"].forEach(function(t){dt.prototype[t.toLowerCase()]=function(e,r){var o=new h.Request(t,e);return this._setDefaults(o),r&&o.end(r),o}}),dt.prototype.del=dt.prototype.delete,h.get=function(t,e,r){var o=h("GET",t);return"function"==typeof e&&(r=e,e=null),e&&o.query(e),r&&o.end(r),o},h.head=function(t,e,r){var o=h("HEAD",t);return"function"==typeof e&&(r=e,e=null),e&&o.query(e),r&&o.end(r),o},h.options=function(t,e,r){var o=h("OPTIONS",t);return"function"==typeof e&&(r=e,e=null),e&&o.send(e),r&&o.end(r),o},h.del=p,h.delete=p,h.patch=function(t,e,r){var o=h("PATCH",t);return"function"==typeof e&&(r=e,e=null),e&&o.send(e),r&&o.end(r),o},h.post=function(t,e,r){var o=h("POST",t);return"function"==typeof e&&(r=e,e=null),e&&o.send(e),r&&o.end(r),o},h.put=function(t,e,r){var o=h("PUT",t);return"function"==typeof e&&(r=e,e=null),e&&o.send(e),r&&o.end(r),o}}),mt=(yt.Request,function(t){return Object.assign(t,{Accept:"application/json"})}),bt=function(t){var e=t.trim().toLowerCase();return e="true"===e||"false"!==e&&t.trim(),"boolean"==typeof e?e:/^\d+$/.test(e)?parseInt(e,16):e},vt=function(t){return!/^\s*$/.test(t)&&(t=t.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,"@"),t=t.replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,"]"),t=t.replace(/(?:^|:|,)(?:\s*\[)+/g,""),/^[\],:{}\s]*$/.test(t))},gt=function(t){for(var e=0,r=Object.entries(t.output.parameters);e<r.length;e++){var o=r[e],n=o[0],i=o[1];if(vt(i))try{var s=JSON.parse(i);t.output.parameters[n.trim()]=s}catch(e){delete t.output.parameters[n]}else i&&""!==i.trim()?t.output.parameters[n.trim()]=bt(i):delete t.output.parameters[n];n!==n.trim()&&n in t.output.parameters&&delete t.output.parameters[n]}return t},wt={status:1,message:"logout"},_t={timeout:{success:!1,status:2,message:"Request Timeout: "},net:{success:!1,status:3,message:"Network Error"},business:{success:!1,status:4,message:"System Error"}},Ot={post:function(t,e,r,o){return void 0===r&&(r={}),new Promise(function(n,i){yt.post(t).withCredentials().type("form").timeout({response:1e3*o,deadline:1e3*o}).set(mt(r)).send(e).then(function(t){var e=t.body;if(e instanceof Object&&"status"in e)return void n(gt(e));if(null===e)return void n(wt);var r=_t.business;return r.message=e,void i(r)},function(e){if(e.timeout){var r=Object.assign({},_t.timeout);r.message=r.message+o+" seconds",i(r)}else if(t.includes("endsession")&&e.message.includes("Access-Control-Allow-Origin"))n(wt);else{var s=_t.business;s.message=e,i(s)}})})}},jt=function(){function t(t){var e=typeof t;if(!("function"===e||"object"===e&&t))throw console.error("ERROR: TeneoResponse: Not an Object",t),new Error("Teneo Response constructed with something that isn't an object");if(!("output"in t))throw console.error("ERROR: TeneoResponse: Obj incorrect",t),new Error("Teneo Response constructed with an Object without an 'output' property");this.json=t}var e=t.prototype;return e.getJson=function(){return this.json},e.getSessionId=function(){return this.json.getSessionId},e.getOutputText=function(){return this.json.output.text},e.getInputText=function(){return this.json.input.text},e.getEmotion=function(){return this.json.output.emotion},e.hasEmotion=function(){return this.json.output.emotion||!1},e.getLink=function(){return this.json.output.link},e.hasLink=function(){return this.json.output.link||!1},e.addParameter=function(t,e){this.json.output.parameters[t]=e},e.hasParameter=function(t){return t in this.json.output.parameters},e.getParameter=function(t){return this.json.output.parameters[t]},e.getParameterNames=function(){for(var t=[],e=0,r=Object.entries(this.json.output.parameters);e<r.length;e++){var o=r[e][0];t.push(o)}return t},e.hasParametersStartingWith=function(t){for(var e=!1,r=0,o=Object.entries(this.json.output.parameters);r<o.length;r++){var n=o[r],i=n[0];n[1];i.startsWith(t)&&(e=!0)}return e},e.hasParametersContaining=function(t){for(var e=!1,r=0,o=Object.entries(this.json.output.parameters);r<o.length;r++){var n=o[r],i=n[0];n[1];i.indexOf(t)>-1&&(e=!0)}return e},e.getParametersStartingWith=function(t){for(var e={},r=0,o=Object.entries(this.json.output.parameters);r<o.length;r++){var n=o[r],i=n[0],s=n[1];i.startsWith(t)&&(e[i]=s)}return e},e.isObject=function(t){var e=typeof t;return"function"===e||"object"===e&&!!t},t}(),Tt=t(function(t,e){Object.defineProperty(e,"__esModule",{value:!0});var r="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},o="undefined"!=typeof window&&void 0!==window.document,n="object"===("undefined"==typeof self?"undefined":r(self))&&self.constructor&&"DedicatedWorkerGlobalScope"===self.constructor.name,i="undefined"!=typeof process&&null!=process.versions&&null!=process.versions.node,s=function(){return"undefined"!=typeof window&&"nodejs"===window.name||navigator.userAgent.includes("Node.js")||navigator.userAgent.includes("jsdom")};e.isBrowser=o,e.isWebWorker=n,e.isNode=i,e.isJsDom=s});!function(t){t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")&&t.default}(Tt);Tt.isBrowser,Tt.isWebWorker;var Et=Tt.isNode,xt=(Tt.isJsDom,function(){if("undefined"!=typeof document&&document.location)return document.location.origin}),St=function(t,e){var r=t&&Et?{Cookie:"JSESSIONID="+t}:{};return"headers"in e?Object.assign(e.headers,r):r},kt=function(t){return function(e){return Object.keys(e).reduce(function(r,o){var n;return t.includes(o)?r:Object.assign({},r,(n={},n[o]=e[o],n))},{})}}(["viewtype","userinput","text","clientOrigin","headers"]),At=function(t){return t.endsWith("/")?t:t+"/"},Pt=function(t,e){return e?t+";jsessionid="+e:t},Ct=function(t){var e=xt(),r={viewtype:"tieapi"},o=e?Object.assign(r,{clientOrigin:e}):r;return Object.assign(o,t)},Rt=function(t){var e=function(t){return["string","number","bool","object"].includes(typeof t)},r=Object.keys(t);if("object"!=typeof t||!r.includes("text"))throw new TypeError("sendInput input data must be an object with atleast a 'text' property: "+JSON.stringify(t));if(!r.every(function(r){return e(t[r])}))throw new TypeError("sendInput input data object can only contain values of type string, number or bool "+JSON.stringify(t))};return{wrap:x,close:T,sendInput:E,init:function(t){return{close:T.bind(null,t),sendInput:E.bind(null,t),wrap:x}}}});