@ztimson/momentum 0.45.1 → 0.47.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.
Files changed (45) hide show
  1. package/dist/actions.d.ts +3 -4
  2. package/dist/actions.d.ts.map +1 -1
  3. package/dist/ai.d.ts +2 -2
  4. package/dist/ai.d.ts.map +1 -1
  5. package/dist/analytics.d.ts +2 -2
  6. package/dist/analytics.d.ts.map +1 -1
  7. package/dist/api.d.ts +15 -10
  8. package/dist/api.d.ts.map +1 -1
  9. package/dist/auth.d.ts +8 -14
  10. package/dist/auth.d.ts.map +1 -1
  11. package/dist/client.d.ts +3 -3
  12. package/dist/client.d.ts.map +1 -1
  13. package/dist/core.d.ts +1 -1
  14. package/dist/core.d.ts.map +1 -1
  15. package/dist/data.d.ts +7 -8
  16. package/dist/data.d.ts.map +1 -1
  17. package/dist/email.d.ts +2 -2
  18. package/dist/email.d.ts.map +1 -1
  19. package/dist/groups.d.ts +3 -4
  20. package/dist/groups.d.ts.map +1 -1
  21. package/dist/index.cjs +538 -655
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.mjs +536 -653
  25. package/dist/logger.d.ts +35 -15
  26. package/dist/logger.d.ts.map +1 -1
  27. package/dist/momentum.d.ts +9 -6
  28. package/dist/momentum.d.ts.map +1 -1
  29. package/dist/payments.d.ts +2 -2
  30. package/dist/payments.d.ts.map +1 -1
  31. package/dist/pdf.d.ts +2 -2
  32. package/dist/pdf.d.ts.map +1 -1
  33. package/dist/settings.d.ts +2 -3
  34. package/dist/settings.d.ts.map +1 -1
  35. package/dist/sockets.d.ts +3 -3
  36. package/dist/sockets.d.ts.map +1 -1
  37. package/dist/static.d.ts +2 -3
  38. package/dist/static.d.ts.map +1 -1
  39. package/dist/storage.d.ts +2 -3
  40. package/dist/storage.d.ts.map +1 -1
  41. package/dist/users.d.ts +2 -3
  42. package/dist/users.d.ts.map +1 -1
  43. package/package.json +3 -2
  44. package/dist/pathed-events.d.ts +0 -121
  45. package/dist/pathed-events.d.ts.map +0 -1
package/dist/index.mjs CHANGED
@@ -1,27 +1,27 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- var it = Object.defineProperty;
5
- var ct = (r, t, e) => t in r ? it(r, t, { enumerable: true, configurable: true, writable: true, value: e }) : r[t] = e;
6
- var c = (r, t, e) => ct(r, typeof t != "symbol" ? t + "" : t, e);
7
- function ut(r, t = false) {
4
+ var st = Object.defineProperty;
5
+ var it = (r, t, e) => t in r ? st(r, t, { enumerable: true, configurable: true, writable: true, value: e }) : r[t] = e;
6
+ var c = (r, t, e) => it(r, typeof t != "symbol" ? t + "" : t, e);
7
+ function ot(r, t = false) {
8
8
  if (r == null) throw new Error("Cannot clean a NULL value");
9
9
  return Array.isArray(r) ? r = r.filter((e) => e != null) : Object.entries(r).forEach(([e, n]) => {
10
10
  (t && n === void 0 || !t && n == null) && delete r[e];
11
11
  }), r;
12
12
  }
13
- function A(r, t) {
13
+ function O(r, t) {
14
14
  const e = typeof r, n = typeof t;
15
- return e != "object" || r == null || n != "object" || t == null ? e == "function" && n == "function" ? r.toString() == t.toString() : r === t : Object.keys(r).length != Object.keys(t).length ? false : Object.keys(r).every((o) => A(r[o], t[o]));
15
+ return e != "object" || r == null || n != "object" || t == null ? e == "function" && n == "function" ? r.toString() == t.toString() : r === t : Object.keys(r).length != Object.keys(t).length ? false : Object.keys(r).every((i) => O(r[i], t[i]));
16
16
  }
17
- function M(r) {
17
+ function I(r) {
18
18
  try {
19
19
  return JSON.parse(r);
20
20
  } catch {
21
21
  return r;
22
22
  }
23
23
  }
24
- function Lt(r, t) {
24
+ function Ot(r, t) {
25
25
  let e = [];
26
26
  return JSON.stringify(r, (n, s) => {
27
27
  if (typeof s == "object" && s !== null) {
@@ -31,10 +31,10 @@ function Lt(r, t) {
31
31
  return s;
32
32
  }, t);
33
33
  }
34
- function ft(r) {
34
+ function m(r) {
35
35
  return Array.isArray(r) ? r : [r];
36
36
  }
37
- class B extends Array {
37
+ class S extends Array {
38
38
  /** Number of elements in set */
39
39
  get size() {
40
40
  return this.length;
@@ -69,7 +69,7 @@ class B extends Array {
69
69
  * @return {ASet<T>} Different elements
70
70
  */
71
71
  difference(t) {
72
- return new B(this.filter((e) => !t.has(e)));
72
+ return new S(this.filter((e) => !t.has(e)));
73
73
  }
74
74
  /**
75
75
  * Check if set includes element
@@ -85,7 +85,7 @@ class B extends Array {
85
85
  * @return {boolean} Set of common elements
86
86
  */
87
87
  intersection(t) {
88
- return new B(this.filter((e) => t.has(e)));
88
+ return new S(this.filter((e) => t.has(e)));
89
89
  }
90
90
  /**
91
91
  * Check if this set has no elements in common with the comparison set
@@ -117,7 +117,7 @@ class B extends Array {
117
117
  * @return {ASet<T>} New set of unique elements
118
118
  */
119
119
  symmetricDifference(t) {
120
- return new B([...this.difference(t), ...t.difference(this)]);
120
+ return new S([...this.difference(t), ...t.difference(this)]);
121
121
  }
122
122
  /**
123
123
  * Create joined list of elements included in this & the comparison set
@@ -125,23 +125,31 @@ class B extends Array {
125
125
  * @return {ASet<T>} New set of both previous sets combined
126
126
  */
127
127
  union(t) {
128
- return new B([...this, ...t]);
128
+ return new S([...this, ...t]);
129
129
  }
130
130
  }
131
- class Dt {
131
+ class Tt {
132
132
  /**
133
133
  * Create new cache
134
134
  *
135
135
  * @param {keyof T} key Default property to use as primary key
136
- * @param {number} ttl Default expiry in milliseconds
136
+ * @param options
137
137
  */
138
- constructor(t, e) {
138
+ constructor(t, e = {}) {
139
139
  c(this, "store", {});
140
140
  c(this, "complete", false);
141
141
  c(this, "values", this.all());
142
- return this.key = t, this.ttl = e, new Proxy(this, {
142
+ if (this.key = t, this.options = e, e.storageKey && !e.storage && (e.storage = localStorage), e.storageKey && e.storage) {
143
+ const n = e.storage.getItem(e.storageKey);
144
+ if (n)
145
+ try {
146
+ Object.assign(this.store, JSON.parse(n));
147
+ } catch {
148
+ }
149
+ }
150
+ return new Proxy(this, {
143
151
  get: (n, s) => s in n ? n[s] : n.store[s],
144
- set: (n, s, o) => (s in n ? n[s] = o : n.store[s] = o, true)
152
+ set: (n, s, i) => (s in n ? n[s] = i : n.store[s] = i, true)
145
153
  });
146
154
  }
147
155
  getKey(t) {
@@ -177,13 +185,19 @@ class Dt {
177
185
  addAll(t, e = true) {
178
186
  return t.forEach((n) => this.add(n)), this.complete = e, this;
179
187
  }
188
+ /**
189
+ * Remove all keys from cache
190
+ */
191
+ clear() {
192
+ this.store = {};
193
+ }
180
194
  /**
181
195
  * Delete an item from the cache
182
196
  *
183
197
  * @param {K} key Item's primary key
184
198
  */
185
199
  delete(t) {
186
- delete this.store[t];
200
+ delete this.store[t], this.options.storageKey && this.options.storage && this.options.storage.setItem(this.options.storageKey, JSON.stringify(this.store));
187
201
  }
188
202
  /**
189
203
  * Return cache as an array of key-value pairs
@@ -221,21 +235,21 @@ class Dt {
221
235
  *
222
236
  * @param {K} key Key item will be cached under
223
237
  * @param {T} value Item to cache
224
- * @param {number | undefined} ttl Override default expiry
238
+ * @param {number | undefined} ttl Override default expiry in seconds
225
239
  * @return {this}
226
240
  */
227
- set(t, e, n = this.ttl) {
228
- return this.store[t] = e, n && setTimeout(() => {
241
+ set(t, e, n = this.options.ttl) {
242
+ return this.store[t] = e, this.options.storageKey && this.options.storage && this.options.storage.setItem(this.options.storageKey, JSON.stringify(this.store)), n && setTimeout(() => {
229
243
  this.complete = false, this.delete(t);
230
- }, n), this;
244
+ }, n * 1e3), this;
231
245
  }
232
246
  }
233
- class E extends Promise {
247
+ class x extends Promise {
234
248
  constructor(e) {
235
249
  super((n, s) => e(
236
- (o) => n(o),
237
- (o) => s(o),
238
- (o) => this.progress = o
250
+ (i) => n(i),
251
+ (i) => s(i),
252
+ (i) => this.progress = i
239
253
  ));
240
254
  c(this, "listeners", []);
241
255
  c(this, "_progress", 0);
@@ -247,10 +261,10 @@ class E extends Promise {
247
261
  e != this._progress && (this._progress = e, this.listeners.forEach((n) => n(e)));
248
262
  }
249
263
  static from(e) {
250
- return e instanceof E ? e : new E((n, s) => e.then((...o) => n(...o)).catch((...o) => s(...o)));
264
+ return e instanceof x ? e : new x((n, s) => e.then((...i) => n(...i)).catch((...i) => s(...i)));
251
265
  }
252
266
  from(e) {
253
- const n = E.from(e);
267
+ const n = x.from(e);
254
268
  return this.onProgress((s) => n.progress = s), n;
255
269
  }
256
270
  onProgress(e) {
@@ -267,16 +281,16 @@ class E extends Promise {
267
281
  return this.from(super.finally(e));
268
282
  }
269
283
  }
270
- function Gt(r, t) {
271
- r instanceof Blob || (r = new Blob(ft(r)));
284
+ function Dt(r, t) {
285
+ r instanceof Blob || (r = new Blob(m(r)));
272
286
  const e = URL.createObjectURL(r);
273
- dt(e, t), URL.revokeObjectURL(e);
287
+ lt(e, t), URL.revokeObjectURL(e);
274
288
  }
275
- function dt(r, t) {
289
+ function lt(r, t) {
276
290
  const e = document.createElement("a");
277
291
  e.href = r, e.download = t || r.split("/").pop(), document.body.appendChild(e), e.click(), document.body.removeChild(e);
278
292
  }
279
- function Ut(r = {}) {
293
+ function Mt(r = {}) {
280
294
  return new Promise((t) => {
281
295
  const e = document.createElement("input");
282
296
  e.type = "file", e.accept = r.accept || "*", e.style.display = "none", e.multiple = !!r.multiple, e.onblur = e.onchange = async () => {
@@ -284,18 +298,18 @@ function Ut(r = {}) {
284
298
  }, document.body.appendChild(e), e.click();
285
299
  });
286
300
  }
287
- function qt(r, t = /* @__PURE__ */ new Date()) {
301
+ function kt(r, t = /* @__PURE__ */ new Date()) {
288
302
  (typeof t == "number" || typeof t == "string") && (t = new Date(t));
289
303
  const e = `${t.getFullYear()}-${(t.getMonth() + 1).toString().padStart(2, "0")}-${t.getDate().toString().padStart(2, "0")}_${t.getHours().toString().padStart(2, "0")}-${t.getMinutes().toString().padStart(2, "0")}-${t.getSeconds().toString().padStart(2, "0")}`;
290
304
  return e;
291
305
  }
292
- function Ft(r) {
293
- return new E((t, e, n) => {
294
- const s = new XMLHttpRequest(), o = new FormData();
295
- r.files.forEach((i) => o.append("file", i)), s.withCredentials = !!r.withCredentials, s.upload.addEventListener("progress", (i) => i.lengthComputable ? n(i.loaded / i.total) : null), s.addEventListener("loadend", () => t(M(s.responseText))), s.addEventListener("error", () => e(M(s.responseText))), s.addEventListener("timeout", () => e({ error: "Request timed out" })), s.open("POST", r.url), Object.entries(r.headers || {}).forEach(([i, a]) => s.setRequestHeader(i, a)), s.send(o);
306
+ function Pt(r) {
307
+ return new x((t, e, n) => {
308
+ const s = new XMLHttpRequest(), i = new FormData();
309
+ r.files.forEach((o) => i.append("file", o)), s.withCredentials = !!r.withCredentials, s.upload.addEventListener("progress", (o) => o.lengthComputable ? n(o.loaded / o.total) : null), s.addEventListener("loadend", () => t(I(s.responseText))), s.addEventListener("error", () => e(I(s.responseText))), s.addEventListener("timeout", () => e({ error: "Request timed out" })), s.open("POST", r.url), Object.entries(r.headers || {}).forEach(([o, a]) => s.setRequestHeader(o, a)), s.send(i);
296
310
  });
297
311
  }
298
- class _ {
312
+ class K {
299
313
  constructor() {
300
314
  c(this, "listeners", {});
301
315
  }
@@ -313,8 +327,8 @@ class _ {
313
327
  }
314
328
  static once(t, e) {
315
329
  return new Promise((n) => {
316
- const s = this.on(t, (...o) => {
317
- n(o.length == 1 ? o[0] : o), e && e(...o), s();
330
+ const s = this.on(t, (...i) => {
331
+ n(i.length == 1 ? i[0] : i), e && e(...i), s();
318
332
  });
319
333
  });
320
334
  }
@@ -330,14 +344,14 @@ class _ {
330
344
  }
331
345
  once(t, e) {
332
346
  return new Promise((n) => {
333
- const s = this.on(t, (...o) => {
334
- n(o.length == 1 ? o[0] : o), e && e(...o), s();
347
+ const s = this.on(t, (...i) => {
348
+ n(i.length == 1 ? i[0] : i), e && e(...i), s();
335
349
  });
336
350
  });
337
351
  }
338
352
  }
339
- c(_, "listeners", {});
340
- class p extends Error {
353
+ c(K, "listeners", {});
354
+ class g extends Error {
341
355
  constructor(e, n) {
342
356
  super(e);
343
357
  c(this, "_code");
@@ -364,8 +378,8 @@ class p extends Error {
364
378
  return this.message || super.toString();
365
379
  }
366
380
  }
367
- c(p, "code", 500);
368
- class W extends p {
381
+ c(g, "code", 500);
382
+ class W extends g {
369
383
  constructor(t = "Bad Request") {
370
384
  super(t);
371
385
  }
@@ -374,7 +388,7 @@ class W extends p {
374
388
  }
375
389
  }
376
390
  c(W, "code", 400);
377
- class J extends p {
391
+ class v extends g {
378
392
  constructor(t = "Unauthorized") {
379
393
  super(t);
380
394
  }
@@ -382,8 +396,8 @@ class J extends p {
382
396
  return t.constructor.code == this.code;
383
397
  }
384
398
  }
385
- c(J, "code", 401);
386
- class z extends p {
399
+ c(v, "code", 401);
400
+ class J extends g {
387
401
  constructor(t = "Payment Required") {
388
402
  super(t);
389
403
  }
@@ -391,8 +405,8 @@ class z extends p {
391
405
  return t.constructor.code == this.code;
392
406
  }
393
407
  }
394
- c(z, "code", 402);
395
- class K extends p {
408
+ c(J, "code", 402);
409
+ class z extends g {
396
410
  constructor(t = "Forbidden") {
397
411
  super(t);
398
412
  }
@@ -400,8 +414,8 @@ class K extends p {
400
414
  return t.constructor.code == this.code;
401
415
  }
402
416
  }
403
- c(K, "code", 403);
404
- class Z extends p {
417
+ c(z, "code", 403);
418
+ class Z extends g {
405
419
  constructor(t = "Not Found") {
406
420
  super(t);
407
421
  }
@@ -410,7 +424,7 @@ class Z extends p {
410
424
  }
411
425
  }
412
426
  c(Z, "code", 404);
413
- class V extends p {
427
+ class V extends g {
414
428
  constructor(t = "Method Not Allowed") {
415
429
  super(t);
416
430
  }
@@ -419,7 +433,7 @@ class V extends p {
419
433
  }
420
434
  }
421
435
  c(V, "code", 405);
422
- class X extends p {
436
+ class X extends g {
423
437
  constructor(t = "Not Acceptable") {
424
438
  super(t);
425
439
  }
@@ -428,7 +442,7 @@ class X extends p {
428
442
  }
429
443
  }
430
444
  c(X, "code", 406);
431
- class Q extends p {
445
+ class Q extends g {
432
446
  constructor(t = "Internal Server Error") {
433
447
  super(t);
434
448
  }
@@ -437,7 +451,7 @@ class Q extends p {
437
451
  }
438
452
  }
439
453
  c(Q, "code", 500);
440
- class tt extends p {
454
+ class _ extends g {
441
455
  constructor(t = "Not Implemented") {
442
456
  super(t);
443
457
  }
@@ -445,8 +459,8 @@ class tt extends p {
445
459
  return t.constructor.code == this.code;
446
460
  }
447
461
  }
448
- c(tt, "code", 501);
449
- class et extends p {
462
+ c(_, "code", 501);
463
+ class tt extends g {
450
464
  constructor(t = "Bad Gateway") {
451
465
  super(t);
452
466
  }
@@ -454,8 +468,8 @@ class et extends p {
454
468
  return t.constructor.code == this.code;
455
469
  }
456
470
  }
457
- c(et, "code", 502);
458
- class rt extends p {
471
+ c(tt, "code", 502);
472
+ class et extends g {
459
473
  constructor(t = "Service Unavailable") {
460
474
  super(t);
461
475
  }
@@ -463,8 +477,8 @@ class rt extends p {
463
477
  return t.constructor.code == this.code;
464
478
  }
465
479
  }
466
- c(rt, "code", 503);
467
- class nt extends p {
480
+ c(et, "code", 503);
481
+ class rt extends g {
468
482
  constructor(t = "Gateway Timeout") {
469
483
  super(t);
470
484
  }
@@ -472,18 +486,18 @@ class nt extends p {
472
486
  return t.constructor.code == this.code;
473
487
  }
474
488
  }
475
- c(nt, "code", 504);
476
- const w = class w2 {
489
+ c(rt, "code", 504);
490
+ const E = class E2 {
477
491
  constructor(t = {}) {
478
492
  c(this, "interceptors", {});
479
493
  c(this, "headers", {});
480
494
  c(this, "url");
481
- this.url = t.url ?? null, this.headers = t.headers || {}, t.interceptors && t.interceptors.forEach((e) => w2.addInterceptor(e));
495
+ this.url = t.url ?? null, this.headers = t.headers || {}, t.interceptors && t.interceptors.forEach((e) => E2.addInterceptor(e));
482
496
  }
483
497
  static addInterceptor(t) {
484
- const e = Object.keys(w2.interceptors).length.toString();
485
- return w2.interceptors[e] = t, () => {
486
- w2.interceptors[e] = null;
498
+ const e = Object.keys(E2.interceptors).length.toString();
499
+ return E2.interceptors[e] = t, () => {
500
+ E2.interceptors[e] = null;
487
501
  };
488
502
  }
489
503
  addInterceptor(t) {
@@ -496,50 +510,54 @@ const w = class w2 {
496
510
  var s;
497
511
  if (!this.url && !t.url) throw new Error("URL needs to be set");
498
512
  let e = ((s = t.url) != null && s.startsWith("http") ? t.url : (this.url || "") + (t.url || "")).replace(/([^:]\/)\/+/g, "$1");
499
- if (t.fragment && (e.includes("#") ? e.replace(/#.*(\?|\n)/g, (o, i) => `#${t.fragment}${i}`) : e += "#" + t.fragment), t.query) {
500
- const o = Array.isArray(t.query) ? t.query : Object.keys(t.query).map((i) => ({ key: i, value: t.query[i] }));
501
- e += (e.includes("?") ? "&" : "?") + o.map((i) => `${i.key}=${i.value}`).join("&");
513
+ if (t.fragment && (e.includes("#") ? e.replace(/#.*(\?|\n)/g, (i, o) => `#${t.fragment}${o}`) : e += "#" + t.fragment), t.query) {
514
+ const i = Array.isArray(t.query) ? t.query : Object.keys(t.query).map((o) => ({ key: o, value: t.query[o] }));
515
+ e += (e.includes("?") ? "&" : "?") + i.map((o) => `${o.key}=${o.value}`).join("&");
502
516
  }
503
- const n = ut({
517
+ const n = ot({
504
518
  "Content-Type": t.body ? t.body instanceof FormData ? "multipart/form-data" : "application/json" : void 0,
505
- ...w2.headers,
519
+ ...E2.headers,
506
520
  ...this.headers,
507
521
  ...t.headers
508
522
  });
509
- return typeof t.body == "object" && t.body != null && n["Content-Type"] == "application/json" && (t.body = JSON.stringify(t.body)), new E((o, i, a) => {
510
- fetch(e, {
511
- headers: n,
512
- method: t.method || (t.body ? "POST" : "GET"),
513
- body: t.body
514
- }).then(async (u) => {
515
- var G, U;
516
- for (let l of [...Object.values(w2.interceptors), ...Object.values(this.interceptors)])
517
- await new Promise((R) => l(u, () => R()));
518
- const v = u.headers.get("Content-Length"), N = v ? parseInt(v, 10) : 0;
519
- let P = 0;
520
- const I = (G = u.body) == null ? void 0 : G.getReader(), ot = new ReadableStream({
521
- start(l) {
522
- function R() {
523
- I == null || I.read().then((O) => {
524
- if (O.done) return l.close();
525
- P += O.value.byteLength, a(P / N), l.enqueue(O.value), R();
526
- }).catch((O) => l.error(O));
523
+ return typeof t.body == "object" && t.body != null && n["Content-Type"] == "application/json" && (t.body = JSON.stringify(t.body)), new x((i, o, a) => {
524
+ try {
525
+ fetch(e, {
526
+ headers: n,
527
+ method: t.method || (t.body ? "POST" : "GET"),
528
+ body: t.body
529
+ }).then(async (u) => {
530
+ var G, U;
531
+ for (let l of [...Object.values(E2.interceptors), ...Object.values(this.interceptors)])
532
+ await new Promise((C) => l(u, () => C()));
533
+ const $ = u.headers.get("Content-Length"), j = $ ? parseInt($, 10) : 0;
534
+ let P = 0;
535
+ const T = (G = u.body) == null ? void 0 : G.getReader(), nt = new ReadableStream({
536
+ start(l) {
537
+ function C() {
538
+ T == null || T.read().then((A) => {
539
+ if (A.done) return l.close();
540
+ P += A.value.byteLength, a(P / j), l.enqueue(A.value), C();
541
+ }).catch((A) => l.error(A));
542
+ }
543
+ C();
527
544
  }
528
- R();
545
+ });
546
+ if (u.data = new Response(nt), t.decode == null || t.decode) {
547
+ const l = (U = u.headers.get("Content-Type")) == null ? void 0 : U.toLowerCase();
548
+ l != null && l.includes("form") ? u.data = await u.data.formData() : l != null && l.includes("json") ? u.data = await u.data.json() : l != null && l.includes("text") ? u.data = await u.data.text() : l != null && l.includes("application") && (u.data = await u.data.blob());
529
549
  }
530
- });
531
- if (u.data = new Response(ot), t.decode == null || t.decode) {
532
- const l = (U = u.headers.get("Content-Type")) == null ? void 0 : U.toLowerCase();
533
- l != null && l.includes("form") ? u.data = await u.data.formData() : l != null && l.includes("json") ? u.data = await u.data.json() : l != null && l.includes("text") ? u.data = await u.data.text() : l != null && l.includes("application") && (u.data = await u.data.blob());
534
- }
535
- u.ok ? o(u) : i(u);
536
- });
550
+ u.ok ? i(u) : o(u);
551
+ }).catch((u) => o(u));
552
+ } catch (u) {
553
+ o(u);
554
+ }
537
555
  });
538
556
  }
539
557
  };
540
- c(w, "interceptors", {}), c(w, "headers", {});
541
- let F = w;
542
- const x = {
558
+ c(E, "interceptors", {}), c(E, "headers", {});
559
+ let F = E;
560
+ const R = {
543
561
  CLEAR: "\x1B[0m",
544
562
  BRIGHT: "\x1B[1m",
545
563
  DIM: "\x1B[2m",
@@ -547,7 +565,7 @@ const x = {
547
565
  BLINK: "\x1B[5m",
548
566
  REVERSE: "\x1B[7m",
549
567
  HIDDEN: "\x1B[8m"
550
- }, $ = {
568
+ }, L = {
551
569
  BLACK: "\x1B[30m",
552
570
  RED: "\x1B[31m",
553
571
  GREEN: "\x1B[32m",
@@ -565,355 +583,193 @@ const x = {
565
583
  LIGHT_CYAN: "\x1B[96m",
566
584
  WHITE: "\x1B[97m"
567
585
  };
568
- var yt = /* @__PURE__ */ ((r) => (r[r.ERROR = 0] = "ERROR", r[r.WARN = 1] = "WARN", r[r.INFO = 2] = "INFO", r[r.LOG = 3] = "LOG", r[r.DEBUG = 4] = "DEBUG", r))(yt || {});
569
- const g = class g2 extends _ {
586
+ var ft = /* @__PURE__ */ ((r) => (r[r.ERROR = 0] = "ERROR", r[r.WARN = 1] = "WARN", r[r.INFO = 2] = "INFO", r[r.LOG = 3] = "LOG", r[r.DEBUG = 4] = "DEBUG", r))(ft || {});
587
+ const w = class w2 extends K {
570
588
  constructor(t) {
571
589
  super(), this.namespace = t;
572
590
  }
573
591
  pad(t, e, n, s = false) {
574
- const o = t.toString(), i = e - o.length;
575
- if (i <= 0) return o;
576
- const a = Array(~~(i / n.length)).fill(n).join("");
577
- return s ? o + a : a + o;
592
+ const i = t.toString(), o = e - i.length;
593
+ if (o <= 0) return i;
594
+ const a = Array(~~(o / n.length)).fill(n).join("");
595
+ return s ? i + a : a + i;
578
596
  }
579
597
  format(...t) {
580
598
  const e = /* @__PURE__ */ new Date();
581
599
  return `${`${e.getFullYear()}-${e.getMonth() + 1}-${e.getDate()} ${this.pad(e.getHours().toString(), 2, "0")}:${this.pad(e.getMinutes().toString(), 2, "0")}:${this.pad(e.getSeconds().toString(), 2, "0")}.${this.pad(e.getMilliseconds().toString(), 3, "0", true)}`}${this.namespace ? ` [${this.namespace}]` : ""} ${t.join(" ")}`;
582
600
  }
583
601
  debug(...t) {
584
- if (g2.LOG_LEVEL < 4) return;
602
+ if (w2.LOG_LEVEL < 4) return;
585
603
  const e = this.format(...t);
586
- g2.emit(4, e), console.debug($.LIGHT_GREY + e + x.CLEAR);
604
+ w2.emit(4, e), console.debug(L.LIGHT_GREY + e + R.CLEAR);
587
605
  }
588
606
  log(...t) {
589
- if (g2.LOG_LEVEL < 3) return;
607
+ if (w2.LOG_LEVEL < 3) return;
590
608
  const e = this.format(...t);
591
- g2.emit(3, e), console.log(x.CLEAR + e);
609
+ w2.emit(3, e), console.log(R.CLEAR + e);
592
610
  }
593
611
  info(...t) {
594
- if (g2.LOG_LEVEL < 2) return;
612
+ if (w2.LOG_LEVEL < 2) return;
595
613
  const e = this.format(...t);
596
- g2.emit(2, e), console.info($.BLUE + e + x.CLEAR);
614
+ w2.emit(2, e), console.info(L.BLUE + e + R.CLEAR);
597
615
  }
598
616
  warn(...t) {
599
- if (g2.LOG_LEVEL < 1) return;
617
+ if (w2.LOG_LEVEL < 1) return;
600
618
  const e = this.format(...t);
601
- g2.emit(1, e), console.warn($.YELLOW + e + x.CLEAR);
619
+ w2.emit(1, e), console.warn(L.YELLOW + e + R.CLEAR);
602
620
  }
603
621
  error(...t) {
604
- if (g2.LOG_LEVEL < 0) return;
622
+ if (w2.LOG_LEVEL < 0) return;
605
623
  const e = this.format(...t);
606
- g2.emit(0, e), console.error($.RED + e + x.CLEAR);
624
+ w2.emit(0, e), console.error(L.RED + e + R.CLEAR);
607
625
  }
608
626
  };
609
- c(g, "LOG_LEVEL", 4);
610
- var j = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, xt = {}, S = {};
611
- Object.defineProperty(S, "__esModule", { value: true });
612
- S.persist = S.Persist = void 0;
613
- class st {
614
- /**
615
- * @param {string} key Primary key value will be stored under
616
- * @param {PersistOptions<T>} options Configure using {@link PersistOptions}
617
- */
618
- constructor(t, e = {}) {
619
- c(this, "key");
620
- c(this, "options");
621
- c(this, "storage");
622
- c(this, "watches", {});
623
- c(this, "_value");
624
- this.key = t, this.options = e, this.storage = e.storage || localStorage, this.load();
625
- }
626
- /** Current value or default if undefined */
627
- get value() {
628
- var t;
629
- return this._value !== void 0 ? this._value : (t = this.options) == null ? void 0 : t.default;
630
- }
631
- /** Set value with proxy object wrapper to sync future changes */
632
- set value(t) {
633
- t == null || typeof t != "object" ? this._value = t : this._value = new Proxy(t, {
634
- get: (e, n) => typeof e[n] == "function" ? (...o) => {
635
- const i = e[n](...o);
636
- return this.save(), i;
637
- } : e[n],
638
- set: (e, n, s) => (e[n] = s, this.save(), true)
639
- }), this.save();
640
- }
641
- /** Notify listeners of change */
642
- notify(t) {
643
- Object.values(this.watches).forEach((e) => e(t));
644
- }
645
- /** Delete value from storage */
646
- clear() {
647
- this.storage.removeItem(this.key);
648
- }
649
- /** Save current value to storage */
650
- save() {
651
- this._value === void 0 ? this.clear() : this.storage.setItem(this.key, JSON.stringify(this._value)), this.notify(this.value);
652
- }
653
- /** Load value from storage */
654
- load() {
655
- if (this.storage[this.key] != null) {
656
- let t = JSON.parse(this.storage.getItem(this.key));
657
- t != null && typeof t == "object" && this.options.type && (t.__proto__ = this.options.type.prototype), this.value = t;
658
- } else
659
- this.value = this.options.default || void 0;
660
- }
661
- /**
662
- * Callback function which is run when there are changes
663
- *
664
- * @param {(value: T) => any} fn Callback will run on each change; it's passed the next value & it's return is ignored
665
- * @returns {() => void} Function which will unsubscribe the watch/callback when called
666
- */
667
- watch(t) {
668
- const e = Object.keys(this.watches).length;
669
- return this.watches[e] = t, () => {
670
- delete this.watches[e];
671
- };
627
+ c(w, "LOG_LEVEL", 4);
628
+ function ee(r, ...t) {
629
+ const e = [];
630
+ for (let n = 0; n < r.length || n < t.length; n++)
631
+ r[n] && e.push(r[n]), t[n] && e.push(t[n]);
632
+ return new y(e.join(""));
633
+ }
634
+ function mt(r, ...t) {
635
+ let e = [];
636
+ for (let i = 0; i < r.length || i < t.length; i++)
637
+ r[i] && e.push(r[i]), t[i] && e.push(t[i]);
638
+ const [n, s] = e.join("").split(":");
639
+ return y.toString(n, s == null ? void 0 : s.split(""));
640
+ }
641
+ class y {
642
+ constructor(t) {
643
+ c(this, "module");
644
+ c(this, "fullPath");
645
+ c(this, "path");
646
+ c(this, "name");
647
+ c(this, "methods");
648
+ c(this, "all");
649
+ c(this, "none");
650
+ c(this, "create");
651
+ c(this, "read");
652
+ c(this, "update");
653
+ c(this, "delete");
654
+ var o;
655
+ if (typeof t == "object") return Object.assign(this, t);
656
+ let [e, n, s] = t.split(":");
657
+ s || (s = n || "*"), (e == "*" || !e && s == "*") && (e = "", s = "*");
658
+ let i = e.split("/").filter((a) => !!a);
659
+ this.module = ((o = i.splice(0, 1)[0]) == null ? void 0 : o.toLowerCase()) || "", this.fullPath = e, this.path = i.join("/"), this.name = i.pop() || "", this.methods = s.split(""), this.all = s == null ? void 0 : s.includes("*"), this.none = s == null ? void 0 : s.includes("n"), this.create = !(s != null && s.includes("n")) && ((s == null ? void 0 : s.includes("*")) || (s == null ? void 0 : s.includes("w")) || (s == null ? void 0 : s.includes("c"))), this.read = !(s != null && s.includes("n")) && ((s == null ? void 0 : s.includes("*")) || (s == null ? void 0 : s.includes("r"))), this.update = !(s != null && s.includes("n")) && ((s == null ? void 0 : s.includes("*")) || (s == null ? void 0 : s.includes("w")) || (s == null ? void 0 : s.includes("u"))), this.delete = !(s != null && s.includes("n")) && ((s == null ? void 0 : s.includes("*")) || (s == null ? void 0 : s.includes("w")) || (s == null ? void 0 : s.includes("d")));
672
660
  }
673
661
  /**
674
- * Return value as JSON string
662
+ * Combine multiple events into one parsed object. Longest path takes precedent, but all subsequent methods are
663
+ * combined until a "none" is reached
675
664
  *
676
- * @returns {string} Stringified object as JSON
665
+ * @param {string | PathEvent} paths Events as strings or pre-parsed
666
+ * @return {PathEvent} Final combined permission
677
667
  */
678
- toString() {
679
- return JSON.stringify(this.value);
668
+ static combine(t) {
669
+ let e = false;
670
+ const n = t.map((s) => new y(s)).toSorted((s, i) => {
671
+ const o = s.fullPath.length, a = i.fullPath.length;
672
+ return o < a ? 1 : o > a ? -1 : 0;
673
+ }).reduce((s, i) => (i.none && (e = true), s ? (e || (i.all && (s.all = true), (i.all || i.create) && (s.create = true), (i.all || i.read) && (s.read = true), (i.all || i.update) && (s.update = true), (i.all || i.delete) && (s.delete = true), s.methods = [...s.methods, ...i.methods]), s) : i), null);
674
+ return n.all && (n.methods = ["*"]), n.none && (n.methods = ["n"]), n.methods = new S(n.methods), n.raw = mt`${n.fullPath}:${n.methods}`, n;
680
675
  }
681
676
  /**
682
- * Return current value
677
+ * Squash 2 sets of paths & return true if any overlap is found
683
678
  *
684
- * @returns {T} Current value
679
+ * @param {string | PathEvent | (string | PathEvent)[]} target Array of Events as strings or pre-parsed
680
+ * @param has Target must have at least one of these path
681
+ * @return {boolean} Whether there is any overlap
685
682
  */
686
- valueOf() {
687
- return this.value;
688
- }
689
- }
690
- S.Persist = st;
691
- function Bt(r) {
692
- return (t, e) => {
693
- const n = (r == null ? void 0 : r.key) || `${t.constructor.name}.${e.toString()}`, s = new st(n, r);
694
- Object.defineProperty(t, e, {
695
- get: function() {
696
- return s.value;
697
- },
698
- set: function(o) {
699
- s.value = o;
700
- }
683
+ static has(t, ...e) {
684
+ const n = m(e).map((i) => new y(i)), s = m(t).map((i) => new y(i));
685
+ return !!n.find((i) => {
686
+ if (!i.fullPath && i.all) return true;
687
+ const o = s.filter((u) => i.fullPath.startsWith(u.fullPath));
688
+ if (!o.length) return false;
689
+ const a = y.combine(o);
690
+ return !a.none && (a.all || new S(a.methods).intersection(new S(i.methods)).length);
701
691
  });
702
- };
703
- }
704
- S.persist = Bt;
705
- var L = {};
706
- Object.defineProperty(L, "__esModule", { value: true });
707
- L.MemoryStorage = void 0;
708
- class At {
709
- get length() {
710
- return Object.keys(this).length;
711
- }
712
- clear() {
713
- Object.keys(this).forEach((t) => this.removeItem(t));
714
- }
715
- getItem(t) {
716
- return this[t];
717
- }
718
- key(t) {
719
- return Object.keys(this)[t];
720
- }
721
- removeItem(t) {
722
- delete this[t];
723
- }
724
- setItem(t, e) {
725
- this[t] = e;
726
- }
727
- }
728
- L.MemoryStorage = At;
729
- (function(r) {
730
- var t = j && j.__createBinding || (Object.create ? function(n, s, o, i) {
731
- i === void 0 && (i = o);
732
- var a = Object.getOwnPropertyDescriptor(s, o);
733
- (!a || ("get" in a ? !s.__esModule : a.writable || a.configurable)) && (a = { enumerable: true, get: function() {
734
- return s[o];
735
- } }), Object.defineProperty(n, i, a);
736
- } : function(n, s, o, i) {
737
- i === void 0 && (i = o), n[i] = s[o];
738
- }), e = j && j.__exportStar || function(n, s) {
739
- for (var o in n) o !== "default" && !Object.prototype.hasOwnProperty.call(s, o) && t(s, n, o);
740
- };
741
- Object.defineProperty(r, "__esModule", { value: true }), e(S, r), e(L, r);
742
- })(xt);
743
- function PE(str, ...args) {
744
- const combined = [];
745
- for (let i = 0; i < str.length || i < args.length; i++) {
746
- if (str[i]) combined.push(str[i]);
747
- if (args[i]) combined.push(args[i]);
748
- }
749
- return new PathEvent(combined.join(""));
750
- }
751
- function PES(str, ...args) {
752
- let combined = [];
753
- for (let i = 0; i < str.length || i < args.length; i++) {
754
- if (str[i]) combined.push(str[i]);
755
- if (args[i]) combined.push(args[i]);
756
- }
757
- const [paths, methods] = combined.join("").split(":");
758
- return PathEvent.toString(paths, methods == null ? void 0 : methods.split(""));
759
- }
760
- class PathEvent {
761
- constructor(pathedEvent) {
762
- /** First directory in path */
763
- __publicField(this, "module");
764
- /** Entire path, including the module & name */
765
- __publicField(this, "fullPath");
766
- /** Path including the name, excluding the module */
767
- __publicField(this, "path");
768
- /** Last sagment of path */
769
- __publicField(this, "name");
770
- /** List of methods */
771
- __publicField(this, "methods");
772
- /** All/Wildcard specified */
773
- __publicField(this, "all");
774
- /** None specified */
775
- __publicField(this, "none");
776
- /** Create method specified */
777
- __publicField(this, "create");
778
- /** Read method specified */
779
- __publicField(this, "read");
780
- /** Update method specified */
781
- __publicField(this, "update");
782
- /** Delete method specified */
783
- __publicField(this, "delete");
784
- var _a;
785
- if (typeof pathedEvent == "object") return Object.assign(this, pathedEvent);
786
- let [p2, scope, method] = pathedEvent.split(":");
787
- if (!method) method = scope || "*";
788
- if (p2 == "*" || !p2 && method == "*") {
789
- p2 = "";
790
- method = "*";
791
- }
792
- let temp = p2.split("/").filter((p22) => !!p22);
793
- this.module = ((_a = temp.splice(0, 1)[0]) == null ? void 0 : _a.toLowerCase()) || "";
794
- this.fullPath = p2;
795
- this.path = temp.join("/");
796
- this.name = temp.pop() || "";
797
- this.methods = method.split("");
798
- this.all = method == null ? void 0 : method.includes("*");
799
- this.none = method == null ? void 0 : method.includes("n");
800
- this.create = !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("w")) || (method == null ? void 0 : method.includes("c")));
801
- this.read = !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("r")));
802
- this.update = !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("w")) || (method == null ? void 0 : method.includes("u")));
803
- this.delete = !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("w")) || (method == null ? void 0 : method.includes("d")));
804
692
  }
805
693
  /**
806
- * Combine multiple pathed events into one parsed object. Longest path takes precedent, but all subsequent methods are
807
- * combined until a "none" is reached
694
+ * Squash 2 sets of paths & return true if the target has all paths
808
695
  *
809
- * @param {string | PathEvent} paths PathedEvents as strings or pre-parsed
810
- * @return {PathEvent} Final combined permission
696
+ * @param {string | PathEvent | (string | PathEvent)[]} target Array of Events as strings or pre-parsed
697
+ * @param has Target must have all these paths
698
+ * @return {boolean} Whether there is any overlap
811
699
  */
812
- static combine(paths) {
813
- let hitNone = false;
814
- const combined = paths.map((p2) => new PathEvent(p2)).toSorted((p1, p2) => {
815
- const l1 = p1.fullPath.length, l2 = p2.fullPath.length;
816
- return l1 < l2 ? 1 : l1 > l2 ? -1 : 0;
817
- }).reduce((acc, p2) => {
818
- if (p2.none) hitNone = true;
819
- if (!acc) return p2;
820
- if (hitNone) return acc;
821
- if (p2.all) acc.all = true;
822
- if (p2.all || p2.create) acc.create = true;
823
- if (p2.all || p2.read) acc.read = true;
824
- if (p2.all || p2.update) acc.update = true;
825
- if (p2.all || p2.delete) acc.delete = true;
826
- acc.methods = [...acc.methods, ...p2.methods];
827
- return acc;
828
- }, null);
829
- if (combined.all) combined.methods = ["*"];
830
- if (combined.none) combined.methods = ["n"];
831
- combined.methods = new B(combined.methods);
832
- combined.raw = PES`${combined.fullPath}:${combined.methods}`;
833
- return combined;
700
+ static hasAll(t, ...e) {
701
+ return e.filter((n) => y.has(t, n)).length == e.length;
834
702
  }
835
703
  /**
836
- * Squash 2 sets of paths & return true if any overlap is found
704
+ * Same as `has` but raises an error if there is no overlap
837
705
  *
838
- * @param {string | PathEvent | (string | PathEvent)[]} target Array of PathedEvents as strings or pre-parsed
839
- * @param has
840
- * @return {boolean} Whether there is any overlap
706
+ * @param {string | string[]} target Array of Events as strings or pre-parsed
707
+ * @param has Target must have at least one of these path
841
708
  */
842
- static has(target, ...has) {
843
- const parsedRequired = ft(has).map((pe) => new PathEvent(pe));
844
- const parsedTarget = ft(target).map((pe) => new PathEvent(pe));
845
- return !!parsedRequired.find((r) => {
846
- if (!r.fullPath && r.all) return true;
847
- const filtered = parsedTarget.filter((p2) => r.fullPath.startsWith(p2.fullPath));
848
- if (!filtered.length) return false;
849
- const combined = PathEvent.combine(filtered);
850
- return !combined.none && (combined.all || new B(combined.methods).intersection(new B(r.methods)).length);
851
- });
709
+ static hasFatal(t, ...e) {
710
+ if (!y.has(t, ...e)) throw new Error(`Requires one of: ${m(e).join(", ")}`);
852
711
  }
853
712
  /**
854
- * Same as `has` but raises an error if there is no overlap
713
+ * Same as `hasAll` but raises an error if the target is missing any paths
855
714
  *
856
- * @param {string | string[]} target Array of PathedEvents as strings or pre-parsed
857
- * @param has
715
+ * @param {string | string[]} target Array of Events as strings or pre-parsed
716
+ * @param has Target must have all these paths
858
717
  */
859
- static hasFatal(target, ...has) {
860
- if (!PathEvent.has(target, ...has)) throw new Error(`Missing permission: ${ft(has).join(", ")}`);
718
+ static hasAllFatal(t, ...e) {
719
+ if (!y.hasAll(t, ...e)) throw new Error(`Requires all: ${m(e).join(", ")}`);
861
720
  }
862
721
  /**
863
- * Create pathed event string from its components
722
+ * Create event string from its components
864
723
  *
865
724
  * @param {string | string[]} path Event path
866
725
  * @param {Method} methods Event method
867
- * @return {string} String representation of PathedEvent
726
+ * @return {string} String representation of Event
868
727
  */
869
- static toString(path, methods) {
870
- let p2 = ft(path).filter((p22) => p22 != null).join("/");
871
- if (methods == null ? void 0 : methods.length) p2 += `:${ft(methods).map((m) => m.toLowerCase()).join("")}`;
872
- return p2 == null ? void 0 : p2.trim().replaceAll(/\/{2,}/g, "/").replaceAll(/(^\/|\/$)/g, "");
728
+ static toString(t, e) {
729
+ let n = m(t).filter((s) => s != null).join("/");
730
+ return e != null && e.length && (n += `:${m(e).map((s) => s.toLowerCase()).join("")}`), n == null ? void 0 : n.trim().replaceAll(/\/{2,}/g, "/").replaceAll(/(^\/|\/$)/g, "");
873
731
  }
874
732
  /**
875
- * Create pathed event string from its components
733
+ * Create event string from its components
876
734
  *
877
- * @return {string} String representation of PathedEvent
735
+ * @return {string} String representation of Event
878
736
  */
879
737
  toString() {
880
- return PathEvent.toString(this.fullPath, this.methods);
738
+ return y.toString(this.fullPath, this.methods);
881
739
  }
882
740
  }
883
- class PathedEventEmitter {
741
+ class re {
884
742
  constructor() {
885
- __publicField(this, "listeners", []);
743
+ c(this, "listeners", []);
886
744
  }
887
- emit(event, ...args) {
888
- const parsed = new PathEvent(event);
889
- this.listeners.filter((l) => PathEvent.has(l[0], event)).forEach((l) => l[1](parsed, ...args));
745
+ emit(t, ...e) {
746
+ const n = new y(t);
747
+ this.listeners.filter((s) => y.has(s[0], t)).forEach(async (s) => s[1](n, ...e));
890
748
  }
891
- off(listener) {
892
- this.listeners = this.listeners.filter((l) => l[1] != listener);
749
+ off(t) {
750
+ this.listeners = this.listeners.filter((e) => e[1] != t);
893
751
  }
894
- on(event, listener) {
895
- ft(event).forEach((e) => this.listeners.push([new PathEvent(e), listener]));
896
- return () => this.off(listener);
752
+ on(t, e) {
753
+ return m(t).forEach((n) => this.listeners.push([new y(n), e])), () => this.off(e);
897
754
  }
898
- once(event, listener) {
899
- return new Promise((res) => {
900
- const unsubscribe = this.on(event, (event2, ...args) => {
901
- res(args.length < 2 ? args[0] : args);
902
- if (listener) listener(event2, ...args);
903
- unsubscribe();
755
+ once(t, e) {
756
+ return new Promise((n) => {
757
+ const s = this.on(t, (i, ...o) => {
758
+ n(o.length < 2 ? o[0] : o), e && e(i, ...o), s();
904
759
  });
905
760
  });
906
761
  }
907
- relayEvents(emitter) {
908
- emitter.on("*", (event, ...args) => this.emit(event, ...args));
762
+ relayEvents(t) {
763
+ t.on("*", (e, ...n) => this.emit(e, ...n));
909
764
  }
910
765
  }
911
766
  class Api extends F {
912
767
  constructor(url = location.origin, opts = {}) {
913
- opts.url = url;
914
- super(opts);
915
- __publicField(this, "emitter", new PathedEventEmitter());
768
+ super({ ...(opts == null ? void 0 : opts.http) || {}, url });
769
+ __publicField(this, "emitter", new re());
916
770
  __publicField(this, "pending", {});
771
+ __publicField(this, "storageKey");
772
+ __publicField(this, "host");
917
773
  __publicField(this, "_token", null);
918
774
  __publicField(this, "emit", this.emitter.emit.bind(this.emitter));
919
775
  __publicField(this, "off", this.emitter.off.bind(this.emitter));
@@ -922,6 +778,12 @@ class Api extends F {
922
778
  __publicField(this, "relayEvents", this.emitter.relayEvents.bind(this.emitter));
923
779
  this.url = url;
924
780
  this.opts = opts;
781
+ this.host = new URL(url).host;
782
+ this.storageKey = `momentum:token:${this.host}`;
783
+ if (opts.persist && localStorage) {
784
+ const token = localStorage.getItem(this.storageKey);
785
+ if (token) this.token = token;
786
+ }
925
787
  }
926
788
  get token() {
927
789
  return this._token;
@@ -930,27 +792,31 @@ class Api extends F {
930
792
  if (token == this._token) return;
931
793
  this._token = token;
932
794
  this.headers["Authorization"] = token ? `Bearer ${token}` : null;
933
- this.emit(PES`api/token:${token ? "u" : "d"}`, token);
795
+ if (this.opts.persist && localStorage) {
796
+ if (token) localStorage.setItem(this.storageKey, token);
797
+ else localStorage.removeItem(this.storageKey);
798
+ }
799
+ this.emit(mt`api/token:${token ? "u" : "d"}`, token);
934
800
  }
935
801
  healthcheck() {
936
802
  return this.request({ url: "/api/healthcheck" }).then((resp) => {
937
- this.emit(PES`api/healthcheck:r`, resp);
803
+ this.emit(mt`api/healthcheck:r`, resp);
938
804
  return resp;
939
805
  });
940
806
  }
941
807
  request(options) {
942
- const key = Lt(options);
808
+ const key = Ot(options);
943
809
  const method = options.method == "GET" ? "r" : options.method == "POST" ? "c" : options.method == "DELETE" ? "d" : "u";
944
810
  if (this.pending[key] != null) return this.pending[key];
945
811
  this.pending[key] = super.request(options).then((response) => {
946
- this.emit(PES`api/response:${method}`, { request: options, response });
812
+ this.emit(mt`api/response:${method}`, { request: options, response });
947
813
  return response.data;
948
814
  }).catch((err) => {
949
815
  const e = (err == null ? void 0 : err.data) || err;
950
- this.emit(PES`api/error:${method}`, { request: options, error: e });
816
+ this.emit(mt`api/error:${method}`, { request: options, error: e });
951
817
  throw e;
952
818
  }).finally(() => delete this.pending[key]);
953
- this.emit(PES`api/request:${method}`, { request: options, response: this.pending[key] });
819
+ this.emit(mt`api/request:${method}`, { request: options, response: this.pending[key] });
954
820
  return this.pending[key];
955
821
  }
956
822
  }
@@ -964,59 +830,59 @@ var ActionType = /* @__PURE__ */ ((ActionType2) => {
964
830
  ActionType2[ActionType2["PUT"] = 6] = "PUT";
965
831
  return ActionType2;
966
832
  })(ActionType || {});
967
- class Actions extends PathedEventEmitter {
833
+ class Actions extends re {
968
834
  constructor(api) {
969
835
  super();
970
836
  __publicField(this, "api");
971
- __publicField(this, "cache", new Dt("_id"));
837
+ __publicField(this, "cache", new Tt("_id"));
972
838
  this.api = typeof api == "string" ? new Api(api) : api;
973
839
  }
974
- delete(id) {
975
- if (!id) throw new Error("Cannot delete action, missing ID");
976
- return this.api.request({ url: `/api/` + PES`actions/${id}`, method: "DELETE" }).then(() => {
977
- this.cache.delete(id);
978
- this.emit(PES`actions/${id}:d`, id);
979
- });
980
- }
981
840
  all() {
982
- return this.api.request({ url: `/api/` + PES`actions` }).then((resp) => {
841
+ return this.api.request({ url: `/api/` + mt`actions` }).then((resp) => {
983
842
  this.cache.addAll(resp);
984
- this.emit(PES`actions:r`, resp || []);
843
+ this.emit(mt`actions:r`, resp || []);
985
844
  return resp;
986
845
  });
987
846
  }
847
+ delete(id) {
848
+ if (!id) throw new Error("Cannot delete action, missing ID");
849
+ return this.api.request({ url: `/api/` + mt`actions/${id}`, method: "DELETE" }).then(() => {
850
+ this.cache.delete(id);
851
+ this.emit(mt`actions/${id}:d`, id);
852
+ });
853
+ }
988
854
  read(id, reload = false) {
989
855
  if (!id) throw new Error("Cannot read action, missing ID");
990
856
  const cached = this.cache.get(id);
991
857
  if (!reload && cached) return Promise.resolve(cached);
992
- return this.api.request({ url: `/api/` + PES`actions/${id}` }).then((action) => {
858
+ return this.api.request({ url: `/api/` + mt`actions/${id}` }).then((action) => {
993
859
  if (action) this.cache.add(action);
994
- this.emit(PES`actions/${id}:r`, action);
860
+ this.emit(mt`actions/${id}:r`, action);
995
861
  return action;
996
862
  });
997
863
  }
998
864
  run(path, opts = {}) {
999
865
  if (!path) throw new Error("Cannot run action, missing path");
1000
- return this.api.request({ url: `/api/` + PES`actions/run/${path}`, ...opts });
866
+ return this.api.request({ url: `/api/` + mt`actions/run/${path}`, ...opts });
1001
867
  }
1002
868
  runById(action, opts = {}) {
1003
869
  const id = typeof action == "string" ? action : action == null ? void 0 : action._id;
1004
870
  if (!id) throw new Error("Cannot run action, missing ID");
1005
- return this.api.request({ url: "/api/" + PES`actions/run-by-id/${id}`, method: "POST", ...opts });
871
+ return this.api.request({ url: "/api/" + mt`actions/run-by-id/${id}`, method: "POST", ...opts });
1006
872
  }
1007
873
  update(action) {
1008
874
  return this.api.request({
1009
- url: `/api/` + PES`actions/${action._id}`,
875
+ url: `/api/` + mt`actions/${action._id}`,
1010
876
  method: "POST",
1011
877
  body: action
1012
878
  }).then((action2) => {
1013
879
  if (action2) this.cache.add(action2);
1014
- this.emit(PES`actions/${action2._id}:u`, action2);
880
+ this.emit(mt`actions/${action2._id}:u`, action2);
1015
881
  return action2;
1016
882
  });
1017
883
  }
1018
884
  }
1019
- class Ai extends PathedEventEmitter {
885
+ class Ai extends re {
1020
886
  constructor(api) {
1021
887
  super();
1022
888
  __publicField(this, "api");
@@ -1024,19 +890,19 @@ class Ai extends PathedEventEmitter {
1024
890
  }
1025
891
  ask(question, context) {
1026
892
  if (!question) throw new Error("Cannot ask AI, missing question");
1027
- return this.api.request({ url: `/api/` + PES`ai`, method: "POST", body: {
893
+ return this.api.request({ url: `/api/` + mt`ai`, method: "POST", body: {
1028
894
  question,
1029
895
  context
1030
896
  } }).then((response) => {
1031
- this.emit(PES`ai:c`, { question, context, response });
897
+ this.emit(mt`ai:c`, { question, context, response });
1032
898
  return response;
1033
899
  });
1034
900
  }
1035
901
  clear() {
1036
- return this.api.request({ url: "/api/" + PES`ai`, method: "DELETE" }).then(() => this.emit(PES`ai:d`, this.api.token));
902
+ return this.api.request({ url: "/api/" + mt`ai`, method: "DELETE" }).then(() => this.emit(mt`ai:d`, this.api.token));
1037
903
  }
1038
904
  }
1039
- class Analytics extends PathedEventEmitter {
905
+ class Analytics extends re {
1040
906
  constructor(api) {
1041
907
  super();
1042
908
  __publicField(this, "api");
@@ -1044,46 +910,24 @@ class Analytics extends PathedEventEmitter {
1044
910
  }
1045
911
  ipTrace(ip) {
1046
912
  if (!ip) throw new Error("Cannot trace, missing IP");
1047
- return this.api.request({ url: `/api/` + PES`analytics/trace/${ip}` }).then((resp) => {
1048
- this.emit(PES`analytics/trace/${ip}:r`, resp);
913
+ return this.api.request({ url: `/api/` + mt`analytics/trace/${ip}` }).then((resp) => {
914
+ this.emit(mt`analytics/trace/${ip}:r`, resp);
1049
915
  return resp;
1050
916
  });
1051
917
  }
1052
918
  }
1053
- class Totp {
1054
- constructor(api) {
1055
- __publicField(this, "enable", this.reset);
1056
- this.api = api;
1057
- }
1058
- disable(username) {
1059
- return this.api.request({ url: `/api/auth/totp/${username}`, method: "DELETE" });
1060
- }
1061
- reset(username) {
1062
- return this.api.request({ url: `/api/auth/totp/${username}`, method: "POST" });
1063
- }
1064
- setup(username, method = "app", totp) {
1065
- return this.api.request({ url: `/api/auth/totp/${username}`, body: ut({
1066
- method,
1067
- totp
1068
- }) });
1069
- }
1070
- }
1071
- class Auth extends PathedEventEmitter {
919
+ class Auth extends re {
1072
920
  constructor(api, opts = {}) {
1073
921
  super();
1074
922
  __publicField(this, "api");
1075
- __publicField(this, "storageKey");
1076
- __publicField(this, "totp");
1077
923
  __publicField(this, "_user");
924
+ __publicField(this, "enableTotp", this.resetTotp);
1078
925
  this.opts = opts;
1079
926
  this.api = typeof api == "string" ? new Api(api) : api;
1080
- this.totp = new Totp(this.api);
1081
927
  this.opts = {
1082
- loginUi: this.api.url + "/ui/#/login",
1083
- persist: true,
928
+ loginUrl: this.api.url + "/ui/#/login",
1084
929
  ...this.opts
1085
930
  };
1086
- this.storageKey = `momentum:${new URL(this.api.url).host}`;
1087
931
  this.api.addInterceptor((resp, next) => {
1088
932
  const blacklist = [
1089
933
  "/api/auth/login",
@@ -1091,35 +935,24 @@ class Auth extends PathedEventEmitter {
1091
935
  "/api/auth/totp"
1092
936
  ];
1093
937
  if (resp.status == 401 && !blacklist.find((url) => resp.url.includes(url)))
1094
- this.emit(PES`auth/session-expired:d`, this.api.token);
938
+ this.emit(mt`auth/session-expired:d`, this.api.token);
1095
939
  next();
1096
940
  });
941
+ if (this.api.token) this.session(this.api.token, true);
942
+ else this.user = null;
1097
943
  this.api.on("api/token", (event, token) => {
1098
- var _a;
1099
- console.log("loading user...");
1100
- if ((_a = this.opts) == null ? void 0 : _a.persist) {
1101
- if (token) localStorage.setItem(this.storageKey, token);
1102
- else localStorage.removeItem(this.storageKey);
1103
- }
1104
944
  if (token) this.session(token, true).catch(() => {
1105
945
  });
1106
946
  else this.user = null;
1107
947
  });
1108
- if (opts == null ? void 0 : opts.persist) {
1109
- const token = localStorage.getItem(this.storageKey);
1110
- if (token) this.api.token = token;
1111
- else this.user = null;
1112
- } else {
1113
- this.user = null;
1114
- }
1115
948
  }
1116
949
  get user() {
1117
950
  return this._user;
1118
951
  }
1119
952
  set user(user) {
1120
- if (!A(this.user, user)) {
953
+ if (!O(this.user, user)) {
1121
954
  this._user = user ? user : null;
1122
- this.emit(PES`auth/user:u`, this._user);
955
+ this.emit(mt`auth/user:u`, this._user);
1123
956
  }
1124
957
  }
1125
958
  knownHost(host = location.origin) {
@@ -1140,16 +973,16 @@ class Auth extends PathedEventEmitter {
1140
973
  }).then(async (resp) => {
1141
974
  this.api.token = (resp == null ? void 0 : resp.token) || null;
1142
975
  const user = await this.once("auth/user");
1143
- this.emit(PES`auth/login/${username}:u`, user);
976
+ this.emit(mt`auth/login/${username}:u`, user);
1144
977
  return user;
1145
978
  });
1146
979
  }
1147
980
  loginRedirect(host = location.origin) {
1148
981
  return new Promise((res, rej) => {
1149
982
  var _a;
1150
- const win = window.open(encodeURI(`${(_a = this.opts) == null ? void 0 : _a.loginUi}?redirect=postmessage&host=${host}`), "_blank");
983
+ const win = window.open(encodeURI(`${(_a = this.opts) == null ? void 0 : _a.loginUrl}?redirect=postmessage&host=${host}`), "_blank");
1151
984
  if (!win) return rej("Unable to open login");
1152
- const origin = new URL(this.opts.loginUi).origin;
985
+ const origin = new URL(this.opts.loginUrl).origin;
1153
986
  win.addEventListener("message", (event) => {
1154
987
  const data = (event == null ? void 0 : event.data) || {};
1155
988
  if (event.origin != data.sender || data.sender != origin) return;
@@ -1161,7 +994,7 @@ class Auth extends PathedEventEmitter {
1161
994
  });
1162
995
  }
1163
996
  logout() {
1164
- this.emit(PES`auth/logout:d`, this.user);
997
+ this.emit(mt`auth/logout:d`, this.user);
1165
998
  this.api.token = null;
1166
999
  this.user = null;
1167
1000
  }
@@ -1170,7 +1003,7 @@ class Auth extends PathedEventEmitter {
1170
1003
  if (!u.username || !u.password) throw new Error("Cannot register user, missing username or password");
1171
1004
  const user = await this.api.request({ url: "/api/auth/register", body: { ...u } });
1172
1005
  if ((_a = user == null ? void 0 : user.image) == null ? void 0 : _a.startsWith("/")) user.image = `${this.api.url}${user.image}?token=${this.api.token}`;
1173
- this.emit(PES`auth/register:c`, user);
1006
+ this.emit(mt`auth/register:c`, user);
1174
1007
  return user;
1175
1008
  }
1176
1009
  reset(emailOrPass, token) {
@@ -1183,7 +1016,7 @@ class Auth extends PathedEventEmitter {
1183
1016
  password: token ? emailOrPass : void 0
1184
1017
  }
1185
1018
  }).then(() => {
1186
- this.emit(PES`auth/reset:${token ? "u" : "c"}`, token || emailOrPass);
1019
+ this.emit(mt`auth/reset:${token ? "u" : "c"}`, token || emailOrPass);
1187
1020
  });
1188
1021
  }
1189
1022
  async session(token, set = false) {
@@ -1192,12 +1025,12 @@ class Auth extends PathedEventEmitter {
1192
1025
  url: "/api/auth/session",
1193
1026
  headers: token ? { "Authorization": `Bearer ${token}` } : void 0
1194
1027
  });
1195
- this.emit(PES`auth/session:r`, session);
1028
+ this.emit(mt`auth/session:r`, session);
1196
1029
  if (set) {
1197
1030
  this.api.token = token;
1198
1031
  if (session == null ? void 0 : session.user) session.user.image = `${this.api.url}${session.user.image}?token=${this.api.token}`;
1199
1032
  this.user = (session == null ? void 0 : session.user) || null;
1200
- if (session) this.emit(PES`auth/login:c`, session.user);
1033
+ if (session) this.emit(mt`auth/login:c`, session.user);
1201
1034
  }
1202
1035
  return session;
1203
1036
  }
@@ -1207,12 +1040,25 @@ class Auth extends PathedEventEmitter {
1207
1040
  url: "/api/auth/password",
1208
1041
  body: { username, password, oldPassword }
1209
1042
  }).then((resp) => {
1210
- this.emit(PES`auth/reset:u`, resp == null ? void 0 : resp.token);
1043
+ this.emit(mt`auth/reset:u`, resp == null ? void 0 : resp.token);
1211
1044
  if (resp == null ? void 0 : resp.token) this.api.token = resp.token;
1212
1045
  });
1213
1046
  }
1047
+ // TOTP ============================================================================================================
1048
+ disableTotp(username) {
1049
+ return this.api.request({ url: `/api/auth/totp/${username}`, method: "DELETE" });
1050
+ }
1051
+ resetTotp(username) {
1052
+ return this.api.request({ url: `/api/auth/totp/${username}`, method: "POST" });
1053
+ }
1054
+ setupTotp(username, method = "app", totp) {
1055
+ return this.api.request({ url: `/api/auth/totp/${username}`, body: ot({
1056
+ method,
1057
+ totp
1058
+ }) });
1059
+ }
1214
1060
  }
1215
- class Client extends PathedEventEmitter {
1061
+ class Client extends re {
1216
1062
  constructor(settings) {
1217
1063
  super();
1218
1064
  __publicField(this, "_platform");
@@ -1239,9 +1085,11 @@ class Client extends PathedEventEmitter {
1239
1085
  this._pwa = window.matchMedia("(display-mode: standalone)").matches || (navigator == null ? void 0 : navigator.standalone) || document.referrer.includes("android-app://");
1240
1086
  return this._pwa;
1241
1087
  }
1242
- async inject(reload = false) {
1088
+ async inject(reload = false, firstLoad = true) {
1243
1089
  var _a, _b, _c, _d, _e, _f, _g, _h;
1244
- const settings = await this.settings.all(false, reload);
1090
+ let settings = this.settings.cache;
1091
+ if (firstLoad) this.settings.all(false, reload).then(() => this.inject(false, false)).catch(() => {
1092
+ });
1245
1093
  if (!document.querySelector('meta[name="mobile-web-app-capable"]')) {
1246
1094
  const meta = document.createElement("meta");
1247
1095
  meta.name = "mobile-web-app-capable";
@@ -1313,7 +1161,7 @@ class Client extends PathedEventEmitter {
1313
1161
  if (!dismissed && !this.pwa && this.mobile) this.pwaPrompt();
1314
1162
  }, 500);
1315
1163
  }
1316
- this.emit(PES`client/inject:c`, this.platform);
1164
+ this.emit(mt`client/inject:c`, this.platform);
1317
1165
  }
1318
1166
  pwaPrompt(platform) {
1319
1167
  const url = this.settings.api.url;
@@ -1430,16 +1278,16 @@ class Client extends PathedEventEmitter {
1430
1278
  setTimeout(() => {
1431
1279
  prompt.remove();
1432
1280
  backdrop.remove();
1433
- this.emit(PES`client/pwa:d`, platform);
1281
+ this.emit(mt`client/pwa:d`, platform);
1434
1282
  }, 500);
1435
1283
  };
1436
1284
  prompt.append(close);
1437
1285
  backdrop.append(prompt);
1438
1286
  document.body.append(backdrop);
1439
- this.emit(PES`client/pwa:c`, platform);
1287
+ this.emit(mt`client/pwa:c`, platform);
1440
1288
  }
1441
1289
  }
1442
- class Data extends PathedEventEmitter {
1290
+ class Data extends re {
1443
1291
  constructor(api) {
1444
1292
  super();
1445
1293
  __publicField(this, "api");
@@ -1448,18 +1296,25 @@ class Data extends PathedEventEmitter {
1448
1296
  create(collection, document2) {
1449
1297
  if (!collection || !document2) throw new Error("Cannot create document, missing collection or document");
1450
1298
  return this.api.request({
1451
- url: `/api/` + PES`data/${collection}`,
1299
+ url: `/api/` + mt`data/${collection}`,
1452
1300
  method: "POST",
1453
1301
  body: document2
1454
1302
  }).then((resp) => {
1455
- this.emit(PES`data/${collection}:c`, resp);
1303
+ this.emit(mt`data/${collection}:c`, resp);
1456
1304
  return resp;
1457
1305
  });
1458
1306
  }
1307
+ delete(collection, id) {
1308
+ if (!collection || !id) throw new Error("Cannot delete document, missing collection or ID");
1309
+ return this.api.request({
1310
+ url: `/api/` + mt`data/${collection}/${id}`,
1311
+ method: "DELETE"
1312
+ }).then(() => this.emit(mt`data/${collection}/${id}:d`, id));
1313
+ }
1459
1314
  read(collection, id) {
1460
1315
  if (!collection) throw new Error("Cannot read documents, missing collection");
1461
- return this.api.request({ url: `/api/` + PES`data/${collection}/${id}` }).then((resp) => {
1462
- this.emit(PES`data/${collection}/${id}:r`, collection, resp);
1316
+ return this.api.request({ url: `/api/` + mt`data/${collection}/${id}` }).then((resp) => {
1317
+ this.emit(mt`data/${collection}/${id}:r`, collection, resp);
1463
1318
  return resp;
1464
1319
  });
1465
1320
  }
@@ -1467,48 +1322,42 @@ class Data extends PathedEventEmitter {
1467
1322
  if (!collection || !document2) throw new Error("Cannot update document, missing collection or document");
1468
1323
  if (!document2._id) return this.create(collection, document2);
1469
1324
  return this.api.request({
1470
- url: `/api/` + PES`data/${collection}/${document2._id}`,
1325
+ url: `/api/` + mt`data/${collection}/${document2._id}`,
1471
1326
  method: append ? "PATCH" : "PUT",
1472
1327
  body: document2
1473
1328
  }).then((resp) => {
1474
- this.emit(PES`data/${collection}/${document2._id}:u`, resp);
1329
+ this.emit(mt`data/${collection}/${document2._id}:u`, resp);
1475
1330
  return resp;
1476
1331
  });
1477
1332
  }
1478
- delete(collection, id) {
1479
- if (!collection || !id) throw new Error("Cannot delete document, missing collection or ID");
1480
- return this.api.request({
1481
- url: `/api/` + PES`data/${collection}/${id}`,
1482
- method: "DELETE"
1483
- }).then(() => this.emit(PES`data/${collection}/${id}:d`, id));
1484
- }
1485
1333
  raw(collection, query) {
1486
1334
  if (!collection || !query) throw new Error("Cannot execute raw query, missing collection or query");
1487
1335
  const mode = query.operand.startsWith("find") ? "r" : query.operand == "insert" ? "c" : query.operand.startsWith("delete") ? "d" : "u";
1488
- return this.api.request({ url: `/api/` + PES`data/${collection}` + "?raw", body: query }).then((resp) => {
1489
- this.emit(PES`data/${collection}:${mode}`, resp);
1336
+ return this.api.request({ url: `/api/` + mt`data/${collection}` + "?raw", body: query }).then((resp) => {
1337
+ this.emit(mt`data/${collection}:${mode}`, resp);
1490
1338
  return resp;
1491
1339
  });
1492
1340
  }
1341
+ // Schema ==========================================================================================================
1493
1342
  deleteSchema(path) {
1494
1343
  if (!path) throw new Error("Cannot delete schema, missing collection path");
1495
- return this.api.request({ url: `/api/` + PES`schema/${path}`, method: "DELETE" }).then(() => this.emit(PES`schema/${path}:d`, path));
1344
+ return this.api.request({ url: `/api/` + mt`schema/${path}`, method: "DELETE" }).then(() => this.emit(mt`schema/${path}:d`, path));
1496
1345
  }
1497
- getSchema(pathOrTree) {
1498
- return this.api.request({ url: "/api/" + PES`schema/${typeof pathOrTree == "string" ? pathOrTree : ""}` + (pathOrTree === true ? `?tree=${pathOrTree}` : "") }).then((resp) => {
1499
- this.emit(PES`schema/${typeof pathOrTree == "string" ? pathOrTree : ""}:r`, resp);
1346
+ readSchema(pathOrTree) {
1347
+ return this.api.request({ url: "/api/" + mt`schema/${typeof pathOrTree == "string" ? pathOrTree : ""}` + (pathOrTree === true ? `?tree=${pathOrTree}` : "") }).then((resp) => {
1348
+ this.emit(mt`schema/${typeof pathOrTree == "string" ? pathOrTree : ""}:r`, resp);
1500
1349
  return resp;
1501
1350
  });
1502
1351
  }
1503
- setSchema(schema) {
1352
+ updateSchema(schema) {
1504
1353
  if (!schema.path) throw new Error("Cannot update schema, missing collection path");
1505
- return this.api.request({ url: "/api/" + PES`schema/${schema.path}`, body: schema }).then((resp) => {
1506
- this.emit(PES`schema/${schema.path}:${schema._id ? "u" : "c"}`, resp);
1354
+ return this.api.request({ url: "/api/" + mt`schema/${schema.path}`, body: schema }).then((resp) => {
1355
+ this.emit(mt`schema/${schema.path}:${schema._id ? "u" : "c"}`, resp);
1507
1356
  return resp;
1508
1357
  });
1509
1358
  }
1510
1359
  }
1511
- class Email extends PathedEventEmitter {
1360
+ class Email extends re {
1512
1361
  constructor(api) {
1513
1362
  super();
1514
1363
  __publicField(this, "api");
@@ -1517,92 +1366,126 @@ class Email extends PathedEventEmitter {
1517
1366
  send(email) {
1518
1367
  var _a;
1519
1368
  if (!email.to && !email.bcc || !email.body) throw new Error("Cannot send email, missing address or body");
1520
- return this.api.request({ url: "/api/" + PES`email/${(_a = email.body) == null ? void 0 : _a.template}`, body: email }).then((response) => {
1369
+ return this.api.request({ url: "/api/" + mt`email/${(_a = email.body) == null ? void 0 : _a.template}`, body: email }).then((response) => {
1521
1370
  var _a2;
1522
- this.emit(PES`email/${(_a2 = email.body) == null ? void 0 : _a2.template}:c`, { email, response });
1371
+ this.emit(mt`email/${(_a2 = email.body) == null ? void 0 : _a2.template}:c`, { email, response });
1523
1372
  return response;
1524
1373
  });
1525
1374
  }
1526
1375
  }
1527
- class Groups extends PathedEventEmitter {
1376
+ class Groups extends re {
1528
1377
  constructor(api) {
1529
1378
  super();
1530
1379
  __publicField(this, "api");
1531
- __publicField(this, "cache", new Dt("name"));
1380
+ __publicField(this, "cache", new Tt("name"));
1532
1381
  this.api = typeof api == "string" ? new Api(api) : api;
1533
1382
  }
1534
1383
  async all(reload) {
1535
1384
  if (!reload && this.cache.complete) return this.cache.all();
1536
- return this.api.request({ url: `/api/` + PES`groups` }).then((resp) => {
1385
+ return this.api.request({ url: `/api/` + mt`groups` }).then((resp) => {
1537
1386
  this.cache.addAll(resp);
1538
- this.emit(PES`groups:r`, resp || []);
1387
+ this.emit(mt`groups:r`, resp || []);
1539
1388
  return resp;
1540
1389
  });
1541
1390
  }
1391
+ delete(name) {
1392
+ if (!name) throw new Error("Cannot delete group, missing name");
1393
+ return this.api.request({
1394
+ url: `/api/` + mt`groups/${name}`,
1395
+ method: "DELETE"
1396
+ }).then(() => {
1397
+ this.cache.delete(name);
1398
+ this.emit(mt`groups/${name}:d`);
1399
+ });
1400
+ }
1542
1401
  create(group) {
1543
1402
  if (!group.name) throw new Error("Cannot create group, missing name");
1544
1403
  return this.api.request({
1545
- url: `/api/` + PES`groups/${group.name}`,
1404
+ url: `/api/` + mt`groups/${group.name}`,
1546
1405
  method: "POST",
1547
1406
  body: group
1548
1407
  }).then((resp) => {
1549
1408
  this.cache.add(resp);
1550
- this.emit(PES`groups/${group.name}:c`, resp);
1409
+ this.emit(mt`groups/${group.name}:c`, resp);
1551
1410
  return resp;
1552
1411
  });
1553
1412
  }
1554
1413
  async read(name, reload) {
1555
1414
  if (!name) throw new Error("Cannot read group, missing name");
1556
1415
  if (!reload && this.cache.get(name)) return this.cache.get(name);
1557
- return this.api.request({ url: `/api/` + PES`groups/${name}` }).then((resp) => {
1416
+ return this.api.request({ url: `/api/` + mt`groups/${name}` }).then((resp) => {
1558
1417
  this.cache.add(resp);
1559
- this.emit(PES`groups/${name}:r`, resp);
1418
+ this.emit(mt`groups/${name}:r`, resp);
1560
1419
  return resp;
1561
1420
  });
1562
1421
  }
1563
1422
  update(group) {
1564
1423
  if (!group.name) throw new Error("Cannot update group, missing name");
1565
1424
  return this.api.request({
1566
- url: `/api/` + PES`groups/${group.name}`,
1425
+ url: `/api/` + mt`groups/${group.name}`,
1567
1426
  method: "PATCH",
1568
1427
  body: group
1569
1428
  }).then((resp) => {
1570
1429
  this.cache.add(resp);
1571
- this.emit(PES`groups/${group.name}:u`, resp);
1430
+ this.emit(mt`groups/${group.name}:u`, resp);
1572
1431
  return resp;
1573
1432
  });
1574
1433
  }
1575
- delete(name) {
1576
- if (!name) throw new Error("Cannot delete group, missing name");
1577
- return this.api.request({
1578
- url: `/api/` + PES`groups/${name}`,
1579
- method: "DELETE"
1580
- }).then(() => {
1581
- this.cache.delete(name);
1582
- this.emit(PES`groups/${name}:d`);
1583
- });
1584
- }
1585
1434
  }
1586
- class Logger extends PathedEventEmitter {
1587
- constructor(api, namespace, logLevel) {
1435
+ class Logger extends re {
1436
+ constructor(api, channel, logLevel) {
1588
1437
  super();
1589
1438
  __publicField(this, "api");
1590
- this.namespace = namespace;
1439
+ __publicField(this, "console", {
1440
+ debug: console.debug,
1441
+ log: console.log,
1442
+ info: console.info,
1443
+ warn: console.warn,
1444
+ error: console.error
1445
+ });
1446
+ this.channel = channel;
1447
+ if (channel.toLowerCase() == "server") throw new Error('"Server" namespace is reserved');
1591
1448
  this.api = typeof api == "string" ? new Api(api) : api;
1592
- if (logLevel != null && logLevel != "NONE") {
1593
- window.addEventListener("error", (event) => {
1594
- var _a, _b;
1595
- return this.error(((_a = event.error) == null ? void 0 : _a.stack) || ((_b = event.error) == null ? void 0 : _b.message) || event.error);
1596
- });
1597
- window.addEventListener("unhandledrejection", async (event) => {
1598
- var _a, _b, _c, _d;
1599
- let log = ((_a = event.reason) == null ? void 0 : _a.stack) || event.reason;
1600
- if ((_b = event.reason) == null ? void 0 : _b.url)
1601
- log = `${event.reason.method} ${event.reason.url} -> ${event.reason.code}
1449
+ if (logLevel != null && logLevel && logLevel != "NONE") {
1450
+ if (ft[logLevel] >= 0) {
1451
+ console.error = (...args) => {
1452
+ this.console.error(...args);
1453
+ this.error(...args);
1454
+ };
1455
+ window.addEventListener("unhandledrejection", async (event) => {
1456
+ var _a, _b, _c, _d;
1457
+ let log = ((_a = event.reason) == null ? void 0 : _a.stack) || event.reason;
1458
+ if ((_b = event.reason) == null ? void 0 : _b.url)
1459
+ log = `${event.reason.method} ${event.reason.url} -> ${event.reason.code}
1602
1460
 
1603
1461
  ${log}`;
1604
- ((_c = event.reason) == null ? void 0 : _c.code) == null || ((_d = event.reason) == null ? void 0 : _d.code) >= 500 ? this.error(log) : this.warn(log);
1605
- });
1462
+ ((_c = event.reason) == null ? void 0 : _c.code) == null || ((_d = event.reason) == null ? void 0 : _d.code) >= 500 ? this.error(log) : this.warn(log);
1463
+ });
1464
+ }
1465
+ if (ft[logLevel] >= 1) {
1466
+ console.warn = (...args) => {
1467
+ this.console.warn(...args);
1468
+ this.warn(...args);
1469
+ };
1470
+ }
1471
+ if (ft[logLevel] >= 2) {
1472
+ console.info = (...args) => {
1473
+ this.console.info(...args);
1474
+ this.info(...args);
1475
+ };
1476
+ }
1477
+ if (ft[logLevel] >= 3) {
1478
+ console.log = (...args) => {
1479
+ this.console.log(...args);
1480
+ this.log(...args);
1481
+ };
1482
+ }
1483
+ if (ft[logLevel] >= 4) {
1484
+ console.debug = (...args) => {
1485
+ this.console.debug(...args);
1486
+ this.debug(...args);
1487
+ };
1488
+ }
1606
1489
  }
1607
1490
  }
1608
1491
  buildLog(level, log) {
@@ -1618,44 +1501,41 @@ ${log}`;
1618
1501
  }
1619
1502
  };
1620
1503
  }
1621
- createLog(log, namespace = this.namespace) {
1622
- return this.api.request({ url: `/api/` + PES`logs/${namespace}`, body: log }).then(() => this.emit(PES`logs/${namespace}:c`, log)).catch(() => {
1504
+ create(log, channel = this.channel) {
1505
+ if (channel.toLowerCase() == "server") throw new Error('"Server" namespace is reserved');
1506
+ return this.api.request({ url: `/api/` + mt`logs/${channel}`, body: log }).then(() => this.emit(mt`logs/${channel}:c`, log)).catch(() => {
1623
1507
  });
1624
1508
  }
1625
- clearLogs(namespace = this.namespace) {
1626
- return this.api.request({ url: `/api/` + PES`logs/${namespace}`, method: "DELETE" }).then(() => this.emit(PES`logs/${namespace}:d`));
1509
+ channels() {
1510
+ return this.api.request({ url: "/api/" + mt`logs/channels` });
1627
1511
  }
1628
- clearServerLogs() {
1629
- return this.clearLogs("server");
1512
+ delete(channel = this.channel) {
1513
+ return this.api.request({ url: `/api/` + mt`logs/${channel}`, method: "DELETE" }).then(() => this.emit(mt`logs/${channel}:d`));
1630
1514
  }
1631
- getLogs(length, page, namespace = this.namespace) {
1632
- if (!namespace) throw new Error("Cannot get logs, missing namespace");
1633
- const query = [length ? `length=${length}` : void 0, page ? `page=${page}` : void 0].filter((v) => !!v).join("&");
1634
- return this.api.request({ url: `/api/` + PES`logs/${namespace}` + (query ? `?${query}` : "") }).then((logs) => {
1635
- this.emit(PES`logs/${namespace}:r`, logs);
1515
+ read(channel = this.channel) {
1516
+ return this.api.request({ url: `/api/` + mt`logs/${channel}` }).then((logs) => {
1517
+ this.emit(mt`logs/${channel}:r`, logs);
1636
1518
  return logs;
1637
1519
  });
1638
1520
  }
1639
- getServerLogs(length, page) {
1640
- return this.getLogs(length, page, "server");
1641
- }
1642
- debug(log, namespace = this.namespace) {
1643
- return this.createLog(this.buildLog(yt.DEBUG, log), namespace);
1521
+ // Console =========================================================================================================
1522
+ debug(log, channel = this.channel) {
1523
+ return this.create(this.buildLog(ft.DEBUG, log), channel);
1644
1524
  }
1645
- log(log, namespace = this.namespace) {
1646
- return this.createLog(this.buildLog(yt.LOG, log), namespace);
1525
+ log(log, channel = this.channel) {
1526
+ return this.create(this.buildLog(ft.LOG, log), channel);
1647
1527
  }
1648
- info(log, namespace = this.namespace) {
1649
- return this.createLog(this.buildLog(yt.INFO, log), namespace);
1528
+ info(log, channel = this.channel) {
1529
+ return this.create(this.buildLog(ft.INFO, log), channel);
1650
1530
  }
1651
- warn(log, namespace = this.namespace) {
1652
- return this.createLog(this.buildLog(yt.WARN, log), namespace);
1531
+ warn(log, channel = this.channel) {
1532
+ return this.create(this.buildLog(ft.WARN, log), channel);
1653
1533
  }
1654
- error(log, namespace = this.namespace) {
1655
- return this.createLog(this.buildLog(yt.ERROR, log), namespace);
1534
+ error(log, channel = this.channel) {
1535
+ return this.create(this.buildLog(ft.ERROR, log), channel);
1656
1536
  }
1657
1537
  }
1658
- class Payments extends PathedEventEmitter {
1538
+ class Payments extends re {
1659
1539
  constructor(api, secret) {
1660
1540
  super();
1661
1541
  __publicField(this, "api");
@@ -1678,7 +1558,7 @@ class Payments extends PathedEventEmitter {
1678
1558
  amount,
1679
1559
  custom
1680
1560
  } });
1681
- this.emit(PES`payments:c`, request.data.clientSecret);
1561
+ this.emit(mt`payments:c`, request.data.clientSecret);
1682
1562
  return request.data.clientSecret;
1683
1563
  }
1684
1564
  async createForm(element, amount, custom) {
@@ -1692,28 +1572,28 @@ class Payments extends PathedEventEmitter {
1692
1572
  });
1693
1573
  }
1694
1574
  async history(username) {
1695
- const history = await this.api.request({ url: `/api/` + PES`payments/${username}` });
1696
- this.emit(PES`payments/${username}:r`, history);
1575
+ const history = await this.api.request({ url: `/api/` + mt`payments/${username}` });
1576
+ this.emit(mt`payments/${username}:r`, history);
1697
1577
  return history;
1698
1578
  }
1699
1579
  }
1700
- class Pdf extends PathedEventEmitter {
1580
+ class Pdf extends re {
1701
1581
  constructor(api) {
1702
1582
  super();
1703
1583
  __publicField(this, "api");
1704
1584
  this.api = typeof api == "string" ? new Api(api) : api;
1705
1585
  }
1706
1586
  createPdf(body, options) {
1707
- return this.api.request({ url: `/api/` + PES`pdf`, body: { ...body, options }, decode: false }).then(async (resp) => {
1587
+ return this.api.request({ url: `/api/` + mt`pdf`, body: { ...body, options }, decode: false }).then(async (resp) => {
1708
1588
  const blob = await resp.blob();
1709
1589
  if (options == null ? void 0 : options.download) {
1710
- let filename = (options == null ? void 0 : options.filename) || qt();
1590
+ let filename = (options == null ? void 0 : options.filename) || kt();
1711
1591
  if (!filename.endsWith(".pdf")) filename += ".pdf";
1712
1592
  const url = URL.createObjectURL(blob);
1713
- dt(url, filename);
1593
+ lt(url, filename);
1714
1594
  URL.revokeObjectURL(url);
1715
1595
  }
1716
- this.emit(PES`pdf:c`, blob);
1596
+ this.emit(mt`pdf:c`, blob);
1717
1597
  return blob;
1718
1598
  });
1719
1599
  }
@@ -1742,42 +1622,45 @@ const _Socket = class _Socket {
1742
1622
  this.connect();
1743
1623
  }
1744
1624
  close() {
1745
- console.debug("Disconnected from Momentum");
1746
- this.open = false;
1747
- this.connection.close();
1748
- }
1749
- connect(retry = 3) {
1750
1625
  var _a;
1751
- if (((_a = this.connection) == null ? void 0 : _a.readyState) < 2) this.connection.close();
1752
- this.connection = new WebSocket(this.url + (this.api.token ? `?token=${this.api.token}` : ""));
1626
+ if (this.open) console.debug("Disconnected from Momentum");
1627
+ this.open = false;
1628
+ (_a = this.connection) == null ? void 0 : _a.close();
1629
+ this.connection = void 0;
1630
+ }
1631
+ connect() {
1632
+ if (this.open) this.close();
1633
+ if (navigator.onLine) {
1634
+ this.connection = new WebSocket(this.url + (this.api.token ? `?token=${this.api.token}` : ""));
1635
+ this.connection.onclose = this.close;
1636
+ this.connection.onmessage = this.handle;
1637
+ this.connection.onopen = () => {
1638
+ this.open = true;
1639
+ clearTimeout(timeout);
1640
+ console.debug("Connected to Momentum");
1641
+ };
1642
+ }
1753
1643
  const timeout = setTimeout(() => {
1754
1644
  if (this.open) return;
1755
- this.connection.close();
1756
- console.error(`Momentum connection timeout`);
1757
- if (retry > 0) this.connect(retry - 1);
1758
- }, _Socket.timeout);
1759
- this.connection.onclose = () => this.open = false;
1760
- this.connection.onmessage = this.handle;
1761
- this.connection.onopen = () => {
1762
- this.open = true;
1763
- clearTimeout(timeout);
1764
- console.debug("Connected to Momentum");
1765
- };
1645
+ this.close();
1646
+ this.connect();
1647
+ }, _Socket.pollingSpeed);
1766
1648
  }
1767
1649
  handle(...args) {
1768
1650
  console.log(args);
1769
1651
  }
1770
1652
  send(channel, payload) {
1771
- this.connection.send(JSON.stringify({
1653
+ var _a;
1654
+ (_a = this.connection) == null ? void 0 : _a.send(JSON.stringify({
1772
1655
  token: this.api.token,
1773
1656
  channel,
1774
1657
  payload
1775
1658
  }));
1776
1659
  }
1777
1660
  };
1778
- __publicField(_Socket, "timeout", 1e4);
1661
+ __publicField(_Socket, "pollingSpeed", 3e4);
1779
1662
  let Socket = _Socket;
1780
- class Storage extends PathedEventEmitter {
1663
+ class Storage extends re {
1781
1664
  constructor(api) {
1782
1665
  super();
1783
1666
  __publicField(this, "api");
@@ -1785,119 +1668,119 @@ class Storage extends PathedEventEmitter {
1785
1668
  }
1786
1669
  copy(source, destination) {
1787
1670
  if (!source || !destination) throw new Error("Cannot copy file or folder, missing source or destination");
1788
- return this.api.request({ url: "/api/" + PES`storage/${destination}`, body: { from: source } }).then((response) => {
1789
- this.emit(PES`storage/${destination}:c`, response);
1671
+ return this.api.request({ url: "/api/" + mt`storage/${destination}`, body: { from: source } }).then((response) => {
1672
+ this.emit(mt`storage/${destination}:c`, response);
1790
1673
  return response;
1791
1674
  });
1792
1675
  }
1793
1676
  delete(path) {
1794
1677
  if (!path) throw new Error("Cannot delete file or folder, missing path");
1795
- return this.api.request({ url: "/api/" + PES`storage/${path}`, method: "DELETE" }).then(() => {
1796
- this.emit(PES`storage/${path}:d`, path);
1678
+ return this.api.request({ url: "/api/" + mt`storage/${path}`, method: "DELETE" }).then(() => {
1679
+ this.emit(mt`storage/${path}:d`, path);
1797
1680
  });
1798
1681
  }
1799
1682
  download(path, opts = {}) {
1800
1683
  if (!path) throw new Error("Cannot download file, missing path");
1801
- return this.api.request({ ...opts, url: "/api/" + PES`storage/${path}`, decode: false }).then(async (response) => {
1684
+ return this.api.request({ ...opts, url: "/api/" + mt`storage/${path}`, decode: false }).then(async (response) => {
1802
1685
  const blob = await response.blob();
1803
1686
  const name = opts.downloadAs || path.split("/").pop();
1804
- this.emit(PES`storage/${path}:r`, blob);
1805
- Gt(blob, name);
1687
+ this.emit(mt`storage/${path}:r`, blob);
1688
+ Dt(blob, name);
1806
1689
  return response;
1807
1690
  });
1808
1691
  }
1809
1692
  list(path) {
1810
1693
  if (!path) path = "/";
1811
- return this.api.request({ url: "/api/" + PES`storage/${path}` + "?list" }).then((resp) => {
1812
- this.emit(PES`storage/${path}:r`, resp);
1694
+ return this.api.request({ url: "/api/" + mt`storage/${path}` + "?list" }).then((resp) => {
1695
+ this.emit(mt`storage/${path}:r`, resp);
1813
1696
  return resp;
1814
1697
  });
1815
1698
  }
1816
1699
  open(path, target = "_blank") {
1817
1700
  if (!path) throw new Error("Cannot download file, missing path");
1818
- const link = `${this.api.url}/api/` + PES`storage/${path}` + (this.api.token ? `?token=${this.api.token}` : "");
1701
+ const link = `${this.api.url}/api/` + mt`storage/${path}` + (this.api.token ? `?token=${this.api.token}` : "");
1819
1702
  if (!target) return link;
1820
- this.emit(PES`storage/${path}:r`, path);
1703
+ this.emit(mt`storage/${path}:r`, path);
1821
1704
  return window.open(link, target);
1822
1705
  }
1823
1706
  mkdir(path) {
1824
1707
  if (!path) throw new Error("Cannot make directory, missing path");
1825
- return this.api.request({ url: "/api/" + PES`storage/${path}`, body: { directory: true } }).then((resp) => {
1826
- this.emit(PES`storage/${path}:c`, resp);
1708
+ return this.api.request({ url: "/api/" + mt`storage/${path}`, body: { directory: true } }).then((resp) => {
1709
+ this.emit(mt`storage/${path}:c`, resp);
1827
1710
  return resp;
1828
1711
  });
1829
1712
  }
1830
1713
  move(source, destination) {
1831
1714
  if (!source || !destination) throw new Error("Cannot move file or folder, missing source or destination");
1832
1715
  if (source == destination) return this.list(destination);
1833
- return this.api.request({ url: "/api/" + PES`storage/${source}`, method: "PATCH", body: { move: destination } }).then((response) => {
1834
- this.emit(PES`storage/${source}:u`, response);
1716
+ return this.api.request({ url: "/api/" + mt`storage/${source}`, method: "PATCH", body: { move: destination } }).then((response) => {
1717
+ this.emit(mt`storage/${source}:u`, response);
1835
1718
  return response;
1836
1719
  });
1837
1720
  }
1838
1721
  upload(files, opts) {
1839
- return new E(async (res, rej, prog) => {
1840
- if (!files) files = await Ut(typeof opts == "object" ? opts : void 0);
1722
+ return new x(async (res, rej, prog) => {
1723
+ if (!files) files = await Mt(typeof opts == "object" ? opts : void 0);
1841
1724
  if (!files || Array.isArray(files) && !files.length) return [];
1842
1725
  const path = (opts && typeof opts == "object" ? opts == null ? void 0 : opts.path : opts) || "/";
1843
- return Ft({
1844
- url: `${this.api.url}/api/` + PES`storage/${path}`,
1845
- files: ft(files),
1726
+ return Pt({
1727
+ url: `${this.api.url}/api/` + mt`storage/${path}`,
1728
+ files: m(files),
1846
1729
  headers: this.api.headers
1847
- }).onProgress((p2) => {
1848
- prog(p2);
1730
+ }).onProgress((p) => {
1731
+ prog(p);
1849
1732
  }).then((resp) => {
1850
- this.emit(PES`storage/${path}:c`, resp);
1733
+ this.emit(mt`storage/${path}:c`, resp);
1851
1734
  res(resp);
1852
1735
  }).catch((err) => rej(err));
1853
1736
  });
1854
1737
  }
1855
1738
  }
1856
- class Users extends PathedEventEmitter {
1739
+ class Users extends re {
1857
1740
  constructor(api) {
1858
1741
  super();
1859
1742
  __publicField(this, "api");
1860
- __publicField(this, "cache", new Dt("username"));
1743
+ __publicField(this, "cache", new Tt("username"));
1861
1744
  this.api = typeof api == "string" ? new Api(api) : api;
1862
1745
  }
1863
1746
  async all(reload) {
1864
1747
  if (!reload && this.cache.complete) return this.cache.all();
1865
- return this.api.request({ url: "/api/" + PES`users` }).then((resp) => {
1748
+ return this.api.request({ url: "/api/" + mt`users` }).then((resp) => {
1866
1749
  resp == null ? void 0 : resp.forEach((r) => {
1867
1750
  r.image = this.api.url + r.image + `?token=${this.api.token}`;
1868
1751
  return r;
1869
1752
  });
1870
1753
  this.cache.addAll(resp);
1871
- this.emit(PES`users:r`, resp || []);
1754
+ this.emit(mt`users:r`, resp || []);
1872
1755
  return resp;
1873
1756
  });
1874
1757
  }
1875
1758
  delete(username) {
1876
1759
  if (!username) throw new Error("Cannot delete user, missing username");
1877
1760
  return this.api.request({
1878
- url: "/api/" + PES`users/${username}`,
1761
+ url: "/api/" + mt`users/${username}`,
1879
1762
  method: "DELETE"
1880
1763
  }).then(() => {
1881
1764
  this.cache.delete(username);
1882
- this.emit(PES`users/${username}:d`, username);
1765
+ this.emit(mt`users/${username}:d`, username);
1883
1766
  });
1884
1767
  }
1885
1768
  async read(username, reload) {
1886
1769
  if (!username) throw new Error("Cannot read user, missing username");
1887
1770
  if (!reload && this.cache.get(username)) return this.cache.get(username);
1888
- return this.api.request({ url: "/api/" + PES`users/${username}` }).then((resp) => {
1771
+ return this.api.request({ url: "/api/" + mt`users/${username}` }).then((resp) => {
1889
1772
  if (resp) {
1890
1773
  resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
1891
1774
  this.cache.add(resp);
1892
1775
  }
1893
- this.emit(PES`users/${username}:r`, resp);
1776
+ this.emit(mt`users/${username}:r`, resp);
1894
1777
  return resp;
1895
1778
  });
1896
1779
  }
1897
1780
  update(user) {
1898
1781
  if (!user.username) throw new Error("Cannot update user, missing username");
1899
1782
  return this.api.request({
1900
- url: `/api/` + PES`users/${user.username}`,
1783
+ url: `/api/` + mt`users/${user.username}`,
1901
1784
  method: "PATCH",
1902
1785
  body: user
1903
1786
  }).then((resp) => {
@@ -1905,60 +1788,64 @@ class Users extends PathedEventEmitter {
1905
1788
  resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
1906
1789
  this.cache.add(resp);
1907
1790
  }
1908
- this.emit(PES`users/${user.username}:${resp._id ? "u" : "c"}`, resp);
1791
+ this.emit(mt`users/${user.username}:${resp._id ? "u" : "c"}`, resp);
1909
1792
  return resp;
1910
1793
  });
1911
1794
  }
1912
1795
  uploadImage(username, file) {
1913
1796
  if (!username || !file) throw new Error("Cannot update user image, missing username or file");
1914
- return Ft({
1915
- url: this.api.url + `/api/` + PES`users/${username}/image`,
1797
+ return Pt({
1798
+ url: this.api.url + `/api/` + mt`users/${username}/image`,
1916
1799
  files: [file],
1917
1800
  headers: this.api.headers
1918
1801
  });
1919
1802
  }
1920
1803
  }
1921
- class Settings extends PathedEventEmitter {
1804
+ class Settings extends re {
1922
1805
  constructor(api) {
1923
1806
  super();
1924
1807
  __publicField(this, "api");
1925
- __publicField(this, "cache", new Dt());
1808
+ __publicField(this, "cache");
1926
1809
  this.api = typeof api == "string" ? new Api(api) : api;
1810
+ this.cache = new Tt("key", { storageKey: `momentum:settings:${this.api.host}` });
1811
+ this.api.on("api/token", () => this.all(false, true));
1927
1812
  }
1928
- async all(detailed = false, reload) {
1813
+ async all(detailed, reload) {
1929
1814
  if (!reload && !detailed && this.cache.complete) return this.cache;
1930
- return this.api.request({ url: `/api/` + PES`settings` + (detailed ? "?detailed" : "") }).then((resp) => {
1815
+ return this.api.request({ url: `/api/` + mt`settings` + (detailed ? "?detailed" : "") }).then((resp) => {
1816
+ this.cache.clear();
1931
1817
  if (resp) Object.keys(resp).forEach((key) => this.cache.set(key, detailed ? resp[key].value : resp[key]));
1932
- this.emit(PES`settings:r`, resp || []);
1818
+ this.cache.complete = true;
1819
+ this.emit(mt`settings:r`, resp || []);
1933
1820
  return resp;
1934
1821
  });
1935
1822
  }
1936
1823
  delete(key) {
1937
1824
  if (!key) throw new Error("Cannot delete setting, missing key");
1938
- return this.api.request({ url: `/api/` + PES`settings/${key}`, method: "DELETE" }).then(() => {
1825
+ return this.api.request({ url: `/api/` + mt`settings/${key}`, method: "DELETE" }).then(() => {
1939
1826
  this.cache.delete(key);
1940
- this.emit(PES`settings/${key}:d`, key);
1827
+ this.emit(mt`settings/${key}:d`, key);
1941
1828
  });
1942
1829
  }
1943
1830
  read(key, reload = false) {
1944
1831
  if (!key) throw new Error("Cannot read setting, missing key");
1945
1832
  if (!reload && this.cache.get(key)) return this.cache.get(key);
1946
- return this.api.request({ url: `/api/` + PES`settings/${key}` }).then((variable) => {
1833
+ return this.api.request({ url: `/api/` + mt`settings/${key}` }).then((variable) => {
1947
1834
  if (variable) this.cache.set(variable.key, variable.value);
1948
- this.emit(PES`settings/${key}:r`, variable);
1835
+ this.emit(mt`settings/${key}:r`, variable);
1949
1836
  return variable;
1950
1837
  });
1951
1838
  }
1952
1839
  update(variable) {
1953
1840
  if (!variable.key) throw new Error("Cannot update setting, missing key");
1954
- return this.api.request({ url: `/api/` + PES`settings/${variable.key}`, body: variable }).then((variable2) => {
1841
+ return this.api.request({ url: `/api/` + mt`settings/${variable.key}`, body: variable }).then((variable2) => {
1955
1842
  if (variable2) this.cache.set(variable2.key, variable2.value);
1956
- this.emit(`/api/` + PES`settings/${variable2.key}:${variable2._id ? "u" : "c"}`, variable2);
1843
+ this.emit(`/api/` + mt`settings/${variable2.key}:${variable2._id ? "u" : "c"}`, variable2);
1957
1844
  return variable2;
1958
1845
  });
1959
1846
  }
1960
1847
  }
1961
- class Static extends PathedEventEmitter {
1848
+ class Static extends re {
1962
1849
  constructor(api) {
1963
1850
  super();
1964
1851
  __publicField(this, "api");
@@ -1966,27 +1853,27 @@ class Static extends PathedEventEmitter {
1966
1853
  }
1967
1854
  delete(path) {
1968
1855
  if (!path) throw new Error("Cannot delete static asset, missing path");
1969
- return this.api.request({ url: `/api/` + PES`static/${path}`, method: "DELETE" }).then(() => {
1970
- this.emit(PES`static/${path}:d`, path);
1856
+ return this.api.request({ url: `/api/` + mt`static/${path}`, method: "DELETE" }).then(() => {
1857
+ this.emit(mt`static/${path}:d`, path);
1971
1858
  });
1972
1859
  }
1973
1860
  upload(files, path = "/") {
1974
1861
  if (!files) throw new Error("Cannot upload static assets, missing file");
1975
- return new E(async (res, rej, prog) => {
1976
- return Ft({
1977
- url: this.api.url + "/api/" + PES`static/${path}`,
1978
- files: ft(files),
1862
+ return new x(async (res, rej, prog) => {
1863
+ return Pt({
1864
+ url: this.api.url + "/api/" + mt`static/${path}`,
1865
+ files: m(files),
1979
1866
  headers: this.api.headers
1980
- }).onProgress((p2) => {
1981
- prog(p2);
1867
+ }).onProgress((p) => {
1868
+ prog(p);
1982
1869
  }).then((resp) => {
1983
- this.emit(PES`static/${path}:c`, resp);
1870
+ this.emit(mt`static/${path}:c`, resp);
1984
1871
  res(resp);
1985
1872
  }).catch((err) => rej(err));
1986
1873
  });
1987
1874
  }
1988
1875
  }
1989
- class Momentum extends PathedEventEmitter {
1876
+ class Momentum extends re {
1990
1877
  constructor(url, opts) {
1991
1878
  super();
1992
1879
  __publicField(this, "api");
@@ -2006,18 +1893,15 @@ class Momentum extends PathedEventEmitter {
2006
1893
  __publicField(this, "static");
2007
1894
  __publicField(this, "storage");
2008
1895
  __publicField(this, "users");
2009
- this.api = new Api(url, opts == null ? void 0 : opts.api);
1896
+ this.api = new Api(url, opts);
2010
1897
  this.actions = new Actions(this.api);
2011
1898
  this.ai = new Ai(this.api);
2012
1899
  this.analytics = new Analytics(this.api);
2013
- this.auth = new Auth(this.api, {
2014
- persist: (opts == null ? void 0 : opts.persist) ?? true,
2015
- loginUi: opts == null ? void 0 : opts.loginUi
2016
- });
1900
+ this.auth = new Auth(this.api, { loginUrl: opts == null ? void 0 : opts.loginUrl });
2017
1901
  this.data = new Data(this.api);
2018
1902
  this.email = new Email(this.api);
2019
1903
  this.groups = new Groups(this.api);
2020
- this.logger = new Logger(this.api, "client", opts == null ? void 0 : opts.logLevel);
1904
+ this.logger = new Logger(this.api, (opts == null ? void 0 : opts.app) || "client", opts == null ? void 0 : opts.logLevel);
2021
1905
  if (opts == null ? void 0 : opts.stripeSecret) this.payments = new Payments(this.api, opts.stripeSecret);
2022
1906
  this.pdf = new Pdf(this.api);
2023
1907
  this.settings = new Settings(this.api);
@@ -2062,16 +1946,15 @@ export {
2062
1946
  Groups,
2063
1947
  Logger,
2064
1948
  Momentum,
2065
- PE,
2066
- PES,
2067
- PathEvent,
2068
- PathedEventEmitter,
1949
+ ee as PE,
1950
+ mt as PES,
1951
+ y as PathEvent,
1952
+ re as PathEventEmitter,
2069
1953
  Payments,
2070
1954
  Pdf,
2071
1955
  Settings,
2072
1956
  Socket,
2073
1957
  Static,
2074
1958
  Storage,
2075
- Totp,
2076
1959
  Users
2077
1960
  };