@ztimson/momentum 0.0.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.
@@ -0,0 +1,1287 @@
1
+ var pt = Object.defineProperty;
2
+ var dt = (i, e, t) => e in i ? pt(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t;
3
+ var a = (i, e, t) => (dt(i, typeof e != "symbol" ? e + "" : e, t), t);
4
+ var ft = Object.defineProperty, mt = (i, e, t) => e in i ? ft(i, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : i[e] = t, h = (i, e, t) => (mt(i, typeof e != "symbol" ? e + "" : e, t), t);
5
+ function Et(i, e = !1) {
6
+ if (i == null)
7
+ throw new Error("Cannot clean a NULL value");
8
+ return Array.isArray(i) ? i = i.filter((t) => t != null) : Object.entries(i).forEach(([t, r]) => {
9
+ (e && r === void 0 || !e && r == null) && delete i[t];
10
+ }), i;
11
+ }
12
+ function X(i, e) {
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((s) => X(i[s], e[s]));
15
+ }
16
+ function yt(i, e) {
17
+ const t = document.createElement("a");
18
+ t.href = i, t.download = e, document.body.appendChild(t), t.click(), document.body.removeChild(t);
19
+ }
20
+ class p {
21
+ constructor() {
22
+ h(this, "listeners", {});
23
+ }
24
+ static emit(e, ...t) {
25
+ (this.listeners["*"] || []).forEach((r) => r(e, ...t)), (this.listeners[e.toString()] || []).forEach((r) => r(...t));
26
+ }
27
+ static off(e, t) {
28
+ const r = e.toString();
29
+ this.listeners[r] = (this.listeners[r] || []).filter((s) => s === t);
30
+ }
31
+ static on(e, t) {
32
+ var r;
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
+ }
36
+ static once(e, t) {
37
+ return new Promise((r) => {
38
+ const s = this.on(e, (...n) => {
39
+ r(n.length == 1 ? n[0] : n), t && t(...n), s();
40
+ });
41
+ });
42
+ }
43
+ emit(e, ...t) {
44
+ (this.listeners["*"] || []).forEach((r) => r(e, ...t)), (this.listeners[e] || []).forEach((r) => r(...t));
45
+ }
46
+ off(e, t) {
47
+ this.listeners[e] = (this.listeners[e] || []).filter((r) => r === t);
48
+ }
49
+ on(e, t) {
50
+ var r;
51
+ return this.listeners[e] || (this.listeners[e] = []), (r = this.listeners[e]) == null || r.push(t), () => this.off(e, t);
52
+ }
53
+ once(e, t) {
54
+ return new Promise((r) => {
55
+ const s = this.on(e, (...n) => {
56
+ r(n.length == 1 ? n[0] : n), t && t(...n), s();
57
+ });
58
+ });
59
+ }
60
+ }
61
+ h(p, "listeners", {});
62
+ const C = class b {
63
+ constructor(e = {}) {
64
+ h(this, "interceptors", {}), h(this, "headers", {}), this.opts = e, this.headers = e.headers || {}, e.interceptors && e.interceptors.forEach((t) => b.addInterceptor(t));
65
+ }
66
+ static addInterceptor(e) {
67
+ const t = Object.keys(b.interceptors).length.toString();
68
+ return b.interceptors[t] = e, () => {
69
+ b.interceptors[t] = null;
70
+ };
71
+ }
72
+ addInterceptor(e) {
73
+ const t = Object.keys(this.interceptors).length.toString();
74
+ return this.interceptors[t] = e, () => {
75
+ this.interceptors[t] = null;
76
+ };
77
+ }
78
+ async request(e = {}) {
79
+ var t, r;
80
+ if (!this.opts.url && !e.url)
81
+ throw new Error("URL needs to be set");
82
+ const s = ((t = e.url) != null && t.startsWith("http") ? e.url : (this.opts.url || "") + (e.url || "")).replace(/([^:]\/)\/+/g, "$1"), n = Et({
83
+ "Content-Type": e.body && !(e.body instanceof FormData) ? "application/json" : void 0,
84
+ ...b.headers,
85
+ ...this.headers,
86
+ ...e.headers
87
+ });
88
+ return fetch(s, {
89
+ headers: n,
90
+ method: e.method || (e.body ? "POST" : "GET"),
91
+ body: (r = n["Content-Type"]) != null && r.startsWith("application/json") && e.body ? JSON.stringify(e.body) : e.body
92
+ }).then(async (o) => {
93
+ var u, c;
94
+ for (let f of [...Object.values(b.interceptors), ...Object.values(this.interceptors)])
95
+ await new Promise((w) => f(o, () => w()));
96
+ if (!o.ok)
97
+ throw new Error(o.statusText);
98
+ return !e.skipConverting && (u = o.headers.get("Content-Type")) != null && u.startsWith("application/json") ? await o.json() : !e.skipConverting && (c = o.headers.get("Content-Type")) != null && c.startsWith("text/plain") ? await o.text() : o;
99
+ });
100
+ }
101
+ };
102
+ h(C, "interceptors", {}), h(C, "headers", {});
103
+ let Z = C;
104
+ Z.addInterceptor((i, e) => {
105
+ if (i.status == 200)
106
+ return e();
107
+ throw i.status == 400 ? new tt(i.statusText) : i.status == 401 ? new et(i.statusText) : i.status == 403 ? new rt(i.statusText) : i.status == 404 ? new it(i.statusText) : i.status == 500 ? new st(i.statusText) : new v(i.statusText, i.status);
108
+ });
109
+ class v extends Error {
110
+ constructor(e, t) {
111
+ super(e), h(this, "_code"), t != null && (this._code = t);
112
+ }
113
+ get code() {
114
+ return this._code || this.constructor.code;
115
+ }
116
+ set code(e) {
117
+ this._code = e;
118
+ }
119
+ static from(e) {
120
+ const t = Number(e.statusCode) ?? Number(e.code), r = new this(e.message || e.toString());
121
+ return Object.assign(r, {
122
+ stack: e.stack,
123
+ ...e,
124
+ code: t ?? void 0
125
+ });
126
+ }
127
+ static instanceof(e) {
128
+ return e.constructor.code != null;
129
+ }
130
+ toString() {
131
+ return this.message || super.toString();
132
+ }
133
+ }
134
+ h(v, "code", 500);
135
+ class tt extends v {
136
+ constructor(e = "Bad Request") {
137
+ super(e);
138
+ }
139
+ static instanceof(e) {
140
+ return e.constructor.code == this.code;
141
+ }
142
+ }
143
+ h(tt, "code", 400);
144
+ class et extends v {
145
+ constructor(e = "Unauthorized") {
146
+ super(e);
147
+ }
148
+ static instanceof(e) {
149
+ return e.constructor.code == this.code;
150
+ }
151
+ }
152
+ h(et, "code", 401);
153
+ class rt extends v {
154
+ constructor(e = "Forbidden") {
155
+ super(e);
156
+ }
157
+ static instanceof(e) {
158
+ return e.constructor.code == this.code;
159
+ }
160
+ }
161
+ h(rt, "code", 403);
162
+ class it extends v {
163
+ constructor(e = "Not Found") {
164
+ super(e);
165
+ }
166
+ static instanceof(e) {
167
+ return e.constructor.code == this.code;
168
+ }
169
+ }
170
+ h(it, "code", 404);
171
+ class st extends v {
172
+ constructor(e = "Internal Server Error") {
173
+ super(e);
174
+ }
175
+ static instanceof(e) {
176
+ return e.constructor.code == this.code;
177
+ }
178
+ }
179
+ h(st, "code", 500);
180
+ const O = {
181
+ CLEAR: "\x1B[0m",
182
+ BRIGHT: "\x1B[1m",
183
+ DIM: "\x1B[2m",
184
+ UNDERSCORE: "\x1B[4m",
185
+ BLINK: "\x1B[5m",
186
+ REVERSE: "\x1B[7m",
187
+ HIDDEN: "\x1B[8m"
188
+ }, $ = {
189
+ BLACK: "\x1B[30m",
190
+ RED: "\x1B[31m",
191
+ GREEN: "\x1B[32m",
192
+ YELLOW: "\x1B[33m",
193
+ BLUE: "\x1B[34m",
194
+ MAGENTA: "\x1B[35m",
195
+ CYAN: "\x1B[36m",
196
+ LIGHT_GREY: "\x1B[37m",
197
+ GREY: "\x1B[90m",
198
+ LIGHT_RED: "\x1B[91m",
199
+ LIGHT_GREEN: "\x1B[92m",
200
+ LIGHT_YELLOW: "\x1B[93m",
201
+ LIGHT_BLUE: "\x1B[94m",
202
+ LIGHT_MAGENTA: "\x1B[95m",
203
+ LIGHT_CYAN: "\x1B[96m",
204
+ WHITE: "\x1B[97m"
205
+ };
206
+ var L = /* @__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))(L || {});
207
+ const gt = class m extends p {
208
+ constructor(e) {
209
+ super(), this.namespace = e;
210
+ }
211
+ pad(e, t, r, s = !1) {
212
+ const n = e.toString(), o = t - n.length;
213
+ if (o <= 0)
214
+ return n;
215
+ const u = Array(~~(o / r.length)).fill(r).join("");
216
+ return s ? n + u : u + n;
217
+ }
218
+ format(...e) {
219
+ const t = /* @__PURE__ */ new Date();
220
+ return `${`${t.getFullYear()}-${t.getMonth() + 1}-${t.getDate()} ${this.pad(t.getHours().toString(), 2, "0")}:${this.pad(t.getMinutes().toString(), 2, "0")}:${this.pad(t.getSeconds().toString(), 2, "0")}.${this.pad(t.getMilliseconds().toString(), 3, "0", !0)}`}${this.namespace ? ` [${this.namespace}]` : ""} ${e.join(" ")}`;
221
+ }
222
+ debug(...e) {
223
+ if (m.LOG_LEVEL < 4)
224
+ return;
225
+ const t = this.format(...e);
226
+ m.emit(4, t), console.debug($.LIGHT_GREY + t + O.CLEAR);
227
+ }
228
+ log(...e) {
229
+ if (m.LOG_LEVEL < 3)
230
+ return;
231
+ const t = this.format(...e);
232
+ m.emit(3, t), console.log(O.CLEAR + t);
233
+ }
234
+ info(...e) {
235
+ if (m.LOG_LEVEL < 2)
236
+ return;
237
+ const t = this.format(...e);
238
+ m.emit(2, t), console.info($.BLUE + t + O.CLEAR);
239
+ }
240
+ warn(...e) {
241
+ if (m.LOG_LEVEL < 1)
242
+ return;
243
+ const t = this.format(...e);
244
+ m.emit(1, t), console.warn($.YELLOW + t + O.CLEAR);
245
+ }
246
+ error(...e) {
247
+ if (m.LOG_LEVEL < 0)
248
+ return;
249
+ const t = this.format(...e);
250
+ m.emit(0, t), console.error($.RED + t + O.CLEAR);
251
+ }
252
+ };
253
+ h(gt, "LOG_LEVEL", 4);
254
+ class bt extends Promise {
255
+ constructor(e) {
256
+ super((t, r) => e(
257
+ (s) => t(s),
258
+ (s) => r(s),
259
+ (s) => this.progress = s
260
+ )), h(this, "listeners", []), h(this, "_progress", 0);
261
+ }
262
+ get progress() {
263
+ return this._progress;
264
+ }
265
+ set progress(e) {
266
+ e != this._progress && (this._progress = e, this.listeners.forEach((t) => t(e)));
267
+ }
268
+ onProgress(e) {
269
+ return this.listeners.push(e), this;
270
+ }
271
+ }
272
+ class d extends Z {
273
+ constructor(t = location.origin, r = {}) {
274
+ r.url = t;
275
+ super(r);
276
+ a(this, "emitter", new p());
277
+ a(this, "_token", null);
278
+ a(this, "emit", this.emitter.emit.bind(this.emitter));
279
+ a(this, "off", this.emitter.off.bind(this.emitter));
280
+ a(this, "on", this.emitter.on.bind(this.emitter));
281
+ a(this, "once", this.emitter.once.bind(this.emitter));
282
+ this.url = t, this.opts = r;
283
+ }
284
+ get token() {
285
+ return this._token;
286
+ }
287
+ set token(t) {
288
+ t != this._token && (this._token = t, this.headers.Authorization = `Bearer ${t}`, this.emit("TOKEN", t));
289
+ }
290
+ request(t) {
291
+ const r = super.request(t).then((s) => (this.emit("RESPONSE", s, t), s)).catch((s) => {
292
+ throw this.emit("REJECTED", s, t), s;
293
+ });
294
+ return this.emit("REQUEST", r, t), r;
295
+ }
296
+ }
297
+ var j = function(i, e) {
298
+ return j = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(t, r) {
299
+ t.__proto__ = r;
300
+ } || function(t, r) {
301
+ for (var s in r)
302
+ Object.prototype.hasOwnProperty.call(r, s) && (t[s] = r[s]);
303
+ }, j(i, e);
304
+ };
305
+ function x(i, e) {
306
+ if (typeof e != "function" && e !== null)
307
+ throw new TypeError("Class extends value " + String(e) + " is not a constructor or null");
308
+ j(i, e);
309
+ function t() {
310
+ this.constructor = i;
311
+ }
312
+ i.prototype = e === null ? Object.create(e) : (t.prototype = e.prototype, new t());
313
+ }
314
+ function k(i) {
315
+ var e = typeof Symbol == "function" && Symbol.iterator, t = e && i[e], r = 0;
316
+ if (t)
317
+ return t.call(i);
318
+ if (i && typeof i.length == "number")
319
+ return {
320
+ next: function() {
321
+ return i && r >= i.length && (i = void 0), { value: i && i[r++], done: !i };
322
+ }
323
+ };
324
+ throw new TypeError(e ? "Object is not iterable." : "Symbol.iterator is not defined.");
325
+ }
326
+ function G(i, e) {
327
+ var t = typeof Symbol == "function" && i[Symbol.iterator];
328
+ if (!t)
329
+ return i;
330
+ var r = t.call(i), s, n = [], o;
331
+ try {
332
+ for (; (e === void 0 || e-- > 0) && !(s = r.next()).done; )
333
+ n.push(s.value);
334
+ } catch (u) {
335
+ o = { error: u };
336
+ } finally {
337
+ try {
338
+ s && !s.done && (t = r.return) && t.call(r);
339
+ } finally {
340
+ if (o)
341
+ throw o.error;
342
+ }
343
+ }
344
+ return n;
345
+ }
346
+ function N(i, e, t) {
347
+ if (t || arguments.length === 2)
348
+ for (var r = 0, s = e.length, n; r < s; r++)
349
+ (n || !(r in e)) && (n || (n = Array.prototype.slice.call(e, 0, r)), n[r] = e[r]);
350
+ return i.concat(n || Array.prototype.slice.call(e));
351
+ }
352
+ function y(i) {
353
+ return typeof i == "function";
354
+ }
355
+ function nt(i) {
356
+ var e = function(r) {
357
+ Error.call(r), r.stack = new Error().stack;
358
+ }, t = i(e);
359
+ return t.prototype = Object.create(Error.prototype), t.prototype.constructor = t, t;
360
+ }
361
+ var U = nt(function(i) {
362
+ return function(t) {
363
+ i(this), this.message = t ? t.length + ` errors occurred during unsubscription:
364
+ ` + t.map(function(r, s) {
365
+ return s + 1 + ") " + r.toString();
366
+ }).join(`
367
+ `) : "", this.name = "UnsubscriptionError", this.errors = t;
368
+ };
369
+ });
370
+ function H(i, e) {
371
+ if (i) {
372
+ var t = i.indexOf(e);
373
+ 0 <= t && i.splice(t, 1);
374
+ }
375
+ }
376
+ var P = function() {
377
+ function i(e) {
378
+ this.initialTeardown = e, this.closed = !1, this._parentage = null, this._finalizers = null;
379
+ }
380
+ return i.prototype.unsubscribe = function() {
381
+ var e, t, r, s, n;
382
+ if (!this.closed) {
383
+ this.closed = !0;
384
+ var o = this._parentage;
385
+ if (o)
386
+ if (this._parentage = null, Array.isArray(o))
387
+ try {
388
+ for (var u = k(o), c = u.next(); !c.done; c = u.next()) {
389
+ var f = c.value;
390
+ f.remove(this);
391
+ }
392
+ } catch (l) {
393
+ e = { error: l };
394
+ } finally {
395
+ try {
396
+ c && !c.done && (t = u.return) && t.call(u);
397
+ } finally {
398
+ if (e)
399
+ throw e.error;
400
+ }
401
+ }
402
+ else
403
+ o.remove(this);
404
+ var w = this.initialTeardown;
405
+ if (y(w))
406
+ try {
407
+ w();
408
+ } catch (l) {
409
+ n = l instanceof U ? l.errors : [l];
410
+ }
411
+ var T = this._finalizers;
412
+ if (T) {
413
+ this._finalizers = null;
414
+ try {
415
+ for (var g = k(T), E = g.next(); !E.done; E = g.next()) {
416
+ var _ = E.value;
417
+ try {
418
+ V(_);
419
+ } catch (l) {
420
+ n = n ?? [], l instanceof U ? n = N(N([], G(n)), G(l.errors)) : n.push(l);
421
+ }
422
+ }
423
+ } catch (l) {
424
+ r = { error: l };
425
+ } finally {
426
+ try {
427
+ E && !E.done && (s = g.return) && s.call(g);
428
+ } finally {
429
+ if (r)
430
+ throw r.error;
431
+ }
432
+ }
433
+ }
434
+ if (n)
435
+ throw new U(n);
436
+ }
437
+ }, i.prototype.add = function(e) {
438
+ var t;
439
+ if (e && e !== this)
440
+ if (this.closed)
441
+ V(e);
442
+ else {
443
+ if (e instanceof i) {
444
+ if (e.closed || e._hasParent(this))
445
+ return;
446
+ e._addParent(this);
447
+ }
448
+ (this._finalizers = (t = this._finalizers) !== null && t !== void 0 ? t : []).push(e);
449
+ }
450
+ }, i.prototype._hasParent = function(e) {
451
+ var t = this._parentage;
452
+ return t === e || Array.isArray(t) && t.includes(e);
453
+ }, i.prototype._addParent = function(e) {
454
+ var t = this._parentage;
455
+ this._parentage = Array.isArray(t) ? (t.push(e), t) : t ? [t, e] : e;
456
+ }, i.prototype._removeParent = function(e) {
457
+ var t = this._parentage;
458
+ t === e ? this._parentage = null : Array.isArray(t) && H(t, e);
459
+ }, i.prototype.remove = function(e) {
460
+ var t = this._finalizers;
461
+ t && H(t, e), e instanceof i && e._removeParent(this);
462
+ }, i.EMPTY = function() {
463
+ var e = new i();
464
+ return e.closed = !0, e;
465
+ }(), i;
466
+ }(), ot = P.EMPTY;
467
+ function ut(i) {
468
+ return i instanceof P || i && "closed" in i && y(i.remove) && y(i.add) && y(i.unsubscribe);
469
+ }
470
+ function V(i) {
471
+ y(i) ? i() : i.unsubscribe();
472
+ }
473
+ var at = {
474
+ onUnhandledError: null,
475
+ onStoppedNotification: null,
476
+ Promise: void 0,
477
+ useDeprecatedSynchronousErrorHandling: !1,
478
+ useDeprecatedNextContext: !1
479
+ }, ct = {
480
+ setTimeout: function(i, e) {
481
+ for (var t = [], r = 2; r < arguments.length; r++)
482
+ t[r - 2] = arguments[r];
483
+ return setTimeout.apply(void 0, N([i, e], G(t)));
484
+ },
485
+ clearTimeout: function(i) {
486
+ var e = ct.delegate;
487
+ return ((e == null ? void 0 : e.clearTimeout) || clearTimeout)(i);
488
+ },
489
+ delegate: void 0
490
+ };
491
+ function vt(i) {
492
+ ct.setTimeout(function() {
493
+ throw i;
494
+ });
495
+ }
496
+ function K() {
497
+ }
498
+ function R(i) {
499
+ i();
500
+ }
501
+ var ht = function(i) {
502
+ x(e, i);
503
+ function e(t) {
504
+ var r = i.call(this) || this;
505
+ return r.isStopped = !1, t ? (r.destination = t, ut(t) && t.add(r)) : r.destination = Tt, r;
506
+ }
507
+ return e.create = function(t, r, s) {
508
+ return new W(t, r, s);
509
+ }, e.prototype.next = function(t) {
510
+ this.isStopped || this._next(t);
511
+ }, e.prototype.error = function(t) {
512
+ this.isStopped || (this.isStopped = !0, this._error(t));
513
+ }, e.prototype.complete = function() {
514
+ this.isStopped || (this.isStopped = !0, this._complete());
515
+ }, e.prototype.unsubscribe = function() {
516
+ this.closed || (this.isStopped = !0, i.prototype.unsubscribe.call(this), this.destination = null);
517
+ }, e.prototype._next = function(t) {
518
+ this.destination.next(t);
519
+ }, e.prototype._error = function(t) {
520
+ try {
521
+ this.destination.error(t);
522
+ } finally {
523
+ this.unsubscribe();
524
+ }
525
+ }, e.prototype._complete = function() {
526
+ try {
527
+ this.destination.complete();
528
+ } finally {
529
+ this.unsubscribe();
530
+ }
531
+ }, e;
532
+ }(P), wt = Function.prototype.bind;
533
+ function B(i, e) {
534
+ return wt.call(i, e);
535
+ }
536
+ var St = function() {
537
+ function i(e) {
538
+ this.partialObserver = e;
539
+ }
540
+ return i.prototype.next = function(e) {
541
+ var t = this.partialObserver;
542
+ if (t.next)
543
+ try {
544
+ t.next(e);
545
+ } catch (r) {
546
+ A(r);
547
+ }
548
+ }, i.prototype.error = function(e) {
549
+ var t = this.partialObserver;
550
+ if (t.error)
551
+ try {
552
+ t.error(e);
553
+ } catch (r) {
554
+ A(r);
555
+ }
556
+ else
557
+ A(e);
558
+ }, i.prototype.complete = function() {
559
+ var e = this.partialObserver;
560
+ if (e.complete)
561
+ try {
562
+ e.complete();
563
+ } catch (t) {
564
+ A(t);
565
+ }
566
+ }, i;
567
+ }(), W = function(i) {
568
+ x(e, i);
569
+ function e(t, r, s) {
570
+ var n = i.call(this) || this, o;
571
+ if (y(t) || !t)
572
+ o = {
573
+ next: t ?? void 0,
574
+ error: r ?? void 0,
575
+ complete: s ?? void 0
576
+ };
577
+ else {
578
+ var u;
579
+ n && at.useDeprecatedNextContext ? (u = Object.create(t), u.unsubscribe = function() {
580
+ return n.unsubscribe();
581
+ }, o = {
582
+ next: t.next && B(t.next, u),
583
+ error: t.error && B(t.error, u),
584
+ complete: t.complete && B(t.complete, u)
585
+ }) : o = t;
586
+ }
587
+ return n.destination = new St(o), n;
588
+ }
589
+ return e;
590
+ }(ht);
591
+ function A(i) {
592
+ vt(i);
593
+ }
594
+ function Lt(i) {
595
+ throw i;
596
+ }
597
+ var Tt = {
598
+ closed: !0,
599
+ next: K,
600
+ error: Lt,
601
+ complete: K
602
+ }, Ot = function() {
603
+ return typeof Symbol == "function" && Symbol.observable || "@@observable";
604
+ }();
605
+ function xt(i) {
606
+ return i;
607
+ }
608
+ function _t(i) {
609
+ return i.length === 0 ? xt : i.length === 1 ? i[0] : function(t) {
610
+ return i.reduce(function(r, s) {
611
+ return s(r);
612
+ }, t);
613
+ };
614
+ }
615
+ var z = function() {
616
+ function i(e) {
617
+ e && (this._subscribe = e);
618
+ }
619
+ return i.prototype.lift = function(e) {
620
+ var t = new i();
621
+ return t.source = this, t.operator = e, t;
622
+ }, i.prototype.subscribe = function(e, t, r) {
623
+ var s = this, n = At(e) ? e : new W(e, t, r);
624
+ return R(function() {
625
+ var o = s, u = o.operator, c = o.source;
626
+ n.add(u ? u.call(n, c) : c ? s._subscribe(n) : s._trySubscribe(n));
627
+ }), n;
628
+ }, i.prototype._trySubscribe = function(e) {
629
+ try {
630
+ return this._subscribe(e);
631
+ } catch (t) {
632
+ e.error(t);
633
+ }
634
+ }, i.prototype.forEach = function(e, t) {
635
+ var r = this;
636
+ return t = J(t), new t(function(s, n) {
637
+ var o = new W({
638
+ next: function(u) {
639
+ try {
640
+ e(u);
641
+ } catch (c) {
642
+ n(c), o.unsubscribe();
643
+ }
644
+ },
645
+ error: n,
646
+ complete: s
647
+ });
648
+ r.subscribe(o);
649
+ });
650
+ }, i.prototype._subscribe = function(e) {
651
+ var t;
652
+ return (t = this.source) === null || t === void 0 ? void 0 : t.subscribe(e);
653
+ }, i.prototype[Ot] = function() {
654
+ return this;
655
+ }, i.prototype.pipe = function() {
656
+ for (var e = [], t = 0; t < arguments.length; t++)
657
+ e[t] = arguments[t];
658
+ return _t(e)(this);
659
+ }, i.prototype.toPromise = function(e) {
660
+ var t = this;
661
+ return e = J(e), new e(function(r, s) {
662
+ var n;
663
+ t.subscribe(function(o) {
664
+ return n = o;
665
+ }, function(o) {
666
+ return s(o);
667
+ }, function() {
668
+ return r(n);
669
+ });
670
+ });
671
+ }, i.create = function(e) {
672
+ return new i(e);
673
+ }, i;
674
+ }();
675
+ function J(i) {
676
+ var e;
677
+ return (e = i ?? at.Promise) !== null && e !== void 0 ? e : Promise;
678
+ }
679
+ function $t(i) {
680
+ return i && y(i.next) && y(i.error) && y(i.complete);
681
+ }
682
+ function At(i) {
683
+ return i && i instanceof ht || $t(i) && ut(i);
684
+ }
685
+ var Rt = nt(function(i) {
686
+ return function() {
687
+ i(this), this.name = "ObjectUnsubscribedError", this.message = "object unsubscribed";
688
+ };
689
+ }), lt = function(i) {
690
+ x(e, i);
691
+ function e() {
692
+ var t = i.call(this) || this;
693
+ return t.closed = !1, t.currentObservers = null, t.observers = [], t.isStopped = !1, t.hasError = !1, t.thrownError = null, t;
694
+ }
695
+ return e.prototype.lift = function(t) {
696
+ var r = new Q(this, this);
697
+ return r.operator = t, r;
698
+ }, e.prototype._throwIfClosed = function() {
699
+ if (this.closed)
700
+ throw new Rt();
701
+ }, e.prototype.next = function(t) {
702
+ var r = this;
703
+ R(function() {
704
+ var s, n;
705
+ if (r._throwIfClosed(), !r.isStopped) {
706
+ r.currentObservers || (r.currentObservers = Array.from(r.observers));
707
+ try {
708
+ for (var o = k(r.currentObservers), u = o.next(); !u.done; u = o.next()) {
709
+ var c = u.value;
710
+ c.next(t);
711
+ }
712
+ } catch (f) {
713
+ s = { error: f };
714
+ } finally {
715
+ try {
716
+ u && !u.done && (n = o.return) && n.call(o);
717
+ } finally {
718
+ if (s)
719
+ throw s.error;
720
+ }
721
+ }
722
+ }
723
+ });
724
+ }, e.prototype.error = function(t) {
725
+ var r = this;
726
+ R(function() {
727
+ if (r._throwIfClosed(), !r.isStopped) {
728
+ r.hasError = r.isStopped = !0, r.thrownError = t;
729
+ for (var s = r.observers; s.length; )
730
+ s.shift().error(t);
731
+ }
732
+ });
733
+ }, e.prototype.complete = function() {
734
+ var t = this;
735
+ R(function() {
736
+ if (t._throwIfClosed(), !t.isStopped) {
737
+ t.isStopped = !0;
738
+ for (var r = t.observers; r.length; )
739
+ r.shift().complete();
740
+ }
741
+ });
742
+ }, e.prototype.unsubscribe = function() {
743
+ this.isStopped = this.closed = !0, this.observers = this.currentObservers = null;
744
+ }, Object.defineProperty(e.prototype, "observed", {
745
+ get: function() {
746
+ var t;
747
+ return ((t = this.observers) === null || t === void 0 ? void 0 : t.length) > 0;
748
+ },
749
+ enumerable: !1,
750
+ configurable: !0
751
+ }), e.prototype._trySubscribe = function(t) {
752
+ return this._throwIfClosed(), i.prototype._trySubscribe.call(this, t);
753
+ }, e.prototype._subscribe = function(t) {
754
+ return this._throwIfClosed(), this._checkFinalizedStatuses(t), this._innerSubscribe(t);
755
+ }, e.prototype._innerSubscribe = function(t) {
756
+ var r = this, s = this, n = s.hasError, o = s.isStopped, u = s.observers;
757
+ return n || o ? ot : (this.currentObservers = null, u.push(t), new P(function() {
758
+ r.currentObservers = null, H(u, t);
759
+ }));
760
+ }, e.prototype._checkFinalizedStatuses = function(t) {
761
+ var r = this, s = r.hasError, n = r.thrownError, o = r.isStopped;
762
+ s ? t.error(n) : o && t.complete();
763
+ }, e.prototype.asObservable = function() {
764
+ var t = new z();
765
+ return t.source = this, t;
766
+ }, e.create = function(t, r) {
767
+ return new Q(t, r);
768
+ }, e;
769
+ }(z), Q = function(i) {
770
+ x(e, i);
771
+ function e(t, r) {
772
+ var s = i.call(this) || this;
773
+ return s.destination = t, s.source = r, s;
774
+ }
775
+ return e.prototype.next = function(t) {
776
+ var r, s;
777
+ (s = (r = this.destination) === null || r === void 0 ? void 0 : r.next) === null || s === void 0 || s.call(r, t);
778
+ }, e.prototype.error = function(t) {
779
+ var r, s;
780
+ (s = (r = this.destination) === null || r === void 0 ? void 0 : r.error) === null || s === void 0 || s.call(r, t);
781
+ }, e.prototype.complete = function() {
782
+ var t, r;
783
+ (r = (t = this.destination) === null || t === void 0 ? void 0 : t.complete) === null || r === void 0 || r.call(t);
784
+ }, e.prototype._subscribe = function(t) {
785
+ var r, s;
786
+ return (s = (r = this.source) === null || r === void 0 ? void 0 : r.subscribe(t)) !== null && s !== void 0 ? s : ot;
787
+ }, e;
788
+ }(lt), I = function(i) {
789
+ x(e, i);
790
+ function e(t) {
791
+ var r = i.call(this) || this;
792
+ return r._value = t, r;
793
+ }
794
+ return Object.defineProperty(e.prototype, "value", {
795
+ get: function() {
796
+ return this.getValue();
797
+ },
798
+ enumerable: !1,
799
+ configurable: !0
800
+ }), e.prototype._subscribe = function(t) {
801
+ var r = i.prototype._subscribe.call(this, t);
802
+ return !r.closed && t.next(this._value), r;
803
+ }, e.prototype.getValue = function() {
804
+ var t = this, r = t.hasError, s = t.thrownError, n = t._value;
805
+ if (r)
806
+ throw s;
807
+ return this._throwIfClosed(), n;
808
+ }, e.prototype.next = function(t) {
809
+ i.prototype.next.call(this, this._value = t);
810
+ }, e;
811
+ }(lt), 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 || {});
812
+ class Pt extends p {
813
+ constructor(t) {
814
+ super();
815
+ a(this, "api");
816
+ a(this, "$cache", new I([]));
817
+ this.api = typeof t == "string" ? new d(t) : t;
818
+ }
819
+ get cache() {
820
+ return this.$cache.value;
821
+ }
822
+ set cache(t) {
823
+ this.$cache.next(t);
824
+ }
825
+ delete(t) {
826
+ return this.api.request({ url: `/api/actions/${t}`, method: "DELETE" }).then(() => {
827
+ this.cache = this.cache.filter((r) => r._id != t), this.emit("DELETE", t);
828
+ });
829
+ }
830
+ list() {
831
+ return this.api.request({ url: "/api/actions" }).then((t) => (this.cache = t, this.emit("LIST", t), t));
832
+ }
833
+ read(t, r = !1) {
834
+ const s = this.cache.find((n) => n._id == t);
835
+ 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));
836
+ }
837
+ run(t, r = {}) {
838
+ return this.api.request({ url: ("/api/actions/run/" + t).replaceAll("//", "/"), ...r });
839
+ }
840
+ runById(t, r = {}) {
841
+ const s = typeof t == "string" ? t : t._id;
842
+ return this.api.request({ url: "/api/actions/run-by-id/" + s, ...r });
843
+ }
844
+ update(t) {
845
+ return this.api.request({
846
+ url: `/api/actions${t._id ? `/${t._id}` : ""}`,
847
+ method: "POST",
848
+ body: t
849
+ }).then((r) => (r && (this.cache = this.cache.filter((s) => s._id != r._id).concat([r])), this.emit("UPDATE", r), r));
850
+ }
851
+ }
852
+ class It extends p {
853
+ constructor(t, r) {
854
+ var s;
855
+ super();
856
+ a(this, "api");
857
+ a(this, "storageKey");
858
+ a(this, "$user", new I(void 0));
859
+ if (this.opts = r, this.api = typeof t == "string" ? new d(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) => {
860
+ var o;
861
+ (o = this.opts) != null && o.persist && (n ? localStorage.setItem(this.storageKey, n) : localStorage.removeItem(this.storageKey)), n ? this.whoAmI(n, !0) : this.user = null;
862
+ }), r != null && r.persist) {
863
+ const n = localStorage.getItem(this.storageKey);
864
+ n ? this.api.token = n : this.user = null;
865
+ } else
866
+ this.user = null;
867
+ }
868
+ get user() {
869
+ return this.$user.value;
870
+ }
871
+ set user(t) {
872
+ if (!X(this.user, t)) {
873
+ const r = t || null;
874
+ this.$user.next(r), this.emit("USER", r);
875
+ }
876
+ }
877
+ knownHost(t = location.origin) {
878
+ return t.startsWith("/") ? Promise.resolve() : this.api.request({ url: `/api/auth/known-host?host=${encodeURI(new URL(t).origin)}` });
879
+ }
880
+ login(t, r) {
881
+ return this.api.request({
882
+ url: "/api/auth/login",
883
+ headers: { Authorization: void 0 },
884
+ body: {
885
+ username: t,
886
+ password: r
887
+ }
888
+ }).then(async (s) => (this.api.token = s.token, await this.once("USER")));
889
+ }
890
+ loginRedirect(t = location.origin) {
891
+ return new Promise((r, s) => {
892
+ var o;
893
+ const n = window.open(encodeURI(`${(o = this.opts) == null ? void 0 : o.loginUi}?redirect=postmessage&host=${t}`), "_blank");
894
+ if (!n)
895
+ return s("Unable to open login");
896
+ n.addEventListener("message", (u) => {
897
+ var c;
898
+ if (!((c = u == null ? void 0 : u.data) != null && c.token))
899
+ return s("Unknown response from login");
900
+ this.api.token = u.data.token, r(u.data.token), n.close();
901
+ });
902
+ });
903
+ }
904
+ logout() {
905
+ this.api.token = null, this.user = null, this.emit("LOGOUT");
906
+ }
907
+ async register(t) {
908
+ const r = await this.api.request({ url: "/api/auth/register", body: { ...t } });
909
+ return this.emit("REGISTER", t), r;
910
+ }
911
+ async reset(t, r) {
912
+ await this.api.request({
913
+ url: "/api/auth/reset",
914
+ headers: { Authorization: r ? `Bearer ${r}` : void 0 },
915
+ body: {
916
+ email: r ? void 0 : t,
917
+ password: r ? t : void 0
918
+ }
919
+ }), this.emit(r ? "RESET_COMPLETE" : "RESET_REQUEST", r || t);
920
+ }
921
+ async whoAmI(t, r = !1) {
922
+ t || (t = this.api.token);
923
+ const s = await this.api.request({
924
+ url: "/api/auth/whoami",
925
+ headers: t ? { Authorization: `Bearer ${t}` } : void 0
926
+ });
927
+ return r && (this.api.token = t, this.user = (s == null ? void 0 : s.user) || null, s && this.emit("LOGIN", s.user)), s;
928
+ }
929
+ }
930
+ class qt extends p {
931
+ constructor(t) {
932
+ super();
933
+ a(this, "api");
934
+ this.api = typeof t == "string" ? new d(t) : t;
935
+ }
936
+ delete(t, r) {
937
+ return this.api.request({
938
+ url: `/api/data/${t}/${r}`,
939
+ method: "DELETE"
940
+ }).then(() => this.emit("DELETE", t, r));
941
+ }
942
+ get(t, r) {
943
+ return this.api.request({ url: `/api/data/${t}${r ? `/${r}` : ""}` }).then((s) => (this.emit("GET", t, s), s));
944
+ }
945
+ raw(t, r, s, n) {
946
+ return this.api.request({
947
+ url: `/api/data/${t}`,
948
+ body: {
949
+ operand: r,
950
+ query: s,
951
+ options: n
952
+ }
953
+ }).then((o) => (this.emit("RAW", t, o), o));
954
+ }
955
+ set(t, r, s = !1) {
956
+ return this.api.request({
957
+ url: `/api/data/${t}/${r._id || ""}`,
958
+ method: s ? "PATCH" : "POST",
959
+ body: r
960
+ }).then((n) => (this.emit("SET", t, r), n));
961
+ }
962
+ }
963
+ class Ut extends p {
964
+ constructor(t) {
965
+ super();
966
+ a(this, "api");
967
+ this.api = typeof t == "string" ? new d(t) : t;
968
+ }
969
+ send(t) {
970
+ let r = "/api/email/send";
971
+ return typeof t.body == "object" && (r += `/${t.body.template}`), this.api.request({ url: r, body: t }).then((s) => (this.emit("SENT", t), s));
972
+ }
973
+ }
974
+ class Bt extends p {
975
+ constructor(t) {
976
+ super();
977
+ a(this, "api");
978
+ this.api = typeof t == "string" ? new d(t) : t;
979
+ }
980
+ create(t) {
981
+ return this.api.request({
982
+ url: `/api/groups/${t.name}`,
983
+ method: "POST",
984
+ body: t
985
+ }).then((r) => (this.emit("CREATE", r), r));
986
+ }
987
+ list() {
988
+ return this.api.request({ url: "/api/groups" }).then((t) => (this.emit("LIST", t), t));
989
+ }
990
+ read(t) {
991
+ return this.api.request({ url: `/api/groups/${t}` }).then((r) => (this.emit("READ", r), r));
992
+ }
993
+ update(t) {
994
+ return this.api.request({
995
+ url: `/api/groups/${t.name}`,
996
+ method: "PATCH",
997
+ body: t
998
+ }).then((r) => (this.emit("UPDATE", r), r));
999
+ }
1000
+ delete(t) {
1001
+ return this.api.request({
1002
+ url: `/api/groups/${t}`,
1003
+ method: "DELETE"
1004
+ }).then(() => this.emit("DELETE", t));
1005
+ }
1006
+ }
1007
+ class Ct {
1008
+ constructor(e, t) {
1009
+ a(this, "api");
1010
+ this.api = typeof e == "string" ? new d(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)));
1011
+ }
1012
+ buildLog(e, t) {
1013
+ return {
1014
+ time: (/* @__PURE__ */ new Date()).getTime(),
1015
+ level: e,
1016
+ log: t,
1017
+ ctx: {
1018
+ url: location.href,
1019
+ res: [window.innerWidth, window.innerHeight]
1020
+ }
1021
+ };
1022
+ }
1023
+ clearClientLogs() {
1024
+ return this.api.request({ url: "/api/logs/client", method: "DELETE" });
1025
+ }
1026
+ clearServerLogs() {
1027
+ return this.api.request({ url: "/api/logs/server", method: "DELETE" });
1028
+ }
1029
+ clientLogs(e, t) {
1030
+ const r = [e ? `length=${e}` : void 0, t ? `page=${t}` : void 0].filter((s) => !!s).join("&");
1031
+ return this.api.request({ url: `/api/logs/client${r ? `?${r}` : ""}` });
1032
+ }
1033
+ serverLogs(e, t) {
1034
+ const r = [e ? `length=${e}` : void 0, t ? `page=${t}` : void 0].filter((s) => !!s).join("&");
1035
+ return this.api.request({ url: `/api/logs/server${r ? `?${r}` : ""}` });
1036
+ }
1037
+ debug(...e) {
1038
+ return this.api.request({ url: "/api/logs/client", body: this.buildLog(L.DEBUG, e) }).catch(() => {
1039
+ });
1040
+ }
1041
+ log(...e) {
1042
+ return this.api.request({ url: "/api/logs/client", body: this.buildLog(L.LOG, e) }).catch(() => {
1043
+ });
1044
+ }
1045
+ info(...e) {
1046
+ return this.api.request({ url: "/api/logs/client", body: this.buildLog(L.INFO, e) }).catch(() => {
1047
+ });
1048
+ }
1049
+ warn(...e) {
1050
+ return this.api.request({ url: "/api/logs/client", body: this.buildLog(L.WARN, e) }).catch(() => {
1051
+ });
1052
+ }
1053
+ error(...e) {
1054
+ return this.api.request({ url: "/api/logs/client", body: this.buildLog(L.ERROR, e) }).catch(() => {
1055
+ });
1056
+ }
1057
+ }
1058
+ const D = class D {
1059
+ constructor(e) {
1060
+ a(this, "api");
1061
+ a(this, "url");
1062
+ a(this, "connection");
1063
+ a(this, "open", !1);
1064
+ this.api = typeof e == "string" ? new d(e) : e, this.url = this.api.url.replace("http", "ws"), this.api.on("TOKEN", () => this.connect()), this.api.token || this.connect();
1065
+ }
1066
+ close() {
1067
+ console.debug("Disconnected from Momentum"), this.open = !1, this.connection.close();
1068
+ }
1069
+ connect(e = 3) {
1070
+ var r;
1071
+ ((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}` : ""));
1072
+ const t = setTimeout(() => {
1073
+ this.open || (this.connection.close(), console.error("Momentum connection timeout"), e > 0 && this.connect(e - 1));
1074
+ }, D.timeout);
1075
+ this.connection.onclose = () => this.open = !1, this.connection.onmessage = this.handle, this.connection.onopen = () => {
1076
+ this.open = !0, clearTimeout(t), console.debug("Connected to Momentum");
1077
+ };
1078
+ }
1079
+ handle(...e) {
1080
+ console.log(e);
1081
+ }
1082
+ send(e, t) {
1083
+ this.connection.send(JSON.stringify({
1084
+ token: this.api.token,
1085
+ channel: e,
1086
+ payload: t
1087
+ }));
1088
+ }
1089
+ };
1090
+ a(D, "timeout", 1e4);
1091
+ let M = D;
1092
+ class jt extends p {
1093
+ constructor(t) {
1094
+ super();
1095
+ a(this, "api");
1096
+ this.api = typeof t == "string" ? new d(t) : t;
1097
+ }
1098
+ delete(t) {
1099
+ const r = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll("//", "/");
1100
+ return this.api.request({ url: r, method: "DELETE" }).then(() => {
1101
+ this.emit("DELETE", r);
1102
+ });
1103
+ }
1104
+ list(t) {
1105
+ const r = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll("//", "/");
1106
+ return this.api.request({ url: r + "?list" }).then((s) => (this.emit("LIST", t, s), s));
1107
+ }
1108
+ open(t, r = "_blank") {
1109
+ 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}` : ""}`;
1110
+ return r ? (this.emit("OPEN", t), window.open(n, r)) : n;
1111
+ }
1112
+ mkdir(t) {
1113
+ const r = (t.startsWith("/api/storage/") ? t : "/api/storage/" + t).replaceAll(/\/{2,}/g, "/");
1114
+ return this.api.request({ url: r + "?directory", method: "POST" });
1115
+ }
1116
+ download(t, r = {}) {
1117
+ return new bt((s, n, o) => {
1118
+ const u = ("/api/storage/" + t).replaceAll("//", "/");
1119
+ this.api.request({ ...r, url: u, skipConverting: !0 }).then((c) => {
1120
+ var l;
1121
+ if (!c.ok)
1122
+ return n(c.statusText);
1123
+ const f = c.headers.get("Content-Length"), w = f ? parseInt(f, 10) : 0;
1124
+ let T = [], g = 0;
1125
+ const E = (l = c.body) == null ? void 0 : l.getReader(), _ = (F) => {
1126
+ if (F.done) {
1127
+ o(1);
1128
+ const S = new Blob(T), q = r.downloadName || new URL(c.url).pathname.split("/").pop(), Y = URL.createObjectURL(S);
1129
+ yt(Y, q.includes(".") ? q : q + ".zip"), URL.revokeObjectURL(Y), this.emit("DOWNLOAD", t, S), s(S);
1130
+ } else {
1131
+ const S = F.value;
1132
+ T.push(S), g += S.length, o(g / w), E.read().then(_);
1133
+ }
1134
+ };
1135
+ E == null || E.read().then(_);
1136
+ });
1137
+ });
1138
+ }
1139
+ async upload(t, r = "") {
1140
+ if (t || (t = await new Promise((u) => {
1141
+ const c = document.createElement("input");
1142
+ 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 () => {
1143
+ u(Array.from(c.files)), c.remove();
1144
+ }, document.body.appendChild(c), c.click();
1145
+ })), !t || Array.isArray(t) && !t.length)
1146
+ return [];
1147
+ const n = new FormData(), o = ("/api/storage/" + (typeof r == "string" ? r : r == null ? void 0 : r.path)).replaceAll("//", "/");
1148
+ 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));
1149
+ }
1150
+ }
1151
+ class kt extends p {
1152
+ constructor(t) {
1153
+ super();
1154
+ a(this, "api");
1155
+ a(this, "listed", !1);
1156
+ a(this, "$cache", new I([]));
1157
+ this.api = typeof t == "string" ? new d(t) : t;
1158
+ }
1159
+ get cache() {
1160
+ return this.$cache.value;
1161
+ }
1162
+ set cache(t) {
1163
+ this.$cache.next(t);
1164
+ }
1165
+ delete(t) {
1166
+ return this.api.request({
1167
+ url: `/api/users/${t}`,
1168
+ method: "DELETE"
1169
+ }).then(() => {
1170
+ this.cache = this.cache.filter((r) => r.username != t), this.emit("DELETE", t);
1171
+ });
1172
+ }
1173
+ list(t = !1) {
1174
+ return !t && this.listed ? Promise.resolve(this.cache) : this.api.request({ url: "/api/users" }).then((r) => (this.cache = r, this.listed = !0, this.emit("LIST", r), r));
1175
+ }
1176
+ read(t, r = !1) {
1177
+ if (!r) {
1178
+ const s = this.cache.find((n) => n.username == t);
1179
+ if (s)
1180
+ return Promise.resolve(s);
1181
+ }
1182
+ return this.api.request({ url: `/api/users/${t}` }).then((s) => (s && (this.cache = { ...this.cache, [s.username]: s }), this.emit("READ", s), s));
1183
+ }
1184
+ update(t) {
1185
+ return this.api.request({
1186
+ url: `/api/users/${t.username}`,
1187
+ method: "PATCH",
1188
+ body: t
1189
+ }).then((r) => (r && (this.cache = this.cache.filter((s) => s.username != t.username).concat([r])), this.emit("UPDATE", r), r));
1190
+ }
1191
+ }
1192
+ class Gt extends p {
1193
+ constructor(t) {
1194
+ super();
1195
+ a(this, "api");
1196
+ a(this, "$cache", new I({}));
1197
+ this.api = typeof t == "string" ? new d(t) : t;
1198
+ }
1199
+ get cache() {
1200
+ return this.$cache.value;
1201
+ }
1202
+ set cache(t) {
1203
+ this.$cache.next(t);
1204
+ }
1205
+ list(t = !1) {
1206
+ 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));
1207
+ }
1208
+ delete(t) {
1209
+ return this.api.request({ url: `/api/settings/${t}`, method: "DELETE" }).then(() => {
1210
+ this.cache = { ...this.cache, [t]: void 0 }, this.emit("DELETE", t);
1211
+ });
1212
+ }
1213
+ read(t, r = !1) {
1214
+ 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));
1215
+ }
1216
+ update(t) {
1217
+ 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));
1218
+ }
1219
+ }
1220
+ class Nt extends p {
1221
+ constructor(t) {
1222
+ super();
1223
+ a(this, "api");
1224
+ this.api = typeof t == "string" ? new d(t) : t;
1225
+ }
1226
+ delete(t) {
1227
+ return this.api.request({ url: `/api/static/${t}`, method: "DELETE" }).then(() => {
1228
+ this.emit("DELETE", t);
1229
+ });
1230
+ }
1231
+ list(t) {
1232
+ const r = ("/api/static/" + t).replaceAll("//", "/");
1233
+ return this.api.request({ url: r }).then((s) => (this.emit("LIST", t, s), s));
1234
+ }
1235
+ upload(t, r = "/") {
1236
+ const s = new FormData();
1237
+ 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));
1238
+ }
1239
+ }
1240
+ class Wt extends p {
1241
+ constructor(t, r) {
1242
+ super();
1243
+ a(this, "api");
1244
+ a(this, "actions");
1245
+ a(this, "auth");
1246
+ a(this, "data");
1247
+ a(this, "email");
1248
+ a(this, "groups");
1249
+ a(this, "logger");
1250
+ a(this, "settings");
1251
+ a(this, "socket");
1252
+ a(this, "static");
1253
+ a(this, "storage");
1254
+ a(this, "users");
1255
+ this.api = new d(t, r == null ? void 0 : r.api), this.actions = new Pt(this.api), this.auth = new It(this.api, {
1256
+ persist: (r == null ? void 0 : r.persist) ?? !0,
1257
+ loginUi: r == null ? void 0 : r.loginUi
1258
+ }), this.data = new qt(this.api), this.email = new Ut(this.api), this.groups = new Bt(this.api), this.logger = new Ct(this.api, r == null ? void 0 : r.logLevel), this.settings = new Gt(this.api), this.static = new Nt(this.api), this.storage = new jt(this.api), this.users = new kt(this.api), r != null && r.socket && (this.socket = new M(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.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) => {
1259
+ var o;
1260
+ if (Array.isArray(n[0])) {
1261
+ const u = n[0].find((c) => {
1262
+ var f;
1263
+ return c._id == ((f = this.auth.user) == null ? void 0 : f._id);
1264
+ });
1265
+ u && (this.auth.user = u);
1266
+ } else
1267
+ n[0]._id == ((o = this.auth.user) == null ? void 0 : o._id) && (this.auth.user = n[0]);
1268
+ });
1269
+ }
1270
+ }
1271
+ export {
1272
+ Dt as ActionType,
1273
+ Pt as Actions,
1274
+ d as Api,
1275
+ It as Auth,
1276
+ qt as Data,
1277
+ Ut as Email,
1278
+ Bt as Groups,
1279
+ Ct as Logger,
1280
+ Wt as Momentum,
1281
+ Gt as Settings,
1282
+ M as Socket,
1283
+ Nt as Static,
1284
+ jt as Storage,
1285
+ kt as Users
1286
+ };
1287
+ //# sourceMappingURL=momentum.mjs.map