@hierotech/api-wrapper
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -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=this._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:{},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})()})); | ||
//# 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=this._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 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})()})); | ||
//# sourceMappingURL=index.node.js.map |
{ | ||
"name": "@hierotech/api-wrapper", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "Implementation of @ololoepepe/api-wrapper for Hiero.tech", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.node.js", |
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
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
164743