@ztimson/momentum 0.21.0 → 0.27.2

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