@ztimson/momentum 0.40.1 → 0.42.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.mjs CHANGED
@@ -1,59 +1,170 @@
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 nt = Object.defineProperty;
5
- var rt = (n, t, e) => t in n ? nt(n, t, { enumerable: true, configurable: true, writable: true, value: e }) : n[t] = e;
6
- var i = (n, t, e) => (rt(n, typeof t != "symbol" ? t + "" : t, e), e);
7
- function ot(n, t = false) {
8
- if (n == null)
9
- throw new Error("Cannot clean a NULL value");
10
- return Array.isArray(n) ? n = n.filter((e) => e != null) : Object.entries(n).forEach(([e, r]) => {
11
- (t && r === void 0 || !t && r == null) && delete n[e];
12
- }), n;
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) {
8
+ if (r == null) throw new Error("Cannot clean a NULL value");
9
+ return Array.isArray(r) ? r = r.filter((e) => e != null) : Object.entries(r).forEach(([e, n]) => {
10
+ (t && n === void 0 || !t && n == null) && delete r[e];
11
+ }), r;
13
12
  }
14
- function b(n, t) {
15
- const e = typeof n, r = typeof t;
16
- 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((s) => b(n[s], t[s]));
13
+ function A(r, t) {
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]));
17
16
  }
18
- function U(n) {
17
+ function M(r) {
19
18
  try {
20
- return JSON.parse(n);
19
+ return JSON.parse(r);
21
20
  } catch {
22
- return n;
21
+ return r;
23
22
  }
24
23
  }
25
- function ut(n) {
26
- return Array.isArray(n) ? n : [n];
24
+ function Lt(r, t) {
25
+ let e = [];
26
+ return JSON.stringify(r, (n, s) => {
27
+ if (typeof s == "object" && s !== null) {
28
+ if (e.includes(s)) return;
29
+ e.push(s);
30
+ }
31
+ return s;
32
+ }, t);
33
+ }
34
+ function ft(r) {
35
+ return Array.isArray(r) ? r : [r];
36
+ }
37
+ class Dt {
38
+ /**
39
+ * Create new cache
40
+ *
41
+ * @param {keyof T} key Default property to use as primary key
42
+ * @param {number} ttl Default expiry in milliseconds
43
+ */
44
+ constructor(t, e) {
45
+ c(this, "store", {});
46
+ c(this, "complete", false);
47
+ c(this, "values", this.all());
48
+ return this.key = t, this.ttl = e, new Proxy(this, {
49
+ get: (n, s) => s in n ? n[s] : n.store[s],
50
+ set: (n, s, o) => (s in n ? n[s] = o : n.store[s] = o, true)
51
+ });
52
+ }
53
+ getKey(t) {
54
+ if (!this.key) throw new Error("No key defined");
55
+ return t[this.key];
56
+ }
57
+ /**
58
+ * Get all cached items
59
+ *
60
+ * @return {T[]} Array of items
61
+ */
62
+ all() {
63
+ return Object.values(this.store);
64
+ }
65
+ /**
66
+ * Add a new item to the cache. Like set, but finds key automatically
67
+ *
68
+ * @param {T} value Item to add to cache
69
+ * @param {number | undefined} ttl Override default expiry
70
+ * @return {this}
71
+ */
72
+ add(t, e = this.ttl) {
73
+ const n = this.getKey(t);
74
+ return this.set(n, t, e), this;
75
+ }
76
+ /**
77
+ * Add several rows to the cache
78
+ *
79
+ * @param {T[]} rows Several items that will be cached using the default key
80
+ * @param complete Mark cache as complete & reliable, defaults to true
81
+ * @return {this}
82
+ */
83
+ addAll(t, e = true) {
84
+ return t.forEach((n) => this.add(n)), this.complete = e, this;
85
+ }
86
+ /**
87
+ * Delete an item from the cache
88
+ *
89
+ * @param {K} key Item's primary key
90
+ */
91
+ delete(t) {
92
+ delete this.store[t];
93
+ }
94
+ /**
95
+ * Return cache as an array of key-value pairs
96
+ * @return {[K, T][]} Key-value pairs array
97
+ */
98
+ entries() {
99
+ return Object.entries(this.store);
100
+ }
101
+ /**
102
+ * Get item from the cache
103
+ * @param {K} key Key to lookup
104
+ * @return {T} Cached item
105
+ */
106
+ get(t) {
107
+ return this.store[t];
108
+ }
109
+ /**
110
+ * Get a list of cached keys
111
+ *
112
+ * @return {K[]} Array of keys
113
+ */
114
+ keys() {
115
+ return Object.keys(this.store);
116
+ }
117
+ /**
118
+ * Get map of cached items
119
+ *
120
+ * @return {Record<K, T>}
121
+ */
122
+ map() {
123
+ return structuredClone(this.store);
124
+ }
125
+ /**
126
+ * Add an item to the cache manually specifying the key
127
+ *
128
+ * @param {K} key Key item will be cached under
129
+ * @param {T} value Item to cache
130
+ * @param {number | undefined} ttl Override default expiry
131
+ * @return {this}
132
+ */
133
+ set(t, e, n = this.ttl) {
134
+ return this.store[t] = e, n && setTimeout(() => {
135
+ this.complete = false, this.delete(t);
136
+ }, n), this;
137
+ }
27
138
  }
28
- class m extends Promise {
139
+ class E extends Promise {
29
140
  constructor(e) {
30
- super((r, o) => e(
31
- (s) => r(s),
32
- (s) => o(s),
33
- (s) => this.progress = s
141
+ super((n, s) => e(
142
+ (o) => n(o),
143
+ (o) => s(o),
144
+ (o) => this.progress = o
34
145
  ));
35
- i(this, "listeners", []);
36
- i(this, "_progress", 0);
146
+ c(this, "listeners", []);
147
+ c(this, "_progress", 0);
37
148
  }
38
149
  get progress() {
39
150
  return this._progress;
40
151
  }
41
152
  set progress(e) {
42
- e != this._progress && (this._progress = e, this.listeners.forEach((r) => r(e)));
153
+ e != this._progress && (this._progress = e, this.listeners.forEach((n) => n(e)));
43
154
  }
44
155
  static from(e) {
45
- return e instanceof m ? e : new m((r, o) => e.then((...s) => r(...s)).catch((...s) => o(...s)));
156
+ return e instanceof E ? e : new E((n, s) => e.then((...o) => n(...o)).catch((...o) => s(...o)));
46
157
  }
47
158
  from(e) {
48
- const r = m.from(e);
49
- return this.onProgress((o) => r.progress = o), r;
159
+ const n = E.from(e);
160
+ return this.onProgress((s) => n.progress = s), n;
50
161
  }
51
162
  onProgress(e) {
52
163
  return this.listeners.push(e), this;
53
164
  }
54
- then(e, r) {
55
- const o = super.then(e, r);
56
- return this.from(o);
165
+ then(e, n) {
166
+ const s = super.then(e, n);
167
+ return this.from(s);
57
168
  }
58
169
  catch(e) {
59
170
  return this.from(super.catch(e));
@@ -62,76 +173,76 @@ class m extends Promise {
62
173
  return this.from(super.finally(e));
63
174
  }
64
175
  }
65
- function Tt(n, t) {
66
- n instanceof Blob || (n = new Blob(ut(n)));
67
- const e = URL.createObjectURL(n);
68
- at(e, t), URL.revokeObjectURL(e);
176
+ function Gt(r, t) {
177
+ r instanceof Blob || (r = new Blob(ft(r)));
178
+ const e = URL.createObjectURL(r);
179
+ dt(e, t), URL.revokeObjectURL(e);
69
180
  }
70
- function at(n, t) {
181
+ function dt(r, t) {
71
182
  const e = document.createElement("a");
72
- e.href = n, e.download = t || n.split("/").pop(), document.body.appendChild(e), e.click(), document.body.removeChild(e);
183
+ e.href = r, e.download = t || r.split("/").pop(), document.body.appendChild(e), e.click(), document.body.removeChild(e);
73
184
  }
74
- function It(n = {}) {
185
+ function Ut(r = {}) {
75
186
  return new Promise((t) => {
76
187
  const e = document.createElement("input");
77
- e.type = "file", e.accept = n.accept || "*", e.style.display = "none", e.multiple = !!n.multiple, e.onblur = e.onchange = async () => {
188
+ e.type = "file", e.accept = r.accept || "*", e.style.display = "none", e.multiple = !!r.multiple, e.onblur = e.onchange = async () => {
78
189
  t(Array.from(e.files)), e.remove();
79
190
  }, document.body.appendChild(e), e.click();
80
191
  });
81
192
  }
82
- function Dt(n) {
83
- return new m((t, e, r) => {
84
- const o = new XMLHttpRequest(), s = new FormData();
85
- n.files.forEach((c) => s.append("file", c)), o.withCredentials = !!n.withCredentials, o.upload.addEventListener("progress", (c) => c.lengthComputable ? r(c.loaded / c.total) : null), o.addEventListener("loadend", () => t(U(o.responseText))), o.addEventListener("error", () => e(U(o.responseText))), o.addEventListener("timeout", () => e({ error: "Request timed out" })), o.open("POST", n.url), Object.entries(n.headers || {}).forEach(([c, y]) => o.setRequestHeader(c, y)), o.send(s);
193
+ function Ft(r) {
194
+ return new E((t, e, n) => {
195
+ const s = new XMLHttpRequest(), o = new FormData();
196
+ 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);
86
197
  });
87
198
  }
88
- class v {
199
+ class _ {
89
200
  constructor() {
90
- i(this, "listeners", {});
201
+ c(this, "listeners", {});
91
202
  }
92
203
  static emit(t, ...e) {
93
- (this.listeners["*"] || []).forEach((r) => r(t, ...e)), (this.listeners[t.toString()] || []).forEach((r) => r(...e));
204
+ (this.listeners["*"] || []).forEach((n) => n(t, ...e)), (this.listeners[t.toString()] || []).forEach((n) => n(...e));
94
205
  }
95
206
  static off(t, e) {
96
- const r = t.toString();
97
- this.listeners[r] = (this.listeners[r] || []).filter((o) => o === e);
207
+ const n = t.toString();
208
+ this.listeners[n] = (this.listeners[n] || []).filter((s) => s === e);
98
209
  }
99
210
  static on(t, e) {
100
- var o;
101
- const r = t.toString();
102
- return this.listeners[r] || (this.listeners[r] = []), (o = this.listeners[r]) == null || o.push(e), () => this.off(t, e);
211
+ var s;
212
+ const n = t.toString();
213
+ return this.listeners[n] || (this.listeners[n] = []), (s = this.listeners[n]) == null || s.push(e), () => this.off(t, e);
103
214
  }
104
215
  static once(t, e) {
105
- return new Promise((r) => {
106
- const o = this.on(t, (...s) => {
107
- r(s.length == 1 ? s[0] : s), e && e(...s), o();
216
+ return new Promise((n) => {
217
+ const s = this.on(t, (...o) => {
218
+ n(o.length == 1 ? o[0] : o), e && e(...o), s();
108
219
  });
109
220
  });
110
221
  }
111
222
  emit(t, ...e) {
112
- (this.listeners["*"] || []).forEach((r) => r(t, ...e)), (this.listeners[t] || []).forEach((r) => r(...e));
223
+ (this.listeners["*"] || []).forEach((n) => n(t, ...e)), (this.listeners[t] || []).forEach((n) => n(...e));
113
224
  }
114
225
  off(t, e) {
115
- this.listeners[t] = (this.listeners[t] || []).filter((r) => r === e);
226
+ this.listeners[t] = (this.listeners[t] || []).filter((n) => n === e);
116
227
  }
117
228
  on(t, e) {
118
- var r;
119
- return this.listeners[t] || (this.listeners[t] = []), (r = this.listeners[t]) == null || r.push(e), () => this.off(t, e);
229
+ var n;
230
+ return this.listeners[t] || (this.listeners[t] = []), (n = this.listeners[t]) == null || n.push(e), () => this.off(t, e);
120
231
  }
121
232
  once(t, e) {
122
- return new Promise((r) => {
123
- const o = this.on(t, (...s) => {
124
- r(s.length == 1 ? s[0] : s), e && e(...s), o();
233
+ return new Promise((n) => {
234
+ const s = this.on(t, (...o) => {
235
+ n(o.length == 1 ? o[0] : o), e && e(...o), s();
125
236
  });
126
237
  });
127
238
  }
128
239
  }
129
- i(v, "listeners", {});
240
+ c(_, "listeners", {});
130
241
  class p extends Error {
131
- constructor(e, r) {
242
+ constructor(e, n) {
132
243
  super(e);
133
- i(this, "_code");
134
- r != null && (this._code = r);
244
+ c(this, "_code");
245
+ n != null && (this._code = n);
135
246
  }
136
247
  get code() {
137
248
  return this._code || this.constructor.code;
@@ -140,11 +251,11 @@ class p extends Error {
140
251
  this._code = e;
141
252
  }
142
253
  static from(e) {
143
- const r = Number(e.statusCode) ?? Number(e.code), o = new this(e.message || e.toString());
144
- return Object.assign(o, {
254
+ const n = Number(e.statusCode) ?? Number(e.code), s = new this(e.message || e.toString());
255
+ return Object.assign(s, {
145
256
  stack: e.stack,
146
257
  ...e,
147
- code: r ?? void 0
258
+ code: n ?? void 0
148
259
  });
149
260
  }
150
261
  static instanceof(e) {
@@ -154,8 +265,8 @@ class p extends Error {
154
265
  return this.message || super.toString();
155
266
  }
156
267
  }
157
- i(p, "code", 500);
158
- class Y extends p {
268
+ c(p, "code", 500);
269
+ class W extends p {
159
270
  constructor(t = "Bad Request") {
160
271
  super(t);
161
272
  }
@@ -163,8 +274,8 @@ class Y extends p {
163
274
  return t.constructor.code == this.code;
164
275
  }
165
276
  }
166
- i(Y, "code", 400);
167
- class H extends p {
277
+ c(W, "code", 400);
278
+ class J extends p {
168
279
  constructor(t = "Unauthorized") {
169
280
  super(t);
170
281
  }
@@ -172,8 +283,8 @@ class H extends p {
172
283
  return t.constructor.code == this.code;
173
284
  }
174
285
  }
175
- i(H, "code", 401);
176
- class W extends p {
286
+ c(J, "code", 401);
287
+ class z extends p {
177
288
  constructor(t = "Payment Required") {
178
289
  super(t);
179
290
  }
@@ -181,8 +292,8 @@ class W extends p {
181
292
  return t.constructor.code == this.code;
182
293
  }
183
294
  }
184
- i(W, "code", 402);
185
- class z extends p {
295
+ c(z, "code", 402);
296
+ class K extends p {
186
297
  constructor(t = "Forbidden") {
187
298
  super(t);
188
299
  }
@@ -190,8 +301,8 @@ class z extends p {
190
301
  return t.constructor.code == this.code;
191
302
  }
192
303
  }
193
- i(z, "code", 403);
194
- class J extends p {
304
+ c(K, "code", 403);
305
+ class Z extends p {
195
306
  constructor(t = "Not Found") {
196
307
  super(t);
197
308
  }
@@ -199,8 +310,8 @@ class J extends p {
199
310
  return t.constructor.code == this.code;
200
311
  }
201
312
  }
202
- i(J, "code", 404);
203
- class K extends p {
313
+ c(Z, "code", 404);
314
+ class V extends p {
204
315
  constructor(t = "Method Not Allowed") {
205
316
  super(t);
206
317
  }
@@ -208,8 +319,8 @@ class K extends p {
208
319
  return t.constructor.code == this.code;
209
320
  }
210
321
  }
211
- i(K, "code", 405);
212
- class Z extends p {
322
+ c(V, "code", 405);
323
+ class X extends p {
213
324
  constructor(t = "Not Acceptable") {
214
325
  super(t);
215
326
  }
@@ -217,8 +328,8 @@ class Z extends p {
217
328
  return t.constructor.code == this.code;
218
329
  }
219
330
  }
220
- i(Z, "code", 406);
221
- class V extends p {
331
+ c(X, "code", 406);
332
+ class Q extends p {
222
333
  constructor(t = "Internal Server Error") {
223
334
  super(t);
224
335
  }
@@ -226,8 +337,8 @@ class V extends p {
226
337
  return t.constructor.code == this.code;
227
338
  }
228
339
  }
229
- i(V, "code", 500);
230
- class X extends p {
340
+ c(Q, "code", 500);
341
+ class tt extends p {
231
342
  constructor(t = "Not Implemented") {
232
343
  super(t);
233
344
  }
@@ -235,8 +346,8 @@ class X extends p {
235
346
  return t.constructor.code == this.code;
236
347
  }
237
348
  }
238
- i(X, "code", 501);
239
- class Q extends p {
349
+ c(tt, "code", 501);
350
+ class et extends p {
240
351
  constructor(t = "Bad Gateway") {
241
352
  super(t);
242
353
  }
@@ -244,8 +355,8 @@ class Q extends p {
244
355
  return t.constructor.code == this.code;
245
356
  }
246
357
  }
247
- i(Q, "code", 502);
248
- class _ extends p {
358
+ c(et, "code", 502);
359
+ class rt extends p {
249
360
  constructor(t = "Service Unavailable") {
250
361
  super(t);
251
362
  }
@@ -253,8 +364,8 @@ class _ extends p {
253
364
  return t.constructor.code == this.code;
254
365
  }
255
366
  }
256
- i(_, "code", 503);
257
- class tt extends p {
367
+ c(rt, "code", 503);
368
+ class nt extends p {
258
369
  constructor(t = "Gateway Timeout") {
259
370
  super(t);
260
371
  }
@@ -262,12 +373,12 @@ class tt extends p {
262
373
  return t.constructor.code == this.code;
263
374
  }
264
375
  }
265
- i(tt, "code", 504);
376
+ c(nt, "code", 504);
266
377
  const w = class w2 {
267
378
  constructor(t = {}) {
268
- i(this, "interceptors", {});
269
- i(this, "headers", {});
270
- i(this, "url");
379
+ c(this, "interceptors", {});
380
+ c(this, "headers", {});
381
+ c(this, "url");
271
382
  this.url = t.url ?? null, this.headers = t.headers || {}, t.interceptors && t.interceptors.forEach((e) => w2.addInterceptor(e));
272
383
  }
273
384
  static addInterceptor(t) {
@@ -283,55 +394,53 @@ const w = class w2 {
283
394
  };
284
395
  }
285
396
  request(t = {}) {
286
- var o;
287
- if (!this.url && !t.url)
288
- throw new Error("URL needs to be set");
289
- let e = ((o = t.url) != null && o.startsWith("http") ? t.url : (this.url || "") + (t.url || "")).replace(/([^:]\/)\/+/g, "$1");
290
- if (t.fragment && (e.includes("#") ? e.replace(/#.*(\?|\n)/g, (s, c) => `#${t.fragment}${c}`) : e += "#" + t.fragment), t.query) {
291
- const s = Array.isArray(t.query) ? t.query : Object.keys(t.query).map((c) => ({ key: c, value: t.query[c] }));
292
- e += (e.includes("?") ? "&" : "?") + s.map((c) => `${c.key}=${c.value}`).join("&");
397
+ var s;
398
+ if (!this.url && !t.url) throw new Error("URL needs to be set");
399
+ let e = ((s = t.url) != null && s.startsWith("http") ? t.url : (this.url || "") + (t.url || "")).replace(/([^:]\/)\/+/g, "$1");
400
+ if (t.fragment && (e.includes("#") ? e.replace(/#.*(\?|\n)/g, (o, i) => `#${t.fragment}${i}`) : e += "#" + t.fragment), t.query) {
401
+ const o = Array.isArray(t.query) ? t.query : Object.keys(t.query).map((i) => ({ key: i, value: t.query[i] }));
402
+ e += (e.includes("?") ? "&" : "?") + o.map((i) => `${i.key}=${i.value}`).join("&");
293
403
  }
294
- const r = ot({
404
+ const n = ut({
295
405
  "Content-Type": t.body ? t.body instanceof FormData ? "multipart/form-data" : "application/json" : void 0,
296
406
  ...w2.headers,
297
407
  ...this.headers,
298
408
  ...t.headers
299
409
  });
300
- return typeof t.body == "object" && t.body != null && r["Content-Type"] == "application/json" && (t.body = JSON.stringify(t.body)), new m((s, c, y) => {
410
+ return typeof t.body == "object" && t.body != null && n["Content-Type"] == "application/json" && (t.body = JSON.stringify(t.body)), new E((o, i, a) => {
301
411
  fetch(e, {
302
- headers: r,
412
+ headers: n,
303
413
  method: t.method || (t.body ? "POST" : "GET"),
304
414
  body: t.body
305
415
  }).then(async (u) => {
306
- var j, k;
307
- for (let a of [...Object.values(w2.interceptors), ...Object.values(this.interceptors)])
308
- await new Promise((O) => a(u, () => O()));
309
- const R = u.headers.get("Content-Length"), C = R ? parseInt(R, 10) : 0;
310
- let D = 0;
311
- const N = (j = u.body) == null ? void 0 : j.getReader(), et = new ReadableStream({
312
- start(a) {
313
- function O() {
314
- N == null || N.read().then((B) => {
315
- if (B.done)
316
- return a.close();
317
- D += B.value.byteLength, y(D / C), a.enqueue(B.value), O();
318
- }).catch((B) => a.error(B));
416
+ var G, U;
417
+ for (let l of [...Object.values(w2.interceptors), ...Object.values(this.interceptors)])
418
+ await new Promise((R) => l(u, () => R()));
419
+ const v = u.headers.get("Content-Length"), N = v ? parseInt(v, 10) : 0;
420
+ let P = 0;
421
+ const I = (G = u.body) == null ? void 0 : G.getReader(), ot = new ReadableStream({
422
+ start(l) {
423
+ function R() {
424
+ I == null || I.read().then((O) => {
425
+ if (O.done) return l.close();
426
+ P += O.value.byteLength, a(P / N), l.enqueue(O.value), R();
427
+ }).catch((O) => l.error(O));
319
428
  }
320
- O();
429
+ R();
321
430
  }
322
431
  });
323
- if (u.data = new Response(et), t.decode == null || t.decode) {
324
- const a = (k = u.headers.get("Content-Type")) == null ? void 0 : k.toLowerCase();
325
- a != null && a.includes("form") ? u.data = await u.data.formData() : a != null && a.includes("json") ? u.data = await u.data.json() : a != null && a.includes("text") ? u.data = await u.data.text() : a != null && a.includes("application") && (u.data = await u.data.blob());
432
+ if (u.data = new Response(ot), t.decode == null || t.decode) {
433
+ const l = (U = u.headers.get("Content-Type")) == null ? void 0 : U.toLowerCase();
434
+ 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());
326
435
  }
327
- u.ok ? s(u) : c(u);
436
+ u.ok ? o(u) : i(u);
328
437
  });
329
438
  });
330
439
  }
331
440
  };
332
- i(w, "interceptors", {}), i(w, "headers", {});
333
- let q = w;
334
- const S = {
441
+ c(w, "interceptors", {}), c(w, "headers", {});
442
+ let F = w;
443
+ const x = {
335
444
  CLEAR: "\x1B[0m",
336
445
  BRIGHT: "\x1B[1m",
337
446
  DIM: "\x1B[2m",
@@ -339,7 +448,7 @@ const S = {
339
448
  BLINK: "\x1B[5m",
340
449
  REVERSE: "\x1B[7m",
341
450
  HIDDEN: "\x1B[8m"
342
- }, $ = {
451
+ }, j = {
343
452
  BLACK: "\x1B[30m",
344
453
  RED: "\x1B[31m",
345
454
  GREEN: "\x1B[32m",
@@ -357,59 +466,187 @@ const S = {
357
466
  LIGHT_CYAN: "\x1B[96m",
358
467
  WHITE: "\x1B[97m"
359
468
  };
360
- var lt = /* @__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))(lt || {});
361
- const g = class g2 extends v {
469
+ 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 || {});
470
+ const g = class g2 extends _ {
362
471
  constructor(t) {
363
472
  super(), this.namespace = t;
364
473
  }
365
- pad(t, e, r, o = false) {
366
- const s = t.toString(), c = e - s.length;
367
- if (c <= 0)
368
- return s;
369
- const y = Array(~~(c / r.length)).fill(r).join("");
370
- return o ? s + y : y + s;
474
+ pad(t, e, n, s = false) {
475
+ const o = t.toString(), i = e - o.length;
476
+ if (i <= 0) return o;
477
+ const a = Array(~~(i / n.length)).fill(n).join("");
478
+ return s ? o + a : a + o;
371
479
  }
372
480
  format(...t) {
373
481
  const e = /* @__PURE__ */ new Date();
374
482
  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(" ")}`;
375
483
  }
376
484
  debug(...t) {
377
- if (g2.LOG_LEVEL < 4)
378
- return;
485
+ if (g2.LOG_LEVEL < 4) return;
379
486
  const e = this.format(...t);
380
- g2.emit(4, e), console.debug($.LIGHT_GREY + e + S.CLEAR);
487
+ g2.emit(4, e), console.debug(j.LIGHT_GREY + e + x.CLEAR);
381
488
  }
382
489
  log(...t) {
383
- if (g2.LOG_LEVEL < 3)
384
- return;
490
+ if (g2.LOG_LEVEL < 3) return;
385
491
  const e = this.format(...t);
386
- g2.emit(3, e), console.log(S.CLEAR + e);
492
+ g2.emit(3, e), console.log(x.CLEAR + e);
387
493
  }
388
494
  info(...t) {
389
- if (g2.LOG_LEVEL < 2)
390
- return;
495
+ if (g2.LOG_LEVEL < 2) return;
391
496
  const e = this.format(...t);
392
- g2.emit(2, e), console.info($.BLUE + e + S.CLEAR);
497
+ g2.emit(2, e), console.info(j.BLUE + e + x.CLEAR);
393
498
  }
394
499
  warn(...t) {
395
- if (g2.LOG_LEVEL < 1)
396
- return;
500
+ if (g2.LOG_LEVEL < 1) return;
397
501
  const e = this.format(...t);
398
- g2.emit(1, e), console.warn($.YELLOW + e + S.CLEAR);
502
+ g2.emit(1, e), console.warn(j.YELLOW + e + x.CLEAR);
399
503
  }
400
504
  error(...t) {
401
- if (g2.LOG_LEVEL < 0)
402
- return;
505
+ if (g2.LOG_LEVEL < 0) return;
403
506
  const e = this.format(...t);
404
- g2.emit(0, e), console.error($.RED + e + S.CLEAR);
507
+ g2.emit(0, e), console.error(j.RED + e + x.CLEAR);
405
508
  }
406
509
  };
407
- i(g, "LOG_LEVEL", 4);
408
- class Api extends q {
510
+ c(g, "LOG_LEVEL", 4);
511
+ var $ = typeof globalThis < "u" ? globalThis : typeof window < "u" ? window : typeof global < "u" ? global : typeof self < "u" ? self : {}, xt = {}, S = {};
512
+ Object.defineProperty(S, "__esModule", { value: true });
513
+ S.persist = S.Persist = void 0;
514
+ class st {
515
+ /**
516
+ * @param {string} key Primary key value will be stored under
517
+ * @param {PersistOptions<T>} options Configure using {@link PersistOptions}
518
+ */
519
+ constructor(t, e = {}) {
520
+ c(this, "key");
521
+ c(this, "options");
522
+ c(this, "storage");
523
+ c(this, "watches", {});
524
+ c(this, "_value");
525
+ this.key = t, this.options = e, this.storage = e.storage || localStorage, this.load();
526
+ }
527
+ /** Current value or default if undefined */
528
+ get value() {
529
+ var t;
530
+ return this._value !== void 0 ? this._value : (t = this.options) == null ? void 0 : t.default;
531
+ }
532
+ /** Set value with proxy object wrapper to sync future changes */
533
+ set value(t) {
534
+ t == null || typeof t != "object" ? this._value = t : this._value = new Proxy(t, {
535
+ get: (e, n) => typeof e[n] == "function" ? (...o) => {
536
+ const i = e[n](...o);
537
+ return this.save(), i;
538
+ } : e[n],
539
+ set: (e, n, s) => (e[n] = s, this.save(), true)
540
+ }), this.save();
541
+ }
542
+ /** Notify listeners of change */
543
+ notify(t) {
544
+ Object.values(this.watches).forEach((e) => e(t));
545
+ }
546
+ /** Delete value from storage */
547
+ clear() {
548
+ this.storage.removeItem(this.key);
549
+ }
550
+ /** Save current value to storage */
551
+ save() {
552
+ this._value === void 0 ? this.clear() : this.storage.setItem(this.key, JSON.stringify(this._value)), this.notify(this.value);
553
+ }
554
+ /** Load value from storage */
555
+ load() {
556
+ if (this.storage[this.key] != null) {
557
+ let t = JSON.parse(this.storage.getItem(this.key));
558
+ t != null && typeof t == "object" && this.options.type && (t.__proto__ = this.options.type.prototype), this.value = t;
559
+ } else
560
+ this.value = this.options.default || void 0;
561
+ }
562
+ /**
563
+ * Callback function which is run when there are changes
564
+ *
565
+ * @param {(value: T) => any} fn Callback will run on each change; it's passed the next value & it's return is ignored
566
+ * @returns {() => void} Function which will unsubscribe the watch/callback when called
567
+ */
568
+ watch(t) {
569
+ const e = Object.keys(this.watches).length;
570
+ return this.watches[e] = t, () => {
571
+ delete this.watches[e];
572
+ };
573
+ }
574
+ /**
575
+ * Return value as JSON string
576
+ *
577
+ * @returns {string} Stringified object as JSON
578
+ */
579
+ toString() {
580
+ return JSON.stringify(this.value);
581
+ }
582
+ /**
583
+ * Return current value
584
+ *
585
+ * @returns {T} Current value
586
+ */
587
+ valueOf() {
588
+ return this.value;
589
+ }
590
+ }
591
+ S.Persist = st;
592
+ function Bt(r) {
593
+ return (t, e) => {
594
+ const n = (r == null ? void 0 : r.key) || `${t.constructor.name}.${e.toString()}`, s = new st(n, r);
595
+ Object.defineProperty(t, e, {
596
+ get: function() {
597
+ return s.value;
598
+ },
599
+ set: function(o) {
600
+ s.value = o;
601
+ }
602
+ });
603
+ };
604
+ }
605
+ S.persist = Bt;
606
+ var L = {};
607
+ Object.defineProperty(L, "__esModule", { value: true });
608
+ L.MemoryStorage = void 0;
609
+ class At {
610
+ get length() {
611
+ return Object.keys(this).length;
612
+ }
613
+ clear() {
614
+ Object.keys(this).forEach((t) => this.removeItem(t));
615
+ }
616
+ getItem(t) {
617
+ return this[t];
618
+ }
619
+ key(t) {
620
+ return Object.keys(this)[t];
621
+ }
622
+ removeItem(t) {
623
+ delete this[t];
624
+ }
625
+ setItem(t, e) {
626
+ this[t] = e;
627
+ }
628
+ }
629
+ L.MemoryStorage = At;
630
+ (function(r) {
631
+ var t = $ && $.__createBinding || (Object.create ? function(n, s, o, i) {
632
+ i === void 0 && (i = o);
633
+ var a = Object.getOwnPropertyDescriptor(s, o);
634
+ (!a || ("get" in a ? !s.__esModule : a.writable || a.configurable)) && (a = { enumerable: true, get: function() {
635
+ return s[o];
636
+ } }), Object.defineProperty(n, i, a);
637
+ } : function(n, s, o, i) {
638
+ i === void 0 && (i = o), n[i] = s[o];
639
+ }), e = $ && $.__exportStar || function(n, s) {
640
+ for (var o in n) o !== "default" && !Object.prototype.hasOwnProperty.call(s, o) && t(s, n, o);
641
+ };
642
+ Object.defineProperty(r, "__esModule", { value: true }), e(S, r), e(L, r);
643
+ })(xt);
644
+ class Api extends F {
409
645
  constructor(url = location.origin, opts = {}) {
410
646
  opts.url = url;
411
647
  super(opts);
412
- __publicField(this, "emitter", new v());
648
+ __publicField(this, "emitter", new _());
649
+ __publicField(this, "pending", {});
413
650
  __publicField(this, "_token", null);
414
651
  __publicField(this, "emit", this.emitter.emit.bind(this.emitter));
415
652
  __publicField(this, "off", this.emitter.off.bind(this.emitter));
@@ -424,7 +661,7 @@ class Api extends q {
424
661
  set token(token) {
425
662
  if (token == this._token) return;
426
663
  this._token = token;
427
- this.headers["Authorization"] = token ? `Bearer ${token}` : void 0;
664
+ this.headers["Authorization"] = token ? `Bearer ${token}` : null;
428
665
  this.emit("token", token);
429
666
  }
430
667
  healthcheck() {
@@ -434,724 +671,20 @@ class Api extends q {
434
671
  return children.filter((p2) => !!p2).join("/").replaceAll("//", "/");
435
672
  }
436
673
  request(options) {
437
- const req = super.request(options).then((resp) => {
674
+ const key = Lt(options);
675
+ if (this.pending[key] != null) return this.pending[key];
676
+ this.pending[key] = super.request(options).then((resp) => {
438
677
  this.emit("response", resp, options);
439
678
  return resp.data;
440
679
  }).catch((err) => {
441
680
  const e = (err == null ? void 0 : err.data) || err;
442
681
  this.emit("rejected", e, options);
443
682
  throw e;
444
- });
445
- this.emit("request", req, options);
446
- return req;
447
- }
448
- }
449
- var extendStatics = function(d, b2) {
450
- extendStatics = Object.setPrototypeOf || { __proto__: [] } instanceof Array && function(d2, b3) {
451
- d2.__proto__ = b3;
452
- } || function(d2, b3) {
453
- for (var p2 in b3) if (Object.prototype.hasOwnProperty.call(b3, p2)) d2[p2] = b3[p2];
454
- };
455
- return extendStatics(d, b2);
456
- };
457
- function __extends(d, b2) {
458
- if (typeof b2 !== "function" && b2 !== null)
459
- throw new TypeError("Class extends value " + String(b2) + " is not a constructor or null");
460
- extendStatics(d, b2);
461
- function __() {
462
- this.constructor = d;
463
- }
464
- d.prototype = b2 === null ? Object.create(b2) : (__.prototype = b2.prototype, new __());
465
- }
466
- function __values(o) {
467
- var s = typeof Symbol === "function" && Symbol.iterator, m2 = s && o[s], i2 = 0;
468
- if (m2) return m2.call(o);
469
- if (o && typeof o.length === "number") return {
470
- next: function() {
471
- if (o && i2 >= o.length) o = void 0;
472
- return { value: o && o[i2++], done: !o };
473
- }
474
- };
475
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
476
- }
477
- function __read(o, n) {
478
- var m2 = typeof Symbol === "function" && o[Symbol.iterator];
479
- if (!m2) return o;
480
- var i2 = m2.call(o), r, ar = [], e;
481
- try {
482
- while ((n === void 0 || n-- > 0) && !(r = i2.next()).done) ar.push(r.value);
483
- } catch (error) {
484
- e = { error };
485
- } finally {
486
- try {
487
- if (r && !r.done && (m2 = i2["return"])) m2.call(i2);
488
- } finally {
489
- if (e) throw e.error;
490
- }
491
- }
492
- return ar;
493
- }
494
- function __spreadArray(to, from, pack) {
495
- if (pack || arguments.length === 2) for (var i2 = 0, l = from.length, ar; i2 < l; i2++) {
496
- if (ar || !(i2 in from)) {
497
- if (!ar) ar = Array.prototype.slice.call(from, 0, i2);
498
- ar[i2] = from[i2];
499
- }
500
- }
501
- return to.concat(ar || Array.prototype.slice.call(from));
502
- }
503
- typeof SuppressedError === "function" ? SuppressedError : function(error, suppressed, message) {
504
- var e = new Error(message);
505
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
506
- };
507
- function isFunction(value) {
508
- return typeof value === "function";
509
- }
510
- function createErrorClass(createImpl) {
511
- var _super = function(instance) {
512
- Error.call(instance);
513
- instance.stack = new Error().stack;
514
- };
515
- var ctorFunc = createImpl(_super);
516
- ctorFunc.prototype = Object.create(Error.prototype);
517
- ctorFunc.prototype.constructor = ctorFunc;
518
- return ctorFunc;
519
- }
520
- var UnsubscriptionError = createErrorClass(function(_super) {
521
- return function UnsubscriptionErrorImpl(errors) {
522
- _super(this);
523
- this.message = errors ? errors.length + " errors occurred during unsubscription:\n" + errors.map(function(err, i2) {
524
- return i2 + 1 + ") " + err.toString();
525
- }).join("\n ") : "";
526
- this.name = "UnsubscriptionError";
527
- this.errors = errors;
528
- };
529
- });
530
- function arrRemove(arr, item) {
531
- if (arr) {
532
- var index = arr.indexOf(item);
533
- 0 <= index && arr.splice(index, 1);
534
- }
535
- }
536
- var Subscription = function() {
537
- function Subscription2(initialTeardown) {
538
- this.initialTeardown = initialTeardown;
539
- this.closed = false;
540
- this._parentage = null;
541
- this._finalizers = null;
542
- }
543
- Subscription2.prototype.unsubscribe = function() {
544
- var e_1, _a, e_2, _b;
545
- var errors;
546
- if (!this.closed) {
547
- this.closed = true;
548
- var _parentage = this._parentage;
549
- if (_parentage) {
550
- this._parentage = null;
551
- if (Array.isArray(_parentage)) {
552
- try {
553
- for (var _parentage_1 = __values(_parentage), _parentage_1_1 = _parentage_1.next(); !_parentage_1_1.done; _parentage_1_1 = _parentage_1.next()) {
554
- var parent_1 = _parentage_1_1.value;
555
- parent_1.remove(this);
556
- }
557
- } catch (e_1_1) {
558
- e_1 = { error: e_1_1 };
559
- } finally {
560
- try {
561
- if (_parentage_1_1 && !_parentage_1_1.done && (_a = _parentage_1.return)) _a.call(_parentage_1);
562
- } finally {
563
- if (e_1) throw e_1.error;
564
- }
565
- }
566
- } else {
567
- _parentage.remove(this);
568
- }
569
- }
570
- var initialFinalizer = this.initialTeardown;
571
- if (isFunction(initialFinalizer)) {
572
- try {
573
- initialFinalizer();
574
- } catch (e) {
575
- errors = e instanceof UnsubscriptionError ? e.errors : [e];
576
- }
577
- }
578
- var _finalizers = this._finalizers;
579
- if (_finalizers) {
580
- this._finalizers = null;
581
- try {
582
- for (var _finalizers_1 = __values(_finalizers), _finalizers_1_1 = _finalizers_1.next(); !_finalizers_1_1.done; _finalizers_1_1 = _finalizers_1.next()) {
583
- var finalizer = _finalizers_1_1.value;
584
- try {
585
- execFinalizer(finalizer);
586
- } catch (err) {
587
- errors = errors !== null && errors !== void 0 ? errors : [];
588
- if (err instanceof UnsubscriptionError) {
589
- errors = __spreadArray(__spreadArray([], __read(errors)), __read(err.errors));
590
- } else {
591
- errors.push(err);
592
- }
593
- }
594
- }
595
- } catch (e_2_1) {
596
- e_2 = { error: e_2_1 };
597
- } finally {
598
- try {
599
- if (_finalizers_1_1 && !_finalizers_1_1.done && (_b = _finalizers_1.return)) _b.call(_finalizers_1);
600
- } finally {
601
- if (e_2) throw e_2.error;
602
- }
603
- }
604
- }
605
- if (errors) {
606
- throw new UnsubscriptionError(errors);
607
- }
608
- }
609
- };
610
- Subscription2.prototype.add = function(teardown) {
611
- var _a;
612
- if (teardown && teardown !== this) {
613
- if (this.closed) {
614
- execFinalizer(teardown);
615
- } else {
616
- if (teardown instanceof Subscription2) {
617
- if (teardown.closed || teardown._hasParent(this)) {
618
- return;
619
- }
620
- teardown._addParent(this);
621
- }
622
- (this._finalizers = (_a = this._finalizers) !== null && _a !== void 0 ? _a : []).push(teardown);
623
- }
624
- }
625
- };
626
- Subscription2.prototype._hasParent = function(parent) {
627
- var _parentage = this._parentage;
628
- return _parentage === parent || Array.isArray(_parentage) && _parentage.includes(parent);
629
- };
630
- Subscription2.prototype._addParent = function(parent) {
631
- var _parentage = this._parentage;
632
- this._parentage = Array.isArray(_parentage) ? (_parentage.push(parent), _parentage) : _parentage ? [_parentage, parent] : parent;
633
- };
634
- Subscription2.prototype._removeParent = function(parent) {
635
- var _parentage = this._parentage;
636
- if (_parentage === parent) {
637
- this._parentage = null;
638
- } else if (Array.isArray(_parentage)) {
639
- arrRemove(_parentage, parent);
640
- }
641
- };
642
- Subscription2.prototype.remove = function(teardown) {
643
- var _finalizers = this._finalizers;
644
- _finalizers && arrRemove(_finalizers, teardown);
645
- if (teardown instanceof Subscription2) {
646
- teardown._removeParent(this);
647
- }
648
- };
649
- Subscription2.EMPTY = function() {
650
- var empty = new Subscription2();
651
- empty.closed = true;
652
- return empty;
653
- }();
654
- return Subscription2;
655
- }();
656
- var EMPTY_SUBSCRIPTION = Subscription.EMPTY;
657
- function isSubscription(value) {
658
- return value instanceof Subscription || value && "closed" in value && isFunction(value.remove) && isFunction(value.add) && isFunction(value.unsubscribe);
659
- }
660
- function execFinalizer(finalizer) {
661
- if (isFunction(finalizer)) {
662
- finalizer();
663
- } else {
664
- finalizer.unsubscribe();
665
- }
666
- }
667
- var config = {
668
- onUnhandledError: null,
669
- onStoppedNotification: null,
670
- Promise: void 0,
671
- useDeprecatedSynchronousErrorHandling: false,
672
- useDeprecatedNextContext: false
673
- };
674
- var timeoutProvider = {
675
- setTimeout: function(handler, timeout) {
676
- var args = [];
677
- for (var _i = 2; _i < arguments.length; _i++) {
678
- args[_i - 2] = arguments[_i];
679
- }
680
- return setTimeout.apply(void 0, __spreadArray([handler, timeout], __read(args)));
681
- },
682
- clearTimeout: function(handle) {
683
- var delegate = timeoutProvider.delegate;
684
- return ((delegate === null || delegate === void 0 ? void 0 : delegate.clearTimeout) || clearTimeout)(handle);
685
- },
686
- delegate: void 0
687
- };
688
- function reportUnhandledError(err) {
689
- timeoutProvider.setTimeout(function() {
690
- {
691
- throw err;
692
- }
693
- });
694
- }
695
- function noop() {
696
- }
697
- function errorContext(cb) {
698
- {
699
- cb();
700
- }
701
- }
702
- var Subscriber = function(_super) {
703
- __extends(Subscriber2, _super);
704
- function Subscriber2(destination) {
705
- var _this = _super.call(this) || this;
706
- _this.isStopped = false;
707
- if (destination) {
708
- _this.destination = destination;
709
- if (isSubscription(destination)) {
710
- destination.add(_this);
711
- }
712
- } else {
713
- _this.destination = EMPTY_OBSERVER;
714
- }
715
- return _this;
716
- }
717
- Subscriber2.create = function(next, error, complete) {
718
- return new SafeSubscriber(next, error, complete);
719
- };
720
- Subscriber2.prototype.next = function(value) {
721
- if (this.isStopped) ;
722
- else {
723
- this._next(value);
724
- }
725
- };
726
- Subscriber2.prototype.error = function(err) {
727
- if (this.isStopped) ;
728
- else {
729
- this.isStopped = true;
730
- this._error(err);
731
- }
732
- };
733
- Subscriber2.prototype.complete = function() {
734
- if (this.isStopped) ;
735
- else {
736
- this.isStopped = true;
737
- this._complete();
738
- }
739
- };
740
- Subscriber2.prototype.unsubscribe = function() {
741
- if (!this.closed) {
742
- this.isStopped = true;
743
- _super.prototype.unsubscribe.call(this);
744
- this.destination = null;
745
- }
746
- };
747
- Subscriber2.prototype._next = function(value) {
748
- this.destination.next(value);
749
- };
750
- Subscriber2.prototype._error = function(err) {
751
- try {
752
- this.destination.error(err);
753
- } finally {
754
- this.unsubscribe();
755
- }
756
- };
757
- Subscriber2.prototype._complete = function() {
758
- try {
759
- this.destination.complete();
760
- } finally {
761
- this.unsubscribe();
762
- }
763
- };
764
- return Subscriber2;
765
- }(Subscription);
766
- var _bind = Function.prototype.bind;
767
- function bind(fn, thisArg) {
768
- return _bind.call(fn, thisArg);
769
- }
770
- var ConsumerObserver = function() {
771
- function ConsumerObserver2(partialObserver) {
772
- this.partialObserver = partialObserver;
773
- }
774
- ConsumerObserver2.prototype.next = function(value) {
775
- var partialObserver = this.partialObserver;
776
- if (partialObserver.next) {
777
- try {
778
- partialObserver.next(value);
779
- } catch (error) {
780
- handleUnhandledError(error);
781
- }
782
- }
783
- };
784
- ConsumerObserver2.prototype.error = function(err) {
785
- var partialObserver = this.partialObserver;
786
- if (partialObserver.error) {
787
- try {
788
- partialObserver.error(err);
789
- } catch (error) {
790
- handleUnhandledError(error);
791
- }
792
- } else {
793
- handleUnhandledError(err);
794
- }
795
- };
796
- ConsumerObserver2.prototype.complete = function() {
797
- var partialObserver = this.partialObserver;
798
- if (partialObserver.complete) {
799
- try {
800
- partialObserver.complete();
801
- } catch (error) {
802
- handleUnhandledError(error);
803
- }
804
- }
805
- };
806
- return ConsumerObserver2;
807
- }();
808
- var SafeSubscriber = function(_super) {
809
- __extends(SafeSubscriber2, _super);
810
- function SafeSubscriber2(observerOrNext, error, complete) {
811
- var _this = _super.call(this) || this;
812
- var partialObserver;
813
- if (isFunction(observerOrNext) || !observerOrNext) {
814
- partialObserver = {
815
- next: observerOrNext !== null && observerOrNext !== void 0 ? observerOrNext : void 0,
816
- error: error !== null && error !== void 0 ? error : void 0,
817
- complete: complete !== null && complete !== void 0 ? complete : void 0
818
- };
819
- } else {
820
- var context_1;
821
- if (_this && config.useDeprecatedNextContext) {
822
- context_1 = Object.create(observerOrNext);
823
- context_1.unsubscribe = function() {
824
- return _this.unsubscribe();
825
- };
826
- partialObserver = {
827
- next: observerOrNext.next && bind(observerOrNext.next, context_1),
828
- error: observerOrNext.error && bind(observerOrNext.error, context_1),
829
- complete: observerOrNext.complete && bind(observerOrNext.complete, context_1)
830
- };
831
- } else {
832
- partialObserver = observerOrNext;
833
- }
834
- }
835
- _this.destination = new ConsumerObserver(partialObserver);
836
- return _this;
837
- }
838
- return SafeSubscriber2;
839
- }(Subscriber);
840
- function handleUnhandledError(error) {
841
- {
842
- reportUnhandledError(error);
683
+ }).finally(() => delete this.pending[key]);
684
+ this.emit("request", this.pending[key], options);
685
+ return this.pending[key];
843
686
  }
844
687
  }
845
- function defaultErrorHandler(err) {
846
- throw err;
847
- }
848
- var EMPTY_OBSERVER = {
849
- closed: true,
850
- next: noop,
851
- error: defaultErrorHandler,
852
- complete: noop
853
- };
854
- var observable = function() {
855
- return typeof Symbol === "function" && Symbol.observable || "@@observable";
856
- }();
857
- function identity(x) {
858
- return x;
859
- }
860
- function pipeFromArray(fns) {
861
- if (fns.length === 0) {
862
- return identity;
863
- }
864
- if (fns.length === 1) {
865
- return fns[0];
866
- }
867
- return function piped(input) {
868
- return fns.reduce(function(prev, fn) {
869
- return fn(prev);
870
- }, input);
871
- };
872
- }
873
- var Observable = function() {
874
- function Observable2(subscribe) {
875
- if (subscribe) {
876
- this._subscribe = subscribe;
877
- }
878
- }
879
- Observable2.prototype.lift = function(operator) {
880
- var observable2 = new Observable2();
881
- observable2.source = this;
882
- observable2.operator = operator;
883
- return observable2;
884
- };
885
- Observable2.prototype.subscribe = function(observerOrNext, error, complete) {
886
- var _this = this;
887
- var subscriber = isSubscriber(observerOrNext) ? observerOrNext : new SafeSubscriber(observerOrNext, error, complete);
888
- errorContext(function() {
889
- var _a = _this, operator = _a.operator, source = _a.source;
890
- subscriber.add(operator ? operator.call(subscriber, source) : source ? _this._subscribe(subscriber) : _this._trySubscribe(subscriber));
891
- });
892
- return subscriber;
893
- };
894
- Observable2.prototype._trySubscribe = function(sink) {
895
- try {
896
- return this._subscribe(sink);
897
- } catch (err) {
898
- sink.error(err);
899
- }
900
- };
901
- Observable2.prototype.forEach = function(next, promiseCtor) {
902
- var _this = this;
903
- promiseCtor = getPromiseCtor(promiseCtor);
904
- return new promiseCtor(function(resolve, reject) {
905
- var subscriber = new SafeSubscriber({
906
- next: function(value) {
907
- try {
908
- next(value);
909
- } catch (err) {
910
- reject(err);
911
- subscriber.unsubscribe();
912
- }
913
- },
914
- error: reject,
915
- complete: resolve
916
- });
917
- _this.subscribe(subscriber);
918
- });
919
- };
920
- Observable2.prototype._subscribe = function(subscriber) {
921
- var _a;
922
- return (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber);
923
- };
924
- Observable2.prototype[observable] = function() {
925
- return this;
926
- };
927
- Observable2.prototype.pipe = function() {
928
- var operations = [];
929
- for (var _i = 0; _i < arguments.length; _i++) {
930
- operations[_i] = arguments[_i];
931
- }
932
- return pipeFromArray(operations)(this);
933
- };
934
- Observable2.prototype.toPromise = function(promiseCtor) {
935
- var _this = this;
936
- promiseCtor = getPromiseCtor(promiseCtor);
937
- return new promiseCtor(function(resolve, reject) {
938
- var value;
939
- _this.subscribe(function(x) {
940
- return value = x;
941
- }, function(err) {
942
- return reject(err);
943
- }, function() {
944
- return resolve(value);
945
- });
946
- });
947
- };
948
- Observable2.create = function(subscribe) {
949
- return new Observable2(subscribe);
950
- };
951
- return Observable2;
952
- }();
953
- function getPromiseCtor(promiseCtor) {
954
- var _a;
955
- return (_a = promiseCtor !== null && promiseCtor !== void 0 ? promiseCtor : config.Promise) !== null && _a !== void 0 ? _a : Promise;
956
- }
957
- function isObserver(value) {
958
- return value && isFunction(value.next) && isFunction(value.error) && isFunction(value.complete);
959
- }
960
- function isSubscriber(value) {
961
- return value && value instanceof Subscriber || isObserver(value) && isSubscription(value);
962
- }
963
- var ObjectUnsubscribedError = createErrorClass(function(_super) {
964
- return function ObjectUnsubscribedErrorImpl() {
965
- _super(this);
966
- this.name = "ObjectUnsubscribedError";
967
- this.message = "object unsubscribed";
968
- };
969
- });
970
- var Subject = function(_super) {
971
- __extends(Subject2, _super);
972
- function Subject2() {
973
- var _this = _super.call(this) || this;
974
- _this.closed = false;
975
- _this.currentObservers = null;
976
- _this.observers = [];
977
- _this.isStopped = false;
978
- _this.hasError = false;
979
- _this.thrownError = null;
980
- return _this;
981
- }
982
- Subject2.prototype.lift = function(operator) {
983
- var subject = new AnonymousSubject(this, this);
984
- subject.operator = operator;
985
- return subject;
986
- };
987
- Subject2.prototype._throwIfClosed = function() {
988
- if (this.closed) {
989
- throw new ObjectUnsubscribedError();
990
- }
991
- };
992
- Subject2.prototype.next = function(value) {
993
- var _this = this;
994
- errorContext(function() {
995
- var e_1, _a;
996
- _this._throwIfClosed();
997
- if (!_this.isStopped) {
998
- if (!_this.currentObservers) {
999
- _this.currentObservers = Array.from(_this.observers);
1000
- }
1001
- try {
1002
- for (var _b = __values(_this.currentObservers), _c = _b.next(); !_c.done; _c = _b.next()) {
1003
- var observer = _c.value;
1004
- observer.next(value);
1005
- }
1006
- } catch (e_1_1) {
1007
- e_1 = { error: e_1_1 };
1008
- } finally {
1009
- try {
1010
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
1011
- } finally {
1012
- if (e_1) throw e_1.error;
1013
- }
1014
- }
1015
- }
1016
- });
1017
- };
1018
- Subject2.prototype.error = function(err) {
1019
- var _this = this;
1020
- errorContext(function() {
1021
- _this._throwIfClosed();
1022
- if (!_this.isStopped) {
1023
- _this.hasError = _this.isStopped = true;
1024
- _this.thrownError = err;
1025
- var observers = _this.observers;
1026
- while (observers.length) {
1027
- observers.shift().error(err);
1028
- }
1029
- }
1030
- });
1031
- };
1032
- Subject2.prototype.complete = function() {
1033
- var _this = this;
1034
- errorContext(function() {
1035
- _this._throwIfClosed();
1036
- if (!_this.isStopped) {
1037
- _this.isStopped = true;
1038
- var observers = _this.observers;
1039
- while (observers.length) {
1040
- observers.shift().complete();
1041
- }
1042
- }
1043
- });
1044
- };
1045
- Subject2.prototype.unsubscribe = function() {
1046
- this.isStopped = this.closed = true;
1047
- this.observers = this.currentObservers = null;
1048
- };
1049
- Object.defineProperty(Subject2.prototype, "observed", {
1050
- get: function() {
1051
- var _a;
1052
- return ((_a = this.observers) === null || _a === void 0 ? void 0 : _a.length) > 0;
1053
- },
1054
- enumerable: false,
1055
- configurable: true
1056
- });
1057
- Subject2.prototype._trySubscribe = function(subscriber) {
1058
- this._throwIfClosed();
1059
- return _super.prototype._trySubscribe.call(this, subscriber);
1060
- };
1061
- Subject2.prototype._subscribe = function(subscriber) {
1062
- this._throwIfClosed();
1063
- this._checkFinalizedStatuses(subscriber);
1064
- return this._innerSubscribe(subscriber);
1065
- };
1066
- Subject2.prototype._innerSubscribe = function(subscriber) {
1067
- var _this = this;
1068
- var _a = this, hasError = _a.hasError, isStopped = _a.isStopped, observers = _a.observers;
1069
- if (hasError || isStopped) {
1070
- return EMPTY_SUBSCRIPTION;
1071
- }
1072
- this.currentObservers = null;
1073
- observers.push(subscriber);
1074
- return new Subscription(function() {
1075
- _this.currentObservers = null;
1076
- arrRemove(observers, subscriber);
1077
- });
1078
- };
1079
- Subject2.prototype._checkFinalizedStatuses = function(subscriber) {
1080
- var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, isStopped = _a.isStopped;
1081
- if (hasError) {
1082
- subscriber.error(thrownError);
1083
- } else if (isStopped) {
1084
- subscriber.complete();
1085
- }
1086
- };
1087
- Subject2.prototype.asObservable = function() {
1088
- var observable2 = new Observable();
1089
- observable2.source = this;
1090
- return observable2;
1091
- };
1092
- Subject2.create = function(destination, source) {
1093
- return new AnonymousSubject(destination, source);
1094
- };
1095
- return Subject2;
1096
- }(Observable);
1097
- var AnonymousSubject = function(_super) {
1098
- __extends(AnonymousSubject2, _super);
1099
- function AnonymousSubject2(destination, source) {
1100
- var _this = _super.call(this) || this;
1101
- _this.destination = destination;
1102
- _this.source = source;
1103
- return _this;
1104
- }
1105
- AnonymousSubject2.prototype.next = function(value) {
1106
- var _a, _b;
1107
- (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.next) === null || _b === void 0 ? void 0 : _b.call(_a, value);
1108
- };
1109
- AnonymousSubject2.prototype.error = function(err) {
1110
- var _a, _b;
1111
- (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.error) === null || _b === void 0 ? void 0 : _b.call(_a, err);
1112
- };
1113
- AnonymousSubject2.prototype.complete = function() {
1114
- var _a, _b;
1115
- (_b = (_a = this.destination) === null || _a === void 0 ? void 0 : _a.complete) === null || _b === void 0 ? void 0 : _b.call(_a);
1116
- };
1117
- AnonymousSubject2.prototype._subscribe = function(subscriber) {
1118
- var _a, _b;
1119
- return (_b = (_a = this.source) === null || _a === void 0 ? void 0 : _a.subscribe(subscriber)) !== null && _b !== void 0 ? _b : EMPTY_SUBSCRIPTION;
1120
- };
1121
- return AnonymousSubject2;
1122
- }(Subject);
1123
- var BehaviorSubject = function(_super) {
1124
- __extends(BehaviorSubject2, _super);
1125
- function BehaviorSubject2(_value) {
1126
- var _this = _super.call(this) || this;
1127
- _this._value = _value;
1128
- return _this;
1129
- }
1130
- Object.defineProperty(BehaviorSubject2.prototype, "value", {
1131
- get: function() {
1132
- return this.getValue();
1133
- },
1134
- enumerable: false,
1135
- configurable: true
1136
- });
1137
- BehaviorSubject2.prototype._subscribe = function(subscriber) {
1138
- var subscription = _super.prototype._subscribe.call(this, subscriber);
1139
- !subscription.closed && subscriber.next(this._value);
1140
- return subscription;
1141
- };
1142
- BehaviorSubject2.prototype.getValue = function() {
1143
- var _a = this, hasError = _a.hasError, thrownError = _a.thrownError, _value = _a._value;
1144
- if (hasError) {
1145
- throw thrownError;
1146
- }
1147
- this._throwIfClosed();
1148
- return _value;
1149
- };
1150
- BehaviorSubject2.prototype.next = function(value) {
1151
- _super.prototype.next.call(this, this._value = value);
1152
- };
1153
- return BehaviorSubject2;
1154
- }(Subject);
1155
688
  var ActionType = /* @__PURE__ */ ((ActionType2) => {
1156
689
  ActionType2[ActionType2["CRON"] = 0] = "CRON";
1157
690
  ActionType2[ActionType2["EVENT"] = 1] = "EVENT";
@@ -1162,37 +695,31 @@ var ActionType = /* @__PURE__ */ ((ActionType2) => {
1162
695
  ActionType2[ActionType2["PUT"] = 6] = "PUT";
1163
696
  return ActionType2;
1164
697
  })(ActionType || {});
1165
- class Actions extends v {
698
+ class Actions extends _ {
1166
699
  constructor(api) {
1167
700
  super();
1168
701
  __publicField(this, "api");
1169
- __publicField(this, "$cache", new BehaviorSubject([]));
702
+ __publicField(this, "cache", new Dt("_id"));
1170
703
  this.api = typeof api == "string" ? new Api(api) : api;
1171
704
  }
1172
- get cache() {
1173
- return this.$cache.value;
1174
- }
1175
- set cache(val) {
1176
- this.$cache.next(val);
1177
- }
1178
705
  delete(id) {
1179
706
  return this.api.request({ url: `/api/actions/${id}`, method: "DELETE" }).then(() => {
1180
- this.cache = this.cache.filter((a) => a._id != id);
707
+ this.cache.delete(id);
1181
708
  this.emit("delete", id);
1182
709
  });
1183
710
  }
1184
711
  all() {
1185
712
  return this.api.request({ url: `/api/actions` }).then((resp) => {
1186
- if (resp) this.cache = resp;
713
+ this.cache.addAll(resp);
1187
714
  this.emit("all", resp || []);
1188
715
  return resp;
1189
716
  });
1190
717
  }
1191
718
  read(id, reload = false) {
1192
- const cached = this.cache.find((a) => a._id == id);
719
+ const cached = this.cache.get(id);
1193
720
  if (!reload && cached) return Promise.resolve(cached);
1194
721
  return this.api.request({ url: `/api/actions/${id}` }).then((action) => {
1195
- if (action) this.cache = this.cache.filter((a) => a._id != id).concat([action]);
722
+ if (action) this.cache.add(action);
1196
723
  this.emit("read", action);
1197
724
  return action;
1198
725
  });
@@ -1216,13 +743,13 @@ class Actions extends v {
1216
743
  method: "POST",
1217
744
  body: action
1218
745
  }).then((action2) => {
1219
- if (action2) this.cache = this.cache.filter((a) => a._id != (action2 == null ? void 0 : action2._id)).concat([action2]);
746
+ if (action2) this.cache.add(action2);
1220
747
  this.emit("update", action2);
1221
748
  return action2;
1222
749
  });
1223
750
  }
1224
751
  }
1225
- class Ai extends v {
752
+ class Ai extends _ {
1226
753
  constructor(api) {
1227
754
  super();
1228
755
  __publicField(this, "api");
@@ -1241,7 +768,7 @@ class Ai extends v {
1241
768
  return this.api.request({ url: "/api/ai", method: "DELETE" });
1242
769
  }
1243
770
  }
1244
- class Analytics extends v {
771
+ class Analytics extends _ {
1245
772
  constructor(api) {
1246
773
  super();
1247
774
  __publicField(this, "api");
@@ -1266,19 +793,19 @@ class Totp {
1266
793
  return this.api.request({ url: `/api/auth/totp/${username}`, method: "POST" });
1267
794
  }
1268
795
  setup(username, method = "app", totp) {
1269
- return this.api.request({ url: `/api/auth/totp/${username}`, body: ot({
796
+ return this.api.request({ url: `/api/auth/totp/${username}`, body: ut({
1270
797
  method,
1271
798
  totp
1272
799
  }) });
1273
800
  }
1274
801
  }
1275
- class Auth extends v {
802
+ class Auth extends _ {
1276
803
  constructor(api, opts = {}) {
1277
804
  super();
1278
805
  __publicField(this, "api");
1279
806
  __publicField(this, "storageKey");
1280
807
  __publicField(this, "totp");
1281
- __publicField(this, "$user", new BehaviorSubject(void 0));
808
+ __publicField(this, "_user");
1282
809
  this.opts = opts;
1283
810
  this.api = typeof api == "string" ? new Api(api) : api;
1284
811
  this.totp = new Totp(this.api);
@@ -1317,13 +844,12 @@ class Auth extends v {
1317
844
  }
1318
845
  }
1319
846
  get user() {
1320
- return this.$user.value;
847
+ return this._user;
1321
848
  }
1322
849
  set user(user) {
1323
- if (!b(this.user, user)) {
1324
- const u = user ? user : null;
1325
- this.$user.next(u);
1326
- this.emit("user", u);
850
+ if (!A(this.user, user)) {
851
+ this._user = user ? user : null;
852
+ this.emit("user", this._user);
1327
853
  }
1328
854
  }
1329
855
  knownHost(host = location.origin) {
@@ -1412,7 +938,230 @@ class Auth extends v {
1412
938
  });
1413
939
  }
1414
940
  }
1415
- class Data extends v {
941
+ class Client {
942
+ constructor(settings) {
943
+ __publicField(this, "_platform");
944
+ __publicField(this, "_pwa");
945
+ this.settings = settings;
946
+ }
947
+ get mobile() {
948
+ return ["android", "ios"].includes(this.platform);
949
+ }
950
+ get platform() {
951
+ if (!this._platform) {
952
+ const userAgent = navigator.userAgent || navigator.vendor;
953
+ if (/windows/i.test(userAgent)) this._platform = "windows";
954
+ else if (/android/i.test(userAgent)) this._platform = "android";
955
+ else if (/iPad|iPhone|iPod/.test(userAgent)) this._platform = "ios";
956
+ else if (/macintosh|mac os x/i.test(userAgent)) this._platform = "mac";
957
+ else if (/linux/i.test(userAgent)) this._platform = "linux";
958
+ else this._platform = "unknown";
959
+ }
960
+ return this._platform;
961
+ }
962
+ get pwa() {
963
+ if (this._pwa == null)
964
+ this._pwa = window.matchMedia("(display-mode: standalone)").matches || (navigator == null ? void 0 : navigator.standalone) || document.referrer.includes("android-app://");
965
+ return this._pwa;
966
+ }
967
+ async inject(reload = false) {
968
+ var _a, _b, _c, _d, _e, _f, _g, _h;
969
+ const settings = await this.settings.all();
970
+ if (!document.querySelector('meta[name="mobile-web-app-capable"]')) {
971
+ const meta = document.createElement("meta");
972
+ meta.name = "mobile-web-app-capable";
973
+ meta.content = "yes";
974
+ document.head.append(meta);
975
+ }
976
+ if (!document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]')) {
977
+ const meta = document.createElement("meta");
978
+ meta.name = "apple-mobile-web-app-status-bar-style";
979
+ meta.content = "default";
980
+ document.head.append(meta);
981
+ }
982
+ if (!document.querySelector('meta[name="apple-mobile-web-app-title"]')) {
983
+ const meta = document.createElement("meta");
984
+ meta.name = "apple-mobile-web-app-title";
985
+ meta.content = settings["title"];
986
+ document.head.append(meta);
987
+ }
988
+ if (!document.querySelector('link[rel="apple-touch-icon"]')) {
989
+ const meta = document.createElement("link");
990
+ meta.rel = "apple-touch-icon";
991
+ meta.href = settings["logo"];
992
+ document.head.append(meta);
993
+ }
994
+ if (!document.querySelector('link[rel="apple-touch-startup-image"]')) {
995
+ const meta = document.createElement("link");
996
+ meta.rel = "apple-touch-startup-image";
997
+ meta.href = settings["logo"];
998
+ document.head.append(meta);
999
+ }
1000
+ window.document.body.classList.add(((_a = settings["theme"]) == null ? void 0 : _a.darkMode) ? "theme-dark" : "theme-light");
1001
+ window.document.body.classList.remove(((_b = settings["theme"]) == null ? void 0 : _b.darkMode) ? "theme-light" : "theme-dark");
1002
+ if (settings["title"])
1003
+ window.document.querySelectorAll(".momentum-title").forEach((el) => el.innerText = settings["title"]);
1004
+ if (settings["description"])
1005
+ window.document.querySelectorAll(".momentum-description").forEach((el) => el.innerText = settings["description"]);
1006
+ if (settings.version)
1007
+ window.document.querySelectorAll(".momentum-version").forEach((el) => el.innerText = settings["version"]);
1008
+ if (settings["logo"]) {
1009
+ window.document.querySelectorAll(".momentum-logo").forEach((el) => {
1010
+ el.src = settings["logo"];
1011
+ el.href = settings["logo"];
1012
+ });
1013
+ }
1014
+ if (settings["theme"]) {
1015
+ let style = window.document.querySelector("#momentum-theme");
1016
+ if (!style) {
1017
+ style = window.document.createElement("style");
1018
+ style.id = "momentum-theme";
1019
+ window.document.head.append(style);
1020
+ }
1021
+ style.innerHTML = `
1022
+ :root {
1023
+ --theme-bg-primary: ${(_c = settings["theme"]) == null ? void 0 : _c.background};
1024
+ --theme-bg-secondary: ${((_d = settings["theme"]) == null ? void 0 : _d.darkMode) ? "#2e2e2e" : "#ffffff"};
1025
+ --theme-primary: ${(_e = settings["theme"]) == null ? void 0 : _e.primary};
1026
+ --theme-secondary: ${(_f = settings["theme"]) == null ? void 0 : _f.secondary};
1027
+ --theme-text: ${((_g = settings["theme"]) == null ? void 0 : _g.darkMode) ? "#ffffff" : "#000000"};
1028
+ --theme-muted: ${((_h = settings["theme"]) == null ? void 0 : _h.darkMode) ? "#cccccc" : "#6c757d"};
1029
+ }`;
1030
+ }
1031
+ if (settings["pwa"]) {
1032
+ const link = window.document.createElement("link");
1033
+ link.setAttribute("rel", "manifest");
1034
+ link.setAttribute("href", this.settings.api.url + "/manifest.json");
1035
+ window.document.head.append(link);
1036
+ setTimeout(() => {
1037
+ const dismissed = !!localStorage.getItem("momentum:install-prompt");
1038
+ if (!dismissed && !this.pwa && this.mobile) this.pwaPrompt();
1039
+ }, 500);
1040
+ }
1041
+ }
1042
+ pwaPrompt(platform) {
1043
+ const url = this.settings.api.url;
1044
+ const settings = this.settings.cache;
1045
+ const android = (platform || this.platform) == "android";
1046
+ let style = document.querySelector("style.momentum-pwa");
1047
+ if (!style) {
1048
+ style = document.createElement("style");
1049
+ style.innerHTML = `
1050
+ .momentum-pwa-prompt-backdrop {
1051
+ position: fixed;
1052
+ display: relative;
1053
+ left: 0;
1054
+ top: 0;
1055
+ right: 0;
1056
+ bottom: 0;
1057
+ background: rgba(0,0,0,.5);
1058
+ z-index: 9999;
1059
+ animation: fadeIn 0.5s ease-in-out forwards;
1060
+ opacity: 0;
1061
+ }
1062
+ .momentum-pwa-prompt-backdrop.exit {
1063
+ animation: fadeOut 0.5s ease-in-out forwards !important;
1064
+ }
1065
+ .momentum-pwa-prompt {
1066
+ position: fixed;
1067
+ background: #fff;
1068
+ color: black;
1069
+ bottom: 0;
1070
+ left: 50%;
1071
+ width: min(100vw, 450px);
1072
+ transform: translate(-50%, 0);
1073
+ animation: slideUp 0.5s ease-in-out forwards;
1074
+ }
1075
+ .momentum-pwa-prompt.exit {
1076
+ animation: slideDown 0.5s ease-in-out forwards !important;
1077
+ }
1078
+ .momentum-pwa-prompt img {
1079
+ width: 18px;
1080
+ height: 18px;
1081
+ }
1082
+ .momentum-pwa-prompt h1 {
1083
+ font-size: 1.25rem;
1084
+ font-weight: bold;
1085
+ }
1086
+ .momentum-pwa-prompt-close {
1087
+ position: absolute;
1088
+ right: 5px;
1089
+ top: 10px;
1090
+ background: transparent;
1091
+ border: none;
1092
+ cursor: pointer;
1093
+ }
1094
+
1095
+ @keyframes fadeIn {
1096
+ from { opacity: 0; }
1097
+ to { opacity: 1; }
1098
+ }
1099
+ @keyframes fadeOut {
1100
+ from { opacity: 1; }
1101
+ to { opacity: 0; }
1102
+ }
1103
+
1104
+ @keyframes slideUp {
1105
+ from { transform: translate(-50%, 100%); }
1106
+ to { transform: translate(-50%, 0); }
1107
+ }
1108
+ @keyframes slideDown {
1109
+ from { transform: translate(-50%, 0); }
1110
+ to { transform: translate(-50%, 100%); }
1111
+ }
1112
+ `;
1113
+ document.head.append(style);
1114
+ }
1115
+ const backdrop = document.createElement("div");
1116
+ backdrop.classList.add("momentum-pwa-prompt-backdrop");
1117
+ const prompt = document.createElement("div");
1118
+ prompt.classList.add("momentum-pwa-prompt");
1119
+ prompt.innerHTML = `
1120
+ <div style="display: flex; padding: 1rem; align-items: center">
1121
+ <img src="${url}${settings.logo}" alt="Logo" style="height: 30px; width: auto; margin-right: .5rem;" />
1122
+ <h1 style="margin: 0">Install ${settings.title}</h1>
1123
+ </div>
1124
+ <div style="display: flex; flex-direction: column; align-items: center">
1125
+ <div style="border-top: 2px solid #00000020; border-bottom: 2px solid #00000020; padding: 0 1rem">
1126
+ <p style="margin-top: 1rem; text-align: center">This website can be installed as an App! Add it to your home screen for quick access & fullscreen use.</p>
1127
+ </div>
1128
+ <table style="margin: 1.5rem 0">
1129
+ <tr>
1130
+ <td style="width: 50px; text-align: center">
1131
+ ${android ? '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="black" style="transform: scale(1.5)"><path d="M480-160q-33 0-56.5-23.5T400-240q0-33 23.5-56.5T480-320q33 0 56.5 23.5T560-240q0 33-23.5 56.5T480-160Zm0-240q-33 0-56.5-23.5T400-480q0-33 23.5-56.5T480-560q33 0 56.5 23.5T560-480q0 33-23.5 56.5T480-400Zm0-240q-33 0-56.5-23.5T400-720q0-33 23.5-56.5T480-800q33 0 56.5 23.5T560-720q0 33-23.5 56.5T480-640Z"/></svg>' : '<svg viewBox="0 0 566 670" xmlns="http://www.w3.org/2000/svg" fill="#0B76FC" height="40px"><path d="M255 12c4-4 10-8 16-8s12 3 16 8l94 89c3 4 6 7 8 12 2 6 0 14-5 19-7 8-20 9-28 2l-7-7-57-60 2 54v276c0 12-10 22-22 22-12 1-24-10-23-22V110l1-43-60 65c-5 5-13 8-21 6a19 19 0 0 1-16-17c-1-7 2-13 7-18l95-91z" /><path d="M43 207c16-17 40-23 63-23h83v46h-79c-12 0-25 3-33 13-8 9-10 21-10 33v260c0 13 0 27 6 38 5 12 18 18 30 19l14 1h302c14 0 28 0 40-8 11-7 16-21 16-34V276c0-11-2-24-9-33-8-10-22-13-34-13h-78v-46h75c13 0 25 1 37 4 16 4 31 13 41 27 11 17 14 37 14 57v280c0 20-3 41-15 58a71 71 0 0 1-45 27c-11 2-23 3-34 3H109c-19-1-40-4-56-15-14-9-23-23-27-38-4-12-5-25-5-38V270c1-22 6-47 22-63z" /></svg>'}
1132
+ </td>
1133
+ <td>
1134
+ <p style="margin: 1rem 0">1) ${android ? "Open the dropdown menu" : 'Press the "Share" button'}</p>
1135
+ </td>
1136
+ </tr>
1137
+ <tr>
1138
+ <td style="width: 50px; text-align: center">
1139
+ ${android ? '<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="black" style="transform: scale(-1.5, 1.5)"><path d="M280-40q-33 0-56.5-23.5T200-120v-720q0-33 23.5-56.5T280-920h280v80H280v40h280v80H280v480h400v-80h80v200q0 33-23.5 56.5T680-40H280Zm0-120v40h400v-40H280Zm440-240L520-600l56-56 104 104v-288h80v288l104-104 56 56-200 200ZM280-800v-40 40Zm0 640v40-40Z"/></svg>' : '<svg viewBox="0 0 578 584" xmlns="http://www.w3.org/2000/svg" fill="black" height="34px"><path d="M101 35l19-1h333c12 0 23 0 35 3 17 3 34 12 44 27 13 16 16 38 16 58v329c0 19 0 39-8 57a65 65 0 0 1-37 37c-18 7-38 7-57 7H130c-21 1-44 0-63-10-14-7-25-20-30-34-6-15-8-30-8-45V121c1-21 5-44 19-61 13-16 33-23 53-25m7 46c-10 1-19 6-24 14-7 8-9 20-9 31v334c0 12 2 25 10 34 9 10 23 12 35 12h336c14 1 30-3 38-15 6-9 8-20 8-31V125c0-12-2-24-10-33-9-9-22-12-35-12H121l-13 1z" /><path d="M271 161c9-11 31-10 38 4 3 5 3 11 3 17v87h88c7 0 16 1 21 7 6 6 7 14 6 22a21 21 0 0 1-10 14c-5 4-11 5-17 5h-88v82c0 7-1 15-6 20-10 10-29 10-37-2-3-6-4-13-4-19v-81h-87c-8-1-17-3-23-9-5-6-6-15-4-22a21 21 0 0 1 11-14c6-3 13-3 19-3h84v-88c0-7 1-14 6-20z" /></svg>'}
1140
+ </td>
1141
+ <td>
1142
+ <p style="margin: 1rem 0">2) Press "Add to Home Screen"</p>
1143
+ </td>
1144
+ </tr>
1145
+ </table>
1146
+ </div>`;
1147
+ const close = document.createElement("button");
1148
+ close.classList.add("momentum-pwa-prompt-close");
1149
+ close.innerText = "X";
1150
+ close.onclick = () => {
1151
+ prompt.classList.add("exit");
1152
+ backdrop.classList.add("exit");
1153
+ localStorage.setItem("momentum:install-prompt", "dismissed");
1154
+ setTimeout(() => {
1155
+ prompt.remove();
1156
+ backdrop.remove();
1157
+ }, 500);
1158
+ };
1159
+ prompt.append(close);
1160
+ backdrop.append(prompt);
1161
+ document.body.append(backdrop);
1162
+ }
1163
+ }
1164
+ class Data extends _ {
1416
1165
  constructor(api) {
1417
1166
  super();
1418
1167
  __publicField(this, "api");
@@ -1420,7 +1169,7 @@ class Data extends v {
1420
1169
  }
1421
1170
  create(collection, document2) {
1422
1171
  return this.api.request({
1423
- url: `/api/data/${collection}`,
1172
+ url: `/api/data/${collection.replaceAll(/(^\/|\/$)/g, "")}`,
1424
1173
  method: "POST",
1425
1174
  body: document2
1426
1175
  }).then((resp) => {
@@ -1429,7 +1178,7 @@ class Data extends v {
1429
1178
  });
1430
1179
  }
1431
1180
  read(collection, id) {
1432
- return this.api.request({ url: `/api/data/${collection}${id ? `/${id}` : ""}` }).then((resp) => {
1181
+ return this.api.request({ url: `/api/data/${collection.replaceAll(/(^\/|\/$)/g, "")}/${id ?? ""}` }).then((resp) => {
1433
1182
  this.emit("read", collection, resp);
1434
1183
  return resp;
1435
1184
  });
@@ -1437,7 +1186,7 @@ class Data extends v {
1437
1186
  update(collection, document2, append = true) {
1438
1187
  if (!document2._id) return this.create(collection, document2);
1439
1188
  return this.api.request({
1440
- url: `/api/data/${collection}/${document2._id}`,
1189
+ url: `/api/data/${collection.replaceAll(/(^\/|\/$)/g, "")}/${document2._id}`,
1441
1190
  method: append ? "PATCH" : "PUT",
1442
1191
  body: document2
1443
1192
  }).then((resp) => {
@@ -1447,18 +1196,30 @@ class Data extends v {
1447
1196
  }
1448
1197
  delete(collection, id) {
1449
1198
  return this.api.request({
1450
- url: `/api/data/${collection}/${id}`,
1199
+ url: `/api/data/${collection.replaceAll(/(^\/|\/$)/g, "")}/${id}`,
1451
1200
  method: "DELETE"
1452
1201
  }).then(() => this.emit("delete", collection, id));
1453
1202
  }
1454
1203
  raw(collection, query) {
1455
- return this.api.request({ url: `/api/data/${collection}`, body: query }).then((resp) => {
1204
+ return this.api.request({ url: `/api/data/${collection.replaceAll(/(^\/|\/$)/g, "")}`, body: query }).then((resp) => {
1456
1205
  this.emit("raw", collection, query, resp);
1457
1206
  return resp;
1458
1207
  });
1459
1208
  }
1209
+ deleteSchema(collection) {
1210
+ return this.api.request({ url: `/api/data/schema/${collection.replaceAll(/(^\/|\/$)/g, "")}`, method: "DELETE" });
1211
+ }
1212
+ getSchema(pathOrTree) {
1213
+ let url = "/api/data/schema";
1214
+ if (typeof pathOrTree == "string") url += `/${pathOrTree.replaceAll(/(^\/|\/$)/g, "")}`;
1215
+ else if (typeof pathOrTree == "boolean") url += `?tree=${pathOrTree}`;
1216
+ return this.api.request({ url });
1217
+ }
1218
+ setSchema(schema) {
1219
+ return this.api.request({ url: `/api/data/schema/${schema.path.replaceAll(/(^\/|\/$)/g, "")}`, body: schema });
1220
+ }
1460
1221
  }
1461
- class Email extends v {
1222
+ class Email extends _ {
1462
1223
  constructor(api) {
1463
1224
  super();
1464
1225
  __publicField(this, "api");
@@ -1473,7 +1234,7 @@ class Email extends v {
1473
1234
  });
1474
1235
  }
1475
1236
  }
1476
- class Groups extends v {
1237
+ class Groups extends _ {
1477
1238
  constructor(api) {
1478
1239
  super();
1479
1240
  __publicField(this, "api");
@@ -1558,40 +1319,40 @@ ${log}`;
1558
1319
  return this.api.request({ url: `/api/logs/server`, method: "DELETE" });
1559
1320
  }
1560
1321
  clientLogs(length, page) {
1561
- const query = [length ? `length=${length}` : void 0, page ? `page=${page}` : void 0].filter((v2) => !!v2).join("&");
1322
+ const query = [length ? `length=${length}` : void 0, page ? `page=${page}` : void 0].filter((v) => !!v).join("&");
1562
1323
  return this.api.request({ url: `/api/logs/client${query ? `?${query}` : ""}` }).then((resp) => resp);
1563
1324
  }
1564
1325
  serverLogs(length, page) {
1565
- const query = [length ? `length=${length}` : void 0, page ? `page=${page}` : void 0].filter((v2) => !!v2).join("&");
1326
+ const query = [length ? `length=${length}` : void 0, page ? `page=${page}` : void 0].filter((v) => !!v).join("&");
1566
1327
  return this.api.request({ url: `/api/logs/server${query ? `?${query}` : ""}` }).then((resp) => resp);
1567
1328
  }
1568
1329
  debug(...logs) {
1569
- return this.api.request({ url: `/api/logs/client`, body: this.buildLog(lt.DEBUG, logs) }).then(() => {
1330
+ return this.api.request({ url: `/api/logs/client`, body: this.buildLog(yt.DEBUG, logs) }).then(() => {
1570
1331
  }).catch(() => {
1571
1332
  });
1572
1333
  }
1573
1334
  log(...logs) {
1574
- return this.api.request({ url: `/api/logs/client`, body: this.buildLog(lt.LOG, logs) }).then(() => {
1335
+ return this.api.request({ url: `/api/logs/client`, body: this.buildLog(yt.LOG, logs) }).then(() => {
1575
1336
  }).catch(() => {
1576
1337
  });
1577
1338
  }
1578
1339
  info(...logs) {
1579
- return this.api.request({ url: `/api/logs/client`, body: this.buildLog(lt.INFO, logs) }).then(() => {
1340
+ return this.api.request({ url: `/api/logs/client`, body: this.buildLog(yt.INFO, logs) }).then(() => {
1580
1341
  }).catch(() => {
1581
1342
  });
1582
1343
  }
1583
1344
  warn(...logs) {
1584
- return this.api.request({ url: `/api/logs/client`, body: this.buildLog(lt.WARN, logs) }).then(() => {
1345
+ return this.api.request({ url: `/api/logs/client`, body: this.buildLog(yt.WARN, logs) }).then(() => {
1585
1346
  }).catch(() => {
1586
1347
  });
1587
1348
  }
1588
1349
  error(...logs) {
1589
- return this.api.request({ url: `/api/logs/client`, body: this.buildLog(lt.ERROR, logs) }).then(() => {
1350
+ return this.api.request({ url: `/api/logs/client`, body: this.buildLog(yt.ERROR, logs) }).then(() => {
1590
1351
  }).catch(() => {
1591
1352
  });
1592
1353
  }
1593
1354
  }
1594
- class Payments extends v {
1355
+ class Payments extends _ {
1595
1356
  constructor(api, secret) {
1596
1357
  super();
1597
1358
  __publicField(this, "api");
@@ -1632,7 +1393,7 @@ class Payments extends v {
1632
1393
  return history;
1633
1394
  }
1634
1395
  }
1635
- class Pdf extends v {
1396
+ class Pdf extends _ {
1636
1397
  constructor(api) {
1637
1398
  super();
1638
1399
  __publicField(this, "api");
@@ -1642,7 +1403,7 @@ class Pdf extends v {
1642
1403
  const blob = await resp.blob();
1643
1404
  if (fileName) {
1644
1405
  const url = URL.createObjectURL(blob);
1645
- at(url, fileName.endsWith(".pdf") ? fileName : fileName + ".pdf");
1406
+ dt(url, fileName.endsWith(".pdf") ? fileName : fileName + ".pdf");
1646
1407
  URL.revokeObjectURL(url);
1647
1408
  }
1648
1409
  this.emit("create", blob);
@@ -1705,7 +1466,7 @@ const _Socket = class _Socket {
1705
1466
  };
1706
1467
  __publicField(_Socket, "timeout", 1e4);
1707
1468
  let Socket = _Socket;
1708
- class Storage extends v {
1469
+ class Storage extends _ {
1709
1470
  constructor(api) {
1710
1471
  super();
1711
1472
  __publicField(this, "api");
@@ -1730,7 +1491,7 @@ class Storage extends v {
1730
1491
  const blob = await response.blob();
1731
1492
  const name = opts.downloadAs || path.split("/").pop();
1732
1493
  this.emit("download", path, blob);
1733
- Tt(blob, name);
1494
+ Gt(blob, name);
1734
1495
  return response;
1735
1496
  });
1736
1497
  }
@@ -1764,13 +1525,13 @@ class Storage extends v {
1764
1525
  });
1765
1526
  }
1766
1527
  upload(files, opts = "") {
1767
- return new m(async (res, rej, prog) => {
1768
- if (!files) files = await It(typeof opts == "object" ? opts : void 0);
1528
+ return new E(async (res, rej, prog) => {
1529
+ if (!files) files = await Ut(typeof opts == "object" ? opts : void 0);
1769
1530
  if (!files || Array.isArray(files) && !files.length) return [];
1770
1531
  const path = this.api.path("/api/storage/", typeof opts == "string" ? opts : opts.path || "");
1771
- return Dt({
1532
+ return Ft({
1772
1533
  url: `${this.api.url}${path}`,
1773
- files: ut(files),
1534
+ files: ft(files),
1774
1535
  headers: this.api.headers
1775
1536
  }).onProgress((p2) => {
1776
1537
  prog(p2);
@@ -1781,255 +1542,42 @@ class Storage extends v {
1781
1542
  });
1782
1543
  }
1783
1544
  }
1784
- class UI {
1785
- constructor(settings) {
1786
- this.settings = settings;
1787
- }
1788
- async inject(reload = false) {
1789
- if (!Object.keys(this.settings.cache).length || reload) await this.settings.all();
1790
- if (!document.querySelector('meta[name="mobile-web-app-capable"]')) {
1791
- const meta = document.createElement("meta");
1792
- meta.name = "mobile-web-app-capable";
1793
- meta.content = "yes";
1794
- document.head.append(meta);
1795
- }
1796
- if (!document.querySelector('meta[name="apple-mobile-web-app-status-bar-style"]')) {
1797
- const meta = document.createElement("meta");
1798
- meta.name = "apple-mobile-web-app-status-bar-style";
1799
- meta.content = "default";
1800
- document.head.append(meta);
1801
- }
1802
- if (!document.querySelector('meta[name="apple-mobile-web-app-title"]')) {
1803
- const meta = document.createElement("meta");
1804
- meta.name = "apple-mobile-web-app-title";
1805
- meta.content = this.settings.cache.title;
1806
- document.head.append(meta);
1807
- }
1808
- if (!document.querySelector('link[rel="apple-touch-icon"]')) {
1809
- const meta = document.createElement("link");
1810
- meta.rel = "apple-touch-icon";
1811
- meta.href = this.settings.cache.logo;
1812
- document.head.append(meta);
1813
- }
1814
- if (!document.querySelector('link[rel="apple-touch-startup-image"]')) {
1815
- const meta = document.createElement("link");
1816
- meta.rel = "apple-touch-startup-image";
1817
- meta.href = this.settings.cache.logo;
1818
- document.head.append(meta);
1819
- }
1820
- window.document.body.classList.add(this.settings.cache.theme.darkMode ? "theme-dark" : "theme-light");
1821
- window.document.body.classList.remove(this.settings.cache.theme.darkMode ? "theme-light" : "theme-dark");
1822
- if (this.settings.cache.title)
1823
- window.document.querySelectorAll(".momentum-title").forEach((el) => el.innerText = this.settings.cache.title);
1824
- if (this.settings.cache.description)
1825
- window.document.querySelectorAll(".momentum-description").forEach((el) => el.innerText = this.settings.cache.description);
1826
- if (this.settings.cache.version)
1827
- window.document.querySelectorAll(".momentum-version").forEach((el) => el.innerText = this.settings.cache.version);
1828
- if (this.settings.cache.logo) {
1829
- window.document.querySelectorAll(".momentum-logo").forEach((el) => {
1830
- el.src = this.settings.cache.logo;
1831
- el.href = this.settings.cache.logo;
1832
- });
1833
- }
1834
- if (this.settings.cache.theme) {
1835
- let style = window.document.querySelector("#momentum-theme");
1836
- if (!style) {
1837
- style = window.document.createElement("style");
1838
- style.id = "momentum-theme";
1839
- window.document.head.append(style);
1840
- }
1841
- style.innerHTML = `
1842
- :root {
1843
- --theme-bg-primary: ${this.settings.cache.theme.background};
1844
- --theme-bg-secondary: ${this.settings.cache.theme.darkMode ? "#2e2e2e" : "#ffffff"};
1845
- --theme-primary: ${this.settings.cache.theme.primary};
1846
- --theme-secondary: ${this.settings.cache.theme.secondary};
1847
- --theme-text: ${this.settings.cache.theme.darkMode ? "#ffffff" : "#000000"};
1848
- --theme-muted: ${this.settings.cache.theme.darkMode ? "#cccccc" : "#6c757d"};
1849
- }`;
1850
- }
1851
- if (this.settings.cache.pwa) {
1852
- const link = window.document.createElement("link");
1853
- link.setAttribute("rel", "manifest");
1854
- link.setAttribute("href", this.settings.api.url + "/manifest.json");
1855
- window.document.head.append(link);
1856
- this.iosPrompt();
1857
- }
1858
- }
1859
- iosPrompt() {
1860
- const url = this.settings.api.url;
1861
- const settings = this.settings.cache;
1862
- let dismissed = !!localStorage.getItem("ios-prompt");
1863
- const ios = /iPad|iPhone|iPod/.test(navigator.platform) || navigator.platform === "MacIntel" && navigator.maxTouchPoints > 1;
1864
- const pwa = window.matchMedia("(display-mode: standalone)").matches || (navigator == null ? void 0 : navigator.standalone) || document.referrer.includes("android-app://");
1865
- function open() {
1866
- let style = document.querySelector("style.ios-prompt");
1867
- if (!style) {
1868
- style = document.createElement("style");
1869
- style.innerHTML = `
1870
- .ios-prompt-backdrop {
1871
- position: fixed;
1872
- display: relative;
1873
- left: 0;
1874
- top: 0;
1875
- right: 0;
1876
- bottom: 0;
1877
- background: rgba(0,0,0,.5);
1878
- z-index: 9999;
1879
- animation: fadeIn 0.5s ease-in-out forwards;
1880
- opacity: 0;
1881
- }
1882
- .ios-prompt-backdrop.exit {
1883
- animation: fadeOut 0.5s ease-in-out forwards !important;
1884
- }
1885
- .ios-prompt {
1886
- position: fixed;
1887
- background: #fff;
1888
- color: black;
1889
- bottom: 0;
1890
- left: 50%;
1891
- width: min(100vw, 450px);
1892
- transform: translate(-50%, 0);
1893
- animation: slideUp 0.5s ease-in-out forwards;
1894
- }
1895
- .ios-prompt.exit {
1896
- animation: slideDown 0.5s ease-in-out forwards !important;
1897
- }
1898
- .ios-prompt img {
1899
- width: 18px;
1900
- height: 18px;
1901
- }
1902
- .ios-prompt h1 {
1903
- font-size: 1.25rem;
1904
- font-weight: bold;
1905
- }
1906
- .ios-prompt-close {
1907
- position: absolute;
1908
- right: 5px;
1909
- top: 10px;
1910
- background: transparent;
1911
- border: none;
1912
- cursor: pointer;
1913
- }
1914
-
1915
- @keyframes fadeIn {
1916
- from { opacity: 0; }
1917
- to { opacity: 1; }
1918
- }
1919
- @keyframes fadeOut {
1920
- from { opacity: 1; }
1921
- to { opacity: 0; }
1922
- }
1923
-
1924
- @keyframes slideUp {
1925
- from { transform: translate(-50%, 100%); }
1926
- to { transform: translate(-50%, 0); }
1927
- }
1928
- @keyframes slideDown {
1929
- from { transform: translate(-50%, 0); }
1930
- to { transform: translate(-50%, 100%); }
1931
- }
1932
- `;
1933
- document.head.append(style);
1934
- }
1935
- const backdrop = document.createElement("div");
1936
- backdrop.classList.add("ios-prompt-backdrop");
1937
- const prompt = document.createElement("div");
1938
- prompt.classList.add("ios-prompt");
1939
- prompt.innerHTML = `
1940
- <div style="display: flex; padding: 1rem; align-items: center">
1941
- <img src="${url}${settings.logo}" alt="Logo" style="height: 30px; width: auto; margin-right: .5rem;" />
1942
- <h1 style="margin: 0">Install ${settings.title}</h1>
1943
- </div>
1944
- <div style="display: flex; flex-direction: column; align-items: center">
1945
- <div style="border-top: 2px solid #00000020; border-bottom: 2px solid #00000020; padding: 0 1rem">
1946
- <p style="margin-top: 1rem; text-align: center">This website can be installed as an App! Add it to your home screen for quick access & fullscreen use.</p>
1947
- </div>
1948
- <table style="margin: 1.5rem 0">
1949
- <tr>
1950
- <td style="width: 50px">
1951
- <svg viewBox="0 0 566 670" xmlns="http://www.w3.org/2000/svg" fill="#0B76FC" height="40px"><path d="M255 12c4-4 10-8 16-8s12 3 16 8l94 89c3 4 6 7 8 12 2 6 0 14-5 19-7 8-20 9-28 2l-7-7-57-60 2 54v276c0 12-10 22-22 22-12 1-24-10-23-22V110l1-43-60 65c-5 5-13 8-21 6a19 19 0 0 1-16-17c-1-7 2-13 7-18l95-91z" /><path d="M43 207c16-17 40-23 63-23h83v46h-79c-12 0-25 3-33 13-8 9-10 21-10 33v260c0 13 0 27 6 38 5 12 18 18 30 19l14 1h302c14 0 28 0 40-8 11-7 16-21 16-34V276c0-11-2-24-9-33-8-10-22-13-34-13h-78v-46h75c13 0 25 1 37 4 16 4 31 13 41 27 11 17 14 37 14 57v280c0 20-3 41-15 58a71 71 0 0 1-45 27c-11 2-23 3-34 3H109c-19-1-40-4-56-15-14-9-23-23-27-38-4-12-5-25-5-38V270c1-22 6-47 22-63z" /></svg>
1952
- </td>
1953
- <td>
1954
- <p style="margin: 1rem 0">1) Press the "Share" button</p>
1955
- </td>
1956
- </tr>
1957
- <tr>
1958
- <td>
1959
- <svg viewBox="0 0 578 584" xmlns="http://www.w3.org/2000/svg" fill="black" height="34px"><path d="M101 35l19-1h333c12 0 23 0 35 3 17 3 34 12 44 27 13 16 16 38 16 58v329c0 19 0 39-8 57a65 65 0 0 1-37 37c-18 7-38 7-57 7H130c-21 1-44 0-63-10-14-7-25-20-30-34-6-15-8-30-8-45V121c1-21 5-44 19-61 13-16 33-23 53-25m7 46c-10 1-19 6-24 14-7 8-9 20-9 31v334c0 12 2 25 10 34 9 10 23 12 35 12h336c14 1 30-3 38-15 6-9 8-20 8-31V125c0-12-2-24-10-33-9-9-22-12-35-12H121l-13 1z" /><path d="M271 161c9-11 31-10 38 4 3 5 3 11 3 17v87h88c7 0 16 1 21 7 6 6 7 14 6 22a21 21 0 0 1-10 14c-5 4-11 5-17 5h-88v82c0 7-1 15-6 20-10 10-29 10-37-2-3-6-4-13-4-19v-81h-87c-8-1-17-3-23-9-5-6-6-15-4-22a21 21 0 0 1 11-14c6-3 13-3 19-3h84v-88c0-7 1-14 6-20z" /></svg>
1960
- </td>
1961
- <td>
1962
- <p style="margin: 1rem 0">2) Press "Add to Home Screen"</p>
1963
- </td>
1964
- </tr>
1965
- </table>
1966
- </div>`;
1967
- const close = document.createElement("button");
1968
- close.classList.add("ios-prompt-close");
1969
- close.innerText = "X";
1970
- close.onclick = () => {
1971
- prompt.classList.add("exit");
1972
- backdrop.classList.add("exit");
1973
- localStorage.setItem("ios-prompt", "dismissed");
1974
- setTimeout(() => {
1975
- prompt.remove();
1976
- backdrop.remove();
1977
- }, 500);
1978
- };
1979
- prompt.append(close);
1980
- backdrop.append(prompt);
1981
- document.body.append(backdrop);
1982
- }
1983
- setTimeout(() => {
1984
- if (ios && !dismissed && !pwa) open();
1985
- }, 1e3);
1986
- }
1987
- }
1988
- class Users extends v {
1545
+ class Users extends _ {
1989
1546
  constructor(api) {
1990
1547
  super();
1991
1548
  __publicField(this, "api");
1992
1549
  __publicField(this, "listed", false);
1993
- __publicField(this, "$cache", new BehaviorSubject([]));
1550
+ __publicField(this, "cache", new Dt("username"));
1994
1551
  this.api = typeof api == "string" ? new Api(api) : api;
1995
1552
  }
1996
- get cache() {
1997
- return this.$cache.value;
1998
- }
1999
- set cache(val) {
2000
- this.$cache.next(val);
2001
- }
2002
1553
  delete(username) {
2003
1554
  return this.api.request({
2004
1555
  url: `/api/users/${username}`,
2005
1556
  method: "DELETE"
2006
1557
  }).then(() => {
2007
- this.cache = this.cache.filter((u) => u.username != username);
1558
+ this.cache.delete(username);
2008
1559
  this.emit("delete", username);
2009
1560
  });
2010
1561
  }
2011
- all(reload = false) {
2012
- if (!reload && this.listed) return Promise.resolve(this.cache);
1562
+ async all(reload = false) {
1563
+ if (!reload && this.cache.complete) return this.cache.all();
2013
1564
  return this.api.request({ url: `/api/users` }).then((resp) => {
2014
- resp == null ? void 0 : resp.map((r) => {
1565
+ resp == null ? void 0 : resp.forEach((r) => {
2015
1566
  r.image = this.api.url + r.image + `?token=${this.api.token}`;
2016
1567
  return r;
2017
1568
  });
2018
- this.cache = resp || [];
1569
+ this.cache.addAll(resp);
2019
1570
  this.listed = true;
2020
1571
  this.emit("all", resp || []);
2021
1572
  return resp;
2022
1573
  });
2023
1574
  }
2024
- read(username, reload = false) {
2025
- if (!reload) {
2026
- const cached = this.cache.find((u) => u.username == username);
2027
- if (cached) return Promise.resolve(cached);
2028
- }
1575
+ async read(username, reload = false) {
1576
+ if (!reload && this.cache.get(username)) return this.cache.get(username);
2029
1577
  return this.api.request({ url: `/api/users/${username}` }).then((resp) => {
2030
1578
  if (resp) {
2031
1579
  resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
2032
- this.cache = [...this.cache.filter((u) => u.username != username), resp];
1580
+ this.cache.add(resp);
2033
1581
  }
2034
1582
  this.emit("read", resp);
2035
1583
  return resp;
@@ -2043,14 +1591,14 @@ class Users extends v {
2043
1591
  }).then((resp) => {
2044
1592
  if (resp) {
2045
1593
  resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
2046
- this.cache = this.cache.filter((u) => u.username != user.username).concat([resp]);
1594
+ this.cache.add(resp);
2047
1595
  }
2048
1596
  this.emit(resp._id ? "update" : "create", resp);
2049
1597
  return resp;
2050
1598
  });
2051
1599
  }
2052
1600
  uploadImage(username, file) {
2053
- return Dt({
1601
+ return Ft({
2054
1602
  url: this.api.url + `/api/users/${username}/image`,
2055
1603
  files: [file],
2056
1604
  headers: this.api.headers
@@ -2060,49 +1608,45 @@ class Users extends v {
2060
1608
  });
2061
1609
  }
2062
1610
  }
2063
- class Settings extends v {
1611
+ class Settings extends _ {
2064
1612
  constructor(api) {
2065
1613
  super();
2066
1614
  __publicField(this, "api");
2067
- __publicField(this, "$cache", new BehaviorSubject({}));
1615
+ __publicField(this, "cache", new Dt());
2068
1616
  this.api = typeof api == "string" ? new Api(api) : api;
2069
1617
  }
2070
- get cache() {
2071
- return this.$cache.value;
2072
- }
2073
- set cache(val) {
2074
- this.$cache.next(val);
2075
- }
2076
- all(detailed = false) {
1618
+ async all(detailed = false, reload) {
1619
+ if (!reload && !detailed && this.cache.complete) return this.cache;
2077
1620
  return this.api.request({ url: `/api/settings` + (detailed ? "?detailed" : "") }).then((resp) => {
2078
- this.cache = !detailed ? resp : Object.values(resp).reduce((acc, v2) => ({ ...acc, [v2.key]: v2.value }), {});
2079
- this.emit("list", resp || []);
1621
+ Object.entries(resp).forEach(([key, value]) => this.cache.set(key, detailed ? value.value : value));
1622
+ this.cache.complete = true;
1623
+ this.emit("all", resp || []);
2080
1624
  return resp;
2081
1625
  });
2082
1626
  }
2083
1627
  delete(key) {
2084
1628
  return this.api.request({ url: `/api/settings/${key}`, method: "DELETE" }).then(() => {
2085
- this.cache = { ...this.cache, [key]: void 0 };
1629
+ this.cache.delete(key);
2086
1630
  this.emit("delete", key);
2087
1631
  });
2088
1632
  }
2089
1633
  read(key, reload = false) {
2090
- if (!reload && this.cache[key]) return Promise.resolve(this.cache[key]);
1634
+ if (!reload && this.cache.get(key)) return this.cache.get(key);
2091
1635
  return this.api.request({ url: `/api/settings/${key}` }).then((variable) => {
2092
- if (variable) this.cache = { ...this.cache, [variable.key]: variable };
1636
+ if (variable) this.cache.set(variable.key, variable.value);
2093
1637
  this.emit("read", variable);
2094
1638
  return variable;
2095
1639
  });
2096
1640
  }
2097
1641
  update(variable) {
2098
1642
  return this.api.request({ url: `/api/settings/${variable.key}`, body: variable }).then((variable2) => {
2099
- if (variable2) this.cache = { ...this.cache, [variable2.key]: variable2.value };
1643
+ if (variable2) this.cache.set(variable2.key, variable2.value);
2100
1644
  this.emit("update", variable2);
2101
1645
  return variable2;
2102
1646
  });
2103
1647
  }
2104
1648
  }
2105
- class Static extends v {
1649
+ class Static extends _ {
2106
1650
  constructor(api) {
2107
1651
  super();
2108
1652
  __publicField(this, "api");
@@ -2114,10 +1658,10 @@ class Static extends v {
2114
1658
  });
2115
1659
  }
2116
1660
  upload(files, path = "/") {
2117
- return new m(async (res, rej, prog) => {
2118
- return Dt({
1661
+ return new E(async (res, rej, prog) => {
1662
+ return Ft({
2119
1663
  url: this.api.url + ("/api/static/" + path).replaceAll("//", "/"),
2120
- files: ut(files),
1664
+ files: ft(files),
2121
1665
  headers: this.api.headers
2122
1666
  }).onProgress((p2) => {
2123
1667
  prog(p2);
@@ -2128,7 +1672,7 @@ class Static extends v {
2128
1672
  });
2129
1673
  }
2130
1674
  }
2131
- class Momentum extends v {
1675
+ class Momentum extends _ {
2132
1676
  constructor(url, opts) {
2133
1677
  super();
2134
1678
  __publicField(this, "api");
@@ -2136,6 +1680,7 @@ class Momentum extends v {
2136
1680
  __publicField(this, "ai");
2137
1681
  __publicField(this, "analytics");
2138
1682
  __publicField(this, "auth");
1683
+ __publicField(this, "client");
2139
1684
  __publicField(this, "data");
2140
1685
  __publicField(this, "email");
2141
1686
  __publicField(this, "groups");
@@ -2146,7 +1691,6 @@ class Momentum extends v {
2146
1691
  __publicField(this, "socket");
2147
1692
  __publicField(this, "static");
2148
1693
  __publicField(this, "storage");
2149
- __publicField(this, "ui");
2150
1694
  __publicField(this, "users");
2151
1695
  this.api = new Api(url, opts == null ? void 0 : opts.api);
2152
1696
  this.actions = new Actions(this.api);
@@ -2166,7 +1710,7 @@ class Momentum extends v {
2166
1710
  if (opts == null ? void 0 : opts.socket) this.socket = new Socket(this.api);
2167
1711
  this.static = new Static(this.api);
2168
1712
  this.storage = new Storage(this.api);
2169
- this.ui = new UI(this.settings);
1713
+ this.client = new Client(this.settings);
2170
1714
  this.users = new Users(this.api);
2171
1715
  this.api.on("*", (event, ...args) => this.emit(`Api:${event}`, ...args));
2172
1716
  this.actions.on("*", (event, ...args) => this.emit(`Actions:${event}`, ...args));
@@ -2181,7 +1725,7 @@ class Momentum extends v {
2181
1725
  this.storage.on("*", (event, ...args) => this.emit(`Storage:${event}`, ...args));
2182
1726
  this.users.on("*", (event, ...args) => this.emit(`Users:${event}`, ...args));
2183
1727
  this.users.on("*", (event, ...args) => {
2184
- const u = ut(args[0]).find((u2) => {
1728
+ const u = ft(args[0]).find((u2) => {
2185
1729
  var _a;
2186
1730
  return (u2 == null ? void 0 : u2._id) == ((_a = this.auth.user) == null ? void 0 : _a._id);
2187
1731
  });
@@ -2196,6 +1740,7 @@ export {
2196
1740
  Analytics,
2197
1741
  Api,
2198
1742
  Auth,
1743
+ Client,
2199
1744
  Data,
2200
1745
  Email,
2201
1746
  Groups,
@@ -2208,6 +1753,5 @@ export {
2208
1753
  Static,
2209
1754
  Storage,
2210
1755
  Totp,
2211
- UI,
2212
1756
  Users
2213
1757
  };