@ztimson/momentum 0.21.0 → 0.27.1
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/README.md +44 -32
- package/dist/actions.d.ts +1 -2
- package/dist/actions.js +70 -0
- package/dist/api.d.ts +1 -2
- package/dist/api.js +40 -0
- package/dist/auth.d.ts +16 -9
- package/dist/auth.d.ts.map +1 -1
- package/dist/auth.js +164 -0
- package/dist/core.js +2 -0
- package/dist/data.d.ts +2 -3
- package/dist/data.js +48 -0
- package/dist/email.d.ts +1 -2
- package/dist/email.js +22 -0
- package/dist/groups.d.ts +3 -4
- package/dist/groups.d.ts.map +1 -1
- package/dist/groups.js +51 -0
- package/dist/index.js +31 -0
- package/dist/index.mjs +1 -0
- package/dist/logger.d.ts +0 -1
- package/dist/logger.js +59 -0
- package/dist/momentum.d.ts +9 -10
- package/dist/momentum.js +74 -0
- package/dist/pdf.d.ts +1 -2
- package/dist/pdf.js +33 -0
- package/dist/settings.d.ts +1 -2
- package/dist/settings.js +48 -0
- package/dist/sockets.d.ts +0 -1
- package/dist/sockets.js +54 -0
- package/dist/static.d.ts +2 -3
- package/dist/static.js +33 -0
- package/dist/storage.d.ts +2 -3
- package/dist/storage.js +99 -0
- package/dist/users.d.ts +10 -8
- package/dist/users.d.ts.map +1 -1
- package/dist/users.js +76 -0
- package/package.json +13 -16
- package/dist/momentum.cjs +0 -4
- package/dist/momentum.cjs.map +0 -1
- package/dist/momentum.mjs +0 -1307
- package/dist/momentum.mjs.map +0 -1
package/dist/index.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./actions"), exports);
|
|
18
|
+
__exportStar(require("./api"), exports);
|
|
19
|
+
__exportStar(require("./auth"), exports);
|
|
20
|
+
__exportStar(require("./core"), exports);
|
|
21
|
+
__exportStar(require("./data"), exports);
|
|
22
|
+
__exportStar(require("./email"), exports);
|
|
23
|
+
__exportStar(require("./groups"), exports);
|
|
24
|
+
__exportStar(require("./logger"), exports);
|
|
25
|
+
__exportStar(require("./momentum"), exports);
|
|
26
|
+
__exportStar(require("./pdf"), exports);
|
|
27
|
+
__exportStar(require("./settings"), exports);
|
|
28
|
+
__exportStar(require("./sockets"), exports);
|
|
29
|
+
__exportStar(require("./static"), exports);
|
|
30
|
+
__exportStar(require("./storage"), exports);
|
|
31
|
+
__exportStar(require("./users"), exports);
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var B=function(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};var Q=function(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)=>Q(t[s],i[s]))};var x=function(t,i){const e=document.createElement("a");e.href=t,e.download=i,document.body.appendChild(e),e.click(),document.body.removeChild(e)};var Mt=Object.defineProperty,St=(t,i,e)=>(i in t)?Mt(t,i,{enumerable:!0,configurable:!0,writable:!0,value:e}):t[i]=e,r=(t,i,e)=>(St(t,typeof i!="symbol"?i+"":i,e),e);class h{constructor(){r(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()})})}}r(h,"listeners",{});class w extends Error{constructor(t,i){super(t);r(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()}}r(w,"code",500);class ft extends w{constructor(t="Bad Request"){super(t)}static instanceof(t){return t.constructor.code==this.code}}r(ft,"code",400);class mt extends w{constructor(t="Unauthorized"){super(t)}static instanceof(t){return t.constructor.code==this.code}}r(mt,"code",401);class ct extends w{constructor(t="Forbidden"){super(t)}static instanceof(t){return t.constructor.code==this.code}}r(ct,"code",403);class dt extends w{constructor(t="Not Found"){super(t)}static instanceof(t){return t.constructor.code==this.code}}r(dt,"code",404);class gt extends w{constructor(t="Internal Server Error"){super(t)}static instanceof(t){return t.constructor.code==this.code}}r(gt,"code",500);var U={CLEAR:"\x1B[0m",BRIGHT:"\x1B[1m",DIM:"\x1B[2m",UNDERSCORE:"\x1B[4m",BLINK:"\x1B[5m",REVERSE:"\x1B[7m",HIDDEN:"\x1B[8m"},k={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 P=((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))(P||{}),kt=class t extends h{constructor(i){super(),this.namespace=i}pad(i,e,n,s=!1){const o=i.toString(),a=e-o.length;if(a<=0)return o;const u=Array(~~(a/n.length)).fill(n).join("");return s?o+u:u+o}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(k.LIGHT_GREY+e+U.CLEAR)}log(...i){if(t.LOG_LEVEL<3)return;const e=this.format(...i);t.emit(3,e),console.log(U.CLEAR+e)}info(...i){if(t.LOG_LEVEL<2)return;const e=this.format(...i);t.emit(2,e),console.info(k.BLUE+e+U.CLEAR)}warn(...i){if(t.LOG_LEVEL<1)return;const e=this.format(...i);t.emit(1,e),console.warn(k.YELLOW+e+U.CLEAR)}error(...i){if(t.LOG_LEVEL<0)return;const e=this.format(...i);t.emit(0,e),console.error(k.RED+e+U.CLEAR)}};r(kt,"LOG_LEVEL",4);var xt="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",Wt="0123456789",Ht="~`!@#$%^&*()_-+={[}]|\\:;\"'<,>.?/",Ct=xt+Wt+Ht;class J extends Promise{constructor(t){super((i,e)=>t((n)=>i(n),(n)=>e(n),(n)=>this.progress=n));r(this,"listeners",[]),r(this,"_progress",0)}get progress(){return this._progress}set progress(t){t!=this._progress&&(this._progress=t,this.listeners.forEach((i)=>i(t)))}onProgress(t){return this.listeners.push(t),this}}var X=class t{constructor(i={}){r(this,"interceptors",{}),r(this,"headers",{}),this.opts=i,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}}async request(i={}){var e,n;if(!this.opts.url&&!i.url)throw new Error("URL needs to be set");let s=((e=i.url)!=null&&e.startsWith("http")?i.url:(this.opts.url||"")+(i.url||"")).replace(/([^:]\/)\/+/g,"$1");if(i.fragment&&(s.includes("#")?s.replace(/#.*(\?|\n)/g,(a,u)=>`#${i.fragment}${u}`):s+="#"+i.fragment),i.query){const a=Array.isArray(i.query)?i.query:Object.keys(i.query).map((u)=>({key:u,value:i.query[u]}));s+=(s.includes("?")?"&":"?")+a.map((u)=>`${u.key}=${u.value}`).join("&")}const o=B({"Content-Type":i.body&&!(i.body instanceof FormData)?"application/json":void 0,...t.headers,...this.headers,...i.headers});return fetch(s,{headers:o,method:i.method||(i.body?"POST":"GET"),body:(n=o["Content-Type"])!=null&&n.startsWith("application/json")&&i.body?JSON.stringify(i.body):i.body}).then(async(a)=>{for(let l of[...Object.values(t.interceptors),...Object.values(this.interceptors)])await new Promise((m)=>l(a,()=>m()));const u=await(async()=>{var l,m;return!i.skipConverting&&((l=a.headers.get("Content-Type"))!=null&&l.startsWith("application/json"))?await a.json():!i.skipConverting&&((m=a.headers.get("Content-Type"))!=null&&m.startsWith("text/plain"))?await a.text():a})();if(a.ok)return u;throw Object.assign(new Error(typeof u=="string"?u:a.statusText),typeof u=="object"?u:{})})}};r(X,"interceptors",{}),r(X,"headers",{});var Et=X;class p extends Et{t;i;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,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)=>{throw this.emit("REJECTED",e,t),e});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");C(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 D(t,i){var e=typeof Symbol==="function"&&t[Symbol.iterator];if(!e)return t;var n=e.call(t),s,o=[],a;try{while((i===void 0||i-- >0)&&!(s=n.next()).done)o.push(s.value)}catch(u){a={error:u}}finally{try{if(s&&!s.done&&(e=n.return))e.call(n)}finally{if(a)throw a.error}}return o}function R(t,i,e){if(e||arguments.length===2){for(var n=0,s=i.length,o;n<s;n++)if(o||!(n in i)){if(!o)o=Array.prototype.slice.call(i,0,n);o[n]=i[n]}}return t.concat(o||Array.prototype.slice.call(i))}var C=function(t,i){return C=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]},C(t,i)};function f(t){return typeof t==="function"}function W(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 H=W(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 S(t,i){if(t){var e=t.indexOf(i);0<=e&&t.splice(e,1)}}function F(t){return t instanceof $||t&&"closed"in t&&f(t.remove)&&f(t.add)&&f(t.unsubscribe)}var Tt=function(t){if(f(t))t();else t.unsubscribe()},$=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,o;if(!this.closed){this.closed=!0;var a=this._parentage;if(a)if(this._parentage=null,Array.isArray(a))try{for(var u=M(a),l=u.next();!l.done;l=u.next()){var m=l.value;m.remove(this)}}catch(y){i={error:y}}finally{try{if(l&&!l.done&&(e=u.return))e.call(u)}finally{if(i)throw i.error}}else a.remove(this);var I=this.initialTeardown;if(f(I))try{I()}catch(y){o=y instanceof H?y.errors:[y]}var G=this._finalizers;if(G){this._finalizers=null;try{for(var A=M(G),g=A.next();!g.done;g=A.next()){var E=g.value;try{Tt(E)}catch(y){if(o=o!==null&&o!==void 0?o:[],y instanceof H)o=R(R([],D(o)),D(y.errors));else o.push(y)}}}catch(y){n={error:y}}finally{try{if(g&&!g.done&&(s=A.return))s.call(A)}finally{if(n)throw n.error}}}if(o)throw new H(o)}},t.prototype.add=function(i){var e;if(i&&i!==this)if(this.closed)Tt(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))S(e,i)},t.prototype.remove=function(i){var e=this._finalizers;if(e&&S(e,i),i instanceof t)i._removeParent(this)},t.EMPTY=function(){var i=new t;return i.closed=!0,i}(),t}();var Z=$.EMPTY;var c={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1};var O={setTimeout:function(t,i){var e=[];for(var n=2;n<arguments.length;n++)e[n-2]=arguments[n];var s=O.delegate;if(s===null||s===void 0?void 0:s.setTimeout)return s.setTimeout.apply(s,R([t,i],D(e)));return setTimeout.apply(void 0,R([t,i],D(e)))},clearTimeout:function(t){var i=O.delegate;return((i===null||i===void 0?void 0:i.clearTimeout)||clearTimeout)(t)},delegate:void 0};function At(t){O.setTimeout(function(){var i=c.onUnhandledError;if(i)i(t);else throw t})}function Y(){}function Pt(t){return v("E",void 0,t)}function Lt(t){return v("N",t,void 0)}function v(t,i,e){return{kind:t,value:i,error:e}}var wt=function(){return v("C",void 0,void 0)}();function q(t){if(c.useDeprecatedSynchronousErrorHandling){var i=!L;if(i)L={errorThrown:!1,error:null};if(t(),i){var e=L,n=e.errorThrown,s=e.error;if(L=null,n)throw s}}else t()}function Dt(t){if(c.useDeprecatedSynchronousErrorHandling&&L)L.errorThrown=!0,L.error=t}var L=null;var j=function(t,i){return Ft.call(t,i)},K=function(t){if(c.useDeprecatedSynchronousErrorHandling)Dt(t);else At(t)},Nt=function(t){throw t},z=function(t,i){var e=c.onStoppedNotification;e&&O.setTimeout(function(){return e(t,i)})},b=function(t){T(i,t);function i(e){var n=t.call(this)||this;if(n.isStopped=!1,e){if(n.destination=e,F(e))e.add(n)}else n.destination=Vt;return n}return i.create=function(e,n,s){return new N(e,n,s)},i.prototype.next=function(e){if(this.isStopped)z(Lt(e),this);else this._next(e)},i.prototype.error=function(e){if(this.isStopped)z(Pt(e),this);else this.isStopped=!0,this._error(e)},i.prototype.complete=function(){if(this.isStopped)z(wt,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}($);var Ft=Function.prototype.bind,Kt=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){K(n)}},t.prototype.error=function(i){var e=this.partialObserver;if(e.error)try{e.error(i)}catch(n){K(n)}else K(i)},t.prototype.complete=function(){var i=this.partialObserver;if(i.complete)try{i.complete()}catch(e){K(e)}},t}(),N=function(t){T(i,t);function i(e,n,s){var o=t.call(this)||this,a;if(f(e)||!e)a={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 u;if(o&&c.useDeprecatedNextContext)u=Object.create(e),u.unsubscribe=function(){return o.unsubscribe()},a={next:e.next&&j(e.next,u),error:e.error&&j(e.error,u),complete:e.complete&&j(e.complete,u)};else a=e}return o.destination=new Kt(a),o}return i}(b);var Vt={closed:!0,next:Y,error:Nt,complete:Y};var Rt=function(){return typeof Symbol==="function"&&Symbol.observable||"@@observable"}();function $t(t){return t}function Ot(t){if(t.length===0)return $t;if(t.length===1)return t[0];return function i(e){return t.reduce(function(n,s){return s(n)},e)}}var qt=function(t){var i;return(i=t!==null&&t!==void 0?t:c.Promise)!==null&&i!==void 0?i:Promise},Xt=function(t){return t&&f(t.next)&&f(t.error)&&f(t.complete)},Bt=function(t){return t&&t instanceof b||Xt(t)&&F(t)},_=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,o=Bt(i)?i:new N(i,e,n);return q(function(){var a=s,u=a.operator,l=a.source;o.add(u?u.call(o,l):l?s._subscribe(o):s._trySubscribe(o))}),o},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=qt(e),new e(function(s,o){var a=new N({next:function(u){try{i(u)}catch(l){o(l),a.unsubscribe()}},error:o,complete:s});n.subscribe(a)})},t.prototype._subscribe=function(i){var e;return(e=this.source)===null||e===void 0?void 0:e.subscribe(i)},t.prototype[Rt]=function(){return this},t.prototype.pipe=function(){var i=[];for(var e=0;e<arguments.length;e++)i[e]=arguments[e];return Ot(i)(this)},t.prototype.toPromise=function(i){var e=this;return i=qt(i),new i(function(n,s){var o;e.subscribe(function(a){return o=a},function(a){return s(a)},function(){return n(o)})})},t.create=function(i){return new t(i)},t}();var It=W(function(t){return function i(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}});var tt=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 Gt(this,this);return n.operator=e,n},i.prototype._throwIfClosed=function(){if(this.closed)throw new It},i.prototype.next=function(e){var n=this;q(function(){var s,o;if(n._throwIfClosed(),!n.isStopped){if(!n.currentObservers)n.currentObservers=Array.from(n.observers);try{for(var a=M(n.currentObservers),u=a.next();!u.done;u=a.next()){var l=u.value;l.next(e)}}catch(m){s={error:m}}finally{try{if(u&&!u.done&&(o=a.return))o.call(a)}finally{if(s)throw s.error}}}})},i.prototype.error=function(e){var n=this;q(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;q(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,o=s.hasError,a=s.isStopped,u=s.observers;if(o||a)return Z;return this.currentObservers=null,u.push(e),new $(function(){n.currentObservers=null,S(u,e)})},i.prototype._checkFinalizedStatuses=function(e){var n=this,s=n.hasError,o=n.thrownError,a=n.isStopped;if(s)e.error(o);else if(a)e.complete()},i.prototype.asObservable=function(){var e=new _;return e.source=this,e},i.create=function(e,n){return new Gt(e,n)},i}(_);var Gt=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}(tt);var d=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,o=e._value;if(n)throw s;return this._throwIfClosed(),o},i.prototype.next=function(e){t.prototype.next.call(this,this._value=e)},i}(tt);var Qt;((u)=>{u[u.CRON=0]="CRON";u[u.EVENT=1]="EVENT";u[u.DELETE=2]="DELETE";u[u.GET=3]="GET";u[u.PATCH=4]="PATCH";u[u.POST=5]="POST";u[u.PUT=6]="PUT"})(Qt||={});class it extends h{api;$cache=new d([]);get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new p(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)=>{return this.cache=t,this.emit("LIST",t),t})}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)this.cache=this.cache.filter((s)=>s._id!=t).concat([n]);return this.emit("READ",n),n})}run(t,i={}){return this.api.request({url:("/api/actions/run/"+t).replaceAll("//","/"),...i})}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})}update(t){return this.api.request({url:`/api/actions${t._id?`/${t._id}`:""}`,method:"POST",body:t}).then((i)=>{if(i)this.cache=this.cache.filter((e)=>e._id!=i._id).concat([i]);return this.emit("UPDATE",i),i})}}class Ut{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 et extends h{i;api;storageKey;totp;$user=new d(void 0);get user(){return this.$user.value}set user(t){if(!Q(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 p(t):t,this.totp=new Ut(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((o)=>e.url.includes(o)))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)}`})}login(t,i,e){return this.api.request({url:"/api/auth/login",headers:{Authorization:void 0},body:{username:t.trim(),password:i.trim(),totp:e}}).then(async(n)=>{return this.api.token=n.token,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}});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}})}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});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?.token)this.api.token=n.token})}}class nt extends h{api;constructor(t){super();this.api=typeof t=="string"?new p(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),e})}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),s})}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,i),n})}}class st extends h{api;constructor(t){super();this.api=typeof t=="string"?new p(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})}}class ot extends h{api;constructor(t){super();this.api=typeof t=="string"?new p(t):t}create(t){return this.api.request({url:`/api/groups/${t.name}`,method:"POST",body:t}).then((i)=>{return this.emit("CREATE",i),i})}list(){return this.api.request({url:"/api/groups"}).then((t)=>{return this.emit("LIST",t),t})}read(t){return this.api.request({url:`/api/groups/${t}`}).then((i)=>{return this.emit("READ",i),i})}update(t){return this.api.request({url:`/api/groups/${t.name}`,method:"PATCH",body:t}).then((i)=>{return this.emit("UPDATE",i),i})}delete(t){return this.api.request({url:`/api/groups/${t}`,method:"DELETE"}).then(()=>this.emit("DELETE",t))}}class at{api;constructor(t,i){if(this.api=typeof t=="string"?new p(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}`:""}`})}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}`:""}`})}debug(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(P.DEBUG,t)}).catch(()=>{})}log(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(P.LOG,t)}).catch(()=>{})}info(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(P.INFO,t)}).catch(()=>{})}warn(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(P.WARN,t)}).catch(()=>{})}error(...t){return this.api.request({url:"/api/logs/client",body:this.buildLog(P.ERROR,t)}).catch(()=>{})}}class ut extends h{api;constructor(t){super();this.api=typeof t=="string"?new p(t):t}async handleResponse(t,i){const e=await t.blob();if(i){const n=URL.createObjectURL(e);x(n,i.endsWith(".pdf")?i:i+".pdf"),URL.revokeObjectURL(n)}return this.emit("CREATE",e),e}generate(t,i={}){const e=t?.template;return this.api.request({url:`/api/pdf${e?`/${e}`:""}`,body:e?t?.data:{html:t}}).then((n)=>this.handleResponse(n,i.download?i.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 V{static timeout=1e4;api;url;connection;open=!1;constructor(t){if(this.api=typeof t=="string"?new p(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)},V.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 ht extends h{api;constructor(t){super();this.api=typeof t=="string"?new p(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),e})}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"})}download(t,i={}){return new J((e,n,s)=>{const o=("/api/storage/"+t).replaceAll("//","/");this.api.request({...i,url:o,skipConverting:!0}).then((a)=>{if(!a.ok)return n(a.statusText);const u=a.headers.get("Content-Length"),l=u?parseInt(u,10):0;let m=[],I=0;const G=a.body?.getReader(),A=(g)=>{if(g.done){s(1);const E=new Blob(m),y=i.downloadAs||new URL(a.url).pathname.split("/").pop(),yt=URL.createObjectURL(E);x(yt,y.includes(".")?y:y+".zip"),URL.revokeObjectURL(yt),this.emit("DOWNLOAD",t,E),e(E)}else{const E=g.value;m.push(E),I+=E.length,s(I/l),G.read().then(A)}};G?.read().then(A)})})}async upload(t,i=""){const e=()=>{return new Promise((o)=>{const a=document.createElement("input");a.type="file",a.accept=i?.accept||"*",a.style.display="none",a.multiple=!!i?.multiple,a.onblur=a.onchange=async()=>{o(Array.from(a.files)),a.remove()},document.body.appendChild(a),a.click()})};if(!t)t=await e();if(!t||Array.isArray(t)&&!t.length)return[];const n=new FormData,s=("/api/storage/"+(typeof i=="string"?i:i?.path)).replaceAll("//","/");return(Array.isArray(t)?t:[t]).forEach((o)=>n.append("file",o)),this.api.request({url:s,body:n}).then((o)=>{return this.emit("UPLOAD",o),o})}}class pt extends h{api;listed=!1;$cache=new d([]);get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new p(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.map((e)=>{return e.image=this.api.url+e.image+`?token=${this.api.token}`,e}),this.cache=i,this.listed=!0,this.emit("LIST",i),i})}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.image=this.api.url+e.image+`?token=${this.api.token}`,e)this.cache=[...this.cache.filter((n)=>n.username!=t),e];return this.emit("READ",e),e})}update(t){return this.api.request({url:`/api/users/${t.username}`,method:"PATCH",body:t}).then((i)=>{if(i.image=this.api.url+i.image+`?token=${this.api.token}`,i)this.cache=this.cache.filter((e)=>e.username!=t.username).concat([i]);return this.emit("UPDATE",i),i})}uploadImage(t,i){const e=new FormData;return e.append("file",i),this.api.request({url:`/api/users/${t}/image`,body:e}).then((n)=>{return this.emit("UPLOAD_IMAGE",i),n})}}class lt extends h{api;$cache=new d({});get cache(){return this.$cache.value}set cache(t){this.$cache.next(t)}constructor(t){super();this.api=typeof t=="string"?new p(t):t}list(t=!1){return this.api.request({url:"/api/settings"+(t?"?detailed":"")}).then((i)=>{return this.cache=!t?i:Object.values(i).reduce((e,n)=>({...e,[n.key]:n.value}),{}),this.emit("LIST",i),i})}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)this.cache={...this.cache,[e.key]:e};return this.emit("READ",e),e})}update(t){return this.api.request({url:`/api/settings/${t.key}`,body:t}).then((i)=>{if(i)this.cache={...this.cache,[i.key]:i.value};return this.emit("UPDATE",i),i})}}class rt extends h{api;constructor(t){super();this.api=typeof t=="string"?new p(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),e})}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),n})}}class Jt extends h{api;actions;auth;data;email;groups;logger;pdf;settings;socket;static;storage;users;constructor(t,i){super();if(this.api=new p(t,i?.api),this.actions=new it(this.api),this.auth=new et(this.api,{persist:i?.persist??!0,loginUi:i?.loginUi}),this.data=new nt(this.api),this.email=new st(this.api),this.groups=new ot(this.api),this.logger=new at(this.api,i?.logLevel),this.pdf=new ut(this.api),this.settings=new lt(this.api),this.static=new rt(this.api),this.storage=new ht(this.api),this.users=new pt(this.api),i?.socket)this.socket=new V(this.api);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.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((o)=>o._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{pt as Users,Ut as Totp,ht as Storage,rt as Static,V as Socket,lt as Settings,ut as Pdf,Jt as Momentum,at as Logger,ot as Groups,st as Email,nt as Data,et as Auth,p as Api,it as Actions,Qt as ActionType};
|
package/dist/logger.d.ts
CHANGED
package/dist/logger.js
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Logger = void 0;
|
|
4
|
+
const api_1 = require("./api");
|
|
5
|
+
const utils_1 = require("@ztimson/utils");
|
|
6
|
+
class Logger {
|
|
7
|
+
api;
|
|
8
|
+
constructor(api, logLevel) {
|
|
9
|
+
this.api = typeof api == 'string' ? new api_1.Api(api) : api;
|
|
10
|
+
if (logLevel != null && logLevel != 'NONE') {
|
|
11
|
+
// LOG_LEVEL[logLevel];
|
|
12
|
+
window.addEventListener('error', (event) => this.error(event.error.stack));
|
|
13
|
+
window.addEventListener('unhandledrejection', async (event) => this.error(event.reason.stack));
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
buildLog(level, log) {
|
|
17
|
+
return {
|
|
18
|
+
time: new Date().getTime(),
|
|
19
|
+
level,
|
|
20
|
+
log,
|
|
21
|
+
ctx: {
|
|
22
|
+
cores: navigator.hardwareConcurrency,
|
|
23
|
+
mem: navigator?.deviceMemory,
|
|
24
|
+
res: [window.innerWidth, window.innerHeight],
|
|
25
|
+
url: location.href,
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
clearClientLogs() {
|
|
30
|
+
return this.api.request({ url: `/api/logs/client`, method: 'DELETE' });
|
|
31
|
+
}
|
|
32
|
+
clearServerLogs() {
|
|
33
|
+
return this.api.request({ url: `/api/logs/server`, method: 'DELETE' });
|
|
34
|
+
}
|
|
35
|
+
clientLogs(length, page) {
|
|
36
|
+
const query = [length ? `length=${length}` : undefined, page ? `page=${page}` : undefined,].filter(v => !!v).join('&');
|
|
37
|
+
return this.api.request({ url: `/api/logs/client${query ? `?${query}` : ''}` });
|
|
38
|
+
}
|
|
39
|
+
serverLogs(length, page) {
|
|
40
|
+
const query = [length ? `length=${length}` : undefined, page ? `page=${page}` : undefined,].filter(v => !!v).join('&');
|
|
41
|
+
return this.api.request({ url: `/api/logs/server${query ? `?${query}` : ''}` });
|
|
42
|
+
}
|
|
43
|
+
debug(...logs) {
|
|
44
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.DEBUG, logs) }).catch(() => { });
|
|
45
|
+
}
|
|
46
|
+
log(...logs) {
|
|
47
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.LOG, logs) }).catch(() => { });
|
|
48
|
+
}
|
|
49
|
+
info(...logs) {
|
|
50
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.INFO, logs) }).catch(() => { });
|
|
51
|
+
}
|
|
52
|
+
warn(...logs) {
|
|
53
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.WARN, logs) }).catch(() => { });
|
|
54
|
+
}
|
|
55
|
+
error(...logs) {
|
|
56
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(utils_1.LOG_LEVEL.ERROR, logs) }).catch(() => { });
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
exports.Logger = Logger;
|
package/dist/momentum.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { Actions } from './actions';
|
|
2
|
-
import { Api, ApiEvents } from './api';
|
|
3
|
-
import { Auth, AuthEvents, AuthOptions } from './auth';
|
|
4
|
-
import { Data, DataEvents } from './data';
|
|
5
|
-
import { Email, EmailEvents } from './email';
|
|
2
|
+
import { Api, type ApiEvents } from './api';
|
|
3
|
+
import { Auth, type AuthEvents, AuthOptions } from './auth';
|
|
4
|
+
import { Data, type DataEvents } from './data';
|
|
5
|
+
import { Email, type EmailEvents } from './email';
|
|
6
6
|
import { Groups } from './groups';
|
|
7
|
-
import { TypedEmitter, TypedEvents, XhrOptions } from '@ztimson/utils';
|
|
7
|
+
import { TypedEmitter, type TypedEvents, type XhrOptions } from '@ztimson/utils';
|
|
8
8
|
import { Logger, LogLevel } from './logger';
|
|
9
|
-
import { Pdf, PdfEvents } from './pdf';
|
|
9
|
+
import { Pdf, type PdfEvents } from './pdf';
|
|
10
10
|
import { Socket } from './sockets';
|
|
11
|
-
import { Storage, StorageEvents } from './storage';
|
|
11
|
+
import { Storage, type StorageEvents } from './storage';
|
|
12
12
|
import { Users } from './users';
|
|
13
|
-
import { Settings, SettingEvents } from './settings';
|
|
14
|
-
import { Static, StaticEvents } from './static';
|
|
15
|
-
|
|
13
|
+
import { Settings, type SettingEvents } from './settings';
|
|
14
|
+
import { Static, type StaticEvents } from './static';
|
|
16
15
|
export type MomentumEvents = TypedEvents & ApiEvents & AuthEvents & DataEvents & EmailEvents & PdfEvents & StaticEvents & StorageEvents & SettingEvents;
|
|
17
16
|
export type MomentumOptions = AuthOptions & {
|
|
18
17
|
logLevel?: LogLevel;
|
package/dist/momentum.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Momentum = void 0;
|
|
4
|
+
const actions_1 = require("./actions");
|
|
5
|
+
const api_1 = require("./api");
|
|
6
|
+
const auth_1 = require("./auth");
|
|
7
|
+
const data_1 = require("./data");
|
|
8
|
+
const email_1 = require("./email");
|
|
9
|
+
const groups_1 = require("./groups");
|
|
10
|
+
const utils_1 = require("@ztimson/utils");
|
|
11
|
+
const logger_1 = require("./logger");
|
|
12
|
+
const pdf_1 = require("./pdf");
|
|
13
|
+
const sockets_1 = require("./sockets");
|
|
14
|
+
const storage_1 = require("./storage");
|
|
15
|
+
const users_1 = require("./users");
|
|
16
|
+
const settings_1 = require("./settings");
|
|
17
|
+
const static_1 = require("./static");
|
|
18
|
+
class Momentum extends utils_1.TypedEmitter {
|
|
19
|
+
api;
|
|
20
|
+
actions;
|
|
21
|
+
auth;
|
|
22
|
+
data;
|
|
23
|
+
email;
|
|
24
|
+
groups;
|
|
25
|
+
logger;
|
|
26
|
+
pdf;
|
|
27
|
+
settings;
|
|
28
|
+
socket;
|
|
29
|
+
static;
|
|
30
|
+
storage;
|
|
31
|
+
users;
|
|
32
|
+
constructor(url, opts) {
|
|
33
|
+
super();
|
|
34
|
+
this.api = new api_1.Api(url, opts?.api);
|
|
35
|
+
this.actions = new actions_1.Actions(this.api);
|
|
36
|
+
this.auth = new auth_1.Auth(this.api, {
|
|
37
|
+
persist: opts?.persist ?? true,
|
|
38
|
+
loginUi: opts?.loginUi
|
|
39
|
+
});
|
|
40
|
+
this.data = new data_1.Data(this.api);
|
|
41
|
+
this.email = new email_1.Email(this.api);
|
|
42
|
+
this.groups = new groups_1.Groups(this.api);
|
|
43
|
+
this.logger = new logger_1.Logger(this.api, opts?.logLevel);
|
|
44
|
+
this.pdf = new pdf_1.Pdf(this.api);
|
|
45
|
+
this.settings = new settings_1.Settings(this.api);
|
|
46
|
+
this.static = new static_1.Static(this.api);
|
|
47
|
+
this.storage = new storage_1.Storage(this.api);
|
|
48
|
+
this.users = new users_1.Users(this.api);
|
|
49
|
+
if (opts?.socket)
|
|
50
|
+
this.socket = new sockets_1.Socket(this.api);
|
|
51
|
+
this.api.on('*', (event, ...args) => this.emit(`API::${event}`, ...args));
|
|
52
|
+
this.actions.on('*', (event, ...args) => this.emit(`ACTIONS::${event}`, ...args));
|
|
53
|
+
this.auth.on('*', (event, ...args) => this.emit(`AUTH::${event}`, ...args));
|
|
54
|
+
this.data.on('*', (event, ...args) => this.emit(`DATA::${event}`, ...args));
|
|
55
|
+
this.email.on('*', (event, ...args) => this.emit(`EMAIL::${event}`, ...args));
|
|
56
|
+
this.groups.on('*', (event, ...args) => this.emit(`GROUPS::${event}`, ...args));
|
|
57
|
+
this.pdf.on('*', (event, ...args) => this.emit(`PDF::${event}`, ...args));
|
|
58
|
+
this.settings.on('*', (event, ...args) => this.emit(`SETTINGS::${event}`, ...args));
|
|
59
|
+
this.static.on('*', (event, ...args) => this.emit(`STATIC::${event}`, ...args));
|
|
60
|
+
this.storage.on('*', (event, ...args) => this.emit(`STORAGE::${event}`, ...args));
|
|
61
|
+
this.users.on('*', (event, ...args) => this.emit(`USERS::${event}`, ...args));
|
|
62
|
+
this.users.on('*', (event, ...args) => {
|
|
63
|
+
if (Array.isArray(args[0])) {
|
|
64
|
+
const u = args[0].find(u => u._id == this.auth.user?._id);
|
|
65
|
+
if (u)
|
|
66
|
+
this.auth.user = u;
|
|
67
|
+
}
|
|
68
|
+
else if (args[0]._id == this.auth.user?._id) {
|
|
69
|
+
this.auth.user = args[0];
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.Momentum = Momentum;
|
package/dist/pdf.d.ts
CHANGED
package/dist/pdf.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Pdf = void 0;
|
|
4
|
+
const api_1 = require("./api");
|
|
5
|
+
const utils_1 = require("@ztimson/utils");
|
|
6
|
+
class Pdf extends utils_1.TypedEmitter {
|
|
7
|
+
api;
|
|
8
|
+
constructor(api) {
|
|
9
|
+
super();
|
|
10
|
+
this.api = typeof api == 'string' ? new api_1.Api(api) : api;
|
|
11
|
+
}
|
|
12
|
+
async handleResponse(resp, fileName) {
|
|
13
|
+
const blob = await resp.blob();
|
|
14
|
+
if (fileName) {
|
|
15
|
+
const url = URL.createObjectURL(blob);
|
|
16
|
+
(0, utils_1.download)(url, fileName.endsWith('.pdf') ? fileName : fileName + '.pdf');
|
|
17
|
+
URL.revokeObjectURL(url);
|
|
18
|
+
}
|
|
19
|
+
this.emit('CREATE', blob);
|
|
20
|
+
return blob;
|
|
21
|
+
}
|
|
22
|
+
generate(content, opts = {}) {
|
|
23
|
+
const template = content?.template;
|
|
24
|
+
return this.api.request({
|
|
25
|
+
url: `/api/pdf${template ? `/${template}` : ''}`,
|
|
26
|
+
body: template ? content?.data : { html: content }
|
|
27
|
+
}).then((resp) => this.handleResponse(resp, opts.download ? (opts.fileName || new Date().toISOString()) : undefined));
|
|
28
|
+
}
|
|
29
|
+
fromUrl(url, opts = {}) {
|
|
30
|
+
return this.api.request({ url: `/api/pdf?url=${url}` }).then((resp) => this.handleResponse(resp, opts.download ? (opts.fileName || new Date().toISOString()) : undefined));
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.Pdf = Pdf;
|
package/dist/settings.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Api } from './api';
|
|
2
|
-
import { TypedEmitter, TypedEvents } from '@ztimson/utils';
|
|
2
|
+
import { TypedEmitter, type TypedEvents } from '@ztimson/utils';
|
|
3
3
|
import { BehaviorSubject } from 'rxjs';
|
|
4
|
-
|
|
5
4
|
/** Momentum variable */
|
|
6
5
|
export type Setting<T> = {
|
|
7
6
|
/** Internal ID */
|
package/dist/settings.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Settings = void 0;
|
|
4
|
+
const api_1 = require("./api");
|
|
5
|
+
const utils_1 = require("@ztimson/utils");
|
|
6
|
+
const rxjs_1 = require("rxjs");
|
|
7
|
+
class Settings extends utils_1.TypedEmitter {
|
|
8
|
+
api;
|
|
9
|
+
$cache = new rxjs_1.BehaviorSubject({});
|
|
10
|
+
get cache() { return this.$cache.value; }
|
|
11
|
+
set cache(val) { this.$cache.next(val); }
|
|
12
|
+
constructor(api) {
|
|
13
|
+
super();
|
|
14
|
+
this.api = typeof api == 'string' ? new api_1.Api(api) : api;
|
|
15
|
+
}
|
|
16
|
+
list(detailed = false) {
|
|
17
|
+
return this.api.request({ url: `/api/settings` + (detailed ? '?detailed' : '') }).then(resp => {
|
|
18
|
+
this.cache = !detailed ? resp : Object.values(resp).reduce((acc, v) => ({ ...acc, [v.key]: v.value }), {});
|
|
19
|
+
this.emit('LIST', resp);
|
|
20
|
+
return resp;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
delete(key) {
|
|
24
|
+
return this.api.request({ url: `/api/settings/${key}`, method: 'DELETE' }).then(() => {
|
|
25
|
+
this.cache = { ...this.cache, [key]: undefined };
|
|
26
|
+
this.emit('DELETE', key);
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
read(key, reload = false) {
|
|
30
|
+
if (!reload && this.cache[key])
|
|
31
|
+
return Promise.resolve(this.cache[key]);
|
|
32
|
+
return this.api.request({ url: `/api/settings/${key}` }).then(variable => {
|
|
33
|
+
if (variable)
|
|
34
|
+
this.cache = { ...this.cache, [variable.key]: variable };
|
|
35
|
+
this.emit('READ', variable);
|
|
36
|
+
return variable;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
update(variable) {
|
|
40
|
+
return this.api.request({ url: `/api/settings/${variable.key}`, body: variable }).then(variable => {
|
|
41
|
+
if (variable)
|
|
42
|
+
this.cache = { ...this.cache, [variable.key]: variable.value };
|
|
43
|
+
this.emit('UPDATE', variable);
|
|
44
|
+
return variable;
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.Settings = Settings;
|
package/dist/sockets.d.ts
CHANGED
package/dist/sockets.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Socket = void 0;
|
|
4
|
+
const api_1 = require("./api");
|
|
5
|
+
class Socket {
|
|
6
|
+
static timeout = 10000;
|
|
7
|
+
api;
|
|
8
|
+
url;
|
|
9
|
+
connection;
|
|
10
|
+
open = false;
|
|
11
|
+
constructor(api) {
|
|
12
|
+
this.api = typeof api == 'string' ? new api_1.Api(api) : api;
|
|
13
|
+
this.url = this.api.url.replace('http', 'ws');
|
|
14
|
+
this.api.on('TOKEN', () => this.connect());
|
|
15
|
+
if (!this.api.token)
|
|
16
|
+
this.connect();
|
|
17
|
+
}
|
|
18
|
+
close() {
|
|
19
|
+
console.debug('Disconnected from Momentum');
|
|
20
|
+
this.open = false;
|
|
21
|
+
this.connection.close();
|
|
22
|
+
}
|
|
23
|
+
connect(retry = 3) {
|
|
24
|
+
if (this.connection?.readyState < 2)
|
|
25
|
+
this.connection.close();
|
|
26
|
+
this.connection = new WebSocket(this.url + (this.api.token ? `?token=${this.api.token}` : ''));
|
|
27
|
+
const timeout = setTimeout(() => {
|
|
28
|
+
if (this.open)
|
|
29
|
+
return;
|
|
30
|
+
this.connection.close();
|
|
31
|
+
console.error(`Momentum connection timeout`);
|
|
32
|
+
if (retry > 0)
|
|
33
|
+
this.connect(retry - 1);
|
|
34
|
+
}, Socket.timeout);
|
|
35
|
+
this.connection.onclose = () => this.open = false;
|
|
36
|
+
this.connection.onmessage = this.handle;
|
|
37
|
+
this.connection.onopen = () => {
|
|
38
|
+
this.open = true;
|
|
39
|
+
clearTimeout(timeout);
|
|
40
|
+
console.debug('Connected to Momentum');
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
handle(...args) {
|
|
44
|
+
console.log(args);
|
|
45
|
+
}
|
|
46
|
+
send(channel, payload) {
|
|
47
|
+
this.connection.send(JSON.stringify({
|
|
48
|
+
token: this.api.token,
|
|
49
|
+
channel,
|
|
50
|
+
payload
|
|
51
|
+
}));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
exports.Socket = Socket;
|
package/dist/static.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Api } from './api';
|
|
2
|
-
import { TypedEmitter, TypedEvents } from '@ztimson/utils';
|
|
3
|
-
import { FileMeta } from './storage';
|
|
4
|
-
|
|
2
|
+
import { TypedEmitter, type TypedEvents } from '@ztimson/utils';
|
|
3
|
+
import { type FileMeta } from './storage';
|
|
5
4
|
export type StaticEvents = TypedEvents & {
|
|
6
5
|
LIST: (path: string, response: string[] | FileMeta) => any;
|
|
7
6
|
DELETE: (path: string) => any;
|
package/dist/static.js
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Static = void 0;
|
|
4
|
+
const api_1 = require("./api");
|
|
5
|
+
const utils_1 = require("@ztimson/utils");
|
|
6
|
+
class Static extends utils_1.TypedEmitter {
|
|
7
|
+
api;
|
|
8
|
+
constructor(api) {
|
|
9
|
+
super();
|
|
10
|
+
this.api = typeof api == 'string' ? new api_1.Api(api) : api;
|
|
11
|
+
}
|
|
12
|
+
delete(path) {
|
|
13
|
+
return this.api.request({ url: `/api/static/${path}`, method: 'DELETE' }).then(() => {
|
|
14
|
+
this.emit('DELETE', path);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
list(path) {
|
|
18
|
+
const url = ('/api/static/' + path).replaceAll('//', '/');
|
|
19
|
+
return this.api.request({ url }).then(resp => {
|
|
20
|
+
this.emit('LIST', path, resp);
|
|
21
|
+
return resp;
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
upload(files, path = '/') {
|
|
25
|
+
const data = new FormData();
|
|
26
|
+
(Array.isArray(files) ? files : [files]).forEach(f => data.append('file', f));
|
|
27
|
+
return this.api.request({ url: '/api/static' + path, body: data }).then(resp => {
|
|
28
|
+
this.emit('UPLOAD', resp);
|
|
29
|
+
return resp;
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.Static = Static;
|
package/dist/storage.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Api } from './api';
|
|
2
|
-
import { Meta } from './core';
|
|
3
|
-
import { PromiseProgress, RequestOptions, TypedEmitter, TypedEvents } from '@ztimson/utils';
|
|
4
|
-
|
|
2
|
+
import { type Meta } from './core';
|
|
3
|
+
import { PromiseProgress, type RequestOptions, TypedEmitter, type TypedEvents } from '@ztimson/utils';
|
|
5
4
|
export type DirMeta = {
|
|
6
5
|
children: (DirMeta | FileMeta)[];
|
|
7
6
|
path: string;
|
package/dist/storage.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Storage = void 0;
|
|
4
|
+
const api_1 = require("./api");
|
|
5
|
+
const utils_1 = require("@ztimson/utils");
|
|
6
|
+
class Storage extends utils_1.TypedEmitter {
|
|
7
|
+
api;
|
|
8
|
+
constructor(api) {
|
|
9
|
+
super();
|
|
10
|
+
this.api = typeof api == 'string' ? new api_1.Api(api) : api;
|
|
11
|
+
}
|
|
12
|
+
delete(path) {
|
|
13
|
+
const url = (path.startsWith('/api/storage/') ? path : '/api/storage/' + path).replaceAll('//', '/');
|
|
14
|
+
return this.api.request({ url, method: 'DELETE' }).then(() => {
|
|
15
|
+
this.emit('DELETE', url);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
list(path) {
|
|
19
|
+
const url = (path.startsWith('/api/storage/') ? path : '/api/storage/' + path).replaceAll('//', '/');
|
|
20
|
+
return this.api.request({ url: url + '?list' }).then(resp => {
|
|
21
|
+
this.emit('LIST', path, resp);
|
|
22
|
+
return resp;
|
|
23
|
+
});
|
|
24
|
+
}
|
|
25
|
+
open(path, target = '_blank') {
|
|
26
|
+
const p = (path.startsWith('/api/storage/') ? path : '/api/storage/' + path).replaceAll(/\/{2,}/g, '/');
|
|
27
|
+
const link = `${this.api.url}${p}${this.api.token ? `?token=${this.api.token}` : ''}`;
|
|
28
|
+
if (!target)
|
|
29
|
+
return link;
|
|
30
|
+
this.emit('OPEN', path);
|
|
31
|
+
return window.open(link, target);
|
|
32
|
+
}
|
|
33
|
+
mkdir(path) {
|
|
34
|
+
const p = (path.startsWith('/api/storage/') ? path : '/api/storage/' + path).replaceAll(/\/{2,}/g, '/');
|
|
35
|
+
return this.api.request({ url: p + '?directory', method: 'POST' });
|
|
36
|
+
}
|
|
37
|
+
download(path, opts = {}) {
|
|
38
|
+
return new utils_1.PromiseProgress((res, rej, progress) => {
|
|
39
|
+
const p = ('/api/storage/' + path).replaceAll('//', '/');
|
|
40
|
+
this.api.request({ ...opts, url: p, skipConverting: true }).then((response) => {
|
|
41
|
+
if (!response.ok)
|
|
42
|
+
return rej(response.statusText);
|
|
43
|
+
const contentLength = response.headers.get('Content-Length');
|
|
44
|
+
const total = contentLength ? parseInt(contentLength, 10) : 0;
|
|
45
|
+
let chunks = [], loaded = 0;
|
|
46
|
+
const reader = response.body?.getReader();
|
|
47
|
+
const process = (result) => {
|
|
48
|
+
if (result.done) {
|
|
49
|
+
progress(1);
|
|
50
|
+
const blob = new Blob(chunks);
|
|
51
|
+
const name = opts.downloadAs || new URL(response.url).pathname.split('/').pop();
|
|
52
|
+
const url = URL.createObjectURL(blob);
|
|
53
|
+
(0, utils_1.download)(url, name.includes('.') ? name : name + '.zip');
|
|
54
|
+
URL.revokeObjectURL(url);
|
|
55
|
+
this.emit('DOWNLOAD', path, blob);
|
|
56
|
+
res(blob);
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
const chunk = result.value;
|
|
60
|
+
chunks.push(chunk);
|
|
61
|
+
loaded += chunk.length;
|
|
62
|
+
progress(loaded / total);
|
|
63
|
+
reader.read().then(process);
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
reader?.read().then(process);
|
|
67
|
+
});
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async upload(files, opts = '') {
|
|
71
|
+
const fileBrowser = () => {
|
|
72
|
+
return new Promise(res => {
|
|
73
|
+
const input = document.createElement('input');
|
|
74
|
+
input.type = 'file';
|
|
75
|
+
input.accept = opts?.accept || '*';
|
|
76
|
+
input.style.display = 'none';
|
|
77
|
+
input.multiple = !!opts?.multiple;
|
|
78
|
+
input.onblur = input.onchange = async () => {
|
|
79
|
+
res(Array.from(input.files));
|
|
80
|
+
input.remove();
|
|
81
|
+
};
|
|
82
|
+
document.body.appendChild(input);
|
|
83
|
+
input.click();
|
|
84
|
+
});
|
|
85
|
+
};
|
|
86
|
+
if (!files)
|
|
87
|
+
files = await fileBrowser();
|
|
88
|
+
if (!files || Array.isArray(files) && !files.length)
|
|
89
|
+
return [];
|
|
90
|
+
const data = new FormData();
|
|
91
|
+
const p = ('/api/storage/' + (typeof opts == 'string' ? opts : opts?.path)).replaceAll('//', '/');
|
|
92
|
+
(Array.isArray(files) ? files : [files]).forEach(f => data.append('file', f));
|
|
93
|
+
return this.api.request({ url: p, body: data }).then(resp => {
|
|
94
|
+
this.emit('UPLOAD', resp);
|
|
95
|
+
return resp;
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
exports.Storage = Storage;
|
package/dist/users.d.ts
CHANGED
|
@@ -1,25 +1,26 @@
|
|
|
1
1
|
import { Api } from './api';
|
|
2
|
-
import { TypedEmitter, TypedEvents } from '@ztimson/utils';
|
|
2
|
+
import { TypedEmitter, type TypedEvents } from '@ztimson/utils';
|
|
3
3
|
import { BehaviorSubject } from 'rxjs';
|
|
4
|
-
import { Meta } from './core';
|
|
5
|
-
|
|
4
|
+
import type { Meta } from './core';
|
|
6
5
|
export type User = Meta & {
|
|
7
6
|
username: string;
|
|
8
7
|
name: string;
|
|
9
8
|
email: string;
|
|
10
|
-
image
|
|
9
|
+
image: string;
|
|
11
10
|
disabled?: boolean;
|
|
12
|
-
groups
|
|
13
|
-
permissions
|
|
14
|
-
notes
|
|
15
|
-
|
|
11
|
+
groups: string[];
|
|
12
|
+
permissions: string[];
|
|
13
|
+
notes: string;
|
|
14
|
+
custom?: any;
|
|
16
15
|
lastLogin?: number | null;
|
|
16
|
+
totp?: false | 'app' | 'email' | 'phone';
|
|
17
17
|
};
|
|
18
18
|
export type UserEvents = TypedEvents & {
|
|
19
19
|
LIST: (users: User[]) => any;
|
|
20
20
|
READ: (user: User) => any;
|
|
21
21
|
UPDATE: (user: User) => any;
|
|
22
22
|
DELETE: (username: string) => any;
|
|
23
|
+
UPLOAD_IMAGE: (file: File) => any;
|
|
23
24
|
};
|
|
24
25
|
export declare class Users extends TypedEmitter<UserEvents> {
|
|
25
26
|
private readonly api;
|
|
@@ -32,5 +33,6 @@ export declare class Users extends TypedEmitter<UserEvents> {
|
|
|
32
33
|
list(reload?: boolean): Promise<User[]>;
|
|
33
34
|
read(username: string, reload?: boolean): Promise<User>;
|
|
34
35
|
update(user: User): Promise<User>;
|
|
36
|
+
uploadImage(username: string, file: File): Promise<unknown>;
|
|
35
37
|
}
|
|
36
38
|
//# sourceMappingURL=users.d.ts.map
|