@hierotech/api-wrapper
Advanced tools
Comparing version 0.0.4 to 0.0.5
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@ololoepepe/api-wrapper"),require("@hierotech/common"),require("axios")):"function"==typeof define&&define.amd?define(["@ololoepepe/api-wrapper","@hierotech/common","axios"],e):"object"==typeof exports?exports.hierotechApiWrapper=e(require("@ololoepepe/api-wrapper"),require("@hierotech/common"),require("axios")):t.hierotechApiWrapper=e(t["@ololoepepe/api-wrapper"],t["@hierotech/common"],t.axios)}(self,(function(t,e,r){return(()=>{var n={757:(t,e,r)=>{t.exports=r(666)},666:t=>{var e=function(t){"use strict";var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(D){u=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=e&&e.prototype instanceof v?e:v,a=Object.create(o.prototype),i=new L(n||[]);return a._invoke=function(t,e,r){var n=f;return function(o,a){if(n===h)throw new Error("Generator is already running");if(n===d){if("throw"===o)throw a;return j()}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var c=O(i,r);if(c){if(c===y)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===f)throw n=d,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=h;var u=l(t,e,r);if("normal"===u.type){if(n=r.done?d:p,u.arg===y)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n=d,r.method="throw",r.arg=u.arg)}}}(t,r,i),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(D){return{type:"throw",arg:D}}}t.wrap=s;var f="suspendedStart",p="suspendedYield",h="executing",d="completed",y={};function v(){}function m(){}function g(){}var w={};w[a]=function(){return this};var b=Object.getPrototypeOf,_=b&&b(b(E([])));_&&_!==r&&n.call(_,a)&&(w=_);var k=g.prototype=v.prototype=Object.create(w);function x(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function S(t,e){function r(o,a,i,c){var u=l(t[o],t,a);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,i,c)}),(function(t){r("throw",t,i,c)})):e.resolve(f).then((function(t){s.value=t,i(s)}),(function(t){return r("throw",t,i,c)}))}c(u.arg)}var o;this._invoke=function(t,n){function a(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(a,a):a()}}function O(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator["return"]&&(r.method="return",r.arg=e,O(t,r),"throw"===r.method))return y;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var o=l(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,y;var a=o.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,y):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function A(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function R(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function E(t){if(t){var r=t[a];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}return{next:j}}function j(){return{value:e,done:!0}}return m.prototype=k.constructor=g,g.constructor=m,m.displayName=u(g,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===m||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,u(t,c,"GeneratorFunction")),t.prototype=Object.create(k),t},t.awrap=function(t){return{__await:t}},x(S.prototype),S.prototype[i]=function(){return this},t.AsyncIterator=S,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new S(s(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},x(k),u(k,c,"Generator"),k[a]=function(){return this},k.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=E,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(R),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return c.type="throw",c.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],c=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var u=n.call(i,"catchLoc"),s=n.call(i,"finallyLoc");if(u&&s){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(u){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,y):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),R(r),y}},"catch":function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;R(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:E(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}(t.exports);try{regeneratorRuntime=e}catch(r){Function("r","regeneratorRuntime = r")(e)}},695:t=>{"use strict";t.exports=e},84:e=>{"use strict";e.exports=t},270:t=>{"use strict";t.exports=r}},o={};function a(t){var e=o[t];if(e!==undefined)return e.exports;var r=o[t]={exports:{}};return n[t](r,r.exports,a),r.exports}a.n=t=>{var e=t&&t.__esModule?()=>t["default"]:()=>t;return a.d(e,{a:e}),e},a.d=(t,e)=>{for(var r in e)a.o(e,r)&&!a.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},a.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),a.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,r){return(e=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,r)}function r(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),r&&e(t,r)}function n(t){return(n="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(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function c(t){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}a.r(i),a.d(i,{"default":()=>E});var u=a(84);function s(t,e,r,n,o,a,i){try{var c=t[a](i),u=c.value}catch(s){return void r(s)}c.done?e(u):Promise.resolve(u).then(n,o)}function l(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var a=t.apply(e,r);function i(t){s(a,n,o,i,c,"next",t)}function c(t){s(a,n,o,i,c,"throw",t)}i(undefined)}))}}function f(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function p(t,e,r){return e&&f(t.prototype,e),r&&f(t,r),t}var h=a(757),d=a.n(h);function y(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=c(t);if(e){var a=c(this).constructor;r=Reflect.construct(n,arguments,a)}else r=n.apply(this,arguments);return o(this,r)}}var v=function(e){r(c,e);var n,o,a,i=y(c);function c(e){var r,n=e.dispatchSetTokenAccess,o=e.getStore,a=e.selectSessionData;return t(this,c),(r=i.call(this))._dispatchSetTokenAccess=n,r._selectSessionData=a,r._getStore=o,r}return p(c,[{key:"authenticate",value:(a=l(d().mark((function u(t,e){var r,n,o,a;return d().wrap((function(i){for(;;)switch(i.prev=i.next){case 0:if(e){i.next=2;break}return i.abrupt("return",null);case 2:return r=e.sessionId,n=e.tokenRefresh,i.next=5,t.callMethod({method:"patch"},{payload:{data:{token_refresh:n},url:"/auth/sessions/".concat(r)}});case 5:return o=i.sent,a=o.data.token_access,i.abrupt("return",{sessionId:r,tokenAccess:a,tokenRefresh:n});case 8:case"end":return i.stop()}}),u)}))),function(t,e){return a.apply(this,arguments)})},{key:"loadAuthenticationData",value:(o=l(d().mark((function s(){var t,e,r,n,o;return d().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return t=this._selectSessionData(this._getStore().getState()),e=t.isLoggedIn,r=t.sessionId,n=t.tokenAccess,o=t.tokenRefresh,a.abrupt("return",e?{sessionId:r,tokenAccess:n,tokenRefresh:o}:null);case 2:case"end":return a.stop()}}),s,this)}))),function(){return o.apply(this,arguments)})},{key:"saveAuthenticationData",value:(n=l(d().mark((function f(t){return d().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}return e.abrupt("return");case 2:this._dispatchSetTokenAccess(this._getStore().dispatch,t.tokenAccess);case 3:case"end":return e.stop()}}),f,this)}))),function(t){return n.apply(this,arguments)})}]),c}(u.ApiAuthenticator),m=a(695);function g(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=c(t);if(e){var a=c(this).constructor;r=Reflect.construct(n,arguments,a)}else r=n.apply(this,arguments);return o(this,r)}}var w=m.Helper.exposeFields,b=m.Helper.stringifyQuery,_=new Map([["addSingle","onAddItem"],["addList","onAddItems"],["editSingle","onChangeItem"],["editList","onChangeItems"],["deleteSingle","onRemoveItem"]]),k=function(e){r(i,e);var n,o,a=g(i);function i(){var e;return t(this,i),(e=a.call(this))._error=null,e._isAuthRetry=!1,e._onConnect=null,e._subscriptions=new Map,e._wrapper=null,e._ws=null,e}return p(i,[{key:"connect",value:function(t){var e=this,r=t.onConnect,n=t.onDisconnect,o=t.wrapper;this._onConnect=r,this._wrapper=o;var a=new WebSocket("ws://".concat(window.location.host,"/api/realtime"));a.onclose=function(){n(e._error),e._error=null,e._isAuthRetry=!1,e._onConnect=null,e._subscriptions.clear(),e._wrapper=null,e._ws=null},a.onerror=function(t){console.warn("ws err:",t)},a.onmessage=function(t){return e._handleMessage(t)},a.onopen=function(){return e._handleConnect()},this._ws=a}},{key:"disconnect",value:function(){this._ws.close(1e3)}},{key:"subscribe",value:function(t){var e=t.callbacks,r=t.onSubscribe,n=t.subscriptionData;this._subscriptions.set(this._createKey(n),{callbacks:e,options:n.options}),"candlestick"===n.name&&this._ws.send(JSON.stringify({type:"subscribe",data:{data:n.options,type:"candlestick"}})),r()}},{key:"unsubscribe",value:function(t){var e=t.subscriptionData;this._subscriptions["delete"](this._createKey(e)),"candlestick"===e.name&&this._ws.send(JSON.stringify({type:"unsubscribe",data:{data:e.options,type:"candlestick"}}))}},{key:"_authenticate",value:(o=l(d().mark((function c(){var t;return d().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,t=this._wrapper.authenticate()){e.next=4;break}throw new Error("No authenticationData provided");case 4:this._send({type:"auth",data:{token:t.tokenAccess}}),e.next=11;break;case 7:e.prev=7,e.t0=e["catch"](0),this._error=e.t0,this.disconnect();case 11:case"end":return e.stop()}}),c,this,[[0,7]])}))),function(){return o.apply(this,arguments)})},{key:"_createKey",value:function(t){var e=t.name,r=t.options;return"candlestick"===e?"".concat(e,"?").concat(b(w(r,"asset_ticker","interval","nominal"))):e}},{key:"_handleAuthMessage",value:function(t){var e=t.error;return t.success?(this._isAuthRetry=!1,void this._onConnect()):401!==(null==e?void 0:e.code)||this._isAuthRetry?(this._error=new Error("Authentication failed"),void this.disconnect()):(this._isAuthRetry=!0,void this._authenticate()["catch"]((function(t){return console.warn(t)})))}},{key:"_handleConnect",value:(n=l(d().mark((function u(){var t;return d().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._wrapper.getAuthenticationData();case 3:if(t=e.sent){e.next=6;break}throw new Error("No authenticationData provided");case 6:this._send({type:"auth",data:{token:t.tokenAccess}}),e.next=13;break;case 9:e.prev=9,e.t0=e["catch"](0),this._error=e.t0,this.disconnect();case 13:case"end":return e.stop()}}),u,this,[[0,9]])}))),function(){return n.apply(this,arguments)})},{key:"_handleMessage",value:function(t){var e,r,n=JSON.parse(t.data),o=n.data,a=n.error,i=n.success,c=n.type;if("auth"!==c)if("notification"===c){var u=this._createKey({name:o.type,options:o.data.data}),s=null===(e=this._subscriptions.get(u))||void 0===e||null===(r=e.callbacks)||void 0===r?void 0:r[_.get(o.data.type)];s&&s(o.data.data)}else console.warn(c,o);else this._handleAuthMessage({error:a,success:i})}},{key:"_send",value:function(t){return this._ws.send(JSON.stringify(t))}}]),i}(u.ApiRealtimeTransport),x=a(270),S=a.n(x);function O(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=c(t);if(e){var a=c(this).constructor;r=Reflect.construct(n,arguments,a)}else r=n.apply(this,arguments);return o(this,r)}}function A(t,e,r){var n,o,a,i=t.apiWrapperOptions,c=t.methodData,u=t.payload,s=c.actionName,l=c.method;return(null==u?void 0:u[e])||(null==i||null===(n=i[s])||void 0===n?void 0:n[e])||(null==i||null===(o=i[l])||void 0===o?void 0:o[e])||(null==i||null===(a=i["default"])||void 0===a?void 0:a[e])||r}var R=function(e){r(a,e);var n,o=O(a);function a(e){var r,n=e.getStore;return t(this,a),(r=o.call(this))._axios=S().create({baseURL:"/api",timeout:1e4}),r._getStore=n,r}return p(a,[{key:"callMethod",value:(n=l(d().mark((function i(t){var e,r,n,o,a,c,u,s,l;return d().wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return e=t.authenticationData,r=t.methodData,n=t.requestData,o=n.apiWrapperOptions,a=n.payload,c=A({apiWrapperOptions:o,methodData:r,payload:a},"data"),u=A({apiWrapperOptions:o,methodData:r,payload:a},"timeout",1e4),s=A({apiWrapperOptions:o,methodData:r,payload:a},"url"),l=this._getStore().getState(),i.next=8,this._axios.request({timeout:u,data:"function"==typeof c?c(a,l):c,headers:e?{Authorization:"Bearer ".concat(e.tokenAccess)}:{},method:r.method,url:"function"==typeof s?s(a,l):s});case 8:return i.abrupt("return",i.sent);case 9:case"end":return i.stop()}}),i,this)}))),function(t){return n.apply(this,arguments)})},{key:"getCreateMethodData",value:function(){return{actionName:"create",method:"post"}}},{key:"getDeleteMethodData",value:function(){return{actionName:"delete",method:"delete"}}},{key:"getReadMethodData",value:function(){return{actionName:"read",method:"get"}}},{key:"getUpdateMethodData",value:function(){return{actionName:"update",method:"patch"}}},{key:"isAuthenticationFailedError",value:function(t){var e;return 403===(null==t||null===(e=t.response)||void 0===e?void 0:e.status)}},{key:"isSessionExpiredError",value:function(t){var e;return 401===(null==t||null===(e=t.response)||void 0===e?void 0:e.status)}}]),a}(u.ApiTransport);function L(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=c(t);if(e){var a=c(this).constructor;r=Reflect.construct(n,arguments,a)}else r=n.apply(this,arguments);return o(this,r)}}var E=function(e){r(o,e);var n=L(o);function o(e){var r=e.dispatchSetTokenAccess,a=e.getStore,i=e.selectSessionData;return t(this,o),n.call(this,{authenticator:new v({dispatchSetTokenAccess:r,getStore:a,selectSessionData:i}),realtimeTransport:new k,transport:new R({getStore:a})})}return o}(u.ApiWrapper)})(),i})()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@ololoepepe/api-wrapper"),require("@hierotech/common"),require("axios")):"function"==typeof define&&define.amd?define(["@ololoepepe/api-wrapper","@hierotech/common","axios"],e):"object"==typeof exports?exports.hierotechApiWrapper=e(require("@ololoepepe/api-wrapper"),require("@hierotech/common"),require("axios")):t.hierotechApiWrapper=e(t["@ololoepepe/api-wrapper"],t["@hierotech/common"],t.axios)}(self,(function(t,e,r){return(()=>{var n={757:(t,e,r)=>{t.exports=r(666)},666:t=>{var e=function(t){"use strict";var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},i=o.iterator||"@@iterator",a=o.asyncIterator||"@@asyncIterator",c=o.toStringTag||"@@toStringTag";function u(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{u({},"")}catch(D){u=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o=e&&e.prototype instanceof v?e:v,i=Object.create(o.prototype),a=new E(n||[]);return i._invoke=function(t,e,r){var n=f;return function(o,i){if(n===h)throw new Error("Generator is already running");if(n===d){if("throw"===o)throw i;return j()}for(r.method=o,r.arg=i;;){var a=r.delegate;if(a){var c=A(a,r);if(c){if(c===y)continue;return c}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===f)throw n=d,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=h;var u=l(t,e,r);if("normal"===u.type){if(n=r.done?d:p,u.arg===y)continue;return{value:u.arg,done:r.done}}"throw"===u.type&&(n=d,r.method="throw",r.arg=u.arg)}}}(t,r,a),i}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(D){return{type:"throw",arg:D}}}t.wrap=s;var f="suspendedStart",p="suspendedYield",h="executing",d="completed",y={};function v(){}function m(){}function g(){}var b={};b[i]=function(){return this};var w=Object.getPrototypeOf,_=w&&w(w(L([])));_&&_!==r&&n.call(_,i)&&(b=_);var k=g.prototype=v.prototype=Object.create(b);function x(t){["next","throw","return"].forEach((function(e){u(t,e,(function(t){return this._invoke(e,t)}))}))}function S(t,e){function r(o,i,a,c){var u=l(t[o],t,i);if("throw"!==u.type){var s=u.arg,f=s.value;return f&&"object"==typeof f&&n.call(f,"__await")?e.resolve(f.__await).then((function(t){r("next",t,a,c)}),(function(t){r("throw",t,a,c)})):e.resolve(f).then((function(t){s.value=t,a(s)}),(function(t){return r("throw",t,a,c)}))}c(u.arg)}var o;this._invoke=function(t,n){function i(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(i,i):i()}}function A(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator["return"]&&(r.method="return",r.arg=e,A(t,r),"throw"===r.method))return y;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var o=l(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,y;var i=o.arg;return i?i.done?(r[t.resultName]=i.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,y):i:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function O(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function R(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(O,this),this.reset(!0)}function L(t){if(t){var r=t[i];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,a=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return a.next=a}}return{next:j}}function j(){return{value:e,done:!0}}return m.prototype=k.constructor=g,g.constructor=m,m.displayName=u(g,c,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===m||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,g):(t.__proto__=g,u(t,c,"GeneratorFunction")),t.prototype=Object.create(k),t},t.awrap=function(t){return{__await:t}},x(S.prototype),S.prototype[a]=function(){return this},t.AsyncIterator=S,t.async=function(e,r,n,o,i){void 0===i&&(i=Promise);var a=new S(s(e,r,n,o),i);return t.isGeneratorFunction(r)?a:a.next().then((function(t){return t.done?t.value:a.next()}))},x(k),u(k,c,"Generator"),k[i]=function(){return this},k.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=L,E.prototype={constructor:E,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(R),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return c.type="throw",c.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var i=this.tryEntries.length-1;i>=0;--i){var a=this.tryEntries[i],c=a.completion;if("root"===a.tryLoc)return o("end");if(a.tryLoc<=this.prev){var u=n.call(a,"catchLoc"),s=n.call(a,"finallyLoc");if(u&&s){if(this.prev<a.catchLoc)return o(a.catchLoc,!0);if(this.prev<a.finallyLoc)return o(a.finallyLoc)}else if(u){if(this.prev<a.catchLoc)return o(a.catchLoc,!0)}else{if(!s)throw new Error("try statement without catch or finally");if(this.prev<a.finallyLoc)return o(a.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var i=o;break}}i&&("break"===t||"continue"===t)&&i.tryLoc<=e&&e<=i.finallyLoc&&(i=null);var a=i?i.completion:{};return a.type=t,a.arg=e,i?(this.method="next",this.next=i.finallyLoc,y):this.complete(a)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),R(r),y}},"catch":function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;R(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:L(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}(t.exports);try{regeneratorRuntime=e}catch(r){Function("r","regeneratorRuntime = r")(e)}},695:t=>{"use strict";t.exports=e},84:e=>{"use strict";e.exports=t},270:t=>{"use strict";t.exports=r}},o={};function i(t){var e=o[t];if(e!==undefined)return e.exports;var r=o[t]={exports:{}};return n[t](r,r.exports,i),r.exports}i.n=t=>{var e=t&&t.__esModule?()=>t["default"]:()=>t;return i.d(e,{a:e}),e},i.d=(t,e)=>{for(var r in e)i.o(e,r)&&!i.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},i.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),i.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var a={};return(()=>{"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,r){return(e=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,r)}function r(t,r){if("function"!=typeof r&&null!==r)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(r&&r.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),r&&e(t,r)}function n(t){return(n="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(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):e}function c(t){return(c=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}i.r(a),i.d(a,{"default":()=>D});var u=i(84);function s(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(s){return void r(s)}c.done?e(u):Promise.resolve(u).then(n,o)}function l(t){return function(){var e=this,r=arguments;return new Promise((function(n,o){var i=t.apply(e,r);function a(t){s(i,n,o,a,c,"next",t)}function c(t){s(i,n,o,a,c,"throw",t)}a(undefined)}))}}function f(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}function p(t,e,r){return e&&f(t.prototype,e),r&&f(t,r),t}var h=i(757),d=i.n(h);function y(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=c(t);if(e){var i=c(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return o(this,r)}}var v=function(e){r(c,e);var n,o,i,a=y(c);function c(e){var r,n=e.dispatchSetTokenAccess,o=e.getStore,i=e.selectSessionData;return t(this,c),(r=a.call(this))._dispatchSetTokenAccess=n,r._selectSessionData=i,r._getStore=o,r}return p(c,[{key:"authenticate",value:(i=l(d().mark((function u(t,e){var r,n,o,i;return d().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:if(e){a.next=2;break}return a.abrupt("return",null);case 2:return r=e.sessionId,n=e.tokenRefresh,a.next=5,t.callMethod({method:"patch"},{payload:{data:{token_refresh:n},url:"/auth/sessions/".concat(r)}});case 5:return o=a.sent,i=o.data.token_access,a.abrupt("return",{sessionId:r,tokenAccess:i,tokenRefresh:n});case 8:case"end":return a.stop()}}),u)}))),function(t,e){return i.apply(this,arguments)})},{key:"loadAuthenticationData",value:(o=l(d().mark((function s(){var t,e,r,n,o;return d().wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return t=this._selectSessionData(this._getStore().getState()),e=t.isLoggedIn,r=t.sessionId,n=t.tokenAccess,o=t.tokenRefresh,i.abrupt("return",e?{sessionId:r,tokenAccess:n,tokenRefresh:o}:null);case 2:case"end":return i.stop()}}),s,this)}))),function(){return o.apply(this,arguments)})},{key:"saveAuthenticationData",value:(n=l(d().mark((function f(t){return d().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}return e.abrupt("return");case 2:this._dispatchSetTokenAccess(this._getStore().dispatch,t.tokenAccess);case 3:case"end":return e.stop()}}),f,this)}))),function(t){return n.apply(this,arguments)})}]),c}(u.ApiAuthenticator),m=i(695);function g(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return b(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return b(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}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,a=!0,c=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return a=t.done,t},e:function(t){c=!0,i=t},f:function(){try{a||null==r["return"]||r["return"]()}finally{if(c)throw i}}}}function b(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function w(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=c(t);if(e){var i=c(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return o(this,r)}}var _=m.Helper.exposeFields,k=m.Helper.stringifyQuery,x=new Map([["addSingle","onAddItem"],["addList","onAddItems"],["editSingle","onChangeItem"],["editList","onChangeItems"],["deleteSingle","onRemoveItem"]]),S=function(e){r(a,e);var n,o,i=w(a);function a(){var e;return t(this,a),(e=i.call(this))._error=null,e._isAuthRetry=!1,e._onConnect=null,e._subscriptions=new Map,e._wrapper=null,e._ws=null,e}return p(a,[{key:"connect",value:function(t){var e=this,r=t.onConnect,n=t.onDisconnect,o=t.wrapper;this._onConnect=r,this._wrapper=o;var i=new WebSocket("ws://".concat(window.location.host,"/api/realtime"));i.onclose=function(){n(e._error);var t,r=g(e._subscriptions);try{for(r.s();!(t=r.n()).done;){(0,t.value.onUnsubscribe)()}}catch(o){r.e(o)}finally{r.f()}e._error=null,e._isAuthRetry=!1,e._onConnect=null,e._subscriptions.clear(),e._wrapper=null,e._ws=null},i.onerror=function(t){console.warn("ws err:",t)},i.onmessage=function(t){return e._handleMessage(t)},i.onopen=function(){return e._handleConnect()},this._ws=i}},{key:"disconnect",value:function(){this._ws.close(1e3)}},{key:"subscribe",value:function(t){var e=t.callbacks,r=t.onSubscribe,n=t.onUnsubscribe,o=t.subscriptionData;this._subscriptions.set(this._createKey(o),{callbacks:e,onUnsubscribe:n,options:o.options}),"candlestick"===o.name&&this._ws.send(JSON.stringify({type:"subscribe",data:{data:o.options,type:"candlestick"}})),r()}},{key:"unsubscribe",value:function(t){var e=t.subscriptionData,r=this._createKey(e),n=this._subscriptions.get(r);this._subscriptions["delete"](r),"candlestick"===e.name&&this._ws.send(JSON.stringify({type:"unsubscribe",data:{data:e.options,type:"candlestick"}})),n.onUnsubscribe()}},{key:"_authenticate",value:(o=l(d().mark((function c(){var t;return d().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,t=this._wrapper.authenticate()){e.next=4;break}throw new Error("No authenticationData provided");case 4:this._send({type:"auth",data:{token:t.tokenAccess}}),e.next=11;break;case 7:e.prev=7,e.t0=e["catch"](0),this._error=e.t0,this.disconnect();case 11:case"end":return e.stop()}}),c,this,[[0,7]])}))),function(){return o.apply(this,arguments)})},{key:"_createKey",value:function(t){var e=t.name,r=t.options;return"candlestick"===e?"".concat(e,"?").concat(k(_(r,"asset_ticker","interval","nominal"))):e}},{key:"_handleAuthMessage",value:function(t){var e=t.error;return t.success?(this._isAuthRetry=!1,void this._onConnect()):401!==(null==e?void 0:e.code)||this._isAuthRetry?(this._error=new Error("Authentication failed"),void this.disconnect()):(this._isAuthRetry=!0,void this._authenticate()["catch"]((function(t){return console.warn(t)})))}},{key:"_handleConnect",value:(n=l(d().mark((function u(){var t;return d().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._wrapper.getAuthenticationData();case 3:if(t=e.sent){e.next=6;break}throw new Error("No authenticationData provided");case 6:this._send({type:"auth",data:{token:t.tokenAccess}}),e.next=13;break;case 9:e.prev=9,e.t0=e["catch"](0),this._error=e.t0,this.disconnect();case 13:case"end":return e.stop()}}),u,this,[[0,9]])}))),function(){return n.apply(this,arguments)})},{key:"_handleMessage",value:function(t){var e,r,n=JSON.parse(t.data),o=n.data,i=n.error,a=n.success,c=n.type;if("auth"!==c)if("notification"===c){var u=this._createKey({name:o.type,options:o.data.data}),s=null===(e=this._subscriptions.get(u))||void 0===e||null===(r=e.callbacks)||void 0===r?void 0:r[x.get(o.data.type)];s&&s(o.data.data)}else console.warn(c,o);else this._handleAuthMessage({error:i,success:a})}},{key:"_send",value:function(t){return this._ws.send(JSON.stringify(t))}}]),a}(u.ApiRealtimeTransport),A=i(270),O=i.n(A);function R(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=c(t);if(e){var i=c(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return o(this,r)}}function E(t,e,r){var n,o,i,a=t.apiWrapperOptions,c=t.methodData,u=t.payload,s=c.actionName,l=c.method;return(null==u?void 0:u[e])||(null==a||null===(n=a[s])||void 0===n?void 0:n[e])||(null==a||null===(o=a[l])||void 0===o?void 0:o[e])||(null==a||null===(i=a["default"])||void 0===i?void 0:i[e])||r}var L=function(e){r(i,e);var n,o=R(i);function i(e){var r,n=e.getStore;return t(this,i),(r=o.call(this))._axios=O().create({baseURL:"/api",timeout:1e4}),r._getStore=n,r}return p(i,[{key:"callMethod",value:(n=l(d().mark((function a(t){var e,r,n,o,i,c,u,s,l;return d().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return e=t.authenticationData,r=t.methodData,n=t.requestData,o=n.apiWrapperOptions,i=n.payload,c=E({apiWrapperOptions:o,methodData:r,payload:i},"data"),u=E({apiWrapperOptions:o,methodData:r,payload:i},"timeout",1e4),s=E({apiWrapperOptions:o,methodData:r,payload:i},"url"),l=this._getStore().getState(),a.next=8,this._axios.request({timeout:u,data:"function"==typeof c?c(i,l):c,headers:e?{Authorization:"Bearer ".concat(e.tokenAccess)}:{},method:r.method,url:"function"==typeof s?s(i,l):s});case 8:return a.abrupt("return",a.sent);case 9:case"end":return a.stop()}}),a,this)}))),function(t){return n.apply(this,arguments)})},{key:"getCreateMethodData",value:function(){return{actionName:"create",method:"post"}}},{key:"getDeleteMethodData",value:function(){return{actionName:"delete",method:"delete"}}},{key:"getReadMethodData",value:function(){return{actionName:"read",method:"get"}}},{key:"getUpdateMethodData",value:function(){return{actionName:"update",method:"patch"}}},{key:"isAuthenticationFailedError",value:function(t){var e;return 403===(null==t||null===(e=t.response)||void 0===e?void 0:e.status)}},{key:"isSessionExpiredError",value:function(t){var e;return 401===(null==t||null===(e=t.response)||void 0===e?void 0:e.status)}}]),i}(u.ApiTransport);function j(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=c(t);if(e){var i=c(this).constructor;r=Reflect.construct(n,arguments,i)}else r=n.apply(this,arguments);return o(this,r)}}var D=function(e){r(o,e);var n=j(o);function o(e){var r=e.dispatchSetTokenAccess,i=e.getStore,a=e.selectSessionData;return t(this,o),n.call(this,{authenticator:new v({dispatchSetTokenAccess:r,getStore:i,selectSessionData:a}),realtimeTransport:new S,transport:new L({getStore:i})})}return o}(u.ApiWrapper)})(),a})()})); | ||
//# sourceMappingURL=index.browser.js.map |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@ololoepepe/api-wrapper"),require("@hierotech/common"),require("axios")):"function"==typeof define&&define.amd?define(["@ololoepepe/api-wrapper","@hierotech/common","axios"],e):"object"==typeof exports?exports.hierotechApiWrapper=e(require("@ololoepepe/api-wrapper"),require("@hierotech/common"),require("axios")):t.hierotechApiWrapper=e(t["@ololoepepe/api-wrapper"],t["@hierotech/common"],t.axios)}(global,(function(t,e,r){return(()=>{var n={506:t=>{t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t},t.exports["default"]=t.exports,t.exports.__esModule=!0},926:t=>{function e(t,e,r,n,o,a,i){try{var s=t[a](i),c=s.value}catch(u){return void r(u)}s.done?e(c):Promise.resolve(c).then(n,o)}t.exports=function(t){return function(){var r=this,n=arguments;return new Promise((function(o,a){var i=t.apply(r,n);function s(t){e(i,o,a,s,c,"next",t)}function c(t){e(i,o,a,s,c,"throw",t)}s(undefined)}))}},t.exports["default"]=t.exports,t.exports.__esModule=!0},575:t=>{t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports["default"]=t.exports,t.exports.__esModule=!0},913:t=>{function e(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}t.exports=function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t},t.exports["default"]=t.exports,t.exports.__esModule=!0},754:t=>{function e(r){return t.exports=e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},t.exports["default"]=t.exports,t.exports.__esModule=!0,e(r)}t.exports=e,t.exports["default"]=t.exports,t.exports.__esModule=!0},205:(t,e,r)=>{var n=r(489);t.exports=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)},t.exports["default"]=t.exports,t.exports.__esModule=!0},585:(t,e,r)=>{var n=r(8)["default"],o=r(506);t.exports=function(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?o(t):e},t.exports["default"]=t.exports,t.exports.__esModule=!0},489:t=>{function e(r,n){return t.exports=e=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},t.exports["default"]=t.exports,t.exports.__esModule=!0,e(r,n)}t.exports=e,t.exports["default"]=t.exports,t.exports.__esModule=!0},8:t=>{function e(r){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(t.exports=e=function(t){return typeof t},t.exports["default"]=t.exports,t.exports.__esModule=!0):(t.exports=e=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports["default"]=t.exports,t.exports.__esModule=!0),e(r)}t.exports=e,t.exports["default"]=t.exports,t.exports.__esModule=!0},757:(t,e,r)=>{t.exports=r(666)},666:t=>{var e=function(t){"use strict";var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(j){c=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=e&&e.prototype instanceof v?e:v,a=Object.create(o.prototype),i=new L(n||[]);return a._invoke=function(t,e,r){var n=p;return function(o,a){if(n===h)throw new Error("Generator is already running");if(n===d){if("throw"===o)throw a;return M()}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var s=O(i,r);if(s){if(s===y)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===p)throw n=d,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=h;var c=l(t,e,r);if("normal"===c.type){if(n=r.done?d:f,c.arg===y)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=d,r.method="throw",r.arg=c.arg)}}}(t,r,i),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(j){return{type:"throw",arg:j}}}t.wrap=u;var p="suspendedStart",f="suspendedYield",h="executing",d="completed",y={};function v(){}function m(){}function x(){}var _={};_[a]=function(){return this};var g=Object.getPrototypeOf,w=g&&g(g(E([])));w&&w!==r&&n.call(w,a)&&(_=w);var b=x.prototype=v.prototype=Object.create(_);function k(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function S(t,e){function r(o,a,i,s){var c=l(t[o],t,a);if("throw"!==c.type){var u=c.arg,p=u.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,i,s)}),(function(t){r("throw",t,i,s)})):e.resolve(p).then((function(t){u.value=t,i(u)}),(function(t){return r("throw",t,i,s)}))}s(c.arg)}var o;this._invoke=function(t,n){function a(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(a,a):a()}}function O(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator["return"]&&(r.method="return",r.arg=e,O(t,r),"throw"===r.method))return y;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var o=l(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,y;var a=o.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,y):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function A(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function R(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function L(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(A,this),this.reset(!0)}function E(t){if(t){var r=t[a];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}return{next:M}}function M(){return{value:e,done:!0}}return m.prototype=b.constructor=x,x.constructor=m,m.displayName=c(x,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===m||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,c(t,s,"GeneratorFunction")),t.prototype=Object.create(b),t},t.awrap=function(t){return{__await:t}},k(S.prototype),S.prototype[i]=function(){return this},t.AsyncIterator=S,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new S(u(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},k(b),c(b,s,"Generator"),b[a]=function(){return this},b.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=E,L.prototype={constructor:L,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(R),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return s.type="throw",s.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],s=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,y):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),R(r),y}},"catch":function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;R(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:E(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}(t.exports);try{regeneratorRuntime=e}catch(r){Function("r","regeneratorRuntime = r")(e)}},695:t=>{"use strict";t.exports=e},84:e=>{"use strict";e.exports=t},376:t=>{"use strict";t.exports=r}},o={};function a(t){var e=o[t];if(e!==undefined)return e.exports;var r=o[t]={exports:{}};return n[t](r,r.exports,a),r.exports}a.n=t=>{var e=t&&t.__esModule?()=>t["default"]:()=>t;return a.d(e,{a:e}),e},a.d=(t,e)=>{for(var r in e)a.o(e,r)&&!a.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},a.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),a.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{"use strict";a.r(i),a.d(i,{"default":()=>j});var t=a(575),e=a.n(t),r=a(205),n=a.n(r),o=a(585),s=a.n(o),c=a(754),u=a.n(c),l=a(84),p=a(926),f=a.n(p),h=a(913),d=a.n(h),y=a(757),v=a.n(y);function m(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u()(t);if(e){var o=u()(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return s()(this,r)}}var x=function(t){n()(s,t);var r,o,a,i=m(s);function s(t){var r,n=t.dispatchSetTokenAccess,o=t.getStore,a=t.selectSessionData;return e()(this,s),(r=i.call(this))._dispatchSetTokenAccess=n,r._selectSessionData=a,r._getStore=o,r}return d()(s,[{key:"authenticate",value:(a=f()(v().mark((function c(t,e){var r,n,o,a;return v().wrap((function(i){for(;;)switch(i.prev=i.next){case 0:if(e){i.next=2;break}return i.abrupt("return",null);case 2:return r=e.sessionId,n=e.tokenRefresh,i.next=5,t.callMethod({method:"patch"},{payload:{data:{token_refresh:n},url:"/auth/sessions/".concat(r)}});case 5:return o=i.sent,a=o.data.token_access,i.abrupt("return",{sessionId:r,tokenAccess:a,tokenRefresh:n});case 8:case"end":return i.stop()}}),c)}))),function(t,e){return a.apply(this,arguments)})},{key:"loadAuthenticationData",value:(o=f()(v().mark((function u(){var t,e,r,n,o;return v().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return t=this._selectSessionData(this._getStore().getState()),e=t.isLoggedIn,r=t.sessionId,n=t.tokenAccess,o=t.tokenRefresh,a.abrupt("return",e?{sessionId:r,tokenAccess:n,tokenRefresh:o}:null);case 2:case"end":return a.stop()}}),u,this)}))),function(){return o.apply(this,arguments)})},{key:"saveAuthenticationData",value:(r=f()(v().mark((function l(t){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}return e.abrupt("return");case 2:this._dispatchSetTokenAccess(this._getStore().dispatch,t.tokenAccess);case 3:case"end":return e.stop()}}),l,this)}))),function(t){return r.apply(this,arguments)})}]),s}(l.ApiAuthenticator),_=a(695);function g(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u()(t);if(e){var o=u()(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return s()(this,r)}}var w=_.Helper.exposeFields,b=_.Helper.stringifyQuery,k=new Map([["addSingle","onAddItem"],["addList","onAddItems"],["editSingle","onChangeItem"],["editList","onChangeItems"],["deleteSingle","onRemoveItem"]]),S=function(t){n()(i,t);var r,o,a=g(i);function i(){var t;return e()(this,i),(t=a.call(this))._error=null,t._isAuthRetry=!1,t._onConnect=null,t._subscriptions=new Map,t._wrapper=null,t._ws=null,t}return d()(i,[{key:"connect",value:function(t){var e=this,r=t.onConnect,n=t.onDisconnect,o=t.wrapper;this._onConnect=r,this._wrapper=o;var a=new WebSocket("ws://".concat(window.location.host,"/api/realtime"));a.onclose=function(){n(e._error),e._error=null,e._isAuthRetry=!1,e._onConnect=null,e._subscriptions.clear(),e._wrapper=null,e._ws=null},a.onerror=function(t){console.warn("ws err:",t)},a.onmessage=function(t){return e._handleMessage(t)},a.onopen=function(){return e._handleConnect()},this._ws=a}},{key:"disconnect",value:function(){this._ws.close(1e3)}},{key:"subscribe",value:function(t){var e=t.callbacks,r=t.onSubscribe,n=t.subscriptionData;this._subscriptions.set(this._createKey(n),{callbacks:e,options:n.options}),"candlestick"===n.name&&this._ws.send(JSON.stringify({type:"subscribe",data:{data:n.options,type:"candlestick"}})),r()}},{key:"unsubscribe",value:function(t){var e=t.subscriptionData;this._subscriptions["delete"](this._createKey(e)),"candlestick"===e.name&&this._ws.send(JSON.stringify({type:"unsubscribe",data:{data:e.options,type:"candlestick"}}))}},{key:"_authenticate",value:(o=f()(v().mark((function s(){var t;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,t=this._wrapper.authenticate()){e.next=4;break}throw new Error("No authenticationData provided");case 4:this._send({type:"auth",data:{token:t.tokenAccess}}),e.next=11;break;case 7:e.prev=7,e.t0=e["catch"](0),this._error=e.t0,this.disconnect();case 11:case"end":return e.stop()}}),s,this,[[0,7]])}))),function(){return o.apply(this,arguments)})},{key:"_createKey",value:function(t){var e=t.name,r=t.options;return"candlestick"===e?"".concat(e,"?").concat(b(w(r,"asset_ticker","interval","nominal"))):e}},{key:"_handleAuthMessage",value:function(t){var e=t.error;return t.success?(this._isAuthRetry=!1,void this._onConnect()):401!==(null==e?void 0:e.code)||this._isAuthRetry?(this._error=new Error("Authentication failed"),void this.disconnect()):(this._isAuthRetry=!0,void this._authenticate()["catch"]((function(t){return console.warn(t)})))}},{key:"_handleConnect",value:(r=f()(v().mark((function c(){var t;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._wrapper.getAuthenticationData();case 3:if(t=e.sent){e.next=6;break}throw new Error("No authenticationData provided");case 6:this._send({type:"auth",data:{token:t.tokenAccess}}),e.next=13;break;case 9:e.prev=9,e.t0=e["catch"](0),this._error=e.t0,this.disconnect();case 13:case"end":return e.stop()}}),c,this,[[0,9]])}))),function(){return r.apply(this,arguments)})},{key:"_handleMessage",value:function(t){var e,r,n=JSON.parse(t.data),o=n.data,a=n.error,i=n.success,s=n.type;if("auth"!==s)if("notification"===s){var c=this._createKey({name:o.type,options:o.data.data}),u=null===(e=this._subscriptions.get(c))||void 0===e||null===(r=e.callbacks)||void 0===r?void 0:r[k.get(o.data.type)];u&&u(o.data.data)}else console.warn(s,o);else this._handleAuthMessage({error:a,success:i})}},{key:"_send",value:function(t){return this._ws.send(JSON.stringify(t))}}]),i}(l.ApiRealtimeTransport),O=a(376),A=a.n(O);function R(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u()(t);if(e){var o=u()(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return s()(this,r)}}function L(t,e,r){var n,o,a,i=t.apiWrapperOptions,s=t.methodData,c=t.payload,u=s.actionName,l=s.method;return(null==c?void 0:c[e])||(null==i||null===(n=i[u])||void 0===n?void 0:n[e])||(null==i||null===(o=i[l])||void 0===o?void 0:o[e])||(null==i||null===(a=i["default"])||void 0===a?void 0:a[e])||r}var E=function(t){n()(a,t);var r,o=R(a);function a(t){var r,n=t.getStore;return e()(this,a),(r=o.call(this))._axios=A().create({baseURL:"/api",timeout:1e4}),r._getStore=n,r}return d()(a,[{key:"callMethod",value:(r=f()(v().mark((function i(t){var e,r,n,o,a,s,c,u,l;return v().wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return e=t.authenticationData,r=t.methodData,n=t.requestData,o=n.apiWrapperOptions,a=n.payload,s=L({apiWrapperOptions:o,methodData:r,payload:a},"data"),c=L({apiWrapperOptions:o,methodData:r,payload:a},"timeout",1e4),u=L({apiWrapperOptions:o,methodData:r,payload:a},"url"),l=this._getStore().getState(),i.next=8,this._axios.request({timeout:c,data:"function"==typeof s?s(a,l):s,headers:e?{Authorization:"Bearer ".concat(e.tokenAccess)}:{},method:r.method,url:"function"==typeof u?u(a,l):u});case 8:return i.abrupt("return",i.sent);case 9:case"end":return i.stop()}}),i,this)}))),function(t){return r.apply(this,arguments)})},{key:"getCreateMethodData",value:function(){return{actionName:"create",method:"post"}}},{key:"getDeleteMethodData",value:function(){return{actionName:"delete",method:"delete"}}},{key:"getReadMethodData",value:function(){return{actionName:"read",method:"get"}}},{key:"getUpdateMethodData",value:function(){return{actionName:"update",method:"patch"}}},{key:"isAuthenticationFailedError",value:function(t){var e;return 403===(null==t||null===(e=t.response)||void 0===e?void 0:e.status)}},{key:"isSessionExpiredError",value:function(t){var e;return 401===(null==t||null===(e=t.response)||void 0===e?void 0:e.status)}}]),a}(l.ApiTransport);function M(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u()(t);if(e){var o=u()(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return s()(this,r)}}var j=function(t){n()(o,t);var r=M(o);function o(t){var n=t.dispatchSetTokenAccess,a=t.getStore,i=t.selectSessionData;return e()(this,o),r.call(this,{authenticator:new x({dispatchSetTokenAccess:n,getStore:a,selectSessionData:i}),realtimeTransport:new S,transport:new E({getStore:a})})}return o}(l.ApiWrapper)})(),i})()})); | ||
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(require("@ololoepepe/api-wrapper"),require("@hierotech/common"),require("axios")):"function"==typeof define&&define.amd?define(["@ololoepepe/api-wrapper","@hierotech/common","axios"],e):"object"==typeof exports?exports.hierotechApiWrapper=e(require("@ololoepepe/api-wrapper"),require("@hierotech/common"),require("axios")):t.hierotechApiWrapper=e(t["@ololoepepe/api-wrapper"],t["@hierotech/common"],t.axios)}(global,(function(t,e,r){return(()=>{var n={506:t=>{t.exports=function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t},t.exports["default"]=t.exports,t.exports.__esModule=!0},926:t=>{function e(t,e,r,n,o,a,i){try{var s=t[a](i),c=s.value}catch(u){return void r(u)}s.done?e(c):Promise.resolve(c).then(n,o)}t.exports=function(t){return function(){var r=this,n=arguments;return new Promise((function(o,a){var i=t.apply(r,n);function s(t){e(i,o,a,s,c,"next",t)}function c(t){e(i,o,a,s,c,"throw",t)}s(undefined)}))}},t.exports["default"]=t.exports,t.exports.__esModule=!0},575:t=>{t.exports=function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")},t.exports["default"]=t.exports,t.exports.__esModule=!0},913:t=>{function e(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,n.key,n)}}t.exports=function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t},t.exports["default"]=t.exports,t.exports.__esModule=!0},754:t=>{function e(r){return t.exports=e=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)},t.exports["default"]=t.exports,t.exports.__esModule=!0,e(r)}t.exports=e,t.exports["default"]=t.exports,t.exports.__esModule=!0},205:(t,e,r)=>{var n=r(489);t.exports=function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&n(t,e)},t.exports["default"]=t.exports,t.exports.__esModule=!0},585:(t,e,r)=>{var n=r(8)["default"],o=r(506);t.exports=function(t,e){return!e||"object"!==n(e)&&"function"!=typeof e?o(t):e},t.exports["default"]=t.exports,t.exports.__esModule=!0},489:t=>{function e(r,n){return t.exports=e=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},t.exports["default"]=t.exports,t.exports.__esModule=!0,e(r,n)}t.exports=e,t.exports["default"]=t.exports,t.exports.__esModule=!0},8:t=>{function e(r){return"function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?(t.exports=e=function(t){return typeof t},t.exports["default"]=t.exports,t.exports.__esModule=!0):(t.exports=e=function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t},t.exports["default"]=t.exports,t.exports.__esModule=!0),e(r)}t.exports=e,t.exports["default"]=t.exports,t.exports.__esModule=!0},757:(t,e,r)=>{t.exports=r(666)},666:t=>{var e=function(t){"use strict";var e,r=Object.prototype,n=r.hasOwnProperty,o="function"==typeof Symbol?Symbol:{},a=o.iterator||"@@iterator",i=o.asyncIterator||"@@asyncIterator",s=o.toStringTag||"@@toStringTag";function c(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{c({},"")}catch(j){c=function(t,e,r){return t[e]=r}}function u(t,e,r,n){var o=e&&e.prototype instanceof v?e:v,a=Object.create(o.prototype),i=new E(n||[]);return a._invoke=function(t,e,r){var n=p;return function(o,a){if(n===h)throw new Error("Generator is already running");if(n===d){if("throw"===o)throw a;return M()}for(r.method=o,r.arg=a;;){var i=r.delegate;if(i){var s=A(i,r);if(s){if(s===y)continue;return s}}if("next"===r.method)r.sent=r._sent=r.arg;else if("throw"===r.method){if(n===p)throw n=d,r.arg;r.dispatchException(r.arg)}else"return"===r.method&&r.abrupt("return",r.arg);n=h;var c=l(t,e,r);if("normal"===c.type){if(n=r.done?d:f,c.arg===y)continue;return{value:c.arg,done:r.done}}"throw"===c.type&&(n=d,r.method="throw",r.arg=c.arg)}}}(t,r,i),a}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(j){return{type:"throw",arg:j}}}t.wrap=u;var p="suspendedStart",f="suspendedYield",h="executing",d="completed",y={};function v(){}function m(){}function x(){}var _={};_[a]=function(){return this};var g=Object.getPrototypeOf,b=g&&g(g(L([])));b&&b!==r&&n.call(b,a)&&(_=b);var w=x.prototype=v.prototype=Object.create(_);function k(t){["next","throw","return"].forEach((function(e){c(t,e,(function(t){return this._invoke(e,t)}))}))}function S(t,e){function r(o,a,i,s){var c=l(t[o],t,a);if("throw"!==c.type){var u=c.arg,p=u.value;return p&&"object"==typeof p&&n.call(p,"__await")?e.resolve(p.__await).then((function(t){r("next",t,i,s)}),(function(t){r("throw",t,i,s)})):e.resolve(p).then((function(t){u.value=t,i(u)}),(function(t){return r("throw",t,i,s)}))}s(c.arg)}var o;this._invoke=function(t,n){function a(){return new e((function(e,o){r(t,n,e,o)}))}return o=o?o.then(a,a):a()}}function A(t,r){var n=t.iterator[r.method];if(n===e){if(r.delegate=null,"throw"===r.method){if(t.iterator["return"]&&(r.method="return",r.arg=e,A(t,r),"throw"===r.method))return y;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return y}var o=l(n,t.iterator,r.arg);if("throw"===o.type)return r.method="throw",r.arg=o.arg,r.delegate=null,y;var a=o.arg;return a?a.done?(r[t.resultName]=a.value,r.next=t.nextLoc,"return"!==r.method&&(r.method="next",r.arg=e),r.delegate=null,y):a:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,y)}function O(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function R(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function E(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(O,this),this.reset(!0)}function L(t){if(t){var r=t[a];if(r)return r.call(t);if("function"==typeof t.next)return t;if(!isNaN(t.length)){var o=-1,i=function r(){for(;++o<t.length;)if(n.call(t,o))return r.value=t[o],r.done=!1,r;return r.value=e,r.done=!0,r};return i.next=i}}return{next:M}}function M(){return{value:e,done:!0}}return m.prototype=w.constructor=x,x.constructor=m,m.displayName=c(x,s,"GeneratorFunction"),t.isGeneratorFunction=function(t){var e="function"==typeof t&&t.constructor;return!!e&&(e===m||"GeneratorFunction"===(e.displayName||e.name))},t.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,x):(t.__proto__=x,c(t,s,"GeneratorFunction")),t.prototype=Object.create(w),t},t.awrap=function(t){return{__await:t}},k(S.prototype),S.prototype[i]=function(){return this},t.AsyncIterator=S,t.async=function(e,r,n,o,a){void 0===a&&(a=Promise);var i=new S(u(e,r,n,o),a);return t.isGeneratorFunction(r)?i:i.next().then((function(t){return t.done?t.value:i.next()}))},k(w),c(w,s,"Generator"),w[a]=function(){return this},w.toString=function(){return"[object Generator]"},t.keys=function(t){var e=[];for(var r in t)e.push(r);return e.reverse(),function n(){for(;e.length;){var r=e.pop();if(r in t)return n.value=r,n.done=!1,n}return n.done=!0,n}},t.values=L,E.prototype={constructor:E,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=e,this.done=!1,this.delegate=null,this.method="next",this.arg=e,this.tryEntries.forEach(R),!t)for(var r in this)"t"===r.charAt(0)&&n.call(this,r)&&!isNaN(+r.slice(1))&&(this[r]=e)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(t){if(this.done)throw t;var r=this;function o(n,o){return s.type="throw",s.arg=t,r.next=n,o&&(r.method="next",r.arg=e),!!o}for(var a=this.tryEntries.length-1;a>=0;--a){var i=this.tryEntries[a],s=i.completion;if("root"===i.tryLoc)return o("end");if(i.tryLoc<=this.prev){var c=n.call(i,"catchLoc"),u=n.call(i,"finallyLoc");if(c&&u){if(this.prev<i.catchLoc)return o(i.catchLoc,!0);if(this.prev<i.finallyLoc)return o(i.finallyLoc)}else if(c){if(this.prev<i.catchLoc)return o(i.catchLoc,!0)}else{if(!u)throw new Error("try statement without catch or finally");if(this.prev<i.finallyLoc)return o(i.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;r>=0;--r){var o=this.tryEntries[r];if(o.tryLoc<=this.prev&&n.call(o,"finallyLoc")&&this.prev<o.finallyLoc){var a=o;break}}a&&("break"===t||"continue"===t)&&a.tryLoc<=e&&e<=a.finallyLoc&&(a=null);var i=a?a.completion:{};return i.type=t,i.arg=e,a?(this.method="next",this.next=a.finallyLoc,y):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),y},finish:function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),R(r),y}},"catch":function(t){for(var e=this.tryEntries.length-1;e>=0;--e){var r=this.tryEntries[e];if(r.tryLoc===t){var n=r.completion;if("throw"===n.type){var o=n.arg;R(r)}return o}}throw new Error("illegal catch attempt")},delegateYield:function(t,r,n){return this.delegate={iterator:L(t),resultName:r,nextLoc:n},"next"===this.method&&(this.arg=e),y}},t}(t.exports);try{regeneratorRuntime=e}catch(r){Function("r","regeneratorRuntime = r")(e)}},695:t=>{"use strict";t.exports=e},84:e=>{"use strict";e.exports=t},376:t=>{"use strict";t.exports=r}},o={};function a(t){var e=o[t];if(e!==undefined)return e.exports;var r=o[t]={exports:{}};return n[t](r,r.exports,a),r.exports}a.n=t=>{var e=t&&t.__esModule?()=>t["default"]:()=>t;return a.d(e,{a:e}),e},a.d=(t,e)=>{for(var r in e)a.o(e,r)&&!a.o(t,r)&&Object.defineProperty(t,r,{enumerable:!0,get:e[r]})},a.o=(t,e)=>Object.prototype.hasOwnProperty.call(t,e),a.r=t=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(t,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(t,"__esModule",{value:!0})};var i={};return(()=>{"use strict";a.r(i),a.d(i,{"default":()=>P});var t=a(575),e=a.n(t),r=a(205),n=a.n(r),o=a(585),s=a.n(o),c=a(754),u=a.n(c),l=a(84),p=a(926),f=a.n(p),h=a(913),d=a.n(h),y=a(757),v=a.n(y);function m(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u()(t);if(e){var o=u()(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return s()(this,r)}}var x=function(t){n()(s,t);var r,o,a,i=m(s);function s(t){var r,n=t.dispatchSetTokenAccess,o=t.getStore,a=t.selectSessionData;return e()(this,s),(r=i.call(this))._dispatchSetTokenAccess=n,r._selectSessionData=a,r._getStore=o,r}return d()(s,[{key:"authenticate",value:(a=f()(v().mark((function c(t,e){var r,n,o,a;return v().wrap((function(i){for(;;)switch(i.prev=i.next){case 0:if(e){i.next=2;break}return i.abrupt("return",null);case 2:return r=e.sessionId,n=e.tokenRefresh,i.next=5,t.callMethod({method:"patch"},{payload:{data:{token_refresh:n},url:"/auth/sessions/".concat(r)}});case 5:return o=i.sent,a=o.data.token_access,i.abrupt("return",{sessionId:r,tokenAccess:a,tokenRefresh:n});case 8:case"end":return i.stop()}}),c)}))),function(t,e){return a.apply(this,arguments)})},{key:"loadAuthenticationData",value:(o=f()(v().mark((function u(){var t,e,r,n,o;return v().wrap((function(a){for(;;)switch(a.prev=a.next){case 0:return t=this._selectSessionData(this._getStore().getState()),e=t.isLoggedIn,r=t.sessionId,n=t.tokenAccess,o=t.tokenRefresh,a.abrupt("return",e?{sessionId:r,tokenAccess:n,tokenRefresh:o}:null);case 2:case"end":return a.stop()}}),u,this)}))),function(){return o.apply(this,arguments)})},{key:"saveAuthenticationData",value:(r=f()(v().mark((function l(t){return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(t){e.next=2;break}return e.abrupt("return");case 2:this._dispatchSetTokenAccess(this._getStore().dispatch,t.tokenAccess);case 3:case"end":return e.stop()}}),l,this)}))),function(t){return r.apply(this,arguments)})}]),s}(l.ApiAuthenticator),_=a(695);function g(t,e){var r;if("undefined"==typeof Symbol||null==t[Symbol.iterator]){if(Array.isArray(t)||(r=function(t,e){if(!t)return;if("string"==typeof t)return b(t,e);var r=Object.prototype.toString.call(t).slice(8,-1);"Object"===r&&t.constructor&&(r=t.constructor.name);if("Map"===r||"Set"===r)return Array.from(t);if("Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r))return b(t,e)}(t))||e&&t&&"number"==typeof t.length){r&&(t=r);var n=0,o=function(){};return{s:o,n:function(){return n>=t.length?{done:!0}:{done:!1,value:t[n++]}},e:function(t){throw t},f:o}}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 a,i=!0,s=!1;return{s:function(){r=t[Symbol.iterator]()},n:function(){var t=r.next();return i=t.done,t},e:function(t){s=!0,a=t},f:function(){try{i||null==r["return"]||r["return"]()}finally{if(s)throw a}}}}function b(t,e){(null==e||e>t.length)&&(e=t.length);for(var r=0,n=new Array(e);r<e;r++)n[r]=t[r];return n}function w(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u()(t);if(e){var o=u()(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return s()(this,r)}}var k=_.Helper.exposeFields,S=_.Helper.stringifyQuery,A=new Map([["addSingle","onAddItem"],["addList","onAddItems"],["editSingle","onChangeItem"],["editList","onChangeItems"],["deleteSingle","onRemoveItem"]]),O=function(t){n()(i,t);var r,o,a=w(i);function i(){var t;return e()(this,i),(t=a.call(this))._error=null,t._isAuthRetry=!1,t._onConnect=null,t._subscriptions=new Map,t._wrapper=null,t._ws=null,t}return d()(i,[{key:"connect",value:function(t){var e=this,r=t.onConnect,n=t.onDisconnect,o=t.wrapper;this._onConnect=r,this._wrapper=o;var a=new WebSocket("ws://".concat(window.location.host,"/api/realtime"));a.onclose=function(){n(e._error);var t,r=g(e._subscriptions);try{for(r.s();!(t=r.n()).done;){(0,t.value.onUnsubscribe)()}}catch(o){r.e(o)}finally{r.f()}e._error=null,e._isAuthRetry=!1,e._onConnect=null,e._subscriptions.clear(),e._wrapper=null,e._ws=null},a.onerror=function(t){console.warn("ws err:",t)},a.onmessage=function(t){return e._handleMessage(t)},a.onopen=function(){return e._handleConnect()},this._ws=a}},{key:"disconnect",value:function(){this._ws.close(1e3)}},{key:"subscribe",value:function(t){var e=t.callbacks,r=t.onSubscribe,n=t.onUnsubscribe,o=t.subscriptionData;this._subscriptions.set(this._createKey(o),{callbacks:e,onUnsubscribe:n,options:o.options}),"candlestick"===o.name&&this._ws.send(JSON.stringify({type:"subscribe",data:{data:o.options,type:"candlestick"}})),r()}},{key:"unsubscribe",value:function(t){var e=t.subscriptionData,r=this._createKey(e),n=this._subscriptions.get(r);this._subscriptions["delete"](r),"candlestick"===e.name&&this._ws.send(JSON.stringify({type:"unsubscribe",data:{data:e.options,type:"candlestick"}})),n.onUnsubscribe()}},{key:"_authenticate",value:(o=f()(v().mark((function s(){var t;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:if(e.prev=0,t=this._wrapper.authenticate()){e.next=4;break}throw new Error("No authenticationData provided");case 4:this._send({type:"auth",data:{token:t.tokenAccess}}),e.next=11;break;case 7:e.prev=7,e.t0=e["catch"](0),this._error=e.t0,this.disconnect();case 11:case"end":return e.stop()}}),s,this,[[0,7]])}))),function(){return o.apply(this,arguments)})},{key:"_createKey",value:function(t){var e=t.name,r=t.options;return"candlestick"===e?"".concat(e,"?").concat(S(k(r,"asset_ticker","interval","nominal"))):e}},{key:"_handleAuthMessage",value:function(t){var e=t.error;return t.success?(this._isAuthRetry=!1,void this._onConnect()):401!==(null==e?void 0:e.code)||this._isAuthRetry?(this._error=new Error("Authentication failed"),void this.disconnect()):(this._isAuthRetry=!0,void this._authenticate()["catch"]((function(t){return console.warn(t)})))}},{key:"_handleConnect",value:(r=f()(v().mark((function c(){var t;return v().wrap((function(e){for(;;)switch(e.prev=e.next){case 0:return e.prev=0,e.next=3,this._wrapper.getAuthenticationData();case 3:if(t=e.sent){e.next=6;break}throw new Error("No authenticationData provided");case 6:this._send({type:"auth",data:{token:t.tokenAccess}}),e.next=13;break;case 9:e.prev=9,e.t0=e["catch"](0),this._error=e.t0,this.disconnect();case 13:case"end":return e.stop()}}),c,this,[[0,9]])}))),function(){return r.apply(this,arguments)})},{key:"_handleMessage",value:function(t){var e,r,n=JSON.parse(t.data),o=n.data,a=n.error,i=n.success,s=n.type;if("auth"!==s)if("notification"===s){var c=this._createKey({name:o.type,options:o.data.data}),u=null===(e=this._subscriptions.get(c))||void 0===e||null===(r=e.callbacks)||void 0===r?void 0:r[A.get(o.data.type)];u&&u(o.data.data)}else console.warn(s,o);else this._handleAuthMessage({error:a,success:i})}},{key:"_send",value:function(t){return this._ws.send(JSON.stringify(t))}}]),i}(l.ApiRealtimeTransport),R=a(376),E=a.n(R);function L(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u()(t);if(e){var o=u()(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return s()(this,r)}}function M(t,e,r){var n,o,a,i=t.apiWrapperOptions,s=t.methodData,c=t.payload,u=s.actionName,l=s.method;return(null==c?void 0:c[e])||(null==i||null===(n=i[u])||void 0===n?void 0:n[e])||(null==i||null===(o=i[l])||void 0===o?void 0:o[e])||(null==i||null===(a=i["default"])||void 0===a?void 0:a[e])||r}var j=function(t){n()(a,t);var r,o=L(a);function a(t){var r,n=t.getStore;return e()(this,a),(r=o.call(this))._axios=E().create({baseURL:"/api",timeout:1e4}),r._getStore=n,r}return d()(a,[{key:"callMethod",value:(r=f()(v().mark((function i(t){var e,r,n,o,a,s,c,u,l;return v().wrap((function(i){for(;;)switch(i.prev=i.next){case 0:return e=t.authenticationData,r=t.methodData,n=t.requestData,o=n.apiWrapperOptions,a=n.payload,s=M({apiWrapperOptions:o,methodData:r,payload:a},"data"),c=M({apiWrapperOptions:o,methodData:r,payload:a},"timeout",1e4),u=M({apiWrapperOptions:o,methodData:r,payload:a},"url"),l=this._getStore().getState(),i.next=8,this._axios.request({timeout:c,data:"function"==typeof s?s(a,l):s,headers:e?{Authorization:"Bearer ".concat(e.tokenAccess)}:{},method:r.method,url:"function"==typeof u?u(a,l):u});case 8:return i.abrupt("return",i.sent);case 9:case"end":return i.stop()}}),i,this)}))),function(t){return r.apply(this,arguments)})},{key:"getCreateMethodData",value:function(){return{actionName:"create",method:"post"}}},{key:"getDeleteMethodData",value:function(){return{actionName:"delete",method:"delete"}}},{key:"getReadMethodData",value:function(){return{actionName:"read",method:"get"}}},{key:"getUpdateMethodData",value:function(){return{actionName:"update",method:"patch"}}},{key:"isAuthenticationFailedError",value:function(t){var e;return 403===(null==t||null===(e=t.response)||void 0===e?void 0:e.status)}},{key:"isSessionExpiredError",value:function(t){var e;return 401===(null==t||null===(e=t.response)||void 0===e?void 0:e.status)}}]),a}(l.ApiTransport);function D(t){var e=function(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(t){return!1}}();return function(){var r,n=u()(t);if(e){var o=u()(this).constructor;r=Reflect.construct(n,arguments,o)}else r=n.apply(this,arguments);return s()(this,r)}}var P=function(t){n()(o,t);var r=D(o);function o(t){var n=t.dispatchSetTokenAccess,a=t.getStore,i=t.selectSessionData;return e()(this,o),r.call(this,{authenticator:new x({dispatchSetTokenAccess:n,getStore:a,selectSessionData:i}),realtimeTransport:new O,transport:new j({getStore:a})})}return o}(l.ApiWrapper)})(),i})()})); | ||
//# sourceMappingURL=index.node.js.map |
{ | ||
"name": "@hierotech/api-wrapper", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "Implementation of @ololoepepe/api-wrapper for Hiero.tech", | ||
@@ -27,3 +27,3 @@ "main": "dist/index.node.js", | ||
"@hierotech/common": "^0.1.9", | ||
"@ololoepepe/api-wrapper": "0.0.7", | ||
"@ololoepepe/api-wrapper": "0.0.8", | ||
"axios": "^0.21.1" | ||
@@ -30,0 +30,0 @@ }, |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
168363
154
3
+ Added@ololoepepe/api-wrapper@0.0.8(transitive)
- Removed@ololoepepe/api-wrapper@0.0.7(transitive)