@ztimson/momentum 0.19.0 → 0.20.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
1
  var ut = Object.defineProperty;
2
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), t);
3
+ var a = (i, e, t) => at(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)
@@ -11,13 +11,13 @@ function lt(i, e = !1) {
11
11
  }
12
12
  function X(i, e) {
13
13
  const t = typeof i, r = typeof e;
14
- return t != "object" || i == null || r != "object" || e == null ? t == "function" && r == "function" ? i.toString() == e.toString() : i === e : Object.keys(i).length != Object.keys(e).length ? !1 : Object.keys(i).every((n) => X(i[n], e[n]));
14
+ return t != "object" || i == null || r != "object" || e == null ? t == "function" && r == "function" ? i.toString() == e.toString() : i === e : Object.keys(i).length != Object.keys(e).length ? !1 : Object.keys(i).every((s) => X(i[s], e[s]));
15
15
  }
16
16
  function Z(i, e) {
17
17
  const t = document.createElement("a");
18
18
  t.href = i, t.download = e, document.body.appendChild(t), t.click(), document.body.removeChild(t);
19
19
  }
20
- class p {
20
+ class d {
21
21
  constructor() {
22
22
  h(this, "listeners", {});
23
23
  }
@@ -26,17 +26,17 @@ class p {
26
26
  }
27
27
  static off(e, t) {
28
28
  const r = e.toString();
29
- this.listeners[r] = (this.listeners[r] || []).filter((n) => n === t);
29
+ this.listeners[r] = (this.listeners[r] || []).filter((s) => s === t);
30
30
  }
31
31
  static on(e, t) {
32
32
  var r;
33
- const n = e.toString();
34
- return this.listeners[n] || (this.listeners[n] = []), (r = this.listeners[n]) == null || r.push(t), () => this.off(e, t);
33
+ const s = e.toString();
34
+ return this.listeners[s] || (this.listeners[s] = []), (r = this.listeners[s]) == null || r.push(t), () => this.off(e, t);
35
35
  }
36
36
  static once(e, t) {
37
37
  return new Promise((r) => {
38
- const n = this.on(e, (...s) => {
39
- r(s.length == 1 ? s[0] : s), t && t(...s), n();
38
+ const s = this.on(e, (...n) => {
39
+ r(n.length == 1 ? n[0] : n), t && t(...n), s();
40
40
  });
41
41
  });
42
42
  }
@@ -52,13 +52,13 @@ class p {
52
52
  }
53
53
  once(e, t) {
54
54
  return new Promise((r) => {
55
- const n = this.on(e, (...s) => {
56
- r(s.length == 1 ? s[0] : s), t && t(...s), n();
55
+ const s = this.on(e, (...n) => {
56
+ r(n.length == 1 ? n[0] : n), t && t(...n), s();
57
57
  });
58
58
  });
59
59
  }
60
60
  }
61
- h(p, "listeners", {});
61
+ h(d, "listeners", {});
62
62
  class L extends Error {
63
63
  constructor(e, t) {
64
64
  super(e), h(this, "_code"), t != null && (this._code = t);
@@ -85,7 +85,7 @@ class L extends Error {
85
85
  }
86
86
  }
87
87
  h(L, "code", 500);
88
- class dt extends L {
88
+ class pt extends L {
89
89
  constructor(e = "Bad Request") {
90
90
  super(e);
91
91
  }
@@ -93,8 +93,8 @@ class dt extends L {
93
93
  return e.constructor.code == this.code;
94
94
  }
95
95
  }
96
- h(dt, "code", 400);
97
- class pt extends L {
96
+ h(pt, "code", 400);
97
+ class dt extends L {
98
98
  constructor(e = "Unauthorized") {
99
99
  super(e);
100
100
  }
@@ -102,7 +102,7 @@ class pt extends L {
102
102
  return e.constructor.code == this.code;
103
103
  }
104
104
  }
105
- h(pt, "code", 401);
105
+ h(dt, "code", 401);
106
106
  class ft extends L {
107
107
  constructor(e = "Forbidden") {
108
108
  super(e);
@@ -121,7 +121,7 @@ class mt extends L {
121
121
  }
122
122
  }
123
123
  h(mt, "code", 404);
124
- class Et extends L {
124
+ class yt extends L {
125
125
  constructor(e = "Internal Server Error") {
126
126
  super(e);
127
127
  }
@@ -129,7 +129,7 @@ class Et extends L {
129
129
  return e.constructor.code == this.code;
130
130
  }
131
131
  }
132
- h(Et, "code", 500);
132
+ h(yt, "code", 500);
133
133
  const O = {
134
134
  CLEAR: "\x1B[0m",
135
135
  BRIGHT: "\x1B[1m",
@@ -138,7 +138,7 @@ const O = {
138
138
  BLINK: "\x1B[5m",
139
139
  REVERSE: "\x1B[7m",
140
140
  HIDDEN: "\x1B[8m"
141
- }, R = {
141
+ }, _ = {
142
142
  BLACK: "\x1B[30m",
143
143
  RED: "\x1B[31m",
144
144
  GREEN: "\x1B[32m",
@@ -157,16 +157,16 @@ 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 yt = class m extends p {
160
+ const gt = class m extends d {
161
161
  constructor(e) {
162
162
  super(), this.namespace = e;
163
163
  }
164
- pad(e, t, r, n = !1) {
165
- const s = e.toString(), o = t - s.length;
164
+ pad(e, t, r, s = !1) {
165
+ const n = e.toString(), o = t - n.length;
166
166
  if (o <= 0)
167
- return s;
167
+ return n;
168
168
  const u = Array(~~(o / r.length)).fill(r).join("");
169
- return n ? s + u : u + s;
169
+ return s ? n + u : u + n;
170
170
  }
171
171
  format(...e) {
172
172
  const t = /* @__PURE__ */ new Date();
@@ -176,7 +176,7 @@ const yt = class m extends p {
176
176
  if (m.LOG_LEVEL < 4)
177
177
  return;
178
178
  const t = this.format(...e);
179
- m.emit(4, t), console.debug(R.LIGHT_GREY + t + O.CLEAR);
179
+ m.emit(4, t), console.debug(_.LIGHT_GREY + t + O.CLEAR);
180
180
  }
181
181
  log(...e) {
182
182
  if (m.LOG_LEVEL < 3)
@@ -188,28 +188,28 @@ const yt = class m extends p {
188
188
  if (m.LOG_LEVEL < 2)
189
189
  return;
190
190
  const t = this.format(...e);
191
- m.emit(2, t), console.info(R.BLUE + t + O.CLEAR);
191
+ m.emit(2, t), console.info(_.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(R.YELLOW + t + O.CLEAR);
197
+ m.emit(1, t), console.warn(_.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(R.RED + t + O.CLEAR);
203
+ m.emit(0, t), console.error(_.RED + t + O.CLEAR);
204
204
  }
205
205
  };
206
- h(yt, "LOG_LEVEL", 4);
207
- class bt extends Promise {
206
+ h(gt, "LOG_LEVEL", 4);
207
+ class Et extends Promise {
208
208
  constructor(e) {
209
209
  super((t, r) => e(
210
- (n) => t(n),
211
- (n) => r(n),
212
- (n) => this.progress = n
210
+ (s) => t(s),
211
+ (s) => r(s),
212
+ (s) => this.progress = s
213
213
  )), h(this, "listeners", []), h(this, "_progress", 0);
214
214
  }
215
215
  get progress() {
@@ -222,7 +222,7 @@ class bt extends Promise {
222
222
  return this.listeners.push(e), this;
223
223
  }
224
224
  }
225
- const B = class v {
225
+ const j = class v {
226
226
  constructor(e = {}) {
227
227
  h(this, "interceptors", {}), h(this, "headers", {}), this.opts = e, this.headers = e.headers || {}, e.interceptors && e.interceptors.forEach((t) => v.addInterceptor(t));
228
228
  }
@@ -242,22 +242,27 @@ const B = class v {
242
242
  var t, r;
243
243
  if (!this.opts.url && !e.url)
244
244
  throw new Error("URL needs to be set");
245
- const n = ((t = e.url) != null && t.startsWith("http") ? e.url : (this.opts.url || "") + (e.url || "")).replace(/([^:]\/)\/+/g, "$1"), s = lt({
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("&");
249
+ }
250
+ const n = lt({
246
251
  "Content-Type": e.body && !(e.body instanceof FormData) ? "application/json" : void 0,
247
252
  ...v.headers,
248
253
  ...this.headers,
249
254
  ...e.headers
250
255
  });
251
- return fetch(n, {
252
- headers: s,
256
+ return fetch(s, {
257
+ headers: n,
253
258
  method: e.method || (e.body ? "POST" : "GET"),
254
- body: (r = s["Content-Type"]) != null && r.startsWith("application/json") && e.body ? JSON.stringify(e.body) : e.body
259
+ body: (r = n["Content-Type"]) != null && r.startsWith("application/json") && e.body ? JSON.stringify(e.body) : e.body
255
260
  }).then(async (o) => {
256
261
  for (let l of [...Object.values(v.interceptors), ...Object.values(this.interceptors)])
257
- await new Promise((y) => l(o, () => y()));
262
+ await new Promise((g) => l(o, () => g()));
258
263
  const u = await (async () => {
259
- var l, y;
260
- return !e.skipConverting && (l = o.headers.get("Content-Type")) != null && l.startsWith("application/json") ? await o.json() : !e.skipConverting && (y = o.headers.get("Content-Type")) != null && y.startsWith("text/plain") ? await o.text() : o;
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;
261
266
  })();
262
267
  if (o.ok)
263
268
  return u;
@@ -266,13 +271,13 @@ const B = class v {
266
271
  });
267
272
  }
268
273
  };
269
- h(B, "interceptors", {}), h(B, "headers", {});
270
- let gt = B;
271
- class f extends gt {
274
+ h(j, "interceptors", {}), h(j, "headers", {});
275
+ let bt = j;
276
+ class f extends bt {
272
277
  constructor(t = location.origin, r = {}) {
273
278
  r.url = t;
274
279
  super(r);
275
- a(this, "emitter", new p());
280
+ a(this, "emitter", new d());
276
281
  a(this, "_token", null);
277
282
  a(this, "emit", this.emitter.emit.bind(this.emitter));
278
283
  a(this, "off", this.emitter.off.bind(this.emitter));
@@ -287,68 +292,61 @@ class f extends gt {
287
292
  t != this._token && (this._token = t, this.headers.Authorization = `Bearer ${t}`, this.emit("TOKEN", t));
288
293
  }
289
294
  request(t) {
290
- const r = super.request(t).then((n) => (this.emit("RESPONSE", n, t), n)).catch((n) => {
291
- throw this.emit("REJECTED", n, t), n;
295
+ const r = super.request(t).then((s) => (this.emit("RESPONSE", s, t), s)).catch((s) => {
296
+ throw this.emit("REJECTED", s, t), s;
292
297
  });
293
298
  return this.emit("REQUEST", r, t), r;
294
299
  }
295
300
  }
296
- var j = function(i, e) {
297
- return j = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, r) {
301
+ var k = function(i, e) {
302
+ return k = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, r) {
298
303
  t.__proto__ = r;
299
304
  } || function(t, r) {
300
- for (var n in r)
301
- Object.prototype.hasOwnProperty.call(r, n) && (t[n] = r[n]);
302
- }, j(i, e);
305
+ for (var s in r) Object.prototype.hasOwnProperty.call(r, s) && (t[s] = r[s]);
306
+ }, k(i, e);
303
307
  };
304
308
  function $(i, e) {
305
309
  if (typeof e != "function" && e !== null)
306
310
  throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
307
- j(i, e);
311
+ k(i, e);
308
312
  function t() {
309
313
  this.constructor = i;
310
314
  }
311
315
  i.prototype = e === null ? Object.create(e) : (t.prototype = e.prototype, new t());
312
316
  }
313
- function k(i) {
317
+ function B(i) {
314
318
  var e = typeof Symbol == "function" && Symbol.iterator, t = e && i[e], r = 0;
315
- if (t)
316
- return t.call(i);
317
- if (i && typeof i.length == "number")
318
- return {
319
- next: function() {
320
- return i && r >= i.length && (i = void 0), { value: i && i[r++], done: !i };
321
- }
322
- };
319
+ if (t) return t.call(i);
320
+ if (i && typeof i.length == "number") return {
321
+ next: function() {
322
+ return i && r >= i.length && (i = void 0), { value: i && i[r++], done: !i };
323
+ }
324
+ };
323
325
  throw new TypeError(e ? "Object is not iterable." : "Symbol.iterator is not defined.");
324
326
  }
325
327
  function G(i, e) {
326
328
  var t = typeof Symbol == "function" && i[Symbol.iterator];
327
- if (!t)
328
- return i;
329
- var r = t.call(i), n, s = [], o;
329
+ if (!t) return i;
330
+ var r = t.call(i), s, n = [], o;
330
331
  try {
331
- for (; (e === void 0 || e-- > 0) && !(n = r.next()).done; )
332
- s.push(n.value);
332
+ for (; (e === void 0 || e-- > 0) && !(s = r.next()).done; ) n.push(s.value);
333
333
  } catch (u) {
334
334
  o = { error: u };
335
335
  } finally {
336
336
  try {
337
- n && !n.done && (t = r.return) && t.call(r);
337
+ s && !s.done && (t = r.return) && t.call(r);
338
338
  } finally {
339
- if (o)
340
- throw o.error;
339
+ if (o) throw o.error;
341
340
  }
342
341
  }
343
- return s;
342
+ return n;
344
343
  }
345
344
  function N(i, e, t) {
346
- if (t || arguments.length === 2)
347
- for (var r = 0, n = e.length, s; r < n; r++)
348
- (s || !(r in e)) && (s || (s = Array.prototype.slice.call(e, 0, r)), s[r] = e[r]);
349
- return i.concat(s || Array.prototype.slice.call(e));
345
+ if (t || arguments.length === 2) for (var r = 0, s = e.length, n; r < s; r++)
346
+ (n || !(r in e)) && (n || (n = Array.prototype.slice.call(e, 0, r)), n[r] = e[r]);
347
+ return i.concat(n || Array.prototype.slice.call(e));
350
348
  }
351
- function b(i) {
349
+ function E(i) {
352
350
  return typeof i == "function";
353
351
  }
354
352
  function tt(i) {
@@ -357,11 +355,11 @@ function tt(i) {
357
355
  }, t = i(e);
358
356
  return t.prototype = Object.create(Error.prototype), t.prototype.constructor = t, t;
359
357
  }
360
- var U = tt(function(i) {
358
+ var I = tt(function(i) {
361
359
  return function(t) {
362
360
  i(this), this.message = t ? t.length + ` errors occurred during unsubscription:
363
- ` + t.map(function(r, n) {
364
- return n + 1 + ") " + r.toString();
361
+ ` + t.map(function(r, s) {
362
+ return s + 1 + ") " + r.toString();
365
363
  }).join(`
366
364
  `) : "", this.name = "UnsubscriptionError", this.errors = t;
367
365
  };
@@ -377,61 +375,59 @@ var P = function() {
377
375
  this.initialTeardown = e, this.closed = !1, this._parentage = null, this._finalizers = null;
378
376
  }
379
377
  return i.prototype.unsubscribe = function() {
380
- var e, t, r, n, s;
378
+ var e, t, r, s, n;
381
379
  if (!this.closed) {
382
380
  this.closed = !0;
383
381
  var o = this._parentage;
384
382
  if (o)
385
383
  if (this._parentage = null, Array.isArray(o))
386
384
  try {
387
- for (var u = k(o), c = u.next(); !c.done; c = u.next()) {
385
+ for (var u = B(o), c = u.next(); !c.done; c = u.next()) {
388
386
  var l = c.value;
389
387
  l.remove(this);
390
388
  }
391
- } catch (d) {
392
- e = { error: d };
389
+ } catch (p) {
390
+ e = { error: p };
393
391
  } finally {
394
392
  try {
395
393
  c && !c.done && (t = u.return) && t.call(u);
396
394
  } finally {
397
- if (e)
398
- throw e.error;
395
+ if (e) throw e.error;
399
396
  }
400
397
  }
401
398
  else
402
399
  o.remove(this);
403
- var y = this.initialTeardown;
404
- if (b(y))
400
+ var g = this.initialTeardown;
401
+ if (E(g))
405
402
  try {
406
- y();
407
- } catch (d) {
408
- s = d instanceof U ? d.errors : [d];
403
+ g();
404
+ } catch (p) {
405
+ n = p instanceof I ? p.errors : [p];
409
406
  }
410
407
  var T = this._finalizers;
411
408
  if (T) {
412
409
  this._finalizers = null;
413
410
  try {
414
- for (var g = k(T), E = g.next(); !E.done; E = g.next()) {
415
- var _ = E.value;
411
+ for (var b = B(T), y = b.next(); !y.done; y = b.next()) {
412
+ var A = y.value;
416
413
  try {
417
- V(_);
418
- } catch (d) {
419
- s = s ?? [], d instanceof U ? s = N(N([], G(s)), G(d.errors)) : s.push(d);
414
+ V(A);
415
+ } catch (p) {
416
+ n = n ?? [], p instanceof I ? n = N(N([], G(n)), G(p.errors)) : n.push(p);
420
417
  }
421
418
  }
422
- } catch (d) {
423
- r = { error: d };
419
+ } catch (p) {
420
+ r = { error: p };
424
421
  } finally {
425
422
  try {
426
- E && !E.done && (n = g.return) && n.call(g);
423
+ y && !y.done && (s = b.return) && s.call(b);
427
424
  } finally {
428
- if (r)
429
- throw r.error;
425
+ if (r) throw r.error;
430
426
  }
431
427
  }
432
428
  }
433
- if (s)
434
- throw new U(s);
429
+ if (n)
430
+ throw new I(n);
435
431
  }
436
432
  }, i.prototype.add = function(e) {
437
433
  var t;
@@ -464,10 +460,10 @@ var P = function() {
464
460
  }(), i;
465
461
  }(), et = P.EMPTY;
466
462
  function rt(i) {
467
- return i instanceof P || i && "closed" in i && b(i.remove) && b(i.add) && b(i.unsubscribe);
463
+ return i instanceof P || i && "closed" in i && E(i.remove) && E(i.add) && E(i.unsubscribe);
468
464
  }
469
465
  function V(i) {
470
- b(i) ? i() : i.unsubscribe();
466
+ E(i) ? i() : i.unsubscribe();
471
467
  }
472
468
  var it = {
473
469
  onUnhandledError: null,
@@ -475,20 +471,20 @@ var it = {
475
471
  Promise: void 0,
476
472
  useDeprecatedSynchronousErrorHandling: !1,
477
473
  useDeprecatedNextContext: !1
478
- }, nt = {
474
+ }, st = {
479
475
  setTimeout: function(i, e) {
480
476
  for (var t = [], r = 2; r < arguments.length; r++)
481
477
  t[r - 2] = arguments[r];
482
478
  return setTimeout.apply(void 0, N([i, e], G(t)));
483
479
  },
484
480
  clearTimeout: function(i) {
485
- var e = nt.delegate;
481
+ var e = st.delegate;
486
482
  return ((e == null ? void 0 : e.clearTimeout) || clearTimeout)(i);
487
483
  },
488
484
  delegate: void 0
489
485
  };
490
486
  function vt(i) {
491
- nt.setTimeout(function() {
487
+ st.setTimeout(function() {
492
488
  throw i;
493
489
  });
494
490
  }
@@ -497,14 +493,14 @@ function K() {
497
493
  function x(i) {
498
494
  i();
499
495
  }
500
- var st = function(i) {
496
+ var nt = function(i) {
501
497
  $(e, i);
502
498
  function e(t) {
503
499
  var r = i.call(this) || this;
504
500
  return r.isStopped = !1, t ? (r.destination = t, rt(t) && t.add(r)) : r.destination = Tt, r;
505
501
  }
506
- return e.create = function(t, r, n) {
507
- return new W(t, r, n);
502
+ return e.create = function(t, r, s) {
503
+ return new W(t, r, s);
508
504
  }, e.prototype.next = function(t) {
509
505
  this.isStopped || this._next(t);
510
506
  }, e.prototype.error = function(t) {
@@ -542,7 +538,7 @@ var St = function() {
542
538
  try {
543
539
  t.next(e);
544
540
  } catch (r) {
545
- A(r);
541
+ R(r);
546
542
  }
547
543
  }, i.prototype.error = function(e) {
548
544
  var t = this.partialObserver;
@@ -550,44 +546,44 @@ var St = function() {
550
546
  try {
551
547
  t.error(e);
552
548
  } catch (r) {
553
- A(r);
549
+ R(r);
554
550
  }
555
551
  else
556
- A(e);
552
+ R(e);
557
553
  }, i.prototype.complete = function() {
558
554
  var e = this.partialObserver;
559
555
  if (e.complete)
560
556
  try {
561
557
  e.complete();
562
558
  } catch (t) {
563
- A(t);
559
+ R(t);
564
560
  }
565
561
  }, i;
566
562
  }(), W = function(i) {
567
563
  $(e, i);
568
- function e(t, r, n) {
569
- var s = i.call(this) || this, o;
570
- if (b(t) || !t)
564
+ function e(t, r, s) {
565
+ var n = i.call(this) || this, o;
566
+ if (E(t) || !t)
571
567
  o = {
572
568
  next: t ?? void 0,
573
569
  error: r ?? void 0,
574
- complete: n ?? void 0
570
+ complete: s ?? void 0
575
571
  };
576
572
  else {
577
573
  var u;
578
- s && it.useDeprecatedNextContext ? (u = Object.create(t), u.unsubscribe = function() {
579
- return s.unsubscribe();
574
+ n && it.useDeprecatedNextContext ? (u = Object.create(t), u.unsubscribe = function() {
575
+ return n.unsubscribe();
580
576
  }, o = {
581
577
  next: t.next && C(t.next, u),
582
578
  error: t.error && C(t.error, u),
583
579
  complete: t.complete && C(t.complete, u)
584
580
  }) : o = t;
585
581
  }
586
- return s.destination = new St(o), s;
582
+ return n.destination = new St(o), n;
587
583
  }
588
584
  return e;
589
- }(st);
590
- function A(i) {
585
+ }(nt);
586
+ function R(i) {
591
587
  vt(i);
592
588
  }
593
589
  function Lt(i) {
@@ -604,10 +600,10 @@ var Tt = {
604
600
  function $t(i) {
605
601
  return i;
606
602
  }
607
- function _t(i) {
603
+ function At(i) {
608
604
  return i.length === 0 ? $t : i.length === 1 ? i[0] : function(t) {
609
- return i.reduce(function(r, n) {
610
- return n(r);
605
+ return i.reduce(function(r, s) {
606
+ return s(r);
611
607
  }, t);
612
608
  };
613
609
  }
@@ -619,11 +615,11 @@ var z = function() {
619
615
  var t = new i();
620
616
  return t.source = this, t.operator = e, t;
621
617
  }, i.prototype.subscribe = function(e, t, r) {
622
- var n = this, s = At(e) ? e : new W(e, t, r);
618
+ var s = this, n = Rt(e) ? e : new W(e, t, r);
623
619
  return x(function() {
624
- var o = n, u = o.operator, c = o.source;
625
- s.add(u ? u.call(s, c) : c ? n._subscribe(s) : n._trySubscribe(s));
626
- }), s;
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));
622
+ }), n;
627
623
  }, i.prototype._trySubscribe = function(e) {
628
624
  try {
629
625
  return this._subscribe(e);
@@ -632,17 +628,17 @@ var z = function() {
632
628
  }
633
629
  }, i.prototype.forEach = function(e, t) {
634
630
  var r = this;
635
- return t = J(t), new t(function(n, s) {
631
+ return t = J(t), new t(function(s, n) {
636
632
  var o = new W({
637
633
  next: function(u) {
638
634
  try {
639
635
  e(u);
640
636
  } catch (c) {
641
- s(c), o.unsubscribe();
637
+ n(c), o.unsubscribe();
642
638
  }
643
639
  },
644
- error: s,
645
- complete: n
640
+ error: n,
641
+ complete: s
646
642
  });
647
643
  r.subscribe(o);
648
644
  });
@@ -654,17 +650,17 @@ var z = function() {
654
650
  }, i.prototype.pipe = function() {
655
651
  for (var e = [], t = 0; t < arguments.length; t++)
656
652
  e[t] = arguments[t];
657
- return _t(e)(this);
653
+ return At(e)(this);
658
654
  }, i.prototype.toPromise = function(e) {
659
655
  var t = this;
660
- return e = J(e), new e(function(r, n) {
661
- var s;
656
+ return e = J(e), new e(function(r, s) {
657
+ var n;
662
658
  t.subscribe(function(o) {
663
- return s = o;
659
+ return n = o;
664
660
  }, function(o) {
665
- return n(o);
661
+ return s(o);
666
662
  }, function() {
667
- return r(s);
663
+ return r(n);
668
664
  });
669
665
  });
670
666
  }, i.create = function(e) {
@@ -675,11 +671,11 @@ function J(i) {
675
671
  var e;
676
672
  return (e = i ?? it.Promise) !== null && e !== void 0 ? e : Promise;
677
673
  }
678
- function Rt(i) {
679
- return i && b(i.next) && b(i.error) && b(i.complete);
674
+ function _t(i) {
675
+ return i && E(i.next) && E(i.error) && E(i.complete);
680
676
  }
681
- function At(i) {
682
- return i && i instanceof st || Rt(i) && rt(i);
677
+ function Rt(i) {
678
+ return i && i instanceof nt || _t(i) && rt(i);
683
679
  }
684
680
  var xt = tt(function(i) {
685
681
  return function() {
@@ -700,22 +696,21 @@ var xt = tt(function(i) {
700
696
  }, e.prototype.next = function(t) {
701
697
  var r = this;
702
698
  x(function() {
703
- var n, s;
699
+ var s, n;
704
700
  if (r._throwIfClosed(), !r.isStopped) {
705
701
  r.currentObservers || (r.currentObservers = Array.from(r.observers));
706
702
  try {
707
- for (var o = k(r.currentObservers), u = o.next(); !u.done; u = o.next()) {
703
+ for (var o = B(r.currentObservers), u = o.next(); !u.done; u = o.next()) {
708
704
  var c = u.value;
709
705
  c.next(t);
710
706
  }
711
707
  } catch (l) {
712
- n = { error: l };
708
+ s = { error: l };
713
709
  } finally {
714
710
  try {
715
- u && !u.done && (s = o.return) && s.call(o);
711
+ u && !u.done && (n = o.return) && n.call(o);
716
712
  } finally {
717
- if (n)
718
- throw n.error;
713
+ if (s) throw s.error;
719
714
  }
720
715
  }
721
716
  }
@@ -725,8 +720,8 @@ var xt = tt(function(i) {
725
720
  x(function() {
726
721
  if (r._throwIfClosed(), !r.isStopped) {
727
722
  r.hasError = r.isStopped = !0, r.thrownError = t;
728
- for (var n = r.observers; n.length; )
729
- n.shift().error(t);
723
+ for (var s = r.observers; s.length; )
724
+ s.shift().error(t);
730
725
  }
731
726
  });
732
727
  }, e.prototype.complete = function() {
@@ -752,13 +747,13 @@ var xt = tt(function(i) {
752
747
  }, e.prototype._subscribe = function(t) {
753
748
  return this._throwIfClosed(), this._checkFinalizedStatuses(t), this._innerSubscribe(t);
754
749
  }, e.prototype._innerSubscribe = function(t) {
755
- var r = this, n = this, s = n.hasError, o = n.isStopped, u = n.observers;
756
- return s || o ? et : (this.currentObservers = null, u.push(t), new P(function() {
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() {
757
752
  r.currentObservers = null, H(u, t);
758
753
  }));
759
754
  }, e.prototype._checkFinalizedStatuses = function(t) {
760
- var r = this, n = r.hasError, s = r.thrownError, o = r.isStopped;
761
- n ? t.error(s) : o && t.complete();
755
+ var r = this, s = r.hasError, n = r.thrownError, o = r.isStopped;
756
+ s ? t.error(n) : o && t.complete();
762
757
  }, e.prototype.asObservable = function() {
763
758
  var t = new z();
764
759
  return t.source = this, t;
@@ -768,23 +763,23 @@ var xt = tt(function(i) {
768
763
  }(z), Q = function(i) {
769
764
  $(e, i);
770
765
  function e(t, r) {
771
- var n = i.call(this) || this;
772
- return n.destination = t, n.source = r, n;
766
+ var s = i.call(this) || this;
767
+ return s.destination = t, s.source = r, s;
773
768
  }
774
769
  return e.prototype.next = function(t) {
775
- var r, n;
776
- (n = (r = this.destination) === null || r === void 0 ? void 0 : r.next) === null || n === void 0 || n.call(r, t);
770
+ var r, s;
771
+ (s = (r = this.destination) === null || r === void 0 ? void 0 : r.next) === null || s === void 0 || s.call(r, t);
777
772
  }, e.prototype.error = function(t) {
778
- var r, n;
779
- (n = (r = this.destination) === null || r === void 0 ? void 0 : r.error) === null || n === void 0 || n.call(r, t);
773
+ var r, s;
774
+ (s = (r = this.destination) === null || r === void 0 ? void 0 : r.error) === null || s === void 0 || s.call(r, t);
780
775
  }, e.prototype.complete = function() {
781
776
  var t, r;
782
777
  (r = (t = this.destination) === null || t === void 0 ? void 0 : t.complete) === null || r === void 0 || r.call(t);
783
778
  }, e.prototype._subscribe = function(t) {
784
- var r, n;
785
- return (n = (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(t)) !== null && n !== void 0 ? n : et;
779
+ var r, s;
780
+ return (s = (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(t)) !== null && s !== void 0 ? s : et;
786
781
  }, e;
787
- }(ot), q = function(i) {
782
+ }(ot), U = function(i) {
788
783
  $(e, i);
789
784
  function e(t) {
790
785
  var r = i.call(this) || this;
@@ -800,19 +795,19 @@ var xt = tt(function(i) {
800
795
  var r = i.prototype._subscribe.call(this, t);
801
796
  return !r.closed && t.next(this._value), r;
802
797
  }, e.prototype.getValue = function() {
803
- var t = this, r = t.hasError, n = t.thrownError, s = t._value;
798
+ var t = this, r = t.hasError, s = t.thrownError, n = t._value;
804
799
  if (r)
805
- throw n;
806
- return this._throwIfClosed(), s;
800
+ throw s;
801
+ return this._throwIfClosed(), n;
807
802
  }, e.prototype.next = function(t) {
808
803
  i.prototype.next.call(this, this._value = t);
809
804
  }, e;
810
- }(ot), Dt = /* @__PURE__ */ ((i) => (i[i.DISABLED = 0] = "DISABLED", i[i.CRON = 1] = "CRON", i[i.EVENT = 2] = "EVENT", i[i.GET = 3] = "GET", i[i.POST = 4] = "POST", i[i.PATCH = 5] = "PATCH", i[i.PUT = 6] = "PUT", i[i.DELETE = 7] = "DELETE", i))(Dt || {});
811
- class Pt extends p {
805
+ }(ot), qt = /* @__PURE__ */ ((i) => (i[i.CRON = 0] = "CRON", i[i.EVENT = 1] = "EVENT", i[i.DELETE = 2] = "DELETE", i[i.GET = 3] = "GET", i[i.PATCH = 4] = "PATCH", i[i.POST = 5] = "POST", i[i.PUT = 6] = "PUT", i))(qt || {});
806
+ class Pt extends d {
812
807
  constructor(t) {
813
808
  super();
814
809
  a(this, "api");
815
- a(this, "$cache", new q([]));
810
+ a(this, "$cache", new U([]));
816
811
  this.api = typeof t == "string" ? new f(t) : t;
817
812
  }
818
813
  get cache() {
@@ -830,37 +825,37 @@ class Pt extends p {
830
825
  return this.api.request({ url: "/api/actions" }).then((t) => (this.cache = t, this.emit("LIST", t), t));
831
826
  }
832
827
  read(t, r = !1) {
833
- const n = this.cache.find((s) => s._id == t);
834
- return !r && n ? Promise.resolve(n) : this.api.request({ url: `/api/actions/${t}` }).then((s) => (s && (this.cache = this.cache.filter((o) => o._id != t).concat([s])), this.emit("READ", s), s));
828
+ const s = this.cache.find((n) => n._id == t);
829
+ return !r && s ? Promise.resolve(s) : this.api.request({ url: `/api/actions/${t}` }).then((n) => (n && (this.cache = this.cache.filter((o) => o._id != t).concat([n])), this.emit("READ", n), n));
835
830
  }
836
831
  run(t, r = {}) {
837
832
  return this.api.request({ url: ("/api/actions/run/" + t).replaceAll("//", "/"), ...r });
838
833
  }
839
834
  runById(t, r = {}) {
840
- const n = typeof t == "string" ? t : t._id;
841
- return this.api.request({ url: "/api/actions/run-by-id/" + n, ...r });
835
+ const s = typeof t == "string" ? t : t._id;
836
+ return this.api.request({ url: "/api/actions/run-by-id/" + s, method: "POST", ...r });
842
837
  }
843
838
  update(t) {
844
839
  return this.api.request({
845
840
  url: `/api/actions${t._id ? `/${t._id}` : ""}`,
846
841
  method: "POST",
847
842
  body: t
848
- }).then((r) => (r && (this.cache = this.cache.filter((n) => n._id != r._id).concat([r])), this.emit("UPDATE", r), r));
843
+ }).then((r) => (r && (this.cache = this.cache.filter((s) => s._id != r._id).concat([r])), this.emit("UPDATE", r), r));
849
844
  }
850
845
  }
851
- class qt extends p {
846
+ class Ut extends d {
852
847
  constructor(t, r) {
853
- var n;
848
+ var s;
854
849
  super();
855
850
  a(this, "api");
856
851
  a(this, "storageKey");
857
- a(this, "$user", new q(void 0));
858
- if (this.opts = r, this.api = typeof t == "string" ? new f(t) : t, (n = this.opts) != null && n.loginUi || (this.opts = { ...this.opts, loginUi: this.api.url + "/ui/login" }), this.storageKey = `momentum:${new URL(this.api.url).host}`, this.api.on("TOKEN", (s) => {
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) => {
859
854
  var o;
860
- (o = this.opts) != null && o.persist && (s ? localStorage.setItem(this.storageKey, s) : localStorage.removeItem(this.storageKey)), s ? this.whoAmI(s, !0) : this.user = null;
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;
861
856
  }), r != null && r.persist) {
862
- const s = localStorage.getItem(this.storageKey);
863
- s ? this.api.token = s : this.user = null;
857
+ const n = localStorage.getItem(this.storageKey);
858
+ n ? this.api.token = n : this.user = null;
864
859
  } else
865
860
  this.user = null;
866
861
  }
@@ -884,19 +879,17 @@ class qt extends p {
884
879
  username: t,
885
880
  password: r
886
881
  }
887
- }).then(async (n) => (this.api.token = n.token, await this.once("USER")));
882
+ }).then(async (s) => (this.api.token = s.token, await this.once("USER")));
888
883
  }
889
884
  loginRedirect(t = location.origin) {
890
- return new Promise((r, n) => {
885
+ return new Promise((r, s) => {
891
886
  var o;
892
- const s = window.open(encodeURI(`${(o = this.opts) == null ? void 0 : o.loginUi}?redirect=postmessage&host=${t}`), "_blank");
893
- if (!s)
894
- return n("Unable to open login");
895
- s.addEventListener("message", (u) => {
887
+ const n = window.open(encodeURI(`${(o = this.opts) == null ? void 0 : o.loginUi}?redirect=postmessage&host=${t}`), "_blank");
888
+ if (!n) return s("Unable to open login");
889
+ n.addEventListener("message", (u) => {
896
890
  var c;
897
- if (!((c = u == null ? void 0 : u.data) != null && c.token))
898
- return n("Unknown response from login");
899
- this.api.token = u.data.token, r(u.data.token), s.close();
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();
900
893
  });
901
894
  });
902
895
  }
@@ -919,14 +912,14 @@ class qt extends p {
919
912
  }
920
913
  async whoAmI(t, r = !1) {
921
914
  t || (t = this.api.token);
922
- const n = await this.api.request({
915
+ const s = await this.api.request({
923
916
  url: "/api/auth/whoami",
924
917
  headers: t ? { Authorization: `Bearer ${t}` } : void 0
925
918
  });
926
- return r && (this.api.token = t, this.user = (n == null ? void 0 : n.user) || null, n && this.emit("LOGIN", n.user)), n;
919
+ return r && (this.api.token = t, this.user = (s == null ? void 0 : s.user) || null, s && this.emit("LOGIN", s.user)), s;
927
920
  }
928
921
  }
929
- class It extends p {
922
+ class Dt extends d {
930
923
  constructor(t) {
931
924
  super();
932
925
  a(this, "api");
@@ -939,27 +932,27 @@ class It extends p {
939
932
  }).then(() => this.emit("DELETE", t, r));
940
933
  }
941
934
  get(t, r) {
942
- return this.api.request({ url: `/api/data/${t}${r ? `/${r}` : ""}` }).then((n) => (this.emit("GET", t, n), n));
935
+ return this.api.request({ url: `/api/data/${t}${r ? `/${r}` : ""}` }).then((s) => (this.emit("GET", t, s), s));
943
936
  }
944
- raw(t, r, n, s) {
937
+ raw(t, r, s, n) {
945
938
  return this.api.request({
946
939
  url: `/api/data/${t}`,
947
940
  body: {
948
941
  operand: r,
949
- query: n,
950
- options: s
942
+ query: s,
943
+ options: n
951
944
  }
952
945
  }).then((o) => (this.emit("RAW", t, o), o));
953
946
  }
954
- set(t, r, n = !1) {
947
+ set(t, r, s = !1) {
955
948
  return this.api.request({
956
949
  url: `/api/data/${t}/${r._id || ""}`,
957
- method: n ? "PATCH" : "POST",
950
+ method: s ? "PATCH" : "POST",
958
951
  body: r
959
- }).then((s) => (this.emit("SET", t, r), s));
952
+ }).then((n) => (this.emit("SET", t, r), n));
960
953
  }
961
954
  }
962
- class Ut extends p {
955
+ class It extends d {
963
956
  constructor(t) {
964
957
  super();
965
958
  a(this, "api");
@@ -967,10 +960,10 @@ class Ut extends p {
967
960
  }
968
961
  send(t) {
969
962
  let r = "/api/email";
970
- return typeof t.body == "object" && (r += `/${t.body.template}`), this.api.request({ url: r, body: t }).then((n) => (this.emit("SENT", t), n));
963
+ return typeof t.body == "object" && (r += `/${t.body.template}`), this.api.request({ url: r, body: t }).then((s) => (this.emit("SENT", t), s));
971
964
  }
972
965
  }
973
- class Ct extends p {
966
+ class Ct extends d {
974
967
  constructor(t) {
975
968
  super();
976
969
  a(this, "api");
@@ -1003,7 +996,7 @@ class Ct extends p {
1003
996
  }).then(() => this.emit("DELETE", t));
1004
997
  }
1005
998
  }
1006
- class Bt {
999
+ class jt {
1007
1000
  constructor(e, t) {
1008
1001
  a(this, "api");
1009
1002
  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)));
@@ -1028,11 +1021,11 @@ class Bt {
1028
1021
  return this.api.request({ url: "/api/logs/server", method: "DELETE" });
1029
1022
  }
1030
1023
  clientLogs(e, t) {
1031
- const r = [e ? `length=${e}` : void 0, t ? `page=${t}` : void 0].filter((n) => !!n).join("&");
1024
+ const r = [e ? `length=${e}` : void 0, t ? `page=${t}` : void 0].filter((s) => !!s).join("&");
1032
1025
  return this.api.request({ url: `/api/logs/client${r ? `?${r}` : ""}` });
1033
1026
  }
1034
1027
  serverLogs(e, t) {
1035
- const r = [e ? `length=${e}` : void 0, t ? `page=${t}` : void 0].filter((n) => !!n).join("&");
1028
+ const r = [e ? `length=${e}` : void 0, t ? `page=${t}` : void 0].filter((s) => !!s).join("&");
1036
1029
  return this.api.request({ url: `/api/logs/server${r ? `?${r}` : ""}` });
1037
1030
  }
1038
1031
  debug(...e) {
@@ -1056,31 +1049,32 @@ class Bt {
1056
1049
  });
1057
1050
  }
1058
1051
  }
1059
- class jt extends p {
1052
+ class kt extends d {
1060
1053
  constructor(t) {
1061
1054
  super();
1062
1055
  a(this, "api");
1063
1056
  this.api = typeof t == "string" ? new f(t) : t;
1064
1057
  }
1065
1058
  async handleResponse(t, r) {
1066
- const n = await t.blob();
1059
+ const s = await t.blob();
1067
1060
  if (r) {
1068
- const s = URL.createObjectURL(n);
1069
- Z(s, r.endsWith(".pdf") ? r : r + ".pdf"), URL.revokeObjectURL(s);
1061
+ const n = URL.createObjectURL(s);
1062
+ Z(n, r.endsWith(".pdf") ? r : r + ".pdf"), URL.revokeObjectURL(n);
1070
1063
  }
1071
- return this.emit("CREATE", n), n;
1064
+ return this.emit("CREATE", s), s;
1072
1065
  }
1073
- fromHtml(t, r = {}) {
1074
- return this.api.request({ url: "/api/pdf", body: { html: t } }).then((n) => this.handleResponse(n, r.download ? r.fileName || (/* @__PURE__ */ new Date()).toISOString() : void 0));
1066
+ generate(t, r = {}) {
1067
+ const s = t == null ? void 0 : t.template;
1068
+ return this.api.request({
1069
+ url: `/api/pdf${s ? `/${s}` : ""}`,
1070
+ body: s ? t == null ? void 0 : t.data : { html: t }
1071
+ }).then((n) => this.handleResponse(n, r.download ? r.fileName || (/* @__PURE__ */ new Date()).toISOString() : void 0));
1075
1072
  }
1076
1073
  fromUrl(t, r = {}) {
1077
- return this.api.request({ url: `/api/pdf?url=${t}` }).then((n) => this.handleResponse(n, r.download ? r.fileName || (/* @__PURE__ */ new Date()).toISOString() : void 0));
1078
- }
1079
- fromTemplate(t, r, n = {}) {
1080
- return this.api.request({ url: `/api/pdf/${t}`, body: { data: r } }).then((s) => this.handleResponse(s, n.download ? n.fileName || (/* @__PURE__ */ new Date()).toISOString() : void 0));
1074
+ return this.api.request({ url: `/api/pdf?url=${t}` }).then((s) => this.handleResponse(s, r.download ? r.fileName || (/* @__PURE__ */ new Date()).toISOString() : void 0));
1081
1075
  }
1082
1076
  }
1083
- const D = class D {
1077
+ const q = class q {
1084
1078
  constructor(e) {
1085
1079
  a(this, "api");
1086
1080
  a(this, "url");
@@ -1096,7 +1090,7 @@ const D = class D {
1096
1090
  ((r = this.connection) == null ? void 0 : r.readyState) < 2 && this.connection.close(), this.connection = new WebSocket(this.url + (this.api.token ? `?token=${this.api.token}` : ""));
1097
1091
  const t = setTimeout(() => {
1098
1092
  this.open || (this.connection.close(), console.error("Momentum connection timeout"), e > 0 && this.connect(e - 1));
1099
- }, D.timeout);
1093
+ }, q.timeout);
1100
1094
  this.connection.onclose = () => this.open = !1, this.connection.onmessage = this.handle, this.connection.onopen = () => {
1101
1095
  this.open = !0, clearTimeout(t), console.debug("Connected to Momentum");
1102
1096
  };
@@ -1112,9 +1106,9 @@ const D = class D {
1112
1106
  }));
1113
1107
  }
1114
1108
  };
1115
- a(D, "timeout", 1e4);
1116
- let F = D;
1117
- class kt extends p {
1109
+ a(q, "timeout", 1e4);
1110
+ let F = q;
1111
+ class Bt extends d {
1118
1112
  constructor(t) {
1119
1113
  super();
1120
1114
  a(this, "api");
@@ -1128,36 +1122,35 @@ class kt extends p {
1128
1122
  }
1129
1123
  list(t) {
1130
1124
  const r = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll("//", "/");
1131
- return this.api.request({ url: r + "?list" }).then((n) => (this.emit("LIST", t, n), n));
1125
+ return this.api.request({ url: r + "?list" }).then((s) => (this.emit("LIST", t, s), s));
1132
1126
  }
1133
1127
  open(t, r = "_blank") {
1134
- const n = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll(/\/{2,}/g, "/"), s = `${this.api.url}${n}${this.api.token ? `?token=${this.api.token}` : ""}`;
1135
- return r ? (this.emit("OPEN", t), window.open(s, r)) : s;
1128
+ const s = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll(/\/{2,}/g, "/"), n = `${this.api.url}${s}${this.api.token ? `?token=${this.api.token}` : ""}`;
1129
+ return r ? (this.emit("OPEN", t), window.open(n, r)) : n;
1136
1130
  }
1137
1131
  mkdir(t) {
1138
1132
  const r = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll(/\/{2,}/g, "/");
1139
1133
  return this.api.request({ url: r + "?directory", method: "POST" });
1140
1134
  }
1141
1135
  download(t, r = {}) {
1142
- return new bt((n, s, o) => {
1136
+ return new Et((s, n, o) => {
1143
1137
  const u = ("/api/storage/" + t).replaceAll("//", "/");
1144
1138
  this.api.request({ ...r, url: u, skipConverting: !0 }).then((c) => {
1145
- var d;
1146
- if (!c.ok)
1147
- return s(c.statusText);
1148
- const l = c.headers.get("Content-Length"), y = l ? parseInt(l, 10) : 0;
1149
- let T = [], g = 0;
1150
- const E = (d = c.body) == null ? void 0 : d.getReader(), _ = (M) => {
1139
+ var p;
1140
+ if (!c.ok) return n(c.statusText);
1141
+ const l = c.headers.get("Content-Length"), g = l ? parseInt(l, 10) : 0;
1142
+ let T = [], b = 0;
1143
+ const y = (p = c.body) == null ? void 0 : p.getReader(), A = (M) => {
1151
1144
  if (M.done) {
1152
1145
  o(1);
1153
- const w = new Blob(T), I = r.downloadAs || new URL(c.url).pathname.split("/").pop(), Y = URL.createObjectURL(w);
1154
- Z(Y, I.includes(".") ? I : I + ".zip"), URL.revokeObjectURL(Y), this.emit("DOWNLOAD", t, w), n(w);
1146
+ const w = new Blob(T), D = r.downloadAs || new URL(c.url).pathname.split("/").pop(), Y = URL.createObjectURL(w);
1147
+ Z(Y, D.includes(".") ? D : D + ".zip"), URL.revokeObjectURL(Y), this.emit("DOWNLOAD", t, w), s(w);
1155
1148
  } else {
1156
1149
  const w = M.value;
1157
- T.push(w), g += w.length, o(g / y), E.read().then(_);
1150
+ T.push(w), b += w.length, o(b / g), y.read().then(A);
1158
1151
  }
1159
1152
  };
1160
- E == null || E.read().then(_);
1153
+ y == null || y.read().then(A);
1161
1154
  });
1162
1155
  });
1163
1156
  }
@@ -1167,18 +1160,17 @@ class kt extends p {
1167
1160
  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 () => {
1168
1161
  u(Array.from(c.files)), c.remove();
1169
1162
  }, document.body.appendChild(c), c.click();
1170
- })), !t || Array.isArray(t) && !t.length)
1171
- return [];
1172
- const s = new FormData(), o = ("/api/storage/" + (typeof r == "string" ? r : r == null ? void 0 : r.path)).replaceAll("//", "/");
1173
- return (Array.isArray(t) ? t : [t]).forEach((u) => s.append("file", u)), this.api.request({ url: o, body: s }).then((u) => (this.emit("UPLOAD", u), u));
1163
+ })), !t || Array.isArray(t) && !t.length) return [];
1164
+ 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));
1174
1166
  }
1175
1167
  }
1176
- class Gt extends p {
1168
+ class Gt extends d {
1177
1169
  constructor(t) {
1178
1170
  super();
1179
1171
  a(this, "api");
1180
1172
  a(this, "listed", !1);
1181
- a(this, "$cache", new q([]));
1173
+ a(this, "$cache", new U([]));
1182
1174
  this.api = typeof t == "string" ? new f(t) : t;
1183
1175
  }
1184
1176
  get cache() {
@@ -1200,25 +1192,24 @@ class Gt extends p {
1200
1192
  }
1201
1193
  read(t, r = !1) {
1202
1194
  if (!r) {
1203
- const n = this.cache.find((s) => s.username == t);
1204
- if (n)
1205
- return Promise.resolve(n);
1195
+ const s = this.cache.find((n) => n.username == t);
1196
+ if (s) return Promise.resolve(s);
1206
1197
  }
1207
- return this.api.request({ url: `/api/users/${t}` }).then((n) => (n && (this.cache = { ...this.cache, [n.username]: n }), this.emit("READ", n), n));
1198
+ return this.api.request({ url: `/api/users/${t}` }).then((s) => (s && (this.cache = { ...this.cache, [s.username]: s }), this.emit("READ", s), s));
1208
1199
  }
1209
1200
  update(t) {
1210
1201
  return this.api.request({
1211
1202
  url: `/api/users/${t.username}`,
1212
1203
  method: "PATCH",
1213
1204
  body: t
1214
- }).then((r) => (r && (this.cache = this.cache.filter((n) => n.username != t.username).concat([r])), this.emit("UPDATE", r), r));
1205
+ }).then((r) => (r && (this.cache = this.cache.filter((s) => s.username != t.username).concat([r])), this.emit("UPDATE", r), r));
1215
1206
  }
1216
1207
  }
1217
- class Nt extends p {
1208
+ class Nt extends d {
1218
1209
  constructor(t) {
1219
1210
  super();
1220
1211
  a(this, "api");
1221
- a(this, "$cache", new q({}));
1212
+ a(this, "$cache", new U({}));
1222
1213
  this.api = typeof t == "string" ? new f(t) : t;
1223
1214
  }
1224
1215
  get cache() {
@@ -1228,7 +1219,7 @@ class Nt extends p {
1228
1219
  this.$cache.next(t);
1229
1220
  }
1230
1221
  list(t = !1) {
1231
- return this.api.request({ url: "/api/settings" + (t ? "?detailed" : "") }).then((r) => (this.cache = t ? Object.values(r).reduce((n, s) => ({ ...n, [s.key]: s.value }), {}) : r, this.emit("LIST", r), r));
1222
+ return this.api.request({ url: "/api/settings" + (t ? "?detailed" : "") }).then((r) => (this.cache = t ? Object.values(r).reduce((s, n) => ({ ...s, [n.key]: n.value }), {}) : r, this.emit("LIST", r), r));
1232
1223
  }
1233
1224
  delete(t) {
1234
1225
  return this.api.request({ url: `/api/settings/${t}`, method: "DELETE" }).then(() => {
@@ -1236,13 +1227,13 @@ class Nt extends p {
1236
1227
  });
1237
1228
  }
1238
1229
  read(t, r = !1) {
1239
- return !r && this.cache[t] ? Promise.resolve(this.cache[t]) : this.api.request({ url: `/api/settings/${t}` }).then((n) => (n && (this.cache = { ...this.cache, [n.key]: n }), this.emit("READ", n), n));
1230
+ return !r && this.cache[t] ? Promise.resolve(this.cache[t]) : this.api.request({ url: `/api/settings/${t}` }).then((s) => (s && (this.cache = { ...this.cache, [s.key]: s }), this.emit("READ", s), s));
1240
1231
  }
1241
1232
  update(t) {
1242
1233
  return this.api.request({ url: `/api/settings/${t.key}`, body: t }).then((r) => (r && (this.cache = { ...this.cache, [r.key]: r.value }), this.emit("UPDATE", r), r));
1243
1234
  }
1244
1235
  }
1245
- class Ht extends p {
1236
+ class Ht extends d {
1246
1237
  constructor(t) {
1247
1238
  super();
1248
1239
  a(this, "api");
@@ -1255,14 +1246,14 @@ class Ht extends p {
1255
1246
  }
1256
1247
  list(t) {
1257
1248
  const r = ("/api/static/" + t).replaceAll("//", "/");
1258
- return this.api.request({ url: r }).then((n) => (this.emit("LIST", t, n), n));
1249
+ return this.api.request({ url: r }).then((s) => (this.emit("LIST", t, s), s));
1259
1250
  }
1260
1251
  upload(t, r = "/") {
1261
- const n = new FormData();
1262
- return (Array.isArray(t) ? t : [t]).forEach((s) => n.append("file", s)), this.api.request({ url: "/api/static" + r, body: n }).then((s) => (this.emit("UPLOAD", s), s));
1252
+ const s = new FormData();
1253
+ return (Array.isArray(t) ? t : [t]).forEach((n) => s.append("file", n)), this.api.request({ url: "/api/static" + r, body: s }).then((n) => (this.emit("UPLOAD", n), n));
1263
1254
  }
1264
1255
  }
1265
- class Ft extends p {
1256
+ class Ft extends d {
1266
1257
  constructor(t, r) {
1267
1258
  super();
1268
1259
  a(this, "api");
@@ -1278,37 +1269,36 @@ class Ft extends p {
1278
1269
  a(this, "static");
1279
1270
  a(this, "storage");
1280
1271
  a(this, "users");
1281
- this.api = new f(t, r == null ? void 0 : r.api), this.actions = new Pt(this.api), this.auth = new qt(this.api, {
1272
+ this.api = new f(t, r == null ? void 0 : r.api), this.actions = new Pt(this.api), this.auth = new Ut(this.api, {
1282
1273
  persist: (r == null ? void 0 : r.persist) ?? !0,
1283
1274
  loginUi: r == null ? void 0 : r.loginUi
1284
- }), this.data = new It(this.api), this.email = new Ut(this.api), this.groups = new Ct(this.api), this.logger = new Bt(this.api, r == null ? void 0 : r.logLevel), this.pdf = new jt(this.api), this.settings = new Nt(this.api), this.static = new Ht(this.api), this.storage = new kt(this.api), this.users = new Gt(this.api), r != null && r.socket && (this.socket = new F(this.api)), this.api.on("*", (n, ...s) => this.emit(`API::${n}`, ...s)), this.actions.on("*", (n, ...s) => this.emit(`ACTIONS::${n}`, ...s)), this.auth.on("*", (n, ...s) => this.emit(`AUTH::${n}`, ...s)), this.data.on("*", (n, ...s) => this.emit(`DATA::${n}`, ...s)), this.email.on("*", (n, ...s) => this.emit(`EMAIL::${n}`, ...s)), this.groups.on("*", (n, ...s) => this.emit(`GROUPS::${n}`, ...s)), this.pdf.on("*", (n, ...s) => this.emit(`PDF::${n}`, ...s)), this.settings.on("*", (n, ...s) => this.emit(`SETTINGS::${n}`, ...s)), this.static.on("*", (n, ...s) => this.emit(`STATIC::${n}`, ...s)), this.storage.on("*", (n, ...s) => this.emit(`STORAGE::${n}`, ...s)), this.users.on("*", (n, ...s) => this.emit(`USERS::${n}`, ...s)), this.users.on("*", (n, ...s) => {
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) => {
1285
1276
  var o;
1286
- if (Array.isArray(s[0])) {
1287
- const u = s[0].find((c) => {
1277
+ if (Array.isArray(n[0])) {
1278
+ const u = n[0].find((c) => {
1288
1279
  var l;
1289
1280
  return c._id == ((l = this.auth.user) == null ? void 0 : l._id);
1290
1281
  });
1291
1282
  u && (this.auth.user = u);
1292
- } else
1293
- s[0]._id == ((o = this.auth.user) == null ? void 0 : o._id) && (this.auth.user = s[0]);
1283
+ } else n[0]._id == ((o = this.auth.user) == null ? void 0 : o._id) && (this.auth.user = n[0]);
1294
1284
  });
1295
1285
  }
1296
1286
  }
1297
1287
  export {
1298
- Dt as ActionType,
1288
+ qt as ActionType,
1299
1289
  Pt as Actions,
1300
1290
  f as Api,
1301
- qt as Auth,
1302
- It as Data,
1303
- Ut as Email,
1291
+ Ut as Auth,
1292
+ Dt as Data,
1293
+ It as Email,
1304
1294
  Ct as Groups,
1305
- Bt as Logger,
1295
+ jt as Logger,
1306
1296
  Ft as Momentum,
1307
- jt as Pdf,
1297
+ kt as Pdf,
1308
1298
  Nt as Settings,
1309
1299
  F as Socket,
1310
1300
  Ht as Static,
1311
- kt as Storage,
1301
+ Bt as Storage,
1312
1302
  Gt as Users
1313
1303
  };
1314
1304
  //# sourceMappingURL=momentum.mjs.map