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