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