@pushwoosh/http-client 2.7.2 → 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +1 -1
- package/dist/index.js.LICENSE.txt +1 -1
- package/dist/index.js.map +1 -1
- package/package.json +13 -44
- package/dist/http-client.errors.d.ts +0 -231
- package/dist/http-client.errors.d.ts.map +0 -1
- package/dist/http-client.helpers.d.ts +0 -3
- package/dist/http-client.helpers.d.ts.map +0 -1
- package/dist/http-client.main.d.ts +0 -180
- package/dist/http-client.main.d.ts.map +0 -1
- package/dist/http-client.types.d.ts +0 -99
- package/dist/http-client.types.d.ts.map +0 -1
- package/dist/http-client.utilities.d.ts +0 -20
- package/dist/http-client.utilities.d.ts.map +0 -1
- package/dist/index.d.ts +0 -6
- package/dist/index.d.ts.map +0 -1
- package/dist/rpc-client.d.ts +0 -105
- package/dist/rpc-client.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
System.register("@pushwoosh/http-client",[],(function(e,t){return{execute:function(){e((()=>{var e={90:e=>{e.exports=function(e){var t=null==e?0:e.length;return t?e[t-1]:void 0}}},t={};function r(o){var n=t[o];if(void 0!==n)return n.exports;var s=t[o]={exports:{}};return e[o](s,s.exports,r),s.exports}r.n=e=>{var t=e&&e.__esModule?()=>e.default:()=>e;return r.d(t,{a:t}),t},r.d=(e,t)=>{for(var o in t)r.o(t,o)&&!r.o(e,o)&&Object.defineProperty(e,o,{enumerable:!0,get:t[o]})},r.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),r.r=e=>{"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var o={};return(()=>{"use strict";function e(t){return e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e(t)}function t(t){var r=function(t,r){if("object"!=e(t)||!t)return t;var o=t[Symbol.toPrimitive];if(void 0!==o){var n=o.call(t,r||"default");if("object"!=e(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===r?String:Number)(t)}(t,"string");return"symbol"==e(r)?r:r+""}function n(e,r,o){return(r=t(r))in e?Object.defineProperty(e,r,{value:o,enumerable:!0,configurable:!0,writable:!0}):e[r]=o,e}r.r(o),r.d(o,{BadGatewayError:()=>T,BadRequestError:()=>h,ClassifiedError:()=>a,ForbiddenError:()=>l,GatewayTimeoutError:()=>m,HttpClient:()=>z,HttpClientError:()=>s,InternalServerError:()=>g,LogicError:()=>i,Method:()=>P,MethodNotAllowedError:()=>p,NotFoundError:()=>d,NotImplementedError:()=>v,PayloadTooLargeError:()=>f,RpcClient:()=>q,RpcException:()=>H,ServiceUnavailableError:()=>O,TooManyRequestsError:()=>E,UnauthorizedError:()=>u,UnprocessableEntityError:()=>y,UnsupportedMediaTypeError:()=>w,UntiledError:()=>c,checkIsResponseSuccess:()=>M,defaultErrorMiddleware:()=>$,defaultResponseMiddleware:()=>j});class s extends Error{constructor(e,t){super(e),n(this,"code",void 0),this.code=t,Object.setPrototypeOf(this,s.prototype)}}class i extends s{constructor(e){super(e,0),Object.setPrototypeOf(this,i.prototype)}}class a extends s{constructor(e,t,r){super(e,t),n(this,"details",void 0),this.details=r,Object.setPrototypeOf(this,a.prototype)}}class c extends a{constructor(e,t,r){super(e,t,r),Object.setPrototypeOf(this,c.prototype)}}class h extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Bad Request!",400,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,h.prototype)}}class u extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Unauthorized!",401,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,u.prototype)}}class l extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Forbidden!",403,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,l.prototype)}}class d extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not Found!",404,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,d.prototype)}}class p extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Method Not Allowed!",405,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,p.prototype)}}class f extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Payload Too Large!",413,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,f.prototype)}}class w extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Unsupported Media Type!",415,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,w.prototype)}}class y extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Unprocessable Entity!",422,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,y.prototype)}}class E extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Too Many Requests!",429,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,E.prototype)}}class g extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Internal Server Error!",500,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,g.prototype)}}class v extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not Implemented!",501,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,v.prototype)}}class T extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Bad Gateway!",502,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,T.prototype)}}class O extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Service Unavailable!",503,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,O.prototype)}}class m extends a{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Gateway Timeout!",504,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,m.prototype)}}function A(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)e[o]=r[o]}return e}var b=function e(t,r){function o(e,o,n){if("undefined"!=typeof document){"number"==typeof(n=A({},r,n)).expires&&(n.expires=new Date(Date.now()+864e5*n.expires)),n.expires&&(n.expires=n.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var i in n)n[i]&&(s+="; "+i,!0!==n[i]&&(s+="="+n[i].split(";")[0]));return document.cookie=e+"="+t.write(o,e)+s}}return Object.create({set:o,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var r=document.cookie?document.cookie.split("; "):[],o={},n=0;n<r.length;n++){var s=r[n].split("="),i=s.slice(1).join("=");try{var a=decodeURIComponent(s[0]);if(o[a]=t.read(i,a),e===a)break}catch(e){}}return e?o[e]:o}},remove:function(e,t){o(e,"",A({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,A({},this.attributes,t))},withConverter:function(t){return e(A({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});class R extends Error{}function _(e){let t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return function(e){return decodeURIComponent(atob(e).replace(/(.)/g,((e,t)=>{let r=t.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r})))}(t)}catch(e){return atob(t)}}function I(e,t){if("string"!=typeof e)throw new R("Invalid token specified: must be a string");t||(t={});const r=!0===t.header?0:1,o=e.split(".")[r];if("string"!=typeof o)throw new R(`Invalid token specified: missing part #${r+1}`);let n;try{n=_(o)}catch(e){throw new R(`Invalid token specified: invalid base64 for part #${r+1} (${e.message})`)}try{return JSON.parse(n)}catch(e){throw new R(`Invalid token specified: invalid json for part #${r+1} (${e.message})`)}}function S(e,t){void 0===t&&(t={});for(var r=function(e){for(var t=[],r=0;r<e.length;){var o=e[r];if("*"!==o&&"+"!==o&&"?"!==o)if("\\"!==o)if("{"!==o)if("}"!==o)if(":"!==o)if("("!==o)t.push({type:"CHAR",index:r,value:e[r++]});else{var n=1,s="";if("?"===e[a=r+1])throw new TypeError('Pattern cannot start with "?" at '.concat(a));for(;a<e.length;)if("\\"!==e[a]){if(")"===e[a]){if(0==--n){a++;break}}else if("("===e[a]&&(n++,"?"!==e[a+1]))throw new TypeError("Capturing groups are not allowed at ".concat(a));s+=e[a++]}else s+=e[a++]+e[a++];if(n)throw new TypeError("Unbalanced pattern at ".concat(r));if(!s)throw new TypeError("Missing pattern at ".concat(r));t.push({type:"PATTERN",index:r,value:s}),r=a}else{for(var i="",a=r+1;a<e.length;){var c=e.charCodeAt(a);if(!(c>=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122||95===c))break;i+=e[a++]}if(!i)throw new TypeError("Missing parameter name at ".concat(r));t.push({type:"NAME",index:r,value:i}),r=a}else t.push({type:"CLOSE",index:r,value:e[r++]});else t.push({type:"OPEN",index:r,value:e[r++]});else t.push({type:"ESCAPED_CHAR",index:r++,value:e[r++]});else t.push({type:"MODIFIER",index:r,value:e[r++]})}return t.push({type:"END",index:r,value:""}),t}(e),o=t.prefixes,n=void 0===o?"./":o,s=t.delimiter,i=void 0===s?"/#?":s,a=[],c=0,h=0,u="",l=function(e){if(h<r.length&&r[h].type===e)return r[h++].value},d=function(e){var t=l(e);if(void 0!==t)return t;var o=r[h],n=o.type,s=o.index;throw new TypeError("Unexpected ".concat(n," at ").concat(s,", expected ").concat(e))},p=function(){for(var e,t="";e=l("CHAR")||l("ESCAPED_CHAR");)t+=e;return t},f=function(e){var t=a[a.length-1],r=e||(t&&"string"==typeof t?t:"");if(t&&!r)throw new TypeError('Must have text between two parameters, missing text after "'.concat(t.name,'"'));return!r||function(e){for(var t=0,r=i;t<r.length;t++){var o=r[t];if(e.indexOf(o)>-1)return!0}return!1}(r)?"[^".concat(U(i),"]+?"):"(?:(?!".concat(U(r),")[^").concat(U(i),"])+?")};h<r.length;){var w=l("CHAR"),y=l("NAME"),E=l("PATTERN");if(y||E){var g=w||"";-1===n.indexOf(g)&&(u+=g,g=""),u&&(a.push(u),u=""),a.push({name:y||c++,prefix:g,suffix:"",pattern:E||f(g),modifier:l("MODIFIER")||""})}else{var v=w||l("ESCAPED_CHAR");if(v)u+=v;else if(u&&(a.push(u),u=""),l("OPEN")){g=p();var T=l("NAME")||"",O=l("PATTERN")||"",m=p();d("CLOSE"),a.push({name:T||(O?c++:""),pattern:T&&!O?f(g):O,prefix:g,suffix:m,modifier:l("MODIFIER")||""})}else d("END")}}return a}function k(e,t){return function(e,t){void 0===t&&(t={});var r=x(t),o=t.encode,n=void 0===o?function(e){return e}:o,s=t.validate,i=void 0===s||s,a=e.map((function(e){if("object"==typeof e)return new RegExp("^(?:".concat(e.pattern,")$"),r)}));return function(t){for(var r="",o=0;o<e.length;o++){var s=e[o];if("string"!=typeof s){var c=t?t[s.name]:void 0,h="?"===s.modifier||"*"===s.modifier,u="*"===s.modifier||"+"===s.modifier;if(Array.isArray(c)){if(!u)throw new TypeError('Expected "'.concat(s.name,'" to not repeat, but got an array'));if(0===c.length){if(h)continue;throw new TypeError('Expected "'.concat(s.name,'" to not be empty'))}for(var l=0;l<c.length;l++){var d=n(c[l],s);if(i&&!a[o].test(d))throw new TypeError('Expected all "'.concat(s.name,'" to match "').concat(s.pattern,'", but got "').concat(d,'"'));r+=s.prefix+d+s.suffix}}else if("string"!=typeof c&&"number"!=typeof c){if(!h){var p=u?"an array":"a string";throw new TypeError('Expected "'.concat(s.name,'" to be ').concat(p))}}else{d=n(String(c),s);if(i&&!a[o].test(d))throw new TypeError('Expected "'.concat(s.name,'" to match "').concat(s.pattern,'", but got "').concat(d,'"'));r+=s.prefix+d+s.suffix}}else r+=s}return r}}(S(e,t),t)}function U(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}function x(e){return e&&e.sensitive?"":"i"}R.prototype.name="InvalidTokenError";const N=/[a-zA-z]+:\/\/[^/]*/;function C(e,t){let r="",o=`${e}`;return function(e){return!!e.match(N)}(e)&&([r]=e.match(N),o=e.slice(r.length)),r+k(o)(t)}var P;!function(e){e.GET="GET",e.POST="POST",e.PUT="PUT",e.PATCH="PATCH",e.DELETE="DELETE"}(P||(P={}));class z{constructor(e,t){n(this,"baseURL",void 0),n(this,"history",void 0),n(this,"config",void 0),n(this,"accessToken",void 0),n(this,"refreshToken",void 0),n(this,"isRefreshing",void 0),n(this,"userName",void 0),n(this,"accountID",void 0),n(this,"checkAuthorization",(async e=>{if(this.isRefreshing)return await new Promise((e=>{setTimeout(e,100)})),void await this.checkAuthorization(e);if(!this.accessToken)throw new u("Unauthorized!",e);const t=(new Date).getTime()/1e3;I(this.accessToken).expired_at<t&&(await this.updateTokenByRefreshToken(e),await this.checkAuthorization(e))})),n(this,"updateToken",(async e=>{const t=`Basic ${btoa(`${this.config.clientId}:`)}`;try{this.isRefreshing=!0;const r=await this.post(this.config.urls.token,{headers:{Authorization:t},query:e,withAuthorization:!1,withCredentials:!0});this.accessToken=r.access_token,this.refreshToken=r.refresh_token,this.isRefreshing=!1}catch(e){throw this.accessToken=null,this.refreshToken=null,this.isRefreshing=!1,e}})),n(this,"updateTokenByAuthorizationCode",(async e=>{await this.updateToken({grant_type:"authorization_code",code:e,redirect_uri:`${window.location.origin}${window.location.pathname}`})})),n(this,"updateTokenByRefreshToken",(async e=>{if(!this.refreshToken)throw this.accessToken=null,new u("Unauthorized!",e);await this.updateToken({grant_type:"refresh_token",refresh_token:this.refreshToken,username:this.userName,account_id:this.accountID})})),n(this,"processFetchResponse",(async(e,t,r)=>{var o;let n;return n=null!==(o=e.headers.get("Content-Type"))&&void 0!==o&&o.includes("application/json")?await e.json().catch((()=>({}))):await e.text().then((e=>{try{return JSON.parse(e)}catch{return e}})).catch((()=>"")),r({result:n,status:e.status,message:e.statusText,details:t})})),n(this,"buildFetchRequest",(async(e,t,r)=>{let o=e;if(this.baseURL&&!o.startsWith("http")&&(o=`${this.baseURL}${o.startsWith("/")?"":"/"}${o}`),r.params&&(o=C(o,r.params)),r.query){const e=r.query;let t;t="string"==typeof e?e:e instanceof URLSearchParams?e.toString():new URLSearchParams(e).toString(),o=`${o}${o.includes("?")?"&":"?"}${t}`}const n=r.headers||{},s={};Object.entries(n).forEach((e=>{let[t,r]=e;s[t]=String(r)})),r.withAuthorization&&(await this.checkAuthorization(null),s.Authorization=`Bearer ${this.accessToken}`);const i={method:t,headers:s,credentials:r.withCredentials?"include":"same-origin",signal:r.signal};return void 0!==r.body&&(r.body instanceof FormData?i.body=r.body:(s["Content-Type"]="application/json",t!==P.GET&&(i.body=JSON.stringify(r.body)))),{fetchUrl:o,fetchOptions:i,headersInit:s}})),n(this,"request",(async(e,t,r)=>{const{basicErrorMiddleware:o,basicResponseMiddleware:n}=this.config,{errorMiddleware:s=o,responseMiddleware:i=n}=r,a={url:e,method:t,headers:r.headers,params:r.params,query:r.query,body:r.body,withCredentials:r.withCredentials,withAuthorization:r.withAuthorization},{fetchUrl:c,fetchOptions:h,headersInit:l}=await this.buildFetchRequest(e,t,{headers:r.headers,withAuthorization:r.withAuthorization,withCredentials:r.withCredentials,params:r.params,query:r.query,body:r.body});try{const e=await fetch(c,h);return await this.processFetchResponse(e,a,i)}catch(e){if(!(e instanceof u))throw await s(e),e;try{r.withAuthorization&&(await this.updateTokenByRefreshToken(a),await this.checkAuthorization(a),l.Authorization=`Bearer ${this.accessToken}`);const e=await fetch(c,h);return await this.processFetchResponse(e,a,i)}catch(e){throw await s(e),e}}})),n(this,"stream",(async(e,t,r)=>{const{basicErrorMiddleware:o}=this.config,{errorMiddleware:n=o}=r,{fetchUrl:s,fetchOptions:i,headersInit:a}=await this.buildFetchRequest(e,t,{headers:r.headers,withAuthorization:r.withAuthorization,withCredentials:r.withCredentials,params:r.params,query:r.query,body:r.body,signal:r.signal}),c={url:e,method:t,params:r.params,query:r.query,body:r.body,withCredentials:r.withCredentials,withAuthorization:r.withAuthorization},{basicResponseMiddleware:h}=this.config;try{const e=await fetch(s,i);return e.ok||await this.processFetchResponse(e,c,h),e}catch(e){if(!(e instanceof u))throw await n(e),e;try{r.withAuthorization&&(await this.updateTokenByRefreshToken(c),await this.checkAuthorization(c),a.Authorization=`Bearer ${this.accessToken}`);const e=await fetch(s,i);return e.ok||await this.processFetchResponse(e,c,h),e}catch(e){throw await n(e),e}}})),n(this,"get",((e,t)=>this.request(e,P.GET,t))),n(this,"post",((e,t)=>this.request(e,P.POST,t))),n(this,"put",((e,t)=>this.request(e,P.PUT,t))),n(this,"patch",((e,t)=>this.request(e,P.PATCH,t))),n(this,"delete",((e,t)=>this.request(e,P.DELETE,t))),n(this,"login",(async()=>{const e=Math.random().toString().slice(2,12);sessionStorage.setItem(z.AUTHORIZATION_STATE_SESSION_KEY,e),sessionStorage.setItem(z.URL_BEFORE_AUTHORIZATION_SESSION_KEY,window.location.href),b.set(z.AUTHORIZATION_STATE_COOKIE_NAME,e),b.set(z.URL_BEFORE_AUTHORIZATION_COOKIE_NAME,window.location.href);const t=new URLSearchParams({response_type:"code",client_id:this.config.clientId,redirect_uri:`${window.location.origin}${window.location.pathname}`,state:e});window.location.href=`${this.config.urls.authorize}?${t.toString()}`})),n(this,"authorize",(async e=>{const t=sessionStorage.getItem(z.AUTHORIZATION_STATE_SESSION_KEY)||b.get(z.AUTHORIZATION_STATE_COOKIE_NAME),r=sessionStorage.getItem(z.URL_BEFORE_AUTHORIZATION_SESSION_KEY)||b.get(z.URL_BEFORE_AUTHORIZATION_COOKIE_NAME);if(sessionStorage.removeItem(z.AUTHORIZATION_STATE_SESSION_KEY),sessionStorage.removeItem(z.URL_BEFORE_AUTHORIZATION_SESSION_KEY),b.remove(z.AUTHORIZATION_STATE_COOKIE_NAME),b.remove(z.URL_BEFORE_AUTHORIZATION_COOKIE_NAME),r){const e=new URL(r);this.history.replace({pathname:e.pathname,search:e.search,hash:e.hash})}if(t!==e.state)throw new y("Stored authorization state and received authorization state are not equal!");if(await this.updateTokenByAuthorizationCode(e.code),!this.accessToken)throw new i("Access token is null after tokens update!");const o=I(this.accessToken);return this.userName=o.username,this.accountID=o.account_id.toString(),o})),n(this,"logout",(async()=>{this.accessToken=null,this.refreshToken=null,await this.get(this.config.urls.logout,{withAuthorization:!1,withCredentials:!0})})),n(this,"getAccessToken",(async()=>{if(await this.checkAuthorization(null),!this.accessToken)throw new i("Access token is null after authorization check!");return this.accessToken})),n(this,"setAccessToken",(e=>{this.accessToken=e}));const{baseURL:r}=t;this.baseURL=r,this.history=e,this.config=t,this.accessToken=null,this.refreshToken=null,this.isRefreshing=!1,this.userName="",this.accountID=""}}function M(e){return e.status>=200&&e.status<300}function j(e){var t;if(M(e))return e.result;const r=(null===(t=e.result)||void 0===t?void 0:t.message)||e.message||void 0;switch(e.status){case 400:throw new h(r,e.details);case 401:throw new u(r,e.details);case 403:throw new l(r,e.details);case 404:throw new d(r,e.details);case 405:throw new p(r,e.details);case 413:throw new f(r,e.details);case 415:throw new w(r,e.details);case 422:throw new y(r,e.details);case 429:throw new E(r,e.details);case 500:throw new g(r,e.details);case 501:throw new v(r,e.details);case 502:throw new T(r,e.details);case 503:throw new O(r,e.details);case 504:throw new m(r,e.details);default:throw new c(r||"Untiled Error!",e.status,e.details)}}function $(e){throw e}n(z,"AUTHORIZATION_STATE_COOKIE_NAME","__PW_AUTHORIZATION_STATE"),n(z,"AUTHORIZATION_STATE_SESSION_KEY","__PW_SESSION_AUTHORIZATION_STATE"),n(z,"URL_BEFORE_AUTHORIZATION_SESSION_KEY","__PW_SESSION_URL_BEFORE_AUTHORIZATION"),n(z,"URL_BEFORE_AUTHORIZATION_COOKIE_NAME","__PW_URL_BEFORE_AUTHORIZATION");var B=r(90),F=r.n(B);class H extends Error{constructor(e,t,r){super(e),n(this,"code",void 0),n(this,"details",void 0),n(this,"error",void 0),this.code=t,this.details=r,this.error=t}}function L(e,t){return`call method '${e}'${t?`: ${t}`:""}`}class q{constructor(e,t){n(this,"httpClient",void 0),n(this,"options",void 0),n(this,"counter",0),n(this,"listeners",[]),this.httpClient=e,this.options=t}subscribe(e){this.listeners.push(e)}callRemoteProcedure(e,t,r){return this.callRemoteProcedureBase("_rpc",{calls:[{name:e,params:t}]},L(e,r))}callRemoteProcedureWithFiles(e,t,r,o){const n=new FormData;return n.append("name",e),n.append("params",JSON.stringify(t)),Object.keys(r).forEach((e=>{const t=F()(e.split("."));n.append(t,r[e])})),this.callRemoteProcedureBase(`_upload_${e}`,n,L(`${e} (upload files)`,o))}callRemoteProcedureBase(e,t,r){return this.fetch(e,t,r).then((e=>{let{auth:t,responses:r}=e;const o=r[0];if(!o)throw new H("no result",500,{});if(function(e){return"error"in e}(o))throw new H(o.message,o.error,o.details);return{auth:t,response:o}}))}fetch(e,t,r){const{enviromentOrigin:o=""}=this.options,n=++this.counter;return this.options.log({num:n,type:"callStart",message:r,data:t}),this.httpClient.post(`${o}/cp/${e}?l=${encodeURI(r)}`,{body:t,withAuthorization:this.options.withAuthorization}).then((e=>(this.options.log({num:n,type:"callEnd",message:r,data:e}),this.listeners.forEach((t=>{try{t(e)}catch(e){this.options.onException({message:"RPC listener error",error:e})}})),e)))}}})(),o})())}}}));
|
|
2
|
+
System.register([],function(e,t){return{execute:function(){e((()=>{var e={126(e,t,r){const o=r(358).y;t.w=function(e){if(e||(e=1),!r.y.meta||!r.y.meta.url)throw console.error("__system_context__",r.y),Error("systemjs-webpack-interop was provided an unknown SystemJS context. Expected context.meta.url, but none was provided");r.p=o(r.y.meta.url,e)}},358(e,t,r){t.y=function(e,t){var r=document.createElement("a");r.href=e;for(var o="/"===r.pathname[0]?r.pathname:"/"+r.pathname,n=0,s=o.length;n!==t&&s>=0;)"/"===o[--s]&&n++;if(n!==t)throw Error("systemjs-webpack-interop: rootDirectoryLevel ("+t+") is greater than the number of directories ("+n+") in the URL path "+e);var i=o.slice(0,s+1);return r.protocol+"//"+r.host+i};Number.isInteger}};const r={};function o(t){const n=r[t];if(void 0!==n)return n.exports;const s=r[t]={exports:{}};return e[t](s,s.exports,o),s.exports}o.y=t,o.d=(e,t)=>{if(Array.isArray(t))for(var r=0;r<t.length;){var n=t[r++],s=t[r++];o.o(e,n)?0===s&&r++:0===s?Object.defineProperty(e,n,{enumerable:!0,value:t[r++]}):Object.defineProperty(e,n,{enumerable:!0,get:s})}else for(var n in t)o.o(t,n)&&!o.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},o.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),o.r=e=>{Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},o.p="";let n={};return(0,o(126).w)(1),(()=>{"use strict";o.r(n),o.d(n,{BadGatewayError:()=>E,BadRequestError:()=>i,ClassifiedError:()=>r,ForbiddenError:()=>c,GatewayTimeoutError:()=>T,HttpClient:()=>S,HttpClientError:()=>e,InternalServerError:()=>w,LogicError:()=>t,Method:()=>I,MethodNotAllowedError:()=>u,NotFoundError:()=>h,NotImplementedError:()=>y,PayloadTooLargeError:()=>l,RpcClient:()=>P,RpcException:()=>N,ServiceUnavailableError:()=>g,TooManyRequestsError:()=>f,UnauthorizedError:()=>a,UnprocessableEntityError:()=>p,UnsupportedMediaTypeError:()=>d,UntiledError:()=>s,checkIsResponseSuccess:()=>k,defaultErrorMiddleware:()=>U,defaultResponseMiddleware:()=>x});class e extends Error{constructor(t,r){super(t),this.code=r,Object.setPrototypeOf(this,e.prototype)}}class t extends e{constructor(e){super(e,0),Object.setPrototypeOf(this,t.prototype)}}class r extends e{constructor(e,t,o){super(e,t),this.details=o,Object.setPrototypeOf(this,r.prototype)}}class s extends r{constructor(e,t,r){super(e,t,r),Object.setPrototypeOf(this,s.prototype)}}class i extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Bad Request!",400,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,i.prototype)}}class a extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Unauthorized!",401,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,a.prototype)}}class c extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Forbidden!",403,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,c.prototype)}}class h extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not Found!",404,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,h.prototype)}}class u extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Method Not Allowed!",405,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,u.prototype)}}class l extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Payload Too Large!",413,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,l.prototype)}}class d extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Unsupported Media Type!",415,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,d.prototype)}}class p extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Unprocessable Entity!",422,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,p.prototype)}}class f extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Too Many Requests!",429,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,f.prototype)}}class w extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Internal Server Error!",500,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,w.prototype)}}class y extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Not Implemented!",501,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,y.prototype)}}class E extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Bad Gateway!",502,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,E.prototype)}}class g extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Service Unavailable!",503,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,g.prototype)}}class T extends r{constructor(){super(arguments.length>0&&void 0!==arguments[0]?arguments[0]:"Gateway Timeout!",504,arguments.length>1&&void 0!==arguments[1]?arguments[1]:null),Object.setPrototypeOf(this,T.prototype)}}function O(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var o in r)"__proto__"!==o&&(e[o]=r[o])}return e}var m=function e(t,r){function o(e,o,n){if("undefined"!=typeof document){"number"==typeof(n=O({},r,n)).expires&&(n.expires=new Date(Date.now()+864e5*n.expires)),n.expires&&(n.expires=n.expires.toUTCString()),e=encodeURIComponent(e).replace(/%(2[346B]|5E|60|7C)/g,decodeURIComponent).replace(/[()]/g,escape);var s="";for(var i in n)n[i]&&(s+="; "+i,!0!==n[i]&&(s+="="+n[i].split(";")[0]));return document.cookie=e+"="+t.write(o,e)+s}}return Object.create({set:o,get:function(e){if("undefined"!=typeof document&&(!arguments.length||e)){for(var r=document.cookie?document.cookie.split("; "):[],o={},n=0;n<r.length;n++){var s=r[n].split("="),i=s.slice(1).join("=");try{var a=decodeURIComponent(s[0]);if(a in o||(o[a]=t.read(i,a)),e===a)break}catch(e){}}return e?o[e]:o}},remove:function(e,t){o(e,"",O({},t,{expires:-1}))},withAttributes:function(t){return e(this.converter,O({},this.attributes,t))},withConverter:function(t){return e(O({},this.converter,t),this.attributes)}},{attributes:{value:Object.freeze(r)},converter:{value:Object.freeze(t)}})}({read:function(e){return'"'===e[0]&&(e=e.slice(1,-1)),e.replace(/(%[\dA-F]{2})+/gi,decodeURIComponent)},write:function(e){return encodeURIComponent(e).replace(/%(2[346BF]|3[AC-F]|40|5[BDE]|60|7[BCD])/g,decodeURIComponent)}},{path:"/"});class v extends Error{}function A(e,t){if("string"!=typeof e)throw new v("Invalid token specified: must be a string");t||(t={});const r=!0===t.header?0:1,o=e.split(".")[r];if("string"!=typeof o)throw new v(`Invalid token specified: missing part #${r+1}`);let n;try{n=function(e){let t=e.replace(/-/g,"+").replace(/_/g,"/");switch(t.length%4){case 0:break;case 2:t+="==";break;case 3:t+="=";break;default:throw new Error("base64 string is not of the correct length")}try{return function(e){return decodeURIComponent(atob(e).replace(/(.)/g,(e,t)=>{let r=t.charCodeAt(0).toString(16).toUpperCase();return r.length<2&&(r="0"+r),"%"+r}))}(t)}catch(e){return atob(t)}}(o)}catch(e){throw new v(`Invalid token specified: invalid base64 for part #${r+1} (${e.message})`)}try{return JSON.parse(n)}catch(e){throw new v(`Invalid token specified: invalid json for part #${r+1} (${e.message})`)}}function _(e,t){return function(e,t){void 0===t&&(t={});var r=function(e){return e&&e.sensitive?"":"i"}(t),o=t.encode,n=void 0===o?function(e){return e}:o,s=t.validate,i=void 0===s||s,a=e.map(function(e){if("object"==typeof e)return new RegExp("^(?:".concat(e.pattern,")$"),r)});return function(t){for(var r="",o=0;o<e.length;o++){var s=e[o];if("string"!=typeof s){var c=t?t[s.name]:void 0,h="?"===s.modifier||"*"===s.modifier,u="*"===s.modifier||"+"===s.modifier;if(Array.isArray(c)){if(!u)throw new TypeError('Expected "'.concat(s.name,'" to not repeat, but got an array'));if(0===c.length){if(h)continue;throw new TypeError('Expected "'.concat(s.name,'" to not be empty'))}for(var l=0;l<c.length;l++){var d=n(c[l],s);if(i&&!a[o].test(d))throw new TypeError('Expected all "'.concat(s.name,'" to match "').concat(s.pattern,'", but got "').concat(d,'"'));r+=s.prefix+d+s.suffix}}else if("string"!=typeof c&&"number"!=typeof c){if(!h){var p=u?"an array":"a string";throw new TypeError('Expected "'.concat(s.name,'" to be ').concat(p))}}else{if(d=n(String(c),s),i&&!a[o].test(d))throw new TypeError('Expected "'.concat(s.name,'" to match "').concat(s.pattern,'", but got "').concat(d,'"'));r+=s.prefix+d+s.suffix}}else r+=s}return r}}(function(e,t){void 0===t&&(t={});for(var r=function(e){for(var t=[],r=0;r<e.length;){var o=e[r];if("*"!==o&&"+"!==o&&"?"!==o)if("\\"!==o)if("{"!==o)if("}"!==o)if(":"!==o)if("("!==o)t.push({type:"CHAR",index:r,value:e[r++]});else{var n=1,s="";if("?"===e[a=r+1])throw new TypeError('Pattern cannot start with "?" at '.concat(a));for(;a<e.length;)if("\\"!==e[a]){if(")"===e[a]){if(0===--n){a++;break}}else if("("===e[a]&&(n++,"?"!==e[a+1]))throw new TypeError("Capturing groups are not allowed at ".concat(a));s+=e[a++]}else s+=e[a++]+e[a++];if(n)throw new TypeError("Unbalanced pattern at ".concat(r));if(!s)throw new TypeError("Missing pattern at ".concat(r));t.push({type:"PATTERN",index:r,value:s}),r=a}else{for(var i="",a=r+1;a<e.length;){var c=e.charCodeAt(a);if(!(c>=48&&c<=57||c>=65&&c<=90||c>=97&&c<=122||95===c))break;i+=e[a++]}if(!i)throw new TypeError("Missing parameter name at ".concat(r));t.push({type:"NAME",index:r,value:i}),r=a}else t.push({type:"CLOSE",index:r,value:e[r++]});else t.push({type:"OPEN",index:r,value:e[r++]});else t.push({type:"ESCAPED_CHAR",index:r++,value:e[r++]});else t.push({type:"MODIFIER",index:r,value:e[r++]})}return t.push({type:"END",index:r,value:""}),t}(e),o=t.prefixes,n=void 0===o?"./":o,s=t.delimiter,i=void 0===s?"/#?":s,a=[],c=0,h=0,u="",l=function(e){if(h<r.length&&r[h].type===e)return r[h++].value},d=function(e){var t=l(e);if(void 0!==t)return t;var o=r[h],n=o.type,s=o.index;throw new TypeError("Unexpected ".concat(n," at ").concat(s,", expected ").concat(e))},p=function(){for(var e,t="";e=l("CHAR")||l("ESCAPED_CHAR");)t+=e;return t},f=function(e){var t=a[a.length-1],r=e||(t&&"string"==typeof t?t:"");if(t&&!r)throw new TypeError('Must have text between two parameters, missing text after "'.concat(t.name,'"'));return!r||function(e){for(var t=0,r=i;t<r.length;t++){var o=r[t];if(e.indexOf(o)>-1)return!0}return!1}(r)?"[^".concat(R(i),"]+?"):"(?:(?!".concat(R(r),")[^").concat(R(i),"])+?")};h<r.length;){var w=l("CHAR"),y=l("NAME"),E=l("PATTERN");if(y||E){var g=w||"";-1===n.indexOf(g)&&(u+=g,g=""),u&&(a.push(u),u=""),a.push({name:y||c++,prefix:g,suffix:"",pattern:E||f(g),modifier:l("MODIFIER")||""})}else{var T=w||l("ESCAPED_CHAR");if(T)u+=T;else if(u&&(a.push(u),u=""),l("OPEN")){g=p();var O=l("NAME")||"",m=l("PATTERN")||"",v=p();d("CLOSE"),a.push({name:O||(m?c++:""),pattern:O&&!m?f(g):m,prefix:g,suffix:v,modifier:l("MODIFIER")||""})}else d("END")}}return a}(e,t),t)}function R(e){return e.replace(/([.+*?=^!:${}()[\]|/\\])/g,"\\$1")}v.prototype.name="InvalidTokenError";const b=/[a-zA-z]+:\/\/[^/]*/;let I=function(e){return e.GET="GET",e.POST="POST",e.PUT="PUT",e.PATCH="PATCH",e.DELETE="DELETE",e}({});class S{static AUTHORIZATION_STATE_COOKIE_NAME="__PW_AUTHORIZATION_STATE";static AUTHORIZATION_STATE_SESSION_KEY="__PW_SESSION_AUTHORIZATION_STATE";static URL_BEFORE_AUTHORIZATION_SESSION_KEY="__PW_SESSION_URL_BEFORE_AUTHORIZATION";static URL_BEFORE_AUTHORIZATION_COOKIE_NAME="__PW_URL_BEFORE_AUTHORIZATION";constructor(e,t){const{baseURL:r}=t;this.baseURL=r,this.history=e,this.config=t,this.accessToken=null,this.refreshToken=null,this.isRefreshing=!1,this.userName="",this.accountID=""}checkAuthorization=async e=>{if(this.isRefreshing)return await new Promise(e=>{setTimeout(e,100)}),void await this.checkAuthorization(e);if(!this.accessToken)throw new a("Unauthorized!",e);const t=(new Date).getTime()/1e3;A(this.accessToken).expired_at<t&&(await this.updateTokenByRefreshToken(e),await this.checkAuthorization(e))};updateToken=async e=>{const t=`Basic ${btoa(`${this.config.clientId}:`)}`;try{this.isRefreshing=!0;const r=await this.post(this.config.urls.token,{headers:{Authorization:t},query:e,withAuthorization:!1,withCredentials:!0});this.accessToken=r.access_token,this.refreshToken=r.refresh_token,this.isRefreshing=!1}catch(e){throw this.accessToken=null,this.refreshToken=null,this.isRefreshing=!1,e}};updateTokenByAuthorizationCode=async e=>{await this.updateToken({grant_type:"authorization_code",code:e,redirect_uri:`${window.location.origin}${window.location.pathname}`})};updateTokenByRefreshToken=async e=>{if(!this.refreshToken)throw this.accessToken=null,new a("Unauthorized!",e);await this.updateToken({grant_type:"refresh_token",refresh_token:this.refreshToken,username:this.userName,account_id:this.accountID})};processFetchResponse=async(e,t,r)=>{var o;let n;return n=null!==(o=e.headers.get("Content-Type"))&&void 0!==o&&o.includes("application/json")?await e.json().catch(()=>({})):await e.text().then(e=>{try{return JSON.parse(e)}catch{return e}}).catch(()=>""),r({result:n,status:e.status,message:e.statusText,details:t})};buildFetchRequest=async(e,t,r)=>{let o=e;if(this.baseURL&&!o.startsWith("http")&&(o=`${this.baseURL}${o.startsWith("/")?"":"/"}${o}`),r.params&&(o=function(e,t){let r="",o=`${e}`;return function(e){return!!e.match(b)}(e)&&([r]=e.match(b),o=e.slice(r.length)),r+_(o)(t)}(o,r.params)),r.query){const e=r.query;let t;t="string"==typeof e?e:e instanceof URLSearchParams?e.toString():new URLSearchParams(e).toString(),o=`${o}${o.includes("?")?"&":"?"}${t}`}const n=r.headers||{},s={};Object.entries(n).forEach(e=>{let[t,r]=e;s[t]=String(r)}),r.withAuthorization&&(await this.checkAuthorization(null),s.Authorization=`Bearer ${this.accessToken}`);const i={method:t,headers:s,credentials:r.withCredentials?"include":"same-origin",signal:r.signal};return void 0!==r.body&&(r.body instanceof FormData?i.body=r.body:(s["Content-Type"]="application/json",t!==I.GET&&(i.body=JSON.stringify(r.body)))),{fetchUrl:o,fetchOptions:i,headersInit:s}};request=async(e,t,r)=>{const{basicErrorMiddleware:o,basicResponseMiddleware:n}=this.config,{errorMiddleware:s=o,responseMiddleware:i=n}=r,c={url:e,method:t,headers:r.headers,params:r.params,query:r.query,body:r.body,withCredentials:r.withCredentials,withAuthorization:r.withAuthorization},{fetchUrl:h,fetchOptions:u,headersInit:l}=await this.buildFetchRequest(e,t,{headers:r.headers,withAuthorization:r.withAuthorization,withCredentials:r.withCredentials,params:r.params,query:r.query,body:r.body});try{const e=await fetch(h,u);return await this.processFetchResponse(e,c,i)}catch(e){if(!(e instanceof a))throw await s(e),e;try{r.withAuthorization&&(await this.updateTokenByRefreshToken(c),await this.checkAuthorization(c),l.Authorization=`Bearer ${this.accessToken}`);const e=await fetch(h,u);return await this.processFetchResponse(e,c,i)}catch(e){throw await s(e),e}}};stream=async(e,t,r)=>{const{basicErrorMiddleware:o}=this.config,{errorMiddleware:n=o}=r,{fetchUrl:s,fetchOptions:i,headersInit:c}=await this.buildFetchRequest(e,t,{headers:r.headers,withAuthorization:r.withAuthorization,withCredentials:r.withCredentials,params:r.params,query:r.query,body:r.body,signal:r.signal}),h={url:e,method:t,params:r.params,query:r.query,body:r.body,withCredentials:r.withCredentials,withAuthorization:r.withAuthorization},{basicResponseMiddleware:u}=this.config;try{const e=await fetch(s,i);return e.ok||await this.processFetchResponse(e,h,u),e}catch(e){if(!(e instanceof a))throw await n(e),e;try{r.withAuthorization&&(await this.updateTokenByRefreshToken(h),await this.checkAuthorization(h),c.Authorization=`Bearer ${this.accessToken}`);const e=await fetch(s,i);return e.ok||await this.processFetchResponse(e,h,u),e}catch(e){throw await n(e),e}}};get=(e,t)=>this.request(e,I.GET,t);post=(e,t)=>this.request(e,I.POST,t);put=(e,t)=>this.request(e,I.PUT,t);patch=(e,t)=>this.request(e,I.PATCH,t);delete=(e,t)=>this.request(e,I.DELETE,t);login=async()=>{const e=Math.random().toString().slice(2,12);sessionStorage.setItem(S.AUTHORIZATION_STATE_SESSION_KEY,e),sessionStorage.setItem(S.URL_BEFORE_AUTHORIZATION_SESSION_KEY,window.location.href),m.set(S.AUTHORIZATION_STATE_COOKIE_NAME,e),m.set(S.URL_BEFORE_AUTHORIZATION_COOKIE_NAME,window.location.href);const t=new URLSearchParams({response_type:"code",client_id:this.config.clientId,redirect_uri:`${window.location.origin}${window.location.pathname}`,state:e});window.location.href=`${this.config.urls.authorize}?${t.toString()}`};authorize=async e=>{const r=sessionStorage.getItem(S.AUTHORIZATION_STATE_SESSION_KEY)||m.get(S.AUTHORIZATION_STATE_COOKIE_NAME),o=sessionStorage.getItem(S.URL_BEFORE_AUTHORIZATION_SESSION_KEY)||m.get(S.URL_BEFORE_AUTHORIZATION_COOKIE_NAME);if(sessionStorage.removeItem(S.AUTHORIZATION_STATE_SESSION_KEY),sessionStorage.removeItem(S.URL_BEFORE_AUTHORIZATION_SESSION_KEY),m.remove(S.AUTHORIZATION_STATE_COOKIE_NAME),m.remove(S.URL_BEFORE_AUTHORIZATION_COOKIE_NAME),o){const e=new URL(o);this.history.replace({pathname:e.pathname,search:e.search,hash:e.hash})}if(r!==e.state)throw new p("Stored authorization state and received authorization state are not equal!");if(await this.updateTokenByAuthorizationCode(e.code),!this.accessToken)throw new t("Access token is null after tokens update!");const n=A(this.accessToken);return this.userName=n.username,this.accountID=n.account_id.toString(),n};logout=async()=>{this.accessToken=null,this.refreshToken=null,await this.get(this.config.urls.logout,{withAuthorization:!1,withCredentials:!0})};getAccessToken=async()=>{if(await this.checkAuthorization(null),!this.accessToken)throw new t("Access token is null after authorization check!");return this.accessToken};setAccessToken=e=>{this.accessToken=e}}function k(e){return e.status>=200&&e.status<300}function x(e){var t;if(k(e))return e.result;const r=(null===(t=e.result)||void 0===t?void 0:t.message)||e.message||void 0;switch(e.status){case 400:throw new i(r,e.details);case 401:throw new a(r,e.details);case 403:throw new c(r,e.details);case 404:throw new h(r,e.details);case 405:throw new u(r,e.details);case 413:throw new l(r,e.details);case 415:throw new d(r,e.details);case 422:throw new p(r,e.details);case 429:throw new f(r,e.details);case 500:throw new w(r,e.details);case 501:throw new y(r,e.details);case 502:throw new E(r,e.details);case 503:throw new g(r,e.details);case 504:throw new T(r,e.details);default:throw new s(r||"Untiled Error!",e.status,e.details)}}function U(e){throw e}class N extends Error{constructor(e,t,r){super(e),this.code=t,this.details=r,this.error=t}}function C(e,t){return`call method '${e}'${t?`: ${t}`:""}`}class P{counter=0;listeners=[];constructor(e,t){this.httpClient=e,this.options=t}subscribe(e){this.listeners.push(e)}callRemoteProcedure(e,t,r){return this.callRemoteProcedureBase("_rpc",{calls:[{name:e,params:t}]},C(e,r))}callRemoteProcedureWithFiles(e,t,r,o){const n=new FormData;return n.append("name",e),n.append("params",JSON.stringify(t)),Object.keys(r).forEach(e=>{const t=e.split(".").at(-1);n.append(t,r[e])}),this.callRemoteProcedureBase(`_upload_${e}`,n,C(`${e} (upload files)`,o))}callRemoteProcedureBase(e,t,r){return this.fetch(e,t,r).then(e=>{let{auth:t,responses:r}=e;const o=r[0];if(!o)throw new N("no result",500,{});if(function(e){return"error"in e}(o))throw new N(o.message,o.error,o.details);return{auth:t,response:o}})}fetch(e,t,r){const{enviromentOrigin:o=""}=this.options,n=++this.counter;return this.options.log({num:n,type:"callStart",message:r,data:t}),this.httpClient.post(`${o}/cp/${e}?l=${encodeURI(r)}`,{body:t,withAuthorization:this.options.withAuthorization}).then(e=>(this.options.log({num:n,type:"callEnd",message:r,data:e}),this.listeners.forEach(t=>{try{t(e)}catch(e){this.options.onException({message:"RPC listener error",error:e})}}),e))}}})(),n})())}}});
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
/*! js-cookie v3.0.
|
|
1
|
+
/*! js-cookie v3.0.8 | MIT */
|