@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/README.md +2 -1
- package/dist/auth.d.ts +2 -21
- package/dist/auth.d.ts.map +1 -1
- package/dist/groups.d.ts +9 -1
- package/dist/groups.d.ts.map +1 -1
- package/dist/momentum.cjs +2 -2
- package/dist/momentum.cjs.map +1 -1
- package/dist/momentum.mjs +131 -128
- package/dist/momentum.mjs.map +1 -1
- package/dist/users.d.ts +13 -1
- package/dist/users.d.ts.map +1 -1
- package/package.json +2 -2
package/dist/momentum.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
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
|
|
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
|
|
169
|
-
return s ? 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(
|
|
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(
|
|
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(
|
|
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(
|
|
203
|
+
m.emit(0, t), console.error(A.RED + t + O.CLEAR);
|
|
204
204
|
}
|
|
205
205
|
};
|
|
206
|
-
h(
|
|
207
|
-
class
|
|
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,
|
|
247
|
-
const o = Array.isArray(e.query) ? e.query : Object.keys(e.query).map((
|
|
248
|
-
s += (s.includes("?") ? "&" : "?") + o.map((
|
|
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((
|
|
263
|
-
const
|
|
264
|
-
var l,
|
|
265
|
-
return !e.skipConverting && (l = o.headers.get("Content-Type")) != null && l.startsWith("application/json") ? await o.json() : !e.skipConverting && (
|
|
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
|
|
269
|
-
const c = o.statusText || (typeof
|
|
270
|
-
throw c ? new Error(c) :
|
|
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
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
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}
|
|
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 (
|
|
334
|
-
o = { error:
|
|
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
|
|
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
|
|
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
|
|
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 =
|
|
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
|
|
401
|
-
if (E
|
|
400
|
+
var E = this.initialTeardown;
|
|
401
|
+
if (g(E))
|
|
402
402
|
try {
|
|
403
|
-
|
|
403
|
+
E();
|
|
404
404
|
} catch (p) {
|
|
405
|
-
n = p instanceof
|
|
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
|
|
412
|
+
var _ = y.value;
|
|
413
413
|
try {
|
|
414
|
-
V(
|
|
414
|
+
V(_);
|
|
415
415
|
} catch (p) {
|
|
416
|
-
n = n ?? [], p instanceof
|
|
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
|
|
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 &&
|
|
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
|
-
|
|
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 (
|
|
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
|
|
574
|
-
n && it.useDeprecatedNextContext ? (
|
|
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,
|
|
578
|
-
error: t.error && C(t.error,
|
|
579
|
-
complete: t.complete && C(t.complete,
|
|
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
|
|
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,
|
|
621
|
-
n.add(
|
|
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(
|
|
633
|
+
next: function(a) {
|
|
634
634
|
try {
|
|
635
|
-
e(
|
|
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
|
|
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
|
|
675
|
-
return i &&
|
|
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 ||
|
|
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),
|
|
704
|
-
var c =
|
|
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
|
-
|
|
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,
|
|
751
|
-
return n || o ? et : (this.currentObservers = null,
|
|
752
|
-
r.currentObservers = null, H(
|
|
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),
|
|
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
|
-
|
|
810
|
-
|
|
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
|
|
846
|
+
class It extends d {
|
|
847
847
|
constructor(t, r) {
|
|
848
848
|
var s;
|
|
849
849
|
super();
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
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.
|
|
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)
|
|
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", (
|
|
892
|
+
n.addEventListener("message", (a) => {
|
|
890
893
|
var c;
|
|
891
|
-
if (!((c =
|
|
892
|
-
this.api.token =
|
|
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
|
-
|
|
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
|
|
958
|
+
class Ut extends d {
|
|
956
959
|
constructor(t) {
|
|
957
960
|
super();
|
|
958
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
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
|
-
|
|
1112
|
+
u(q, "timeout", 1e4);
|
|
1110
1113
|
let F = q;
|
|
1111
1114
|
class Bt extends d {
|
|
1112
1115
|
constructor(t) {
|
|
1113
1116
|
super();
|
|
1114
|
-
|
|
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
|
|
1137
|
-
const
|
|
1138
|
-
this.api.request({ ...r, url:
|
|
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"),
|
|
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(),
|
|
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 /
|
|
1153
|
+
T.push(w), b += w.length, o(b / E), y.read().then(_);
|
|
1151
1154
|
}
|
|
1152
1155
|
};
|
|
1153
|
-
y == null || y.read().then(
|
|
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((
|
|
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
|
-
|
|
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((
|
|
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
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
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
|
-
|
|
1212
|
-
|
|
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
|
-
|
|
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
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
this.api = new f(t, r == null ? void 0 : r.api), this.actions = new Pt(this.api), this.auth = new
|
|
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
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
1294
|
+
It as Auth,
|
|
1292
1295
|
Dt as Data,
|
|
1293
|
-
|
|
1296
|
+
Ut as Email,
|
|
1294
1297
|
Ct as Groups,
|
|
1295
1298
|
jt as Logger,
|
|
1296
1299
|
Ft as Momentum,
|