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