@ztimson/momentum 0.20.0 → 0.21.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/momentum.mjs CHANGED
@@ -1,6 +1,6 @@
1
- var ut = Object.defineProperty;
2
- var at = (i, e, t) => e in i ? ut(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
- var a = (i, e, t) => at(i, typeof e != "symbol" ? e + "" : e, t);
1
+ var at = Object.defineProperty;
2
+ var ut = (i, e, t) => e in i ? at(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var u = (i, e, t) => ut(i, typeof e != "symbol" ? e + "" : e, t);
4
4
  var ct = Object.defineProperty, ht = (i, e, t) => e in i ? ct(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, h = (i, e, t) => (ht(i, typeof e != "symbol" ? e + "" : e, t), t);
5
5
  function lt(i, e = !1) {
6
6
  if (i == null)
@@ -138,7 +138,7 @@ const O = {
138
138
  BLINK: "\x1B[5m",
139
139
  REVERSE: "\x1B[7m",
140
140
  HIDDEN: "\x1B[8m"
141
- }, _ = {
141
+ }, A = {
142
142
  BLACK: "\x1B[30m",
143
143
  RED: "\x1B[31m",
144
144
  GREEN: "\x1B[32m",
@@ -157,7 +157,7 @@ const O = {
157
157
  WHITE: "\x1B[97m"
158
158
  };
159
159
  var S = /* @__PURE__ */ ((i) => (i[i.ERROR = 0] = "ERROR", i[i.WARN = 1] = "WARN", i[i.INFO = 2] = "INFO", i[i.LOG = 3] = "LOG", i[i.DEBUG = 4] = "DEBUG", i))(S || {});
160
- const gt = class m extends d {
160
+ const Et = class m extends d {
161
161
  constructor(e) {
162
162
  super(), this.namespace = e;
163
163
  }
@@ -165,8 +165,8 @@ const gt = class m extends d {
165
165
  const n = e.toString(), o = t - n.length;
166
166
  if (o <= 0)
167
167
  return n;
168
- const u = Array(~~(o / r.length)).fill(r).join("");
169
- return s ? n + u : u + n;
168
+ const a = Array(~~(o / r.length)).fill(r).join("");
169
+ return s ? n + a : a + n;
170
170
  }
171
171
  format(...e) {
172
172
  const t = /* @__PURE__ */ new Date();
@@ -176,7 +176,7 @@ const gt = class m extends d {
176
176
  if (m.LOG_LEVEL < 4)
177
177
  return;
178
178
  const t = this.format(...e);
179
- m.emit(4, t), console.debug(_.LIGHT_GREY + t + O.CLEAR);
179
+ m.emit(4, t), console.debug(A.LIGHT_GREY + t + O.CLEAR);
180
180
  }
181
181
  log(...e) {
182
182
  if (m.LOG_LEVEL < 3)
@@ -188,23 +188,23 @@ const gt = class m extends d {
188
188
  if (m.LOG_LEVEL < 2)
189
189
  return;
190
190
  const t = this.format(...e);
191
- m.emit(2, t), console.info(_.BLUE + t + O.CLEAR);
191
+ m.emit(2, t), console.info(A.BLUE + t + O.CLEAR);
192
192
  }
193
193
  warn(...e) {
194
194
  if (m.LOG_LEVEL < 1)
195
195
  return;
196
196
  const t = this.format(...e);
197
- m.emit(1, t), console.warn(_.YELLOW + t + O.CLEAR);
197
+ m.emit(1, t), console.warn(A.YELLOW + t + O.CLEAR);
198
198
  }
199
199
  error(...e) {
200
200
  if (m.LOG_LEVEL < 0)
201
201
  return;
202
202
  const t = this.format(...e);
203
- m.emit(0, t), console.error(_.RED + t + O.CLEAR);
203
+ m.emit(0, t), console.error(A.RED + t + O.CLEAR);
204
204
  }
205
205
  };
206
- h(gt, "LOG_LEVEL", 4);
207
- class Et extends Promise {
206
+ h(Et, "LOG_LEVEL", 4);
207
+ class gt extends Promise {
208
208
  constructor(e) {
209
209
  super((t, r) => e(
210
210
  (s) => t(s),
@@ -243,9 +243,9 @@ const j = class v {
243
243
  if (!this.opts.url && !e.url)
244
244
  throw new Error("URL needs to be set");
245
245
  let s = ((t = e.url) != null && t.startsWith("http") ? e.url : (this.opts.url || "") + (e.url || "")).replace(/([^:]\/)\/+/g, "$1");
246
- if (e.fragment && (s.includes("#") ? s.replace(/#.*(\?|\n)/g, (o, u) => `#${e.fragment}${u}`) : s += "#" + e.fragment), e.query) {
247
- const o = Array.isArray(e.query) ? e.query : Object.keys(e.query).map((u) => ({ key: u, value: e.query[u] }));
248
- s += (s.includes("?") ? "&" : "?") + o.map((u) => `${u.key}=${u.value}`).join("&");
246
+ if (e.fragment && (s.includes("#") ? s.replace(/#.*(\?|\n)/g, (o, a) => `#${e.fragment}${a}`) : s += "#" + e.fragment), e.query) {
247
+ const o = Array.isArray(e.query) ? e.query : Object.keys(e.query).map((a) => ({ key: a, value: e.query[a] }));
248
+ s += (s.includes("?") ? "&" : "?") + o.map((a) => `${a.key}=${a.value}`).join("&");
249
249
  }
250
250
  const n = lt({
251
251
  "Content-Type": e.body && !(e.body instanceof FormData) ? "application/json" : void 0,
@@ -259,15 +259,15 @@ const j = class v {
259
259
  body: (r = n["Content-Type"]) != null && r.startsWith("application/json") && e.body ? JSON.stringify(e.body) : e.body
260
260
  }).then(async (o) => {
261
261
  for (let l of [...Object.values(v.interceptors), ...Object.values(this.interceptors)])
262
- await new Promise((g) => l(o, () => g()));
263
- const u = await (async () => {
264
- var l, g;
265
- return !e.skipConverting && (l = o.headers.get("Content-Type")) != null && l.startsWith("application/json") ? await o.json() : !e.skipConverting && (g = o.headers.get("Content-Type")) != null && g.startsWith("text/plain") ? await o.text() : o;
262
+ await new Promise((E) => l(o, () => E()));
263
+ const a = await (async () => {
264
+ var l, E;
265
+ return !e.skipConverting && (l = o.headers.get("Content-Type")) != null && l.startsWith("application/json") ? await o.json() : !e.skipConverting && (E = o.headers.get("Content-Type")) != null && E.startsWith("text/plain") ? await o.text() : o;
266
266
  })();
267
267
  if (o.ok)
268
- return u;
269
- const c = o.statusText || (typeof u == "string" ? u : null);
270
- throw c ? new Error(c) : u;
268
+ return a;
269
+ const c = o.statusText || (typeof a == "string" ? a : null);
270
+ throw c ? new Error(c) : a;
271
271
  });
272
272
  }
273
273
  };
@@ -277,19 +277,19 @@ class f extends bt {
277
277
  constructor(t = location.origin, r = {}) {
278
278
  r.url = t;
279
279
  super(r);
280
- a(this, "emitter", new d());
281
- a(this, "_token", null);
282
- a(this, "emit", this.emitter.emit.bind(this.emitter));
283
- a(this, "off", this.emitter.off.bind(this.emitter));
284
- a(this, "on", this.emitter.on.bind(this.emitter));
285
- a(this, "once", this.emitter.once.bind(this.emitter));
280
+ u(this, "emitter", new d());
281
+ u(this, "_token", null);
282
+ u(this, "emit", this.emitter.emit.bind(this.emitter));
283
+ u(this, "off", this.emitter.off.bind(this.emitter));
284
+ u(this, "on", this.emitter.on.bind(this.emitter));
285
+ u(this, "once", this.emitter.once.bind(this.emitter));
286
286
  this.url = t, this.opts = r;
287
287
  }
288
288
  get token() {
289
289
  return this._token;
290
290
  }
291
291
  set token(t) {
292
- t != this._token && (this._token = t, this.headers.Authorization = `Bearer ${t}`, this.emit("TOKEN", t));
292
+ t != this._token && (this._token = t, this.headers.Authorization = t ? `Bearer ${t}` : void 0, this.emit("TOKEN", t));
293
293
  }
294
294
  request(t) {
295
295
  const r = super.request(t).then((s) => (this.emit("RESPONSE", s, t), s)).catch((s) => {
@@ -330,8 +330,8 @@ function G(i, e) {
330
330
  var r = t.call(i), s, n = [], o;
331
331
  try {
332
332
  for (; (e === void 0 || e-- > 0) && !(s = r.next()).done; ) n.push(s.value);
333
- } catch (u) {
334
- o = { error: u };
333
+ } catch (a) {
334
+ o = { error: a };
335
335
  } finally {
336
336
  try {
337
337
  s && !s.done && (t = r.return) && t.call(r);
@@ -346,7 +346,7 @@ function N(i, e, t) {
346
346
  (n || !(r in e)) && (n || (n = Array.prototype.slice.call(e, 0, r)), n[r] = e[r]);
347
347
  return i.concat(n || Array.prototype.slice.call(e));
348
348
  }
349
- function E(i) {
349
+ function g(i) {
350
350
  return typeof i == "function";
351
351
  }
352
352
  function tt(i) {
@@ -355,7 +355,7 @@ function tt(i) {
355
355
  }, t = i(e);
356
356
  return t.prototype = Object.create(Error.prototype), t.prototype.constructor = t, t;
357
357
  }
358
- var I = tt(function(i) {
358
+ var U = tt(function(i) {
359
359
  return function(t) {
360
360
  i(this), this.message = t ? t.length + ` errors occurred during unsubscription:
361
361
  ` + t.map(function(r, s) {
@@ -382,7 +382,7 @@ var P = function() {
382
382
  if (o)
383
383
  if (this._parentage = null, Array.isArray(o))
384
384
  try {
385
- for (var u = B(o), c = u.next(); !c.done; c = u.next()) {
385
+ for (var a = B(o), c = a.next(); !c.done; c = a.next()) {
386
386
  var l = c.value;
387
387
  l.remove(this);
388
388
  }
@@ -390,30 +390,30 @@ var P = function() {
390
390
  e = { error: p };
391
391
  } finally {
392
392
  try {
393
- c && !c.done && (t = u.return) && t.call(u);
393
+ c && !c.done && (t = a.return) && t.call(a);
394
394
  } finally {
395
395
  if (e) throw e.error;
396
396
  }
397
397
  }
398
398
  else
399
399
  o.remove(this);
400
- var g = this.initialTeardown;
401
- if (E(g))
400
+ var E = this.initialTeardown;
401
+ if (g(E))
402
402
  try {
403
- g();
403
+ E();
404
404
  } catch (p) {
405
- n = p instanceof I ? p.errors : [p];
405
+ n = p instanceof U ? p.errors : [p];
406
406
  }
407
407
  var T = this._finalizers;
408
408
  if (T) {
409
409
  this._finalizers = null;
410
410
  try {
411
411
  for (var b = B(T), y = b.next(); !y.done; y = b.next()) {
412
- var A = y.value;
412
+ var _ = y.value;
413
413
  try {
414
- V(A);
414
+ V(_);
415
415
  } catch (p) {
416
- n = n ?? [], p instanceof I ? n = N(N([], G(n)), G(p.errors)) : n.push(p);
416
+ n = n ?? [], p instanceof U ? n = N(N([], G(n)), G(p.errors)) : n.push(p);
417
417
  }
418
418
  }
419
419
  } catch (p) {
@@ -427,7 +427,7 @@ var P = function() {
427
427
  }
428
428
  }
429
429
  if (n)
430
- throw new I(n);
430
+ throw new U(n);
431
431
  }
432
432
  }, i.prototype.add = function(e) {
433
433
  var t;
@@ -460,10 +460,10 @@ var P = function() {
460
460
  }(), i;
461
461
  }(), et = P.EMPTY;
462
462
  function rt(i) {
463
- return i instanceof P || i && "closed" in i && E(i.remove) && E(i.add) && E(i.unsubscribe);
463
+ return i instanceof P || i && "closed" in i && g(i.remove) && g(i.add) && g(i.unsubscribe);
464
464
  }
465
465
  function V(i) {
466
- E(i) ? i() : i.unsubscribe();
466
+ g(i) ? i() : i.unsubscribe();
467
467
  }
468
468
  var it = {
469
469
  onUnhandledError: null,
@@ -563,20 +563,20 @@ var St = function() {
563
563
  $(e, i);
564
564
  function e(t, r, s) {
565
565
  var n = i.call(this) || this, o;
566
- if (E(t) || !t)
566
+ if (g(t) || !t)
567
567
  o = {
568
568
  next: t ?? void 0,
569
569
  error: r ?? void 0,
570
570
  complete: s ?? void 0
571
571
  };
572
572
  else {
573
- var u;
574
- n && it.useDeprecatedNextContext ? (u = Object.create(t), u.unsubscribe = function() {
573
+ var a;
574
+ n && it.useDeprecatedNextContext ? (a = Object.create(t), a.unsubscribe = function() {
575
575
  return n.unsubscribe();
576
576
  }, o = {
577
- next: t.next && C(t.next, u),
578
- error: t.error && C(t.error, u),
579
- complete: t.complete && C(t.complete, u)
577
+ next: t.next && C(t.next, a),
578
+ error: t.error && C(t.error, a),
579
+ complete: t.complete && C(t.complete, a)
580
580
  }) : o = t;
581
581
  }
582
582
  return n.destination = new St(o), n;
@@ -600,7 +600,7 @@ var Tt = {
600
600
  function $t(i) {
601
601
  return i;
602
602
  }
603
- function At(i) {
603
+ function _t(i) {
604
604
  return i.length === 0 ? $t : i.length === 1 ? i[0] : function(t) {
605
605
  return i.reduce(function(r, s) {
606
606
  return s(r);
@@ -617,8 +617,8 @@ var z = function() {
617
617
  }, i.prototype.subscribe = function(e, t, r) {
618
618
  var s = this, n = Rt(e) ? e : new W(e, t, r);
619
619
  return x(function() {
620
- var o = s, u = o.operator, c = o.source;
621
- n.add(u ? u.call(n, c) : c ? s._subscribe(n) : s._trySubscribe(n));
620
+ var o = s, a = o.operator, c = o.source;
621
+ n.add(a ? a.call(n, c) : c ? s._subscribe(n) : s._trySubscribe(n));
622
622
  }), n;
623
623
  }, i.prototype._trySubscribe = function(e) {
624
624
  try {
@@ -630,9 +630,9 @@ var z = function() {
630
630
  var r = this;
631
631
  return t = J(t), new t(function(s, n) {
632
632
  var o = new W({
633
- next: function(u) {
633
+ next: function(a) {
634
634
  try {
635
- e(u);
635
+ e(a);
636
636
  } catch (c) {
637
637
  n(c), o.unsubscribe();
638
638
  }
@@ -650,7 +650,7 @@ var z = function() {
650
650
  }, i.prototype.pipe = function() {
651
651
  for (var e = [], t = 0; t < arguments.length; t++)
652
652
  e[t] = arguments[t];
653
- return At(e)(this);
653
+ return _t(e)(this);
654
654
  }, i.prototype.toPromise = function(e) {
655
655
  var t = this;
656
656
  return e = J(e), new e(function(r, s) {
@@ -671,11 +671,11 @@ function J(i) {
671
671
  var e;
672
672
  return (e = i ?? it.Promise) !== null && e !== void 0 ? e : Promise;
673
673
  }
674
- function _t(i) {
675
- return i && E(i.next) && E(i.error) && E(i.complete);
674
+ function At(i) {
675
+ return i && g(i.next) && g(i.error) && g(i.complete);
676
676
  }
677
677
  function Rt(i) {
678
- return i && i instanceof nt || _t(i) && rt(i);
678
+ return i && i instanceof nt || At(i) && rt(i);
679
679
  }
680
680
  var xt = tt(function(i) {
681
681
  return function() {
@@ -700,15 +700,15 @@ var xt = tt(function(i) {
700
700
  if (r._throwIfClosed(), !r.isStopped) {
701
701
  r.currentObservers || (r.currentObservers = Array.from(r.observers));
702
702
  try {
703
- for (var o = B(r.currentObservers), u = o.next(); !u.done; u = o.next()) {
704
- var c = u.value;
703
+ for (var o = B(r.currentObservers), a = o.next(); !a.done; a = o.next()) {
704
+ var c = a.value;
705
705
  c.next(t);
706
706
  }
707
707
  } catch (l) {
708
708
  s = { error: l };
709
709
  } finally {
710
710
  try {
711
- u && !u.done && (n = o.return) && n.call(o);
711
+ a && !a.done && (n = o.return) && n.call(o);
712
712
  } finally {
713
713
  if (s) throw s.error;
714
714
  }
@@ -747,9 +747,9 @@ var xt = tt(function(i) {
747
747
  }, e.prototype._subscribe = function(t) {
748
748
  return this._throwIfClosed(), this._checkFinalizedStatuses(t), this._innerSubscribe(t);
749
749
  }, e.prototype._innerSubscribe = function(t) {
750
- var r = this, s = this, n = s.hasError, o = s.isStopped, u = s.observers;
751
- return n || o ? et : (this.currentObservers = null, u.push(t), new P(function() {
752
- r.currentObservers = null, H(u, t);
750
+ var r = this, s = this, n = s.hasError, o = s.isStopped, a = s.observers;
751
+ return n || o ? et : (this.currentObservers = null, a.push(t), new P(function() {
752
+ r.currentObservers = null, H(a, t);
753
753
  }));
754
754
  }, e.prototype._checkFinalizedStatuses = function(t) {
755
755
  var r = this, s = r.hasError, n = r.thrownError, o = r.isStopped;
@@ -779,7 +779,7 @@ var xt = tt(function(i) {
779
779
  var r, s;
780
780
  return (s = (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(t)) !== null && s !== void 0 ? s : et;
781
781
  }, e;
782
- }(ot), U = function(i) {
782
+ }(ot), I = function(i) {
783
783
  $(e, i);
784
784
  function e(t) {
785
785
  var r = i.call(this) || this;
@@ -806,8 +806,8 @@ var xt = tt(function(i) {
806
806
  class Pt extends d {
807
807
  constructor(t) {
808
808
  super();
809
- a(this, "api");
810
- a(this, "$cache", new U([]));
809
+ u(this, "api");
810
+ u(this, "$cache", new I([]));
811
811
  this.api = typeof t == "string" ? new f(t) : t;
812
812
  }
813
813
  get cache() {
@@ -843,16 +843,19 @@ class Pt extends d {
843
843
  }).then((r) => (r && (this.cache = this.cache.filter((s) => s._id != r._id).concat([r])), this.emit("UPDATE", r), r));
844
844
  }
845
845
  }
846
- class Ut extends d {
846
+ class It extends d {
847
847
  constructor(t, r) {
848
848
  var s;
849
849
  super();
850
- a(this, "api");
851
- a(this, "storageKey");
852
- a(this, "$user", new U(void 0));
853
- if (this.opts = r, this.api = typeof t == "string" ? new f(t) : t, (s = this.opts) != null && s.loginUi || (this.opts = { ...this.opts, loginUi: this.api.url + "/ui/login" }), this.storageKey = `momentum:${new URL(this.api.url).host}`, this.api.on("TOKEN", (n) => {
850
+ u(this, "api");
851
+ u(this, "storageKey");
852
+ u(this, "$user", new I(void 0));
853
+ if (this.opts = r, this.api = typeof t == "string" ? new f(t) : t, (s = this.opts) != null && s.loginUi || (this.opts = { ...this.opts, loginUi: this.api.url + "/ui/login" }), this.storageKey = `momentum:${new URL(this.api.url).host}`, this.api.addInterceptor((n, o) => {
854
+ n.status == 401 && !n.url.includes(`${this.api.url}/api/auth/login`) && this.emit("SESSION_EXPIRED"), o();
855
+ }), this.api.on("TOKEN", (n) => {
854
856
  var o;
855
- (o = this.opts) != null && o.persist && (n ? localStorage.setItem(this.storageKey, n) : localStorage.removeItem(this.storageKey)), n ? this.whoAmI(n, !0) : this.user = null;
857
+ (o = this.opts) != null && o.persist && (n ? localStorage.setItem(this.storageKey, n) : localStorage.removeItem(this.storageKey)), n ? this.whoAmI(n, !0).catch(() => {
858
+ }) : this.user = null;
856
859
  }), r != null && r.persist) {
857
860
  const n = localStorage.getItem(this.storageKey);
858
861
  n ? this.api.token = n : this.user = null;
@@ -876,8 +879,8 @@ class Ut extends d {
876
879
  url: "/api/auth/login",
877
880
  headers: { Authorization: void 0 },
878
881
  body: {
879
- username: t,
880
- password: r
882
+ username: t.trim(),
883
+ password: r.trim()
881
884
  }
882
885
  }).then(async (s) => (this.api.token = s.token, await this.once("USER")));
883
886
  }
@@ -886,10 +889,10 @@ class Ut extends d {
886
889
  var o;
887
890
  const n = window.open(encodeURI(`${(o = this.opts) == null ? void 0 : o.loginUi}?redirect=postmessage&host=${t}`), "_blank");
888
891
  if (!n) return s("Unable to open login");
889
- n.addEventListener("message", (u) => {
892
+ n.addEventListener("message", (a) => {
890
893
  var c;
891
- if (!((c = u == null ? void 0 : u.data) != null && c.token)) return s("Unknown response from login");
892
- this.api.token = u.data.token, r(u.data.token), n.close();
894
+ if (!((c = a == null ? void 0 : a.data) != null && c.token)) return s("Unknown response from login");
895
+ this.api.token = a.data.token, r(a.data.token), n.close();
893
896
  });
894
897
  });
895
898
  }
@@ -922,7 +925,7 @@ class Ut extends d {
922
925
  class Dt extends d {
923
926
  constructor(t) {
924
927
  super();
925
- a(this, "api");
928
+ u(this, "api");
926
929
  this.api = typeof t == "string" ? new f(t) : t;
927
930
  }
928
931
  delete(t, r) {
@@ -952,10 +955,10 @@ class Dt extends d {
952
955
  }).then((n) => (this.emit("SET", t, r), n));
953
956
  }
954
957
  }
955
- class It extends d {
958
+ class Ut extends d {
956
959
  constructor(t) {
957
960
  super();
958
- a(this, "api");
961
+ u(this, "api");
959
962
  this.api = typeof t == "string" ? new f(t) : t;
960
963
  }
961
964
  send(t) {
@@ -966,7 +969,7 @@ class It extends d {
966
969
  class Ct extends d {
967
970
  constructor(t) {
968
971
  super();
969
- a(this, "api");
972
+ u(this, "api");
970
973
  this.api = typeof t == "string" ? new f(t) : t;
971
974
  }
972
975
  create(t) {
@@ -998,7 +1001,7 @@ class Ct extends d {
998
1001
  }
999
1002
  class jt {
1000
1003
  constructor(e, t) {
1001
- a(this, "api");
1004
+ u(this, "api");
1002
1005
  this.api = typeof e == "string" ? new f(e) : e, t != null && t != "NONE" && (window.addEventListener("error", (r) => this.error(r.error.stack)), window.addEventListener("unhandledrejection", async (r) => this.error(r.reason.stack)));
1003
1006
  }
1004
1007
  buildLog(e, t) {
@@ -1052,7 +1055,7 @@ class jt {
1052
1055
  class kt extends d {
1053
1056
  constructor(t) {
1054
1057
  super();
1055
- a(this, "api");
1058
+ u(this, "api");
1056
1059
  this.api = typeof t == "string" ? new f(t) : t;
1057
1060
  }
1058
1061
  async handleResponse(t, r) {
@@ -1076,10 +1079,10 @@ class kt extends d {
1076
1079
  }
1077
1080
  const q = class q {
1078
1081
  constructor(e) {
1079
- a(this, "api");
1080
- a(this, "url");
1081
- a(this, "connection");
1082
- a(this, "open", !1);
1082
+ u(this, "api");
1083
+ u(this, "url");
1084
+ u(this, "connection");
1085
+ u(this, "open", !1);
1083
1086
  this.api = typeof e == "string" ? new f(e) : e, this.url = this.api.url.replace("http", "ws"), this.api.on("TOKEN", () => this.connect()), this.api.token || this.connect();
1084
1087
  }
1085
1088
  close() {
@@ -1106,12 +1109,12 @@ const q = class q {
1106
1109
  }));
1107
1110
  }
1108
1111
  };
1109
- a(q, "timeout", 1e4);
1112
+ u(q, "timeout", 1e4);
1110
1113
  let F = q;
1111
1114
  class Bt extends d {
1112
1115
  constructor(t) {
1113
1116
  super();
1114
- a(this, "api");
1117
+ u(this, "api");
1115
1118
  this.api = typeof t == "string" ? new f(t) : t;
1116
1119
  }
1117
1120
  delete(t) {
@@ -1133,44 +1136,44 @@ class Bt extends d {
1133
1136
  return this.api.request({ url: r + "?directory", method: "POST" });
1134
1137
  }
1135
1138
  download(t, r = {}) {
1136
- return new Et((s, n, o) => {
1137
- const u = ("/api/storage/" + t).replaceAll("//", "/");
1138
- this.api.request({ ...r, url: u, skipConverting: !0 }).then((c) => {
1139
+ return new gt((s, n, o) => {
1140
+ const a = ("/api/storage/" + t).replaceAll("//", "/");
1141
+ this.api.request({ ...r, url: a, skipConverting: !0 }).then((c) => {
1139
1142
  var p;
1140
1143
  if (!c.ok) return n(c.statusText);
1141
- const l = c.headers.get("Content-Length"), g = l ? parseInt(l, 10) : 0;
1144
+ const l = c.headers.get("Content-Length"), E = l ? parseInt(l, 10) : 0;
1142
1145
  let T = [], b = 0;
1143
- const y = (p = c.body) == null ? void 0 : p.getReader(), A = (M) => {
1146
+ const y = (p = c.body) == null ? void 0 : p.getReader(), _ = (M) => {
1144
1147
  if (M.done) {
1145
1148
  o(1);
1146
1149
  const w = new Blob(T), D = r.downloadAs || new URL(c.url).pathname.split("/").pop(), Y = URL.createObjectURL(w);
1147
1150
  Z(Y, D.includes(".") ? D : D + ".zip"), URL.revokeObjectURL(Y), this.emit("DOWNLOAD", t, w), s(w);
1148
1151
  } else {
1149
1152
  const w = M.value;
1150
- T.push(w), b += w.length, o(b / g), y.read().then(A);
1153
+ T.push(w), b += w.length, o(b / E), y.read().then(_);
1151
1154
  }
1152
1155
  };
1153
- y == null || y.read().then(A);
1156
+ y == null || y.read().then(_);
1154
1157
  });
1155
1158
  });
1156
1159
  }
1157
1160
  async upload(t, r = "") {
1158
- if (t || (t = await new Promise((u) => {
1161
+ if (t || (t = await new Promise((a) => {
1159
1162
  const c = document.createElement("input");
1160
1163
  c.type = "file", c.accept = (r == null ? void 0 : r.accept) || "*", c.style.display = "none", c.multiple = !!(r != null && r.multiple), c.onblur = c.onchange = async () => {
1161
- u(Array.from(c.files)), c.remove();
1164
+ a(Array.from(c.files)), c.remove();
1162
1165
  }, document.body.appendChild(c), c.click();
1163
1166
  })), !t || Array.isArray(t) && !t.length) return [];
1164
1167
  const n = new FormData(), o = ("/api/storage/" + (typeof r == "string" ? r : r == null ? void 0 : r.path)).replaceAll("//", "/");
1165
- return (Array.isArray(t) ? t : [t]).forEach((u) => n.append("file", u)), this.api.request({ url: o, body: n }).then((u) => (this.emit("UPLOAD", u), u));
1168
+ return (Array.isArray(t) ? t : [t]).forEach((a) => n.append("file", a)), this.api.request({ url: o, body: n }).then((a) => (this.emit("UPLOAD", a), a));
1166
1169
  }
1167
1170
  }
1168
1171
  class Gt extends d {
1169
1172
  constructor(t) {
1170
1173
  super();
1171
- a(this, "api");
1172
- a(this, "listed", !1);
1173
- a(this, "$cache", new U([]));
1174
+ u(this, "api");
1175
+ u(this, "listed", !1);
1176
+ u(this, "$cache", new I([]));
1174
1177
  this.api = typeof t == "string" ? new f(t) : t;
1175
1178
  }
1176
1179
  get cache() {
@@ -1208,8 +1211,8 @@ class Gt extends d {
1208
1211
  class Nt extends d {
1209
1212
  constructor(t) {
1210
1213
  super();
1211
- a(this, "api");
1212
- a(this, "$cache", new U({}));
1214
+ u(this, "api");
1215
+ u(this, "$cache", new I({}));
1213
1216
  this.api = typeof t == "string" ? new f(t) : t;
1214
1217
  }
1215
1218
  get cache() {
@@ -1236,7 +1239,7 @@ class Nt extends d {
1236
1239
  class Ht extends d {
1237
1240
  constructor(t) {
1238
1241
  super();
1239
- a(this, "api");
1242
+ u(this, "api");
1240
1243
  this.api = typeof t == "string" ? new f(t) : t;
1241
1244
  }
1242
1245
  delete(t) {
@@ -1256,30 +1259,30 @@ class Ht extends d {
1256
1259
  class Ft extends d {
1257
1260
  constructor(t, r) {
1258
1261
  super();
1259
- a(this, "api");
1260
- a(this, "actions");
1261
- a(this, "auth");
1262
- a(this, "data");
1263
- a(this, "email");
1264
- a(this, "groups");
1265
- a(this, "logger");
1266
- a(this, "pdf");
1267
- a(this, "settings");
1268
- a(this, "socket");
1269
- a(this, "static");
1270
- a(this, "storage");
1271
- a(this, "users");
1272
- this.api = new f(t, r == null ? void 0 : r.api), this.actions = new Pt(this.api), this.auth = new Ut(this.api, {
1262
+ u(this, "api");
1263
+ u(this, "actions");
1264
+ u(this, "auth");
1265
+ u(this, "data");
1266
+ u(this, "email");
1267
+ u(this, "groups");
1268
+ u(this, "logger");
1269
+ u(this, "pdf");
1270
+ u(this, "settings");
1271
+ u(this, "socket");
1272
+ u(this, "static");
1273
+ u(this, "storage");
1274
+ u(this, "users");
1275
+ this.api = new f(t, r == null ? void 0 : r.api), this.actions = new Pt(this.api), this.auth = new It(this.api, {
1273
1276
  persist: (r == null ? void 0 : r.persist) ?? !0,
1274
1277
  loginUi: r == null ? void 0 : r.loginUi
1275
- }), this.data = new Dt(this.api), this.email = new It(this.api), this.groups = new Ct(this.api), this.logger = new jt(this.api, r == null ? void 0 : r.logLevel), this.pdf = new kt(this.api), this.settings = new Nt(this.api), this.static = new Ht(this.api), this.storage = new Bt(this.api), this.users = new Gt(this.api), r != null && r.socket && (this.socket = new F(this.api)), this.api.on("*", (s, ...n) => this.emit(`API::${s}`, ...n)), this.actions.on("*", (s, ...n) => this.emit(`ACTIONS::${s}`, ...n)), this.auth.on("*", (s, ...n) => this.emit(`AUTH::${s}`, ...n)), this.data.on("*", (s, ...n) => this.emit(`DATA::${s}`, ...n)), this.email.on("*", (s, ...n) => this.emit(`EMAIL::${s}`, ...n)), this.groups.on("*", (s, ...n) => this.emit(`GROUPS::${s}`, ...n)), this.pdf.on("*", (s, ...n) => this.emit(`PDF::${s}`, ...n)), this.settings.on("*", (s, ...n) => this.emit(`SETTINGS::${s}`, ...n)), this.static.on("*", (s, ...n) => this.emit(`STATIC::${s}`, ...n)), this.storage.on("*", (s, ...n) => this.emit(`STORAGE::${s}`, ...n)), this.users.on("*", (s, ...n) => this.emit(`USERS::${s}`, ...n)), this.users.on("*", (s, ...n) => {
1278
+ }), this.data = new Dt(this.api), this.email = new Ut(this.api), this.groups = new Ct(this.api), this.logger = new jt(this.api, r == null ? void 0 : r.logLevel), this.pdf = new kt(this.api), this.settings = new Nt(this.api), this.static = new Ht(this.api), this.storage = new Bt(this.api), this.users = new Gt(this.api), r != null && r.socket && (this.socket = new F(this.api)), this.api.on("*", (s, ...n) => this.emit(`API::${s}`, ...n)), this.actions.on("*", (s, ...n) => this.emit(`ACTIONS::${s}`, ...n)), this.auth.on("*", (s, ...n) => this.emit(`AUTH::${s}`, ...n)), this.data.on("*", (s, ...n) => this.emit(`DATA::${s}`, ...n)), this.email.on("*", (s, ...n) => this.emit(`EMAIL::${s}`, ...n)), this.groups.on("*", (s, ...n) => this.emit(`GROUPS::${s}`, ...n)), this.pdf.on("*", (s, ...n) => this.emit(`PDF::${s}`, ...n)), this.settings.on("*", (s, ...n) => this.emit(`SETTINGS::${s}`, ...n)), this.static.on("*", (s, ...n) => this.emit(`STATIC::${s}`, ...n)), this.storage.on("*", (s, ...n) => this.emit(`STORAGE::${s}`, ...n)), this.users.on("*", (s, ...n) => this.emit(`USERS::${s}`, ...n)), this.users.on("*", (s, ...n) => {
1276
1279
  var o;
1277
1280
  if (Array.isArray(n[0])) {
1278
- const u = n[0].find((c) => {
1281
+ const a = n[0].find((c) => {
1279
1282
  var l;
1280
1283
  return c._id == ((l = this.auth.user) == null ? void 0 : l._id);
1281
1284
  });
1282
- u && (this.auth.user = u);
1285
+ a && (this.auth.user = a);
1283
1286
  } else n[0]._id == ((o = this.auth.user) == null ? void 0 : o._id) && (this.auth.user = n[0]);
1284
1287
  });
1285
1288
  }
@@ -1288,9 +1291,9 @@ export {
1288
1291
  qt as ActionType,
1289
1292
  Pt as Actions,
1290
1293
  f as Api,
1291
- Ut as Auth,
1294
+ It as Auth,
1292
1295
  Dt as Data,
1293
- It as Email,
1296
+ Ut as Email,
1294
1297
  Ct as Groups,
1295
1298
  jt as Logger,
1296
1299
  Ft as Momentum,