@ztimson/momentum 0.27.3 → 0.27.4

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/api.d.ts.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EACf,IAAI,EAAE,YAAY,EAClB,kBAAkB,EAClB,eAAe,EAEf,KAAK,WAAW,EAChB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG;IACrC,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,kBAAkB,KAAK,GAAG,CAAC;IACrE,QAAQ,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,kBAAkB,KAAK,GAAG,CAAC;IAC9D,QAAQ,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,kBAAkB,KAAK,GAAG,CAAC;IAChE,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,GAAG,CAAA;CACpC,CAAA;AAED,qBAAa,GAAI,SAAQ,IAAI;aAYA,GAAG,EAAE,MAAM;aAAoC,IAAI,EAAE,YAAY;IAX7F,OAAO,CAAC,OAAO,CAAiC;IAEhD,OAAO,CAAC,MAAM,CAAuB;IACrC,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAAwB;IAClD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAK7B;gBAE2B,GAAG,GAAE,MAAwB,EAAkB,IAAI,GAAE,YAAiB;IAKlG,IAAI,mFAAwC;IAC5C,GAAG,iFAAuC;IAC1C,EAAE,uFAAsC;IACxC,IAAI,sGAAwC;IAE5C,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,GAAG,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;CAY5E"}
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../src/api.ts"],"names":[],"mappings":"AAAA,OAAO,EACN,eAAe,EACf,IAAI,EAAE,YAAY,EAClB,kBAAkB,EAClB,eAAe,EAEf,KAAK,WAAW,EAChB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,SAAS,GAAG,WAAW,GAAG;IACrC,OAAO,EAAE,CAAC,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,EAAE,OAAO,EAAE,kBAAkB,KAAK,GAAG,CAAC;IACrE,QAAQ,EAAE,CAAC,QAAQ,EAAE,GAAG,EAAE,OAAO,EAAE,kBAAkB,KAAK,GAAG,CAAC;IAC9D,QAAQ,EAAE,CAAC,QAAQ,EAAE,KAAK,EAAE,OAAO,EAAE,kBAAkB,KAAK,GAAG,CAAC;IAChE,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,KAAK,GAAG,CAAA;CACpC,CAAA;AAED,qBAAa,GAAI,SAAQ,IAAI;aAYA,GAAG,EAAE,MAAM;aAAoC,IAAI,EAAE,YAAY;IAX7F,OAAO,CAAC,OAAO,CAAiC;IAEhD,OAAO,CAAC,MAAM,CAAuB;IACrC,IAAI,KAAK,IAAI,MAAM,GAAG,IAAI,CAAwB;IAClD,IAAI,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,EAK7B;gBAE2B,GAAG,GAAE,MAAwB,EAAkB,IAAI,GAAE,YAAiB;IAKlG,IAAI,mFAAwC;IAC5C,GAAG,iFAAuC;IAC1C,EAAE,uFAAsC;IACxC,IAAI,sGAAwC;IAE5C,OAAO,CAAC,CAAC,EAAE,OAAO,EAAE,kBAAkB,GAAG,eAAe,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;CAa5E"}
package/dist/api.js CHANGED
@@ -31,8 +31,9 @@ class Api extends utils_1.Http {
31
31
  this.emit('RESPONSE', resp, options);
32
32
  return resp;
33
33
  }).catch(err => {
34
- this.emit('REJECTED', err, options);
35
- throw err;
34
+ const e = err?.data || err;
35
+ this.emit('REJECTED', e, options);
36
+ throw e;
36
37
  });
37
38
  this.emit('REQUEST', req, options);
38
39
  return req;
package/dist/index.mjs CHANGED
@@ -1 +1 @@
1
- var v=function(t,e=!1){if(t==null)throw new Error("Cannot clean a NULL value");return Array.isArray(t)?t=t.filter((i)=>i!=null):Object.entries(t).forEach(([i,n])=>{(e&&n===void 0||!e&&n==null)&&delete t[i]}),t};var j=function(t,e){const i=typeof t,n=typeof e;return i!="object"||t==null||n!="object"||e==null?i=="function"&&n=="function"?t.toString()==e.toString():t===e:Object.keys(t).length!=Object.keys(e).length?!1:Object.keys(t).every((s)=>j(t[s],e[s]))};var z=function(t,e){const i=document.createElement("a");i.href=t,i.download=e,document.body.appendChild(i),i.click(),document.body.removeChild(i)},Tt=function(t,e){const i=URL.createObjectURL(t);z(i,e),URL.revokeObjectURL(i)},At=function(t={}){return new Promise((e)=>{const i=document.createElement("input");i.type="file",i.accept=t.accept||"*",i.style.display="none",i.multiple=!!t.multiple,i.onblur=i.onchange=async()=>{e(Array.from(i.files)),i.remove()},document.body.appendChild(i),i.click()})},V=function(t){return new E((e,i,n)=>{const s=new XMLHttpRequest,a=new FormData;t.files.forEach((o)=>a.append("file",o)),s.withCredentials=!!t.withCredentials,s.upload.addEventListener("progress",(o)=>o.lengthComputable?n(o.loaded/o.total):null),s.upload.addEventListener("load",(o)=>e(o)),s.upload.addEventListener("error",(o)=>i(o)),s.open("POST",t.url),Object.entries(t.headers||{}).forEach(([o,p])=>s.setRequestHeader(o,p)),s.send(a)})};var Nt=Object.defineProperty,Vt=(t,e,i)=>(e in t)?Nt(t,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):t[e]=i,l=(t,e,i)=>(Vt(t,typeof e!="symbol"?e+"":e,i),i);class E extends Promise{constructor(t){super((e,i)=>t((n)=>e(n),(n)=>i(n),(n)=>this.progress=n));l(this,"listeners",[]),l(this,"_progress",0)}get progress(){return this._progress}set progress(t){t!=this._progress&&(this._progress=t,this.listeners.forEach((e)=>e(t)))}static from(t){return t instanceof E?t:new E((e,i)=>t.then((...n)=>e(...n)).catch((...n)=>i(...n)))}from(t){const e=E.from(t);return this.onProgress((i)=>e.progress=i),e}onProgress(t){return this.listeners.push(t),this}then(t,e){const i=super.then(t,e);return this.from(i)}catch(t){return this.from(super.catch(t))}finally(t){return this.from(super.finally(t))}}class h{constructor(){l(this,"listeners",{})}static emit(t,...e){(this.listeners["*"]||[]).forEach((i)=>i(t,...e)),(this.listeners[t.toString()]||[]).forEach((i)=>i(...e))}static off(t,e){const i=t.toString();this.listeners[i]=(this.listeners[i]||[]).filter((n)=>n===e)}static on(t,e){var i;const n=t.toString();return this.listeners[n]||(this.listeners[n]=[]),(i=this.listeners[n])==null||i.push(e),()=>this.off(t,e)}static once(t,e){return new Promise((i)=>{const n=this.on(t,(...s)=>{i(s.length==1?s[0]:s),e&&e(...s),n()})})}emit(t,...e){(this.listeners["*"]||[]).forEach((i)=>i(t,...e)),(this.listeners[t]||[]).forEach((i)=>i(...e))}off(t,e){this.listeners[t]=(this.listeners[t]||[]).filter((i)=>i===e)}on(t,e){var i;return this.listeners[t]||(this.listeners[t]=[]),(i=this.listeners[t])==null||i.push(e),()=>this.off(t,e)}once(t,e){return new Promise((i)=>{const n=this.on(t,(...s)=>{i(s.length==1?s[0]:s),e&&e(...s),n()})})}}l(h,"listeners",{});class A extends Error{constructor(t,e){super(t);l(this,"_code"),e!=null&&(this._code=e)}get code(){return this._code||this.constructor.code}set code(t){this._code=t}static from(t){const e=Number(t.statusCode)??Number(t.code),i=new this(t.message||t.toString());return Object.assign(i,{stack:t.stack,...t,code:e??void 0})}static instanceof(t){return t.constructor.code!=null}toString(){return this.message||super.toString()}}l(A,"code",500);class wt extends A{constructor(t="Bad Request"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(wt,"code",400);class Pt extends A{constructor(t="Unauthorized"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(Pt,"code",401);class Dt extends A{constructor(t="Forbidden"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(Dt,"code",403);class Lt extends A{constructor(t="Not Found"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(Lt,"code",404);class Rt extends A{constructor(t="Internal Server Error"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(Rt,"code",500);var Y=class t{constructor(e={}){l(this,"interceptors",{}),l(this,"headers",{}),l(this,"url"),this.url=e.url??null,this.headers=e.headers||{},e.interceptors&&e.interceptors.forEach((i)=>t.addInterceptor(i))}static addInterceptor(e){const i=Object.keys(t.interceptors).length.toString();return t.interceptors[i]=e,()=>{t.interceptors[i]=null}}addInterceptor(e){const i=Object.keys(this.interceptors).length.toString();return this.interceptors[i]=e,()=>{this.interceptors[i]=null}}request(e={}){var i;if(!this.url&&!e.url)throw new Error("URL needs to be set");let n=((i=e.url)!=null&&i.startsWith("http")?e.url:(this.url||"")+(e.url||"")).replace(/([^:]\/)\/+/g,"$1");if(e.fragment&&(n.includes("#")?n.replace(/#.*(\?|\n)/g,(a,o)=>`#${e.fragment}${o}`):n+="#"+e.fragment),e.query){const a=Array.isArray(e.query)?e.query:Object.keys(e.query).map((o)=>({key:o,value:e.query[o]}));n+=(n.includes("?")?"&":"?")+a.map((o)=>`${o.key}=${o.value}`).join("&")}const s=v({"Content-Type":e.body?e.body instanceof FormData?"multipart/form-data":"application/json":void 0,...t.headers,...this.headers,...e.headers});return typeof e.body=="object"&&e.body!=null&&s["Content-Type"]=="application/json"&&(e.body=JSON.stringify(e.body)),new E((a,o,p)=>{fetch(n,{headers:s,method:e.method||(e.body?"POST":"GET"),body:e.body}).then(async(u)=>{var D,S;for(let U of[...Object.values(t.interceptors),...Object.values(this.interceptors)])await new Promise((K)=>U(u,()=>K()));const G=u.headers.get("Content-Length"),L=G?parseInt(G,10):0;let g=0;const W=(D=u.body)==null?void 0:D.getReader(),y=new ReadableStream({start(U){function K(){W==null||W.read().then((H)=>{if(H.done)return U.close();g+=H.value.byteLength,p(g/L),U.enqueue(H.value),K()}).catch((H)=>U.error(H))}K()}}),F=new Response(y),c=(S=u.headers.get("Content-Type"))==null?void 0:S.toLowerCase();c!=null&&c.includes("json")?u.data=await F.json():c!=null&&c.includes("text")?u.data=await F.text():c!=null&&c.includes("form")?u.data=await F.formData():c!=null&&c.includes("application")?u.data=await F.blob():u.data=null,u.ok?a(u):o(u)})})}};l(Y,"interceptors",{}),l(Y,"headers",{});var $t=Y,M={CLEAR:"\x1B[0m",BRIGHT:"\x1B[1m",DIM:"\x1B[2m",UNDERSCORE:"\x1B[4m",BLINK:"\x1B[5m",REVERSE:"\x1B[7m",HIDDEN:"\x1B[8m"},N={BLACK:"\x1B[30m",RED:"\x1B[31m",GREEN:"\x1B[32m",YELLOW:"\x1B[33m",BLUE:"\x1B[34m",MAGENTA:"\x1B[35m",CYAN:"\x1B[36m",LIGHT_GREY:"\x1B[37m",GREY:"\x1B[90m",LIGHT_RED:"\x1B[91m",LIGHT_GREEN:"\x1B[92m",LIGHT_YELLOW:"\x1B[93m",LIGHT_BLUE:"\x1B[94m",LIGHT_MAGENTA:"\x1B[95m",LIGHT_CYAN:"\x1B[96m",WHITE:"\x1B[97m"};var w=((t)=>(t[t.ERROR=0]="ERROR",t[t.WARN=1]="WARN",t[t.INFO=2]="INFO",t[t.LOG=3]="LOG",t[t.DEBUG=4]="DEBUG",t))(w||{}),Ct=class t extends h{constructor(e){super(),this.namespace=e}pad(e,i,n,s=!1){const a=e.toString(),o=i-a.length;if(o<=0)return a;const p=Array(~~(o/n.length)).fill(n).join("");return s?a+p:p+a}format(...e){const i=new Date;return`${`${i.getFullYear()}-${i.getMonth()+1}-${i.getDate()} ${this.pad(i.getHours().toString(),2,"0")}:${this.pad(i.getMinutes().toString(),2,"0")}:${this.pad(i.getSeconds().toString(),2,"0")}.${this.pad(i.getMilliseconds().toString(),3,"0",!0)}`}${this.namespace?` [${this.namespace}]`:""} ${e.join(" ")}`}debug(...e){if(t.LOG_LEVEL<4)return;const i=this.format(...e);t.emit(4,i),console.debug(N.LIGHT_GREY+i+M.CLEAR)}log(...e){if(t.LOG_LEVEL<3)return;const i=this.format(...e);t.emit(3,i),console.log(M.CLEAR+i)}info(...e){if(t.LOG_LEVEL<2)return;const i=this.format(...e);t.emit(2,i),console.info(N.BLUE+i+M.CLEAR)}warn(...e){if(t.LOG_LEVEL<1)return;const i=this.format(...e);t.emit(1,i),console.warn(N.YELLOW+i+M.CLEAR)}error(...e){if(t.LOG_LEVEL<0)return;const i=this.format(...e);t.emit(0,i),console.error(N.RED+i+M.CLEAR)}};l(Ct,"LOG_LEVEL",4);var Bt="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",Jt="0123456789",Xt="~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/",ti=Bt+Jt+Xt;class r extends $t{t;e;emitter=new h;_token=null;get token(){return this._token}set token(t){if(t==this._token)return;this._token=t,this.headers.Authorization=t?`Bearer ${t}`:void 0,this.emit("TOKEN",t)}constructor(t=location.origin,e={}){e.url=t;super(e);this.url=t;this.opts=e}emit=this.emitter.emit.bind(this.emitter);off=this.emitter.off.bind(this.emitter);on=this.emitter.on.bind(this.emitter);once=this.emitter.once.bind(this.emitter);request(t){const e=super.request(t).then((i)=>{return this.emit("RESPONSE",i,t),i}).catch((i)=>{throw this.emit("REJECTED",i,t),i});return this.emit("REQUEST",e,t),e}}function T(t,e){if(typeof e!=="function"&&e!==null)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");b(t,e);function i(){this.constructor=t}t.prototype=e===null?Object.create(e):(i.prototype=e.prototype,new i)}function x(t){var e=typeof Symbol==="function"&&Symbol.iterator,i=e&&t[e],n=0;if(i)return i.call(t);if(t&&typeof t.length==="number")return{next:function(){if(t&&n>=t.length)t=void 0;return{value:t&&t[n++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function R(t,e){var i=typeof Symbol==="function"&&t[Symbol.iterator];if(!i)return t;var n=i.call(t),s,a=[],o;try{while((e===void 0||e-- >0)&&!(s=n.next()).done)a.push(s.value)}catch(p){o={error:p}}finally{try{if(s&&!s.done&&(i=n.return))i.call(n)}finally{if(o)throw o.error}}return a}function $(t,e,i){if(i||arguments.length===2){for(var n=0,s=e.length,a;n<s;n++)if(a||!(n in e)){if(!a)a=Array.prototype.slice.call(e,0,n);a[n]=e[n]}}return t.concat(a||Array.prototype.slice.call(e))}var b=function(t,e){return b=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(i,n){i.__proto__=n}||function(i,n){for(var s in n)if(Object.prototype.hasOwnProperty.call(n,s))i[s]=n[s]},b(t,e)};function d(t){return typeof t==="function"}function C(t){var e=function(n){Error.call(n),n.stack=new Error().stack},i=t(e);return i.prototype=Object.create(Error.prototype),i.prototype.constructor=i,i}var B=C(function(t){return function e(i){t(this),this.message=i?i.length+" errors occurred during unsubscription:\n"+i.map(function(n,s){return s+1+") "+n.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=i}});function k(t,e){if(t){var i=t.indexOf(e);0<=i&&t.splice(i,1)}}function J(t){return t instanceof O||t&&"closed"in t&&d(t.remove)&&d(t.add)&&d(t.unsubscribe)}var Ot=function(t){if(d(t))t();else t.unsubscribe()},O=function(){function t(e){this.initialTeardown=e,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var e,i,n,s,a;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var p=x(o),u=p.next();!u.done;u=p.next()){var D=u.value;D.remove(this)}}catch(y){e={error:y}}finally{try{if(u&&!u.done&&(i=p.return))i.call(p)}finally{if(e)throw e.error}}else o.remove(this);var S=this.initialTeardown;if(d(S))try{S()}catch(y){a=y instanceof B?y.errors:[y]}var G=this._finalizers;if(G){this._finalizers=null;try{for(var L=x(G),g=L.next();!g.done;g=L.next()){var W=g.value;try{Ot(W)}catch(y){if(a=a!==null&&a!==void 0?a:[],y instanceof B)a=$($([],R(a)),R(y.errors));else a.push(y)}}}catch(y){n={error:y}}finally{try{if(g&&!g.done&&(s=L.return))s.call(L)}finally{if(n)throw n.error}}}if(a)throw new B(a)}},t.prototype.add=function(e){var i;if(e&&e!==this)if(this.closed)Ot(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=(i=this._finalizers)!==null&&i!==void 0?i:[]).push(e)}},t.prototype._hasParent=function(e){var i=this._parentage;return i===e||Array.isArray(i)&&i.includes(e)},t.prototype._addParent=function(e){var i=this._parentage;this._parentage=Array.isArray(i)?(i.push(e),i):i?[i,e]:e},t.prototype._removeParent=function(e){var i=this._parentage;if(i===e)this._parentage=null;else if(Array.isArray(i))k(i,e)},t.prototype.remove=function(e){var i=this._finalizers;if(i&&k(i,e),e instanceof t)e._removeParent(this)},t.EMPTY=function(){var e=new t;return e.closed=!0,e}(),t}();var _=O.EMPTY;var f={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var q={setTimeout:function(t,e){var i=[];for(var n=2;n<arguments.length;n++)i[n-2]=arguments[n];var s=q.delegate;if(s===null||s===void 0?void 0:s.setTimeout)return s.setTimeout.apply(s,$([t,e],R(i)));return setTimeout.apply(void 0,$([t,e],R(i)))},clearTimeout:function(t){var e=q.delegate;return((e===null||e===void 0?void 0:e.clearTimeout)||clearTimeout)(t)},delegate:void 0};function qt(t){q.setTimeout(function(){var e=f.onUnhandledError;if(e)e(t);else throw t})}function tt(){}function St(t){return it("E",void 0,t)}function Gt(t){return it("N",t,void 0)}function it(t,e,i){return{kind:t,value:e,error:i}}var It=function(){return it("C",void 0,void 0)}();function I(t){if(f.useDeprecatedSynchronousErrorHandling){var e=!P;if(e)P={errorThrown:!1,error:null};if(t(),e){var i=P,n=i.errorThrown,s=i.error;if(P=null,n)throw s}}else t()}function Ut(t){if(f.useDeprecatedSynchronousErrorHandling&&P)P.errorThrown=!0,P.error=t}var P=null;var et=function(t,e){return Qt.call(t,e)},X=function(t){if(f.useDeprecatedSynchronousErrorHandling)Ut(t);else qt(t)},Yt=function(t){throw t},nt=function(t,e){var i=f.onStoppedNotification;i&&q.setTimeout(function(){return i(t,e)})},st=function(t){T(e,t);function e(i){var n=t.call(this)||this;if(n.isStopped=!1,i){if(n.destination=i,J(i))i.add(n)}else n.destination=vt;return n}return e.create=function(i,n,s){return new Q(i,n,s)},e.prototype.next=function(i){if(this.isStopped)nt(Gt(i),this);else this._next(i)},e.prototype.error=function(i){if(this.isStopped)nt(St(i),this);else this.isStopped=!0,this._error(i)},e.prototype.complete=function(){if(this.isStopped)nt(It,this);else this.isStopped=!0,this._complete()},e.prototype.unsubscribe=function(){if(!this.closed)this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null},e.prototype._next=function(i){this.destination.next(i)},e.prototype._error=function(i){try{this.destination.error(i)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(O);var Qt=Function.prototype.bind,Zt=function(){function t(e){this.partialObserver=e}return t.prototype.next=function(e){var i=this.partialObserver;if(i.next)try{i.next(e)}catch(n){X(n)}},t.prototype.error=function(e){var i=this.partialObserver;if(i.error)try{i.error(e)}catch(n){X(n)}else X(e)},t.prototype.complete=function(){var e=this.partialObserver;if(e.complete)try{e.complete()}catch(i){X(i)}},t}(),Q=function(t){T(e,t);function e(i,n,s){var a=t.call(this)||this,o;if(d(i)||!i)o={next:i!==null&&i!==void 0?i:void 0,error:n!==null&&n!==void 0?n:void 0,complete:s!==null&&s!==void 0?s:void 0};else{var p;if(a&&f.useDeprecatedNextContext)p=Object.create(i),p.unsubscribe=function(){return a.unsubscribe()},o={next:i.next&&et(i.next,p),error:i.error&&et(i.error,p),complete:i.complete&&et(i.complete,p)};else o=i}return a.destination=new Zt(o),a}return e}(st);var vt={closed:!0,next:tt,error:Yt,complete:tt};var Ht=function(){return typeof Symbol==="function"&&Symbol.observable||"@@observable"}();function Mt(t){return t}function xt(t){if(t.length===0)return Mt;if(t.length===1)return t[0];return function e(i){return t.reduce(function(n,s){return s(n)},i)}}var kt=function(t){var e;return(e=t!==null&&t!==void 0?t:f.Promise)!==null&&e!==void 0?e:Promise},jt=function(t){return t&&d(t.next)&&d(t.error)&&d(t.complete)},zt=function(t){return t&&t instanceof st||jt(t)&&J(t)},at=function(){function t(e){if(e)this._subscribe=e}return t.prototype.lift=function(e){var i=new t;return i.source=this,i.operator=e,i},t.prototype.subscribe=function(e,i,n){var s=this,a=zt(e)?e:new Q(e,i,n);return I(function(){var o=s,p=o.operator,u=o.source;a.add(p?p.call(a,u):u?s._subscribe(a):s._trySubscribe(a))}),a},t.prototype._trySubscribe=function(e){try{return this._subscribe(e)}catch(i){e.error(i)}},t.prototype.forEach=function(e,i){var n=this;return i=kt(i),new i(function(s,a){var o=new Q({next:function(p){try{e(p)}catch(u){a(u),o.unsubscribe()}},error:a,complete:s});n.subscribe(o)})},t.prototype._subscribe=function(e){var i;return(i=this.source)===null||i===void 0?void 0:i.subscribe(e)},t.prototype[Ht]=function(){return this},t.prototype.pipe=function(){var e=[];for(var i=0;i<arguments.length;i++)e[i]=arguments[i];return xt(e)(this)},t.prototype.toPromise=function(e){var i=this;return e=kt(e),new e(function(n,s){var a;i.subscribe(function(o){return a=o},function(o){return s(o)},function(){return n(a)})})},t.create=function(e){return new t(e)},t}();var Wt=C(function(t){return function e(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}});var ot=function(t){T(e,t);function e(){var i=t.call(this)||this;return i.closed=!1,i.currentObservers=null,i.observers=[],i.isStopped=!1,i.hasError=!1,i.thrownError=null,i}return e.prototype.lift=function(i){var n=new Ft(this,this);return n.operator=i,n},e.prototype._throwIfClosed=function(){if(this.closed)throw new Wt},e.prototype.next=function(i){var n=this;I(function(){var s,a;if(n._throwIfClosed(),!n.isStopped){if(!n.currentObservers)n.currentObservers=Array.from(n.observers);try{for(var o=x(n.currentObservers),p=o.next();!p.done;p=o.next()){var u=p.value;u.next(i)}}catch(D){s={error:D}}finally{try{if(p&&!p.done&&(a=o.return))a.call(o)}finally{if(s)throw s.error}}}})},e.prototype.error=function(i){var n=this;I(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=i;var s=n.observers;while(s.length)s.shift().error(i)}})},e.prototype.complete=function(){var i=this;I(function(){if(i._throwIfClosed(),!i.isStopped){i.isStopped=!0;var n=i.observers;while(n.length)n.shift().complete()}})},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var i;return((i=this.observers)===null||i===void 0?void 0:i.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(i){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,i)},e.prototype._subscribe=function(i){return this._throwIfClosed(),this._checkFinalizedStatuses(i),this._innerSubscribe(i)},e.prototype._innerSubscribe=function(i){var n=this,s=this,a=s.hasError,o=s.isStopped,p=s.observers;if(a||o)return _;return this.currentObservers=null,p.push(i),new O(function(){n.currentObservers=null,k(p,i)})},e.prototype._checkFinalizedStatuses=function(i){var n=this,s=n.hasError,a=n.thrownError,o=n.isStopped;if(s)i.error(a);else if(o)i.complete()},e.prototype.asObservable=function(){var i=new at;return i.source=this,i},e.create=function(i,n){return new Ft(i,n)},e}(at);var Ft=function(t){T(e,t);function e(i,n){var s=t.call(this)||this;return s.destination=i,s.source=n,s}return e.prototype.next=function(i){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.next)===null||s===void 0||s.call(n,i)},e.prototype.error=function(i){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.error)===null||s===void 0||s.call(n,i)},e.prototype.complete=function(){var i,n;(n=(i=this.destination)===null||i===void 0?void 0:i.complete)===null||n===void 0||n.call(i)},e.prototype._subscribe=function(i){var n,s;return(s=(n=this.source)===null||n===void 0?void 0:n.subscribe(i))!==null&&s!==void 0?s:_},e}(ot);var m=function(t){T(e,t);function e(i){var n=t.call(this)||this;return n._value=i,n}return Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),e.prototype._subscribe=function(i){var n=t.prototype._subscribe.call(this,i);return!n.closed&&i.next(this._value),n},e.prototype.getValue=function(){var i=this,n=i.hasError,s=i.thrownError,a=i._value;if(n)throw s;return this._throwIfClosed(),a},e.prototype.next=function(i){t.prototype.next.call(this,this._value=i)},e}(ot);var bt;((p)=>{p[p.CRON=0]="CRON";p[p.EVENT=1]="EVENT";p[p.DELETE=2]="DELETE";p[p.GET=3]="GET";p[p.PATCH=4]="PATCH";p[p.POST=5]="POST";p[p.PUT=6]="PUT"})(bt||={});class pt extends h{api;$cache=new m([]);get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t){return this.api.request({url:`/api/actions/${t}`,method:"DELETE"}).then(()=>{this.cache=this.cache.filter((e)=>e._id!=t),this.emit("DELETE",t)})}list(){return this.api.request({url:"/api/actions"}).then((t)=>{if(t.data)this.cache=t.data;return this.emit("LIST",t.data||[]),t.data})}read(t,e=!1){const i=this.cache.find((n)=>n._id==t);if(!e&&i)return Promise.resolve(i);return this.api.request({url:`/api/actions/${t}`}).then((n)=>{if(n.data)this.cache=this.cache.filter((s)=>s._id!=t).concat([n.data]);return this.emit("READ",n.data),n.data})}run(t,e={}){return this.api.request({url:("/api/actions/run/"+t).replaceAll("//","/"),...e}).then((i)=>i.data)}runById(t,e={}){const i=typeof t=="string"?t:t._id;return this.api.request({url:"/api/actions/run-by-id/"+i,method:"POST",...e}).then((n)=>n.data)}update(t){return this.api.request({url:`/api/actions${t._id?`/${t._id}`:""}`,method:"POST",body:t}).then((e)=>{if(e.data)this.cache=this.cache.filter((i)=>i._id!=e.data?._id).concat([e.data]);return this.emit("UPDATE",e.data),e.data})}}class Kt{t;constructor(t){this.api=t}disable(t){return this.api.request({url:`/api/auth/totp/${t}`,method:"DELETE"})}enable=this.reset;reset(t){return this.api.request({url:`/api/auth/totp/${t}`,method:"POST"})}setup(t,e="app",i){return this.api.request({url:`/api/auth/totp/${t}`,body:v({method:e,totp:i})})}}class ht extends h{e;api;storageKey;totp;$user=new m(void 0);get user(){return this.$user.value}set user(t){if(!j(this.user,t)){const e=t?t:null;this.$user.next(e),this.emit("USER",e)}}constructor(t,e){super();this.opts=e;if(this.api=typeof t=="string"?new r(t):t,this.totp=new Kt(this.api),!this.opts?.loginUi)this.opts={...this.opts,loginUi:this.api.url+"/ui/login"};if(this.storageKey=`momentum:${new URL(this.api.url).host}`,this.api.addInterceptor((i,n)=>{const s=["/api/auth/login","/api/auth/password","/api/auth/totp"];if(i.status==401&&!s.find((a)=>i.url.includes(a)))this.emit("SESSION_EXPIRED");n()}),this.api.on("TOKEN",(i)=>{if(this.opts?.persist)if(i)localStorage.setItem(this.storageKey,i);else localStorage.removeItem(this.storageKey);if(i)this.session(i,!0).catch(()=>{});else this.user=null}),e?.persist){const i=localStorage.getItem(this.storageKey);if(i)this.api.token=i;else this.user=null}else this.user=null}knownHost(t=location.origin){if(t.startsWith("/"))return Promise.resolve();return this.api.request({url:`/api/auth/known-host?host=${encodeURI(new URL(t).origin)}`}).then(()=>{})}login(t,e,i){return this.api.request({url:"/api/auth/login",headers:{Authorization:void 0},method:"POST",body:{username:t.trim(),password:e.trim(),totp:i}}).then(async(n)=>{return this.api.token=n.data?.token||null,await this.once("USER")})}loginRedirect(t=location.origin){return new Promise((e,i)=>{const n=window.open(encodeURI(`${this.opts?.loginUi}?redirect=postmessage&host=${t}`),"_blank");if(!n)return i("Unable to open login");n.addEventListener("message",(s)=>{if(!s?.data?.token)return i("Unknown response from login");this.api.token=s.data.token,e(s.data.token),n.close()})})}logout(){this.api.token=null,this.user=null,this.emit("LOGOUT")}async register(t){const e=(await this.api.request({url:"/api/auth/register",body:{...t}}))?.data;if(e?.image?.startsWith("/"))e.image=`${this.api.url}${e.image}?token=${this.api.token}`;return this.emit("REGISTER",e),e}reset(t,e){return this.api.request({url:"/api/auth/reset",headers:{Authorization:e?`Bearer ${e}`:void 0},body:{email:e?void 0:t,password:e?t:void 0}}).then(()=>{})}async session(t,e=!1){if(!t)t=this.api.token;const i=(await this.api.request({url:"/api/auth/session",headers:t?{Authorization:`Bearer ${t}`}:void 0}))?.data;if(e){if(this.api.token=t,i?.user)i.user.image=`${this.api.url}${i.user.image}?token=${this.api.token}`;if(this.user=i?.user||null,i)this.emit("LOGIN",i.user)}return i}async updatePassword(t,e,i){return this.api.request({url:"/api/auth/password",body:{username:t,password:e,oldPassword:i}}).then((n)=>{if(n?.data?.token)this.api.token=n.data.token})}}class rt extends h{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t,e){return this.api.request({url:`/api/data/${t}/${e}`,method:"DELETE"}).then(()=>this.emit("DELETE",t,e))}get(t,e){return this.api.request({url:`/api/data/${t}${e?`/${e}`:""}`}).then((i)=>{return this.emit("GET",t,i.data),i.data})}raw(t,e,i,n){return this.api.request({url:`/api/data/${t}`,body:{operand:e,query:i,options:n}}).then((s)=>{return this.emit("RAW",t,s.data),s.data})}set(t,e,i=!1){return this.api.request({url:`/api/data/${t}/${e._id||""}`,method:i?"PATCH":"POST",body:e}).then((n)=>{return this.emit("SET",t,n.data),n.data})}}class ut extends h{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}send(t){let e="/api/email";if(typeof t.body=="object")e+=`/${t.body.template}`;return this.api.request({url:e,body:t}).then((i)=>{return this.emit("SENT",t),i.data})}}class lt extends h{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}create(t){return this.api.request({url:`/api/groups/${t.name}`,method:"POST",body:t}).then((e)=>{return this.emit("CREATE",e.data),e.data})}list(){return this.api.request({url:"/api/groups"}).then((t)=>{return this.emit("LIST",t.data||[]),t.data})}read(t){return this.api.request({url:`/api/groups/${t}`}).then((e)=>{return this.emit("READ",e.data),e.data})}update(t){return this.api.request({url:`/api/groups/${t.name}`,method:"PATCH",body:t}).then((e)=>{return this.emit("UPDATE",e.data),e.data})}delete(t){return this.api.request({url:`/api/groups/${t}`,method:"DELETE"}).then(()=>this.emit("DELETE",t))}}class yt{api;constructor(t,e){if(this.api=typeof t=="string"?new r(t):t,e!=null&&e!="NONE")window.addEventListener("error",(i)=>this.error(i.error.stack)),window.addEventListener("unhandledrejection",async(i)=>this.error(i.reason.stack))}buildLog(t,e){return{time:(new Date()).getTime(),level:t,log:e,ctx:{cores:navigator.hardwareConcurrency,mem:navigator?.deviceMemory,res:[window.innerWidth,window.innerHeight],url:location.href}}}clearClientLogs(){return this.api.request({url:"/api/logs/client",method:"DELETE"})}clearServerLogs(){return this.api.request({url:"/api/logs/server",method:"DELETE"})}clientLogs(t,e){const i=[t?`length=${t}`:void 0,e?`page=${e}`:void 0].filter((n)=>!!n).join("&");return this.api.request({url:`/api/logs/client${i?`?${i}`:""}`}).then((n)=>n.data)}serverLogs(t,e){const i=[t?`length=${t}`:void 0,e?`page=${e}`:void 0].filter((n)=>!!n).join("&");return this.api.request({url:`/api/logs/server${i?`?${i}`:""}`}).then((n)=>n.data)}debug(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.DEBUG,t)}).then(()=>{}).catch(()=>{})}log(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.LOG,t)}).then(()=>{}).catch(()=>{})}info(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.INFO,t)}).then(()=>{}).catch(()=>{})}warn(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.WARN,t)}).then(()=>{}).catch(()=>{})}error(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.ERROR,t)}).then(()=>{}).catch(()=>{})}}class dt extends h{api;stripe;constructor(t,e){super();this.api=typeof t=="string"?new r(t):t;const i=(n=1)=>{try{if(!Stripe)throw new Error("Stripe not added");this.stripe=Stripe(e)}catch(s){if(n>0)setTimeout(()=>i(n--),250);else console.warn("Stripe failed, did you add the library & setup your API key?",s)}};i()}async charge(t,e={}){return this.emit("CHECKOUT",t,e),(await this.api.request({url:"/api/payments",body:{amount:t,custom:e}})).data.clientSecret}async createForm(t,e,i){const n=await this.charge(e,i),s=this.stripe.elements({clientSecret:n});return s.create("payment").mount(t),()=>this.stripe.confirmPayment({elements:s,redirect:"if_required",confirmParams:{return_url:location.origin}})}async history(t){const e=await this.api.request({url:`/api/payments${t?`/${t}`:""}`});return this.emit("LIST",t||null,e.data),e.data}}class ft extends h{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}async handleResponse(t,e){const i=await t.blob();if(e){const n=URL.createObjectURL(i);z(n,e.endsWith(".pdf")?e:e+".pdf"),URL.revokeObjectURL(n)}return this.emit("CREATE",i),i}fromHtml(t,e={}){return this.api.request({url:"/api/pdf",body:{html:t}}).then((i)=>this.handleResponse(i,e.download?e.fileName||(new Date()).toISOString():void 0))}fromTemplate(t,e,i={}){return this.api.request({url:`/api/pdf${t}`,body:e}).then((n)=>this.handleResponse(n,i.download?i.fileName||(new Date()).toISOString():void 0))}fromUrl(t,e={}){return this.api.request({url:`/api/pdf?url=${t}`}).then((i)=>this.handleResponse(i,e.download?e.fileName||(new Date()).toISOString():void 0))}}class Z{static timeout=1e4;api;url;connection;open=!1;constructor(t){if(this.api=typeof t=="string"?new r(t):t,this.url=this.api.url.replace("http","ws"),this.api.on("TOKEN",()=>this.connect()),!this.api.token)this.connect()}close(){console.debug("Disconnected from Momentum"),this.open=!1,this.connection.close()}connect(t=3){if(this.connection?.readyState<2)this.connection.close();this.connection=new WebSocket(this.url+(this.api.token?`?token=${this.api.token}`:""));const e=setTimeout(()=>{if(this.open)return;if(this.connection.close(),console.error("Momentum connection timeout"),t>0)this.connect(t-1)},Z.timeout);this.connection.onclose=()=>this.open=!1,this.connection.onmessage=this.handle,this.connection.onopen=()=>{this.open=!0,clearTimeout(e),console.debug("Connected to Momentum")}}handle(...t){console.log(t)}send(t,e){this.connection.send(JSON.stringify({token:this.api.token,channel:t,payload:e}))}}class mt extends h{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t){const e=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll("//","/");return this.api.request({url:e,method:"DELETE"}).then(()=>{this.emit("DELETE",e)})}list(t){const e=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll("//","/");return this.api.request({url:e+"?list"}).then((i)=>{return this.emit("LIST",t,i.data),i.data})}open(t,e="_blank"){const i=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll(/\/{2,}/g,"/"),n=`${this.api.url}${i}${this.api.token?`?token=${this.api.token}`:""}`;if(!e)return n;return this.emit("OPEN",t),window.open(n,e)}mkdir(t){const e=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll(/\/{2,}/g,"/");return this.api.request({url:e+"?directory",method:"POST"}).then((i)=>i.data)}download(t,e={}){const i=("/api/storage/"+t).replaceAll("//","/");return this.api.request({...e,url:i,skipConverting:!0}).then((n)=>{const s=e.downloadAs||new URL(n.url).pathname.split("/").pop();return this.emit("DOWNLOAD",t,n.data),Tt(n.data,s),n.data})}upload(t,e=""){return new E(async(i,n,s)=>{if(!t)t=await At();if(!t||Array.isArray(t)&&!t.length)return[];const a=this.api.url+("/api/storage/"+(typeof e=="string"?e:e?.path)).replaceAll("//","/");return V({url:a,files:Array.isArray(t)?t:[t],headers:this.api.headers}).onProgress((o)=>{s(o)}).then((o)=>{this.emit("UPLOAD",o),i(o)}).catch((o)=>n(o))})}}class gt extends h{api;listed=!1;$cache=new m([]);get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t){return this.api.request({url:`/api/users/${t}`,method:"DELETE"}).then(()=>{this.cache=this.cache.filter((e)=>e.username!=t),this.emit("DELETE",t)})}list(t=!1){if(!t&&this.listed)return Promise.resolve(this.cache);return this.api.request({url:"/api/users"}).then((e)=>{return e.data?.map((i)=>{return i.image=this.api.url+i.image+`?token=${this.api.token}`,i}),this.cache=e.data||[],this.listed=!0,this.emit("LIST",e.data||[]),e.data})}read(t,e=!1){if(!e){const i=this.cache.find((n)=>n.username==t);if(i)return Promise.resolve(i)}return this.api.request({url:`/api/users/${t}`}).then((i)=>{if(i.data)i.data.image=this.api.url+i.data.image+`?token=${this.api.token}`,this.cache=[...this.cache.filter((n)=>n.username!=t),i.data];return this.emit("READ",i.data),i.data})}update(t){return this.api.request({url:`/api/users/${t.username}`,method:"PATCH",body:t}).then((e)=>{if(e.data)e.data.image=this.api.url+e.data.image+`?token=${this.api.token}`,this.cache=this.cache.filter((i)=>i.username!=t.username).concat([e.data]);return this.emit(t._id?"UPDATE":"CREATE",e.data),e.data})}uploadImage(t,e){return V({url:this.api.url+`/api/users/${t}/image`,files:[e],headers:this.api.headers}).then((i)=>{return this.emit("UPLOAD_IMAGE",t,e),i})}}class ct extends h{api;$cache=new m({});get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new r(t):t}list(t=!1){return this.api.request({url:"/api/settings"+(t?"?detailed":"")}).then((e)=>{return this.cache=!t?e.data:Object.values(e.data||{}).reduce((i,n)=>({...i,[n.key]:n.value}),{}),this.emit("LIST",e.data||[]),e.data})}delete(t){return this.api.request({url:`/api/settings/${t}`,method:"DELETE"}).then(()=>{this.cache={...this.cache,[t]:void 0},this.emit("DELETE",t)})}read(t,e=!1){if(!e&&this.cache[t])return Promise.resolve(this.cache[t]);return this.api.request({url:`/api/settings/${t}`}).then((i)=>{if(i.data)this.cache={...this.cache,[i.data.key]:i};return this.emit("READ",i.data),i.data})}update(t){return this.api.request({url:`/api/settings/${t.key}`,body:t}).then((e)=>{if(e.data)this.cache={...this.cache,[e.data.key]:e.data.value};return this.emit("UPDATE",e.data),e.data})}}class Et extends h{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t){return this.api.request({url:`/api/static/${t}`,method:"DELETE"}).then(()=>{this.emit("DELETE",t)})}list(t){const e=("/api/static/"+t).replaceAll("//","/");return this.api.request({url:e}).then((i)=>{return this.emit("LIST",t,i.data||[]),i.data})}upload(t,e="/"){const i=new FormData;return(Array.isArray(t)?t:[t]).forEach((n)=>i.append("file",n)),this.api.request({url:"/api/static"+e,body:i}).then((n)=>{return this.emit("UPLOAD",n.data||[]),n.data})}}class _t extends h{api;actions;auth;data;email;groups;logger;payments;pdf;settings;socket;static;storage;users;constructor(t,e){super();if(this.api=new r(t,e?.api),this.actions=new pt(this.api),this.auth=new ht(this.api,{persist:e?.persist??!0,loginUi:e?.loginUi}),this.data=new rt(this.api),this.email=new ut(this.api),this.groups=new lt(this.api),this.logger=new yt(this.api,e?.logLevel),e?.stripeSecret)this.payments=new dt(this.api,e.stripeSecret);if(this.pdf=new ft(this.api),this.settings=new ct(this.api),this.static=new Et(this.api),this.storage=new mt(this.api),this.users=new gt(this.api),e?.socket)this.socket=new Z(this.api);if(this.api.on("*",(i,...n)=>this.emit(`API::${i}`,...n)),this.actions.on("*",(i,...n)=>this.emit(`ACTIONS::${i}`,...n)),this.auth.on("*",(i,...n)=>this.emit(`AUTH::${i}`,...n)),this.data.on("*",(i,...n)=>this.emit(`DATA::${i}`,...n)),this.email.on("*",(i,...n)=>this.emit(`EMAIL::${i}`,...n)),this.groups.on("*",(i,...n)=>this.emit(`GROUPS::${i}`,...n)),this.payments)this.payments.on("*",(i,...n)=>this.emit(`PAYMENT::${i}`,...n));this.pdf.on("*",(i,...n)=>this.emit(`PDF::${i}`,...n)),this.settings.on("*",(i,...n)=>this.emit(`SETTINGS::${i}`,...n)),this.static.on("*",(i,...n)=>this.emit(`STATIC::${i}`,...n)),this.storage.on("*",(i,...n)=>this.emit(`STORAGE::${i}`,...n)),this.users.on("*",(i,...n)=>this.emit(`USERS::${i}`,...n)),this.users.on("*",(i,...n)=>{if(Array.isArray(n[0])){const s=n[0].find((a)=>a._id==this.auth.user?._id);if(s)this.auth.user=s}else if(n[0]._id==this.auth.user?._id)this.auth.user=n[0]})}}export{gt as Users,Kt as Totp,mt as Storage,Et as Static,Z as Socket,ct as Settings,ft as Pdf,dt as Payments,_t as Momentum,yt as Logger,lt as Groups,ut as Email,rt as Data,ht as Auth,r as Api,pt as Actions,bt as ActionType};
1
+ function B(t,i=!1){if(t==null)throw new Error("Cannot clean a NULL value");return Array.isArray(t)?t=t.filter((e)=>e!=null):Object.entries(t).forEach(([e,n])=>{(i&&n===void 0||!i&&n==null)&&delete t[e]}),t}function Z(t,i){const e=typeof t,n=typeof i;return e!="object"||t==null||n!="object"||i==null?e=="function"&&n=="function"?t.toString()==i.toString():t===i:Object.keys(t).length!=Object.keys(i).length?!1:Object.keys(t).every((s)=>Z(t[s],i[s]))}function v(t,i){const e=document.createElement("a");e.href=t,e.download=i,document.body.appendChild(e),e.click(),document.body.removeChild(e)}function ct(t,i){const e=URL.createObjectURL(t);v(e,i),URL.revokeObjectURL(e)}function Et(t={}){return new Promise((i)=>{const e=document.createElement("input");e.type="file",e.accept=t.accept||"*",e.style.display="none",e.multiple=!!t.multiple,e.onblur=e.onchange=async()=>{i(Array.from(e.files)),e.remove()},document.body.appendChild(e),e.click()})}function K(t){return new E((i,e,n)=>{const s=new XMLHttpRequest,a=new FormData;t.files.forEach((o)=>a.append("file",o)),s.withCredentials=!!t.withCredentials,s.upload.addEventListener("progress",(o)=>o.lengthComputable?n(o.loaded/o.total):null),s.upload.addEventListener("load",(o)=>i(o)),s.upload.addEventListener("error",(o)=>e(o)),s.open("POST",t.url),Object.entries(t.headers||{}).forEach(([o,p])=>s.setRequestHeader(o,p)),s.send(a)})}var Ft=Object.defineProperty,Kt=(t,i,e)=>(i in t)?Ft(t,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[i]=e,l=(t,i,e)=>(Kt(t,typeof i!="symbol"?i+"":i,e),e);class E extends Promise{constructor(t){super((i,e)=>t((n)=>i(n),(n)=>e(n),(n)=>this.progress=n));l(this,"listeners",[]),l(this,"_progress",0)}get progress(){return this._progress}set progress(t){t!=this._progress&&(this._progress=t,this.listeners.forEach((i)=>i(t)))}static from(t){return t instanceof E?t:new E((i,e)=>t.then((...n)=>i(...n)).catch((...n)=>e(...n)))}from(t){const i=E.from(t);return this.onProgress((e)=>i.progress=e),i}onProgress(t){return this.listeners.push(t),this}then(t,i){const e=super.then(t,i);return this.from(e)}catch(t){return this.from(super.catch(t))}finally(t){return this.from(super.finally(t))}}class u{constructor(){l(this,"listeners",{})}static emit(t,...i){(this.listeners["*"]||[]).forEach((e)=>e(t,...i)),(this.listeners[t.toString()]||[]).forEach((e)=>e(...i))}static off(t,i){const e=t.toString();this.listeners[e]=(this.listeners[e]||[]).filter((n)=>n===i)}static on(t,i){var e;const n=t.toString();return this.listeners[n]||(this.listeners[n]=[]),(e=this.listeners[n])==null||e.push(i),()=>this.off(t,i)}static once(t,i){return new Promise((e)=>{const n=this.on(t,(...s)=>{e(s.length==1?s[0]:s),i&&i(...s),n()})})}emit(t,...i){(this.listeners["*"]||[]).forEach((e)=>e(t,...i)),(this.listeners[t]||[]).forEach((e)=>e(...i))}off(t,i){this.listeners[t]=(this.listeners[t]||[]).filter((e)=>e===i)}on(t,i){var e;return this.listeners[t]||(this.listeners[t]=[]),(e=this.listeners[t])==null||e.push(i),()=>this.off(t,i)}once(t,i){return new Promise((e)=>{const n=this.on(t,(...s)=>{e(s.length==1?s[0]:s),i&&i(...s),n()})})}}l(u,"listeners",{});class A extends Error{constructor(t,i){super(t);l(this,"_code"),i!=null&&(this._code=i)}get code(){return this._code||this.constructor.code}set code(t){this._code=t}static from(t){const i=Number(t.statusCode)??Number(t.code),e=new this(t.message||t.toString());return Object.assign(e,{stack:t.stack,...t,code:i??void 0})}static instanceof(t){return t.constructor.code!=null}toString(){return this.message||super.toString()}}l(A,"code",500);class Tt extends A{constructor(t="Bad Request"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(Tt,"code",400);class At extends A{constructor(t="Unauthorized"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(At,"code",401);class wt extends A{constructor(t="Forbidden"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(wt,"code",403);class Pt extends A{constructor(t="Not Found"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(Pt,"code",404);class Dt extends A{constructor(t="Internal Server Error"){super(t)}static instanceof(t){return t.constructor.code==this.code}}l(Dt,"code",500);var X=class t{constructor(i={}){l(this,"interceptors",{}),l(this,"headers",{}),l(this,"url"),this.url=i.url??null,this.headers=i.headers||{},i.interceptors&&i.interceptors.forEach((e)=>t.addInterceptor(e))}static addInterceptor(i){const e=Object.keys(t.interceptors).length.toString();return t.interceptors[e]=i,()=>{t.interceptors[e]=null}}addInterceptor(i){const e=Object.keys(this.interceptors).length.toString();return this.interceptors[e]=i,()=>{this.interceptors[e]=null}}request(i={}){var e;if(!this.url&&!i.url)throw new Error("URL needs to be set");let n=((e=i.url)!=null&&e.startsWith("http")?i.url:(this.url||"")+(i.url||"")).replace(/([^:]\/)\/+/g,"$1");if(i.fragment&&(n.includes("#")?n.replace(/#.*(\?|\n)/g,(a,o)=>`#${i.fragment}${o}`):n+="#"+i.fragment),i.query){const a=Array.isArray(i.query)?i.query:Object.keys(i.query).map((o)=>({key:o,value:i.query[o]}));n+=(n.includes("?")?"&":"?")+a.map((o)=>`${o.key}=${o.value}`).join("&")}const s=B({"Content-Type":i.body?i.body instanceof FormData?"multipart/form-data":"application/json":void 0,...t.headers,...this.headers,...i.headers});return typeof i.body=="object"&&i.body!=null&&s["Content-Type"]=="application/json"&&(i.body=JSON.stringify(i.body)),new E((a,o,p)=>{fetch(n,{headers:s,method:i.method||(i.body?"POST":"GET"),body:i.body}).then(async(h)=>{var D,S;for(let y of[...Object.values(t.interceptors),...Object.values(this.interceptors)])await new Promise((W)=>y(h,()=>W()));const G=h.headers.get("Content-Length"),L=G?parseInt(G,10):0;let c=0;const k=(D=h.body)==null?void 0:D.getReader(),d=new ReadableStream({start(y){function W(){k==null||k.read().then((U)=>{if(U.done)return y.close();c+=U.value.byteLength,p(c/L),y.enqueue(U.value),W()}).catch((U)=>y.error(U))}W()}});if(h.data=new Response(d),i.decode==null||i.decode){const y=(S=h.headers.get("Content-Type"))==null?void 0:S.toLowerCase();y!=null&&y.includes("form")?h.data=await h.data.formData():y!=null&&y.includes("json")?h.data=await h.data.json():y!=null&&y.includes("text")?h.data=await h.data.text():y!=null&&y.includes("application")&&(h.data=await h.data.blob())}h.ok?a(h):o(h)})})}};l(X,"interceptors",{}),l(X,"headers",{});var Lt=X,H={CLEAR:"\x1B[0m",BRIGHT:"\x1B[1m",DIM:"\x1B[2m",UNDERSCORE:"\x1B[4m",BLINK:"\x1B[5m",REVERSE:"\x1B[7m",HIDDEN:"\x1B[8m"},F={BLACK:"\x1B[30m",RED:"\x1B[31m",GREEN:"\x1B[32m",YELLOW:"\x1B[33m",BLUE:"\x1B[34m",MAGENTA:"\x1B[35m",CYAN:"\x1B[36m",LIGHT_GREY:"\x1B[37m",GREY:"\x1B[90m",LIGHT_RED:"\x1B[91m",LIGHT_GREEN:"\x1B[92m",LIGHT_YELLOW:"\x1B[93m",LIGHT_BLUE:"\x1B[94m",LIGHT_MAGENTA:"\x1B[95m",LIGHT_CYAN:"\x1B[96m",WHITE:"\x1B[97m"};var w=((t)=>(t[t.ERROR=0]="ERROR",t[t.WARN=1]="WARN",t[t.INFO=2]="INFO",t[t.LOG=3]="LOG",t[t.DEBUG=4]="DEBUG",t))(w||{}),Nt=class t extends u{constructor(i){super(),this.namespace=i}pad(i,e,n,s=!1){const a=i.toString(),o=e-a.length;if(o<=0)return a;const p=Array(~~(o/n.length)).fill(n).join("");return s?a+p:p+a}format(...i){const e=new Date;return`${`${e.getFullYear()}-${e.getMonth()+1}-${e.getDate()} ${this.pad(e.getHours().toString(),2,"0")}:${this.pad(e.getMinutes().toString(),2,"0")}:${this.pad(e.getSeconds().toString(),2,"0")}.${this.pad(e.getMilliseconds().toString(),3,"0",!0)}`}${this.namespace?` [${this.namespace}]`:""} ${i.join(" ")}`}debug(...i){if(t.LOG_LEVEL<4)return;const e=this.format(...i);t.emit(4,e),console.debug(F.LIGHT_GREY+e+H.CLEAR)}log(...i){if(t.LOG_LEVEL<3)return;const e=this.format(...i);t.emit(3,e),console.log(H.CLEAR+e)}info(...i){if(t.LOG_LEVEL<2)return;const e=this.format(...i);t.emit(2,e),console.info(F.BLUE+e+H.CLEAR)}warn(...i){if(t.LOG_LEVEL<1)return;const e=this.format(...i);t.emit(1,e),console.warn(F.YELLOW+e+H.CLEAR)}error(...i){if(t.LOG_LEVEL<0)return;const e=this.format(...i);t.emit(0,e),console.error(F.RED+e+H.CLEAR)}};l(Nt,"LOG_LEVEL",4);var Vt="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",Ct="0123456789",Jt="~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/",bt=Vt+Ct+Jt;class r extends Lt{t;i;emitter=new u;_token=null;get token(){return this._token}set token(t){if(t==this._token)return;this._token=t,this.headers.Authorization=t?`Bearer ${t}`:void 0,this.emit("TOKEN",t)}constructor(t=location.origin,i={}){i.url=t;super(i);this.url=t;this.opts=i}emit=this.emitter.emit.bind(this.emitter);off=this.emitter.off.bind(this.emitter);on=this.emitter.on.bind(this.emitter);once=this.emitter.once.bind(this.emitter);request(t){const i=super.request(t).then((e)=>{return this.emit("RESPONSE",e,t),e}).catch((e)=>{const n=e?.data||e;throw this.emit("REJECTED",n,t),n});return this.emit("REQUEST",i,t),i}}function T(t,i){if(typeof i!=="function"&&i!==null)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");j(t,i);function e(){this.constructor=t}t.prototype=i===null?Object.create(i):(e.prototype=i.prototype,new e)}function M(t){var i=typeof Symbol==="function"&&Symbol.iterator,e=i&&t[i],n=0;if(e)return e.call(t);if(t&&typeof t.length==="number")return{next:function(){if(t&&n>=t.length)t=void 0;return{value:t&&t[n++],done:!t}}};throw new TypeError(i?"Object is not iterable.":"Symbol.iterator is not defined.")}function R(t,i){var e=typeof Symbol==="function"&&t[Symbol.iterator];if(!e)return t;var n=e.call(t),s,a=[],o;try{while((i===void 0||i-- >0)&&!(s=n.next()).done)a.push(s.value)}catch(p){o={error:p}}finally{try{if(s&&!s.done&&(e=n.return))e.call(n)}finally{if(o)throw o.error}}return a}function $(t,i,e){if(e||arguments.length===2){for(var n=0,s=i.length,a;n<s;n++)if(a||!(n in i)){if(!a)a=Array.prototype.slice.call(i,0,n);a[n]=i[n]}}return t.concat(a||Array.prototype.slice.call(i))}var j=function(t,i){return j=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(e,n){e.__proto__=n}||function(e,n){for(var s in n)if(Object.prototype.hasOwnProperty.call(n,s))e[s]=n[s]},j(t,i)};function f(t){return typeof t==="function"}function N(t){var i=function(n){Error.call(n),n.stack=new Error().stack},e=t(i);return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}var V=N(function(t){return function i(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map(function(n,s){return s+1+") "+n.toString()}).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}});function x(t,i){if(t){var e=t.indexOf(i);0<=e&&t.splice(e,1)}}function C(t){return t instanceof O||t&&"closed"in t&&f(t.remove)&&f(t.add)&&f(t.unsubscribe)}function Rt(t){if(f(t))t();else t.unsubscribe()}var O=function(){function t(i){this.initialTeardown=i,this.closed=!1,this._parentage=null,this._finalizers=null}return t.prototype.unsubscribe=function(){var i,e,n,s,a;if(!this.closed){this.closed=!0;var o=this._parentage;if(o)if(this._parentage=null,Array.isArray(o))try{for(var p=M(o),h=p.next();!h.done;h=p.next()){var D=h.value;D.remove(this)}}catch(d){i={error:d}}finally{try{if(h&&!h.done&&(e=p.return))e.call(p)}finally{if(i)throw i.error}}else o.remove(this);var S=this.initialTeardown;if(f(S))try{S()}catch(d){a=d instanceof V?d.errors:[d]}var G=this._finalizers;if(G){this._finalizers=null;try{for(var L=M(G),c=L.next();!c.done;c=L.next()){var k=c.value;try{Rt(k)}catch(d){if(a=a!==null&&a!==void 0?a:[],d instanceof V)a=$($([],R(a)),R(d.errors));else a.push(d)}}}catch(d){n={error:d}}finally{try{if(c&&!c.done&&(s=L.return))s.call(L)}finally{if(n)throw n.error}}}if(a)throw new V(a)}},t.prototype.add=function(i){var e;if(i&&i!==this)if(this.closed)Rt(i);else{if(i instanceof t){if(i.closed||i._hasParent(this))return;i._addParent(this)}(this._finalizers=(e=this._finalizers)!==null&&e!==void 0?e:[]).push(i)}},t.prototype._hasParent=function(i){var e=this._parentage;return e===i||Array.isArray(e)&&e.includes(i)},t.prototype._addParent=function(i){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(i),e):e?[e,i]:i},t.prototype._removeParent=function(i){var e=this._parentage;if(e===i)this._parentage=null;else if(Array.isArray(e))x(e,i)},t.prototype.remove=function(i){var e=this._finalizers;if(e&&x(e,i),i instanceof t)i._removeParent(this)},t.EMPTY=function(){var i=new t;return i.closed=!0,i}(),t}();var z=O.EMPTY;var m={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var q={setTimeout:function(t,i){var e=[];for(var n=2;n<arguments.length;n++)e[n-2]=arguments[n];var s=q.delegate;if(s===null||s===void 0?void 0:s.setTimeout)return s.setTimeout.apply(s,$([t,i],R(e)));return setTimeout.apply(void 0,$([t,i],R(e)))},clearTimeout:function(t){var i=q.delegate;return((i===null||i===void 0?void 0:i.clearTimeout)||clearTimeout)(t)},delegate:void 0};function $t(t){q.setTimeout(function(){var i=m.onUnhandledError;if(i)i(t);else throw t})}function b(){}function qt(t){return _("E",void 0,t)}function It(t){return _("N",t,void 0)}function _(t,i,e){return{kind:t,value:i,error:e}}var Ot=function(){return _("C",void 0,void 0)}();function I(t){if(m.useDeprecatedSynchronousErrorHandling){var i=!P;if(i)P={errorThrown:!1,error:null};if(t(),i){var e=P,n=e.errorThrown,s=e.error;if(P=null,n)throw s}}else t()}function St(t){if(m.useDeprecatedSynchronousErrorHandling&&P)P.errorThrown=!0,P.error=t}var P=null;function tt(t,i){return Yt.call(t,i)}function J(t){if(m.useDeprecatedSynchronousErrorHandling)St(t);else $t(t)}function Xt(t){throw t}function it(t,i){var e=m.onStoppedNotification;e&&q.setTimeout(function(){return e(t,i)})}var et=function(t){T(i,t);function i(e){var n=t.call(this)||this;if(n.isStopped=!1,e){if(n.destination=e,C(e))e.add(n)}else n.destination=Bt;return n}return i.create=function(e,n,s){return new Y(e,n,s)},i.prototype.next=function(e){if(this.isStopped)it(It(e),this);else this._next(e)},i.prototype.error=function(e){if(this.isStopped)it(qt(e),this);else this.isStopped=!0,this._error(e)},i.prototype.complete=function(){if(this.isStopped)it(Ot,this);else this.isStopped=!0,this._complete()},i.prototype.unsubscribe=function(){if(!this.closed)this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null},i.prototype._next=function(e){this.destination.next(e)},i.prototype._error=function(e){try{this.destination.error(e)}finally{this.unsubscribe()}},i.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},i}(O);var Yt=Function.prototype.bind,Qt=function(){function t(i){this.partialObserver=i}return t.prototype.next=function(i){var e=this.partialObserver;if(e.next)try{e.next(i)}catch(n){J(n)}},t.prototype.error=function(i){var e=this.partialObserver;if(e.error)try{e.error(i)}catch(n){J(n)}else J(i)},t.prototype.complete=function(){var i=this.partialObserver;if(i.complete)try{i.complete()}catch(e){J(e)}},t}(),Y=function(t){T(i,t);function i(e,n,s){var a=t.call(this)||this,o;if(f(e)||!e)o={next:e!==null&&e!==void 0?e:void 0,error:n!==null&&n!==void 0?n:void 0,complete:s!==null&&s!==void 0?s:void 0};else{var p;if(a&&m.useDeprecatedNextContext)p=Object.create(e),p.unsubscribe=function(){return a.unsubscribe()},o={next:e.next&&tt(e.next,p),error:e.error&&tt(e.error,p),complete:e.complete&&tt(e.complete,p)};else o=e}return a.destination=new Qt(o),a}return i}(et);var Bt={closed:!0,next:b,error:Xt,complete:b};var Gt=function(){return typeof Symbol==="function"&&Symbol.observable||"@@observable"}();function Ut(t){return t}function Ht(t){if(t.length===0)return Ut;if(t.length===1)return t[0];return function i(e){return t.reduce(function(n,s){return s(n)},e)}}function Mt(t){var i;return(i=t!==null&&t!==void 0?t:m.Promise)!==null&&i!==void 0?i:Promise}function Zt(t){return t&&f(t.next)&&f(t.error)&&f(t.complete)}function vt(t){return t&&t instanceof et||Zt(t)&&C(t)}var nt=function(){function t(i){if(i)this._subscribe=i}return t.prototype.lift=function(i){var e=new t;return e.source=this,e.operator=i,e},t.prototype.subscribe=function(i,e,n){var s=this,a=vt(i)?i:new Y(i,e,n);return I(function(){var o=s,p=o.operator,h=o.source;a.add(p?p.call(a,h):h?s._subscribe(a):s._trySubscribe(a))}),a},t.prototype._trySubscribe=function(i){try{return this._subscribe(i)}catch(e){i.error(e)}},t.prototype.forEach=function(i,e){var n=this;return e=Mt(e),new e(function(s,a){var o=new Y({next:function(p){try{i(p)}catch(h){a(h),o.unsubscribe()}},error:a,complete:s});n.subscribe(o)})},t.prototype._subscribe=function(i){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(i)},t.prototype[Gt]=function(){return this},t.prototype.pipe=function(){var i=[];for(var e=0;e<arguments.length;e++)i[e]=arguments[e];return Ht(i)(this)},t.prototype.toPromise=function(i){var e=this;return i=Mt(i),new i(function(n,s){var a;e.subscribe(function(o){return a=o},function(o){return s(o)},function(){return n(a)})})},t.create=function(i){return new t(i)},t}();var xt=N(function(t){return function i(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}});var st=function(t){T(i,t);function i(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return i.prototype.lift=function(e){var n=new kt(this,this);return n.operator=e,n},i.prototype._throwIfClosed=function(){if(this.closed)throw new xt},i.prototype.next=function(e){var n=this;I(function(){var s,a;if(n._throwIfClosed(),!n.isStopped){if(!n.currentObservers)n.currentObservers=Array.from(n.observers);try{for(var o=M(n.currentObservers),p=o.next();!p.done;p=o.next()){var h=p.value;h.next(e)}}catch(D){s={error:D}}finally{try{if(p&&!p.done&&(a=o.return))a.call(o)}finally{if(s)throw s.error}}}})},i.prototype.error=function(e){var n=this;I(function(){if(n._throwIfClosed(),!n.isStopped){n.hasError=n.isStopped=!0,n.thrownError=e;var s=n.observers;while(s.length)s.shift().error(e)}})},i.prototype.complete=function(){var e=this;I(function(){if(e._throwIfClosed(),!e.isStopped){e.isStopped=!0;var n=e.observers;while(n.length)n.shift().complete()}})},i.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(i.prototype,"observed",{get:function(){var e;return((e=this.observers)===null||e===void 0?void 0:e.length)>0},enumerable:!1,configurable:!0}),i.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},i.prototype._subscribe=function(e){return this._throwIfClosed(),this._checkFinalizedStatuses(e),this._innerSubscribe(e)},i.prototype._innerSubscribe=function(e){var n=this,s=this,a=s.hasError,o=s.isStopped,p=s.observers;if(a||o)return z;return this.currentObservers=null,p.push(e),new O(function(){n.currentObservers=null,x(p,e)})},i.prototype._checkFinalizedStatuses=function(e){var n=this,s=n.hasError,a=n.thrownError,o=n.isStopped;if(s)e.error(a);else if(o)e.complete()},i.prototype.asObservable=function(){var e=new nt;return e.source=this,e},i.create=function(e,n){return new kt(e,n)},i}(nt);var kt=function(t){T(i,t);function i(e,n){var s=t.call(this)||this;return s.destination=e,s.source=n,s}return i.prototype.next=function(e){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.next)===null||s===void 0||s.call(n,e)},i.prototype.error=function(e){var n,s;(s=(n=this.destination)===null||n===void 0?void 0:n.error)===null||s===void 0||s.call(n,e)},i.prototype.complete=function(){var e,n;(n=(e=this.destination)===null||e===void 0?void 0:e.complete)===null||n===void 0||n.call(e)},i.prototype._subscribe=function(e){var n,s;return(s=(n=this.source)===null||n===void 0?void 0:n.subscribe(e))!==null&&s!==void 0?s:z},i}(st);var g=function(t){T(i,t);function i(e){var n=t.call(this)||this;return n._value=e,n}return Object.defineProperty(i.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),i.prototype._subscribe=function(e){var n=t.prototype._subscribe.call(this,e);return!n.closed&&e.next(this._value),n},i.prototype.getValue=function(){var e=this,n=e.hasError,s=e.thrownError,a=e._value;if(n)throw s;return this._throwIfClosed(),a},i.prototype.next=function(e){t.prototype.next.call(this,this._value=e)},i}(st);var jt;((p)=>{p[p.CRON=0]="CRON";p[p.EVENT=1]="EVENT";p[p.DELETE=2]="DELETE";p[p.GET=3]="GET";p[p.PATCH=4]="PATCH";p[p.POST=5]="POST";p[p.PUT=6]="PUT"})(jt||={});class at extends u{api;$cache=new g([]);get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t){return this.api.request({url:`/api/actions/${t}`,method:"DELETE"}).then(()=>{this.cache=this.cache.filter((i)=>i._id!=t),this.emit("DELETE",t)})}list(){return this.api.request({url:"/api/actions"}).then((t)=>{if(t.data)this.cache=t.data;return this.emit("LIST",t.data||[]),t.data})}read(t,i=!1){const e=this.cache.find((n)=>n._id==t);if(!i&&e)return Promise.resolve(e);return this.api.request({url:`/api/actions/${t}`}).then((n)=>{if(n.data)this.cache=this.cache.filter((s)=>s._id!=t).concat([n.data]);return this.emit("READ",n.data),n.data})}run(t,i={}){return this.api.request({url:("/api/actions/run/"+t).replaceAll("//","/"),...i}).then((e)=>e.data)}runById(t,i={}){const e=typeof t=="string"?t:t._id;return this.api.request({url:"/api/actions/run-by-id/"+e,method:"POST",...i}).then((n)=>n.data)}update(t){return this.api.request({url:`/api/actions${t._id?`/${t._id}`:""}`,method:"POST",body:t}).then((i)=>{if(i.data)this.cache=this.cache.filter((e)=>e._id!=i.data?._id).concat([i.data]);return this.emit("UPDATE",i.data),i.data})}}class Wt{t;constructor(t){this.api=t}disable(t){return this.api.request({url:`/api/auth/totp/${t}`,method:"DELETE"})}enable=this.reset;reset(t){return this.api.request({url:`/api/auth/totp/${t}`,method:"POST"})}setup(t,i="app",e){return this.api.request({url:`/api/auth/totp/${t}`,body:B({method:i,totp:e})})}}class ot extends u{i;api;storageKey;totp;$user=new g(void 0);get user(){return this.$user.value}set user(t){if(!Z(this.user,t)){const i=t?t:null;this.$user.next(i),this.emit("USER",i)}}constructor(t,i){super();this.opts=i;if(this.api=typeof t=="string"?new r(t):t,this.totp=new Wt(this.api),!this.opts?.loginUi)this.opts={...this.opts,loginUi:this.api.url+"/ui/login"};if(this.storageKey=`momentum:${new URL(this.api.url).host}`,this.api.addInterceptor((e,n)=>{const s=["/api/auth/login","/api/auth/password","/api/auth/totp"];if(e.status==401&&!s.find((a)=>e.url.includes(a)))this.emit("SESSION_EXPIRED");n()}),this.api.on("TOKEN",(e)=>{if(this.opts?.persist)if(e)localStorage.setItem(this.storageKey,e);else localStorage.removeItem(this.storageKey);if(e)this.session(e,!0).catch(()=>{});else this.user=null}),i?.persist){const e=localStorage.getItem(this.storageKey);if(e)this.api.token=e;else this.user=null}else this.user=null}knownHost(t=location.origin){if(t.startsWith("/"))return Promise.resolve();return this.api.request({url:`/api/auth/known-host?host=${encodeURI(new URL(t).origin)}`}).then(()=>{})}login(t,i,e){return this.api.request({url:"/api/auth/login",headers:{Authorization:void 0},method:"POST",body:{username:t.trim(),password:i.trim(),totp:e}}).then(async(n)=>{return this.api.token=n.data?.token||null,await this.once("USER")})}loginRedirect(t=location.origin){return new Promise((i,e)=>{const n=window.open(encodeURI(`${this.opts?.loginUi}?redirect=postmessage&host=${t}`),"_blank");if(!n)return e("Unable to open login");n.addEventListener("message",(s)=>{if(!s?.data?.token)return e("Unknown response from login");this.api.token=s.data.token,i(s.data.token),n.close()})})}logout(){this.api.token=null,this.user=null,this.emit("LOGOUT")}async register(t){const i=(await this.api.request({url:"/api/auth/register",body:{...t}}))?.data;if(i?.image?.startsWith("/"))i.image=`${this.api.url}${i.image}?token=${this.api.token}`;return this.emit("REGISTER",i),i}reset(t,i){return this.api.request({url:"/api/auth/reset",headers:{Authorization:i?`Bearer ${i}`:void 0},body:{email:i?void 0:t,password:i?t:void 0}}).then(()=>{})}async session(t,i=!1){if(!t)t=this.api.token;const e=(await this.api.request({url:"/api/auth/session",headers:t?{Authorization:`Bearer ${t}`}:void 0}))?.data;if(i){if(this.api.token=t,e?.user)e.user.image=`${this.api.url}${e.user.image}?token=${this.api.token}`;if(this.user=e?.user||null,e)this.emit("LOGIN",e.user)}return e}async updatePassword(t,i,e){return this.api.request({url:"/api/auth/password",body:{username:t,password:i,oldPassword:e}}).then((n)=>{if(n?.data?.token)this.api.token=n.data.token})}}class pt extends u{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t,i){return this.api.request({url:`/api/data/${t}/${i}`,method:"DELETE"}).then(()=>this.emit("DELETE",t,i))}get(t,i){return this.api.request({url:`/api/data/${t}${i?`/${i}`:""}`}).then((e)=>{return this.emit("GET",t,e.data),e.data})}raw(t,i,e,n){return this.api.request({url:`/api/data/${t}`,body:{operand:i,query:e,options:n}}).then((s)=>{return this.emit("RAW",t,s.data),s.data})}set(t,i,e=!1){return this.api.request({url:`/api/data/${t}/${i._id||""}`,method:e?"PATCH":"POST",body:i}).then((n)=>{return this.emit("SET",t,n.data),n.data})}}class ht extends u{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}send(t){let i="/api/email";if(typeof t.body=="object")i+=`/${t.body.template}`;return this.api.request({url:i,body:t}).then((e)=>{return this.emit("SENT",t),e.data})}}class ut extends u{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}create(t){return this.api.request({url:`/api/groups/${t.name}`,method:"POST",body:t}).then((i)=>{return this.emit("CREATE",i.data),i.data})}list(){return this.api.request({url:"/api/groups"}).then((t)=>{return this.emit("LIST",t.data||[]),t.data})}read(t){return this.api.request({url:`/api/groups/${t}`}).then((i)=>{return this.emit("READ",i.data),i.data})}update(t){return this.api.request({url:`/api/groups/${t.name}`,method:"PATCH",body:t}).then((i)=>{return this.emit("UPDATE",i.data),i.data})}delete(t){return this.api.request({url:`/api/groups/${t}`,method:"DELETE"}).then(()=>this.emit("DELETE",t))}}class rt{api;constructor(t,i){if(this.api=typeof t=="string"?new r(t):t,i!=null&&i!="NONE")window.addEventListener("error",(e)=>this.error(e.error.stack)),window.addEventListener("unhandledrejection",async(e)=>this.error(e.reason.stack))}buildLog(t,i){return{time:new Date().getTime(),level:t,log:i,ctx:{cores:navigator.hardwareConcurrency,mem:navigator?.deviceMemory,res:[window.innerWidth,window.innerHeight],url:location.href}}}clearClientLogs(){return this.api.request({url:"/api/logs/client",method:"DELETE"})}clearServerLogs(){return this.api.request({url:"/api/logs/server",method:"DELETE"})}clientLogs(t,i){const e=[t?`length=${t}`:void 0,i?`page=${i}`:void 0].filter((n)=>!!n).join("&");return this.api.request({url:`/api/logs/client${e?`?${e}`:""}`}).then((n)=>n.data)}serverLogs(t,i){const e=[t?`length=${t}`:void 0,i?`page=${i}`:void 0].filter((n)=>!!n).join("&");return this.api.request({url:`/api/logs/server${e?`?${e}`:""}`}).then((n)=>n.data)}debug(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.DEBUG,t)}).then(()=>{}).catch(()=>{})}log(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.LOG,t)}).then(()=>{}).catch(()=>{})}info(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.INFO,t)}).then(()=>{}).catch(()=>{})}warn(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.WARN,t)}).then(()=>{}).catch(()=>{})}error(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(w.ERROR,t)}).then(()=>{}).catch(()=>{})}}class lt extends u{api;stripe;constructor(t,i){super();this.api=typeof t=="string"?new r(t):t;const e=(n=1)=>{try{if(!Stripe)throw new Error("Stripe not added");this.stripe=Stripe(i)}catch(s){if(n>0)setTimeout(()=>e(n--),250);else console.warn("Stripe failed, did you add the library & setup your API key?",s)}};e()}async charge(t,i={}){return this.emit("CHECKOUT",t,i),(await this.api.request({url:"/api/payments",body:{amount:t,custom:i}})).data.clientSecret}async createForm(t,i,e){const n=await this.charge(i,e),s=this.stripe.elements({clientSecret:n});return s.create("payment").mount(t),()=>this.stripe.confirmPayment({elements:s,redirect:"if_required",confirmParams:{return_url:location.origin}})}async history(t){const i=await this.api.request({url:`/api/payments${t?`/${t}`:""}`});return this.emit("LIST",t||null,i.data),i.data}}class yt extends u{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}async handleResponse(t,i){const e=await t.blob();if(i){const n=URL.createObjectURL(e);v(n,i.endsWith(".pdf")?i:i+".pdf"),URL.revokeObjectURL(n)}return this.emit("CREATE",e),e}fromHtml(t,i={}){return this.api.request({url:"/api/pdf",body:{html:t}}).then((e)=>this.handleResponse(e,i.download?i.fileName||new Date().toISOString():void 0))}fromTemplate(t,i,e={}){return this.api.request({url:`/api/pdf${t}`,body:i}).then((n)=>this.handleResponse(n,e.download?e.fileName||new Date().toISOString():void 0))}fromUrl(t,i={}){return this.api.request({url:`/api/pdf?url=${t}`}).then((e)=>this.handleResponse(e,i.download?i.fileName||new Date().toISOString():void 0))}}class Q{static timeout=1e4;api;url;connection;open=!1;constructor(t){if(this.api=typeof t=="string"?new r(t):t,this.url=this.api.url.replace("http","ws"),this.api.on("TOKEN",()=>this.connect()),!this.api.token)this.connect()}close(){console.debug("Disconnected from Momentum"),this.open=!1,this.connection.close()}connect(t=3){if(this.connection?.readyState<2)this.connection.close();this.connection=new WebSocket(this.url+(this.api.token?`?token=${this.api.token}`:""));const i=setTimeout(()=>{if(this.open)return;if(this.connection.close(),console.error("Momentum connection timeout"),t>0)this.connect(t-1)},Q.timeout);this.connection.onclose=()=>this.open=!1,this.connection.onmessage=this.handle,this.connection.onopen=()=>{this.open=!0,clearTimeout(i),console.debug("Connected to Momentum")}}handle(...t){console.log(t)}send(t,i){this.connection.send(JSON.stringify({token:this.api.token,channel:t,payload:i}))}}class dt extends u{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t){const i=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll("//","/");return this.api.request({url:i,method:"DELETE"}).then(()=>{this.emit("DELETE",i)})}list(t){const i=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll("//","/");return this.api.request({url:i+"?list"}).then((e)=>{return this.emit("LIST",t,e.data),e.data})}open(t,i="_blank"){const e=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll(/\/{2,}/g,"/"),n=`${this.api.url}${e}${this.api.token?`?token=${this.api.token}`:""}`;if(!i)return n;return this.emit("OPEN",t),window.open(n,i)}mkdir(t){const i=(t.startsWith("/api/storage/")?t:"/api/storage/"+t).replaceAll(/\/{2,}/g,"/");return this.api.request({url:i+"?directory",method:"POST"}).then((e)=>e.data)}download(t,i={}){const e=("/api/storage/"+t).replaceAll("//","/");return this.api.request({...i,url:e,decode:!1}).then(async(n)=>{const s=await n.data.blob(),a=i.downloadAs||new URL(n.url).pathname.split("/").pop();return this.emit("DOWNLOAD",t,s),ct(s,a),n.data})}upload(t,i=""){return new E(async(e,n,s)=>{if(!t)t=await Et();if(!t||Array.isArray(t)&&!t.length)return[];const a=this.api.url+("/api/storage/"+(typeof i=="string"?i:i?.path)).replaceAll("//","/");return K({url:a,files:Array.isArray(t)?t:[t],headers:this.api.headers}).onProgress((o)=>{s(o)}).then((o)=>{this.emit("UPLOAD",o),e(o)}).catch((o)=>n(o))})}}class ft extends u{api;listed=!1;$cache=new g([]);get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t){return this.api.request({url:`/api/users/${t}`,method:"DELETE"}).then(()=>{this.cache=this.cache.filter((i)=>i.username!=t),this.emit("DELETE",t)})}list(t=!1){if(!t&&this.listed)return Promise.resolve(this.cache);return this.api.request({url:"/api/users"}).then((i)=>{return i.data?.map((e)=>{return e.image=this.api.url+e.image+`?token=${this.api.token}`,e}),this.cache=i.data||[],this.listed=!0,this.emit("LIST",i.data||[]),i.data})}read(t,i=!1){if(!i){const e=this.cache.find((n)=>n.username==t);if(e)return Promise.resolve(e)}return this.api.request({url:`/api/users/${t}`}).then((e)=>{if(e.data)e.data.image=this.api.url+e.data.image+`?token=${this.api.token}`,this.cache=[...this.cache.filter((n)=>n.username!=t),e.data];return this.emit("READ",e.data),e.data})}update(t){return this.api.request({url:`/api/users/${t.username}`,method:"PATCH",body:t}).then((i)=>{if(i.data)i.data.image=this.api.url+i.data.image+`?token=${this.api.token}`,this.cache=this.cache.filter((e)=>e.username!=t.username).concat([i.data]);return this.emit(t._id?"UPDATE":"CREATE",i.data),i.data})}uploadImage(t,i){return K({url:this.api.url+`/api/users/${t}/image`,files:[i],headers:this.api.headers}).then((e)=>{return this.emit("UPLOAD_IMAGE",t,i),e})}}class mt extends u{api;$cache=new g({});get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new r(t):t}list(t=!1){return this.api.request({url:"/api/settings"+(t?"?detailed":"")}).then((i)=>{return this.cache=!t?i.data:Object.values(i.data||{}).reduce((e,n)=>({...e,[n.key]:n.value}),{}),this.emit("LIST",i.data||[]),i.data})}delete(t){return this.api.request({url:`/api/settings/${t}`,method:"DELETE"}).then(()=>{this.cache={...this.cache,[t]:void 0},this.emit("DELETE",t)})}read(t,i=!1){if(!i&&this.cache[t])return Promise.resolve(this.cache[t]);return this.api.request({url:`/api/settings/${t}`}).then((e)=>{if(e.data)this.cache={...this.cache,[e.data.key]:e};return this.emit("READ",e.data),e.data})}update(t){return this.api.request({url:`/api/settings/${t.key}`,body:t}).then((i)=>{if(i.data)this.cache={...this.cache,[i.data.key]:i.data.value};return this.emit("UPDATE",i.data),i.data})}}class gt extends u{api;constructor(t){super();this.api=typeof t=="string"?new r(t):t}delete(t){return this.api.request({url:`/api/static/${t}`,method:"DELETE"}).then(()=>{this.emit("DELETE",t)})}list(t){const i=("/api/static/"+t).replaceAll("//","/");return this.api.request({url:i}).then((e)=>{return this.emit("LIST",t,e.data||[]),e.data})}upload(t,i="/"){const e=new FormData;return(Array.isArray(t)?t:[t]).forEach((n)=>e.append("file",n)),this.api.request({url:"/api/static"+i,body:e}).then((n)=>{return this.emit("UPLOAD",n.data||[]),n.data})}}class zt extends u{api;actions;auth;data;email;groups;logger;payments;pdf;settings;socket;static;storage;users;constructor(t,i){super();if(this.api=new r(t,i?.api),this.actions=new at(this.api),this.auth=new ot(this.api,{persist:i?.persist??!0,loginUi:i?.loginUi}),this.data=new pt(this.api),this.email=new ht(this.api),this.groups=new ut(this.api),this.logger=new rt(this.api,i?.logLevel),i?.stripeSecret)this.payments=new lt(this.api,i.stripeSecret);if(this.pdf=new yt(this.api),this.settings=new mt(this.api),this.static=new gt(this.api),this.storage=new dt(this.api),this.users=new ft(this.api),i?.socket)this.socket=new Q(this.api);if(this.api.on("*",(e,...n)=>this.emit(`API::${e}`,...n)),this.actions.on("*",(e,...n)=>this.emit(`ACTIONS::${e}`,...n)),this.auth.on("*",(e,...n)=>this.emit(`AUTH::${e}`,...n)),this.data.on("*",(e,...n)=>this.emit(`DATA::${e}`,...n)),this.email.on("*",(e,...n)=>this.emit(`EMAIL::${e}`,...n)),this.groups.on("*",(e,...n)=>this.emit(`GROUPS::${e}`,...n)),this.payments)this.payments.on("*",(e,...n)=>this.emit(`PAYMENT::${e}`,...n));this.pdf.on("*",(e,...n)=>this.emit(`PDF::${e}`,...n)),this.settings.on("*",(e,...n)=>this.emit(`SETTINGS::${e}`,...n)),this.static.on("*",(e,...n)=>this.emit(`STATIC::${e}`,...n)),this.storage.on("*",(e,...n)=>this.emit(`STORAGE::${e}`,...n)),this.users.on("*",(e,...n)=>this.emit(`USERS::${e}`,...n)),this.users.on("*",(e,...n)=>{if(Array.isArray(n[0])){const s=n[0].find((a)=>a._id==this.auth.user?._id);if(s)this.auth.user=s}else if(n[0]._id==this.auth.user?._id)this.auth.user=n[0]})}}export{ft as Users,Wt as Totp,dt as Storage,gt as Static,Q as Socket,mt as Settings,yt as Pdf,lt as Payments,zt as Momentum,rt as Logger,ut as Groups,ht as Email,pt as Data,ot as Auth,r as Api,at as Actions,jt as ActionType};
@@ -1 +1 @@
1
- {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,KAAK,IAAI,EAAC,MAAM,QAAQ,CAAC;AACjC,OAAO,EACN,eAAe,EACf,YAAY,EACZ,KAAK,WAAW,EAChB,kBAAkB,EAElB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,OAAO,GAAG;IACrB,QAAQ,EAAE,CAAC,OAAO,GAAG,QAAQ,CAAC,EAAE,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACb,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACb,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG;IACzC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,QAAQ,KAAK,GAAG,CAAC;IAC1D,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;IAC9B,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;IAC5C,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;IAC5B,MAAM,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,GAAG,CAAC;CACnC,CAAC;AACF,qBAAa,OAAQ,SAAQ,YAAY,CAAC,aAAa,CAAC;IACvD,QAAQ,CAAC,GAAG,EAAG,GAAG,CAAC;gBAEP,GAAG,EAAE,GAAG,GAAG,MAAM;IAK7B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOnC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,QAAQ,CAAC;IAQ/C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,GAAG,MAAM;IACzC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI;IAS9D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKrC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,kBAAkB,GAAG;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAM,GAAG,eAAe,CAAC,IAAI,CAAC;IAUtG,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,GAAE,MAAM,GAAG;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAM,GAAG,eAAe,CAAC,QAAQ,EAAE,CAAC;CAkB3I"}
1
+ {"version":3,"file":"storage.d.ts","sourceRoot":"","sources":["../src/storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,KAAK,IAAI,EAAC,MAAM,QAAQ,CAAC;AACjC,OAAO,EACN,eAAe,EACf,YAAY,EACZ,KAAK,WAAW,EAChB,kBAAkB,EAElB,MAAM,gBAAgB,CAAC;AAExB,MAAM,MAAM,OAAO,GAAG;IACrB,QAAQ,EAAE,CAAC,OAAO,GAAG,QAAQ,CAAC,EAAE,CAAC;IACjC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,WAAW,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;CACb,CAAA;AAED,MAAM,MAAM,QAAQ,GAAG,IAAI,GAAG;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;CACb,CAAA;AAED,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG;IACzC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,QAAQ,KAAK,GAAG,CAAC;IAC1D,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;IAC9B,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,KAAK,GAAG,CAAC;IAC5C,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;IAC5B,MAAM,EAAE,CAAC,KAAK,EAAE,QAAQ,EAAE,KAAK,GAAG,CAAC;CACnC,CAAC;AACF,qBAAa,OAAQ,SAAQ,YAAY,CAAC,aAAa,CAAC;IACvD,QAAQ,CAAC,GAAG,EAAG,GAAG,CAAC;gBAEP,GAAG,EAAE,GAAG,GAAG,MAAM;IAK7B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAOnC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,QAAQ,CAAC;IAQ/C,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,GAAG,MAAM;IACzC,IAAI,CAAC,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI;IAS9D,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAKrC,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,GAAE,kBAAkB,GAAG;QAAC,YAAY,CAAC,EAAE,MAAM,CAAA;KAAM,GAAG,eAAe,CAAC,IAAI,CAAC;IAWtG,MAAM,CAAC,KAAK,CAAC,EAAE,IAAI,GAAG,IAAI,EAAE,GAAG,IAAI,EAAE,IAAI,GAAE,MAAM,GAAG;QAAC,IAAI,CAAC,EAAE,MAAM,CAAC;QAAC,MAAM,CAAC,EAAE,MAAM,CAAC;QAAC,QAAQ,CAAC,EAAE,OAAO,CAAA;KAAM,GAAG,eAAe,CAAC,QAAQ,EAAE,CAAC;CAkB3I"}
package/dist/storage.js CHANGED
@@ -36,10 +36,11 @@ class Storage extends utils_1.TypedEmitter {
36
36
  }
37
37
  download(path, opts = {}) {
38
38
  const p = ('/api/storage/' + path).replaceAll('//', '/');
39
- return this.api.request({ ...opts, url: p, skipConverting: true }).then((response) => {
39
+ return this.api.request({ ...opts, url: p, decode: false }).then(async (response) => {
40
+ const blob = await response.data.blob();
40
41
  const name = opts.downloadAs || new URL(response.url).pathname.split('/').pop();
41
- this.emit('DOWNLOAD', path, response.data);
42
- (0, utils_1.downloadBlob)(response.data, name);
42
+ this.emit('DOWNLOAD', path, blob);
43
+ (0, utils_1.downloadBlob)(blob, name);
43
44
  return response.data;
44
45
  });
45
46
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ztimson/momentum",
3
- "version": "0.27.3",
3
+ "version": "0.27.4",
4
4
  "description": "Client library for momentum",
5
5
  "keywords": [
6
6
  "Momentum"
@@ -26,7 +26,7 @@
26
26
  "watch": "tsc -w & bun build --watch --target browser --outfile dist/index.mjs --minify src/index.ts"
27
27
  },
28
28
  "dependencies": {
29
- "@ztimson/utils": "^0.14.5",
29
+ "@ztimson/utils": "^0.14.11",
30
30
  "rxjs": "^7.8.1"
31
31
  },
32
32
  "devDependencies": {