@ztimson/momentum 0.28.4 → 0.28.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +62 -55
- package/dist/index.mjs +62 -55
- package/package.json +2 -2
package/dist/index.cjs
CHANGED
|
@@ -5,10 +5,10 @@
|
|
|
5
5
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6
6
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
7
7
|
|
|
8
|
-
var
|
|
9
|
-
var F = (n, e, t) => e in n ?
|
|
8
|
+
var v = Object.defineProperty;
|
|
9
|
+
var F = (n, e, t) => e in n ? v(n, e, { enumerable: true, configurable: true, writable: true, value: t }) : n[e] = t;
|
|
10
10
|
var a = (n, e, t) => (F(n, typeof e != "symbol" ? e + "" : e, t), t);
|
|
11
|
-
function
|
|
11
|
+
function W(n, e = false) {
|
|
12
12
|
if (n == null)
|
|
13
13
|
throw new Error("Cannot clean a NULL value");
|
|
14
14
|
return Array.isArray(n) ? n = n.filter((t) => t != null) : Object.entries(n).forEach(([t, r]) => {
|
|
@@ -19,6 +19,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
19
19
|
const t = typeof n, r = typeof e;
|
|
20
20
|
return t != "object" || n == null || r != "object" || e == null ? t == "function" && r == "function" ? n.toString() == e.toString() : n === e : Object.keys(n).length != Object.keys(e).length ? false : Object.keys(n).every((s) => b(n[s], e[s]));
|
|
21
21
|
}
|
|
22
|
+
function q(n) {
|
|
23
|
+
try {
|
|
24
|
+
return JSON.parse(n);
|
|
25
|
+
} catch {
|
|
26
|
+
return n;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
22
29
|
class E extends Promise {
|
|
23
30
|
constructor(t) {
|
|
24
31
|
super((r, o) => t(
|
|
@@ -56,15 +63,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
56
63
|
return this.from(super.finally(t));
|
|
57
64
|
}
|
|
58
65
|
}
|
|
59
|
-
function
|
|
66
|
+
function Z(n, e) {
|
|
60
67
|
const t = document.createElement("a");
|
|
61
68
|
t.href = n, t.download = e, document.body.appendChild(t), t.click(), document.body.removeChild(t);
|
|
62
69
|
}
|
|
63
|
-
function
|
|
70
|
+
function Bt(n, e) {
|
|
64
71
|
const t = URL.createObjectURL(n);
|
|
65
|
-
|
|
72
|
+
Z(t, e), URL.revokeObjectURL(t);
|
|
66
73
|
}
|
|
67
|
-
function
|
|
74
|
+
function bt(n = {}) {
|
|
68
75
|
return new Promise((e) => {
|
|
69
76
|
const t = document.createElement("input");
|
|
70
77
|
t.type = "file", t.accept = n.accept || "*", t.style.display = "none", t.multiple = !!n.multiple, t.onblur = t.onchange = async () => {
|
|
@@ -72,13 +79,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
72
79
|
}, document.body.appendChild(t), t.click();
|
|
73
80
|
});
|
|
74
81
|
}
|
|
75
|
-
function
|
|
82
|
+
function Rt(n) {
|
|
76
83
|
return new E((e, t, r) => {
|
|
77
84
|
const o = new XMLHttpRequest(), s = new FormData();
|
|
78
|
-
n.files.forEach((i) => s.append("file", i)), o.withCredentials = !!n.withCredentials, o.upload.addEventListener("progress", (i) => i.lengthComputable ? r(i.loaded / i.total) : null), o.
|
|
85
|
+
n.files.forEach((i) => s.append("file", i)), o.withCredentials = !!n.withCredentials, o.upload.addEventListener("progress", (i) => i.lengthComputable ? r(i.loaded / i.total) : null), o.addEventListener("loadend", () => e(q(o.responseText))), o.addEventListener("error", () => t(q(o.responseText))), o.addEventListener("timeout", () => t({ error: "Request timed out" })), o.open("POST", n.url), Object.entries(n.headers || {}).forEach(([i, p]) => o.setRequestHeader(i, p)), o.send(s);
|
|
79
86
|
});
|
|
80
87
|
}
|
|
81
|
-
class
|
|
88
|
+
class H {
|
|
82
89
|
constructor() {
|
|
83
90
|
a(this, "listeners", {});
|
|
84
91
|
}
|
|
@@ -119,7 +126,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
119
126
|
});
|
|
120
127
|
}
|
|
121
128
|
}
|
|
122
|
-
a(
|
|
129
|
+
a(H, "listeners", {});
|
|
123
130
|
class w extends Error {
|
|
124
131
|
constructor(t, r) {
|
|
125
132
|
super(t);
|
|
@@ -148,7 +155,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
148
155
|
}
|
|
149
156
|
}
|
|
150
157
|
a(w, "code", 500);
|
|
151
|
-
class
|
|
158
|
+
class X extends w {
|
|
152
159
|
constructor(e = "Bad Request") {
|
|
153
160
|
super(e);
|
|
154
161
|
}
|
|
@@ -156,8 +163,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
156
163
|
return e.constructor.code == this.code;
|
|
157
164
|
}
|
|
158
165
|
}
|
|
159
|
-
a(
|
|
160
|
-
class
|
|
166
|
+
a(X, "code", 400);
|
|
167
|
+
class Q extends w {
|
|
161
168
|
constructor(e = "Unauthorized") {
|
|
162
169
|
super(e);
|
|
163
170
|
}
|
|
@@ -165,8 +172,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
165
172
|
return e.constructor.code == this.code;
|
|
166
173
|
}
|
|
167
174
|
}
|
|
168
|
-
a(
|
|
169
|
-
class
|
|
175
|
+
a(Q, "code", 401);
|
|
176
|
+
class _ extends w {
|
|
170
177
|
constructor(e = "Forbidden") {
|
|
171
178
|
super(e);
|
|
172
179
|
}
|
|
@@ -174,8 +181,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
174
181
|
return e.constructor.code == this.code;
|
|
175
182
|
}
|
|
176
183
|
}
|
|
177
|
-
a(
|
|
178
|
-
class
|
|
184
|
+
a(_, "code", 403);
|
|
185
|
+
class tt extends w {
|
|
179
186
|
constructor(e = "Not Found") {
|
|
180
187
|
super(e);
|
|
181
188
|
}
|
|
@@ -183,8 +190,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
183
190
|
return e.constructor.code == this.code;
|
|
184
191
|
}
|
|
185
192
|
}
|
|
186
|
-
a(
|
|
187
|
-
class
|
|
193
|
+
a(tt, "code", 404);
|
|
194
|
+
class et extends w {
|
|
188
195
|
constructor(e = "Internal Server Error") {
|
|
189
196
|
super(e);
|
|
190
197
|
}
|
|
@@ -192,7 +199,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
192
199
|
return e.constructor.code == this.code;
|
|
193
200
|
}
|
|
194
201
|
}
|
|
195
|
-
a(
|
|
202
|
+
a(et, "code", 500);
|
|
196
203
|
const g = class g2 {
|
|
197
204
|
constructor(e = {}) {
|
|
198
205
|
a(this, "interceptors", {});
|
|
@@ -221,7 +228,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
221
228
|
const s = Array.isArray(e.query) ? e.query : Object.keys(e.query).map((i) => ({ key: i, value: e.query[i] }));
|
|
222
229
|
t += (t.includes("?") ? "&" : "?") + s.map((i) => `${i.key}=${i.value}`).join("&");
|
|
223
230
|
}
|
|
224
|
-
const r =
|
|
231
|
+
const r = W({
|
|
225
232
|
"Content-Type": e.body ? e.body instanceof FormData ? "multipart/form-data" : "application/json" : void 0,
|
|
226
233
|
...g2.headers,
|
|
227
234
|
...this.headers,
|
|
@@ -233,24 +240,24 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
233
240
|
method: e.method || (e.body ? "POST" : "GET"),
|
|
234
241
|
body: e.body
|
|
235
242
|
}).then(async (c) => {
|
|
236
|
-
var
|
|
243
|
+
var j, G;
|
|
237
244
|
for (let u of [...Object.values(g2.interceptors), ...Object.values(this.interceptors)])
|
|
238
245
|
await new Promise((O) => u(c, () => O()));
|
|
239
246
|
const R = c.headers.get("Content-Length"), N = R ? parseInt(R, 10) : 0;
|
|
240
|
-
let
|
|
241
|
-
const
|
|
247
|
+
let k = 0;
|
|
248
|
+
const T = (j = c.body) == null ? void 0 : j.getReader(), Y = new ReadableStream({
|
|
242
249
|
start(u) {
|
|
243
250
|
function O() {
|
|
244
|
-
|
|
251
|
+
T == null || T.read().then((x) => {
|
|
245
252
|
if (x.done)
|
|
246
253
|
return u.close();
|
|
247
|
-
|
|
254
|
+
k += x.value.byteLength, p(k / N), u.enqueue(x.value), O();
|
|
248
255
|
}).catch((x) => u.error(x));
|
|
249
256
|
}
|
|
250
257
|
O();
|
|
251
258
|
}
|
|
252
259
|
});
|
|
253
|
-
if (c.data = new Response(
|
|
260
|
+
if (c.data = new Response(Y), e.decode == null || e.decode) {
|
|
254
261
|
const u = (G = c.headers.get("Content-Type")) == null ? void 0 : G.toLowerCase();
|
|
255
262
|
u != null && u.includes("form") ? c.data = await c.data.formData() : u != null && u.includes("json") ? c.data = await c.data.json() : u != null && u.includes("text") ? c.data = await c.data.text() : u != null && u.includes("application") && (c.data = await c.data.blob());
|
|
256
263
|
}
|
|
@@ -287,8 +294,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
287
294
|
LIGHT_CYAN: "\x1B[96m",
|
|
288
295
|
WHITE: "\x1B[97m"
|
|
289
296
|
};
|
|
290
|
-
var
|
|
291
|
-
const y = class y2 extends
|
|
297
|
+
var nt = /* @__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))(nt || {});
|
|
298
|
+
const y = class y2 extends H {
|
|
292
299
|
constructor(e) {
|
|
293
300
|
super(), this.namespace = e;
|
|
294
301
|
}
|
|
@@ -339,7 +346,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
339
346
|
constructor(url = location.origin, opts = {}) {
|
|
340
347
|
opts.url = url;
|
|
341
348
|
super(opts);
|
|
342
|
-
__publicField(this, "emitter", new
|
|
349
|
+
__publicField(this, "emitter", new H());
|
|
343
350
|
__publicField(this, "_token", null);
|
|
344
351
|
__publicField(this, "emit", this.emitter.emit.bind(this.emitter));
|
|
345
352
|
__publicField(this, "off", this.emitter.off.bind(this.emitter));
|
|
@@ -1089,7 +1096,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1089
1096
|
ActionType2[ActionType2["PUT"] = 6] = "PUT";
|
|
1090
1097
|
return ActionType2;
|
|
1091
1098
|
})(ActionType || {});
|
|
1092
|
-
class Actions extends
|
|
1099
|
+
class Actions extends H {
|
|
1093
1100
|
constructor(api) {
|
|
1094
1101
|
super();
|
|
1095
1102
|
__publicField(this, "api");
|
|
@@ -1155,13 +1162,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1155
1162
|
return this.api.request({ url: `/api/auth/totp/${username}`, method: "POST" });
|
|
1156
1163
|
}
|
|
1157
1164
|
setup(username, method = "app", totp) {
|
|
1158
|
-
return this.api.request({ url: `/api/auth/totp/${username}`, body:
|
|
1165
|
+
return this.api.request({ url: `/api/auth/totp/${username}`, body: W({
|
|
1159
1166
|
method,
|
|
1160
1167
|
totp
|
|
1161
1168
|
}) });
|
|
1162
1169
|
}
|
|
1163
1170
|
}
|
|
1164
|
-
class Auth extends
|
|
1171
|
+
class Auth extends H {
|
|
1165
1172
|
constructor(api, opts) {
|
|
1166
1173
|
var _a;
|
|
1167
1174
|
super();
|
|
@@ -1292,7 +1299,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1292
1299
|
});
|
|
1293
1300
|
}
|
|
1294
1301
|
}
|
|
1295
|
-
class Data extends
|
|
1302
|
+
class Data extends H {
|
|
1296
1303
|
constructor(api) {
|
|
1297
1304
|
super();
|
|
1298
1305
|
__publicField(this, "api");
|
|
@@ -1334,7 +1341,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1334
1341
|
});
|
|
1335
1342
|
}
|
|
1336
1343
|
}
|
|
1337
|
-
class Email extends
|
|
1344
|
+
class Email extends H {
|
|
1338
1345
|
constructor(api) {
|
|
1339
1346
|
super();
|
|
1340
1347
|
__publicField(this, "api");
|
|
@@ -1349,7 +1356,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1349
1356
|
});
|
|
1350
1357
|
}
|
|
1351
1358
|
}
|
|
1352
|
-
class Groups extends
|
|
1359
|
+
class Groups extends H {
|
|
1353
1360
|
constructor(api) {
|
|
1354
1361
|
super();
|
|
1355
1362
|
__publicField(this, "api");
|
|
@@ -1431,32 +1438,32 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1431
1438
|
return this.api.request({ url: `/api/logs/server${query ? `?${query}` : ""}` }).then((resp) => resp);
|
|
1432
1439
|
}
|
|
1433
1440
|
debug(...logs) {
|
|
1434
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1441
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.DEBUG, logs) }).then(() => {
|
|
1435
1442
|
}).catch(() => {
|
|
1436
1443
|
});
|
|
1437
1444
|
}
|
|
1438
1445
|
log(...logs) {
|
|
1439
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1446
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.LOG, logs) }).then(() => {
|
|
1440
1447
|
}).catch(() => {
|
|
1441
1448
|
});
|
|
1442
1449
|
}
|
|
1443
1450
|
info(...logs) {
|
|
1444
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1451
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.INFO, logs) }).then(() => {
|
|
1445
1452
|
}).catch(() => {
|
|
1446
1453
|
});
|
|
1447
1454
|
}
|
|
1448
1455
|
warn(...logs) {
|
|
1449
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1456
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.WARN, logs) }).then(() => {
|
|
1450
1457
|
}).catch(() => {
|
|
1451
1458
|
});
|
|
1452
1459
|
}
|
|
1453
1460
|
error(...logs) {
|
|
1454
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1461
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.ERROR, logs) }).then(() => {
|
|
1455
1462
|
}).catch(() => {
|
|
1456
1463
|
});
|
|
1457
1464
|
}
|
|
1458
1465
|
}
|
|
1459
|
-
class Payments extends
|
|
1466
|
+
class Payments extends H {
|
|
1460
1467
|
constructor(api, secret) {
|
|
1461
1468
|
super();
|
|
1462
1469
|
__publicField(this, "api");
|
|
@@ -1497,7 +1504,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1497
1504
|
return history;
|
|
1498
1505
|
}
|
|
1499
1506
|
}
|
|
1500
|
-
class Pdf extends
|
|
1507
|
+
class Pdf extends H {
|
|
1501
1508
|
constructor(api) {
|
|
1502
1509
|
super();
|
|
1503
1510
|
__publicField(this, "api");
|
|
@@ -1507,7 +1514,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1507
1514
|
const blob = await resp.blob();
|
|
1508
1515
|
if (fileName) {
|
|
1509
1516
|
const url = URL.createObjectURL(blob);
|
|
1510
|
-
|
|
1517
|
+
Z(url, fileName.endsWith(".pdf") ? fileName : fileName + ".pdf");
|
|
1511
1518
|
URL.revokeObjectURL(url);
|
|
1512
1519
|
}
|
|
1513
1520
|
this.emit("CREATE", blob);
|
|
@@ -1570,7 +1577,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1570
1577
|
};
|
|
1571
1578
|
__publicField(_Socket, "timeout", 1e4);
|
|
1572
1579
|
let Socket = _Socket;
|
|
1573
|
-
class Storage extends
|
|
1580
|
+
class Storage extends H {
|
|
1574
1581
|
constructor(api) {
|
|
1575
1582
|
super();
|
|
1576
1583
|
__publicField(this, "api");
|
|
@@ -1606,16 +1613,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1606
1613
|
const blob = await response.blob();
|
|
1607
1614
|
const name = opts.downloadAs || new URL(path).pathname.split("/").pop();
|
|
1608
1615
|
this.emit("DOWNLOAD", path, blob);
|
|
1609
|
-
|
|
1616
|
+
Bt(blob, name);
|
|
1610
1617
|
return response;
|
|
1611
1618
|
});
|
|
1612
1619
|
}
|
|
1613
1620
|
upload(files, opts = "") {
|
|
1614
1621
|
return new E(async (res, rej, prog) => {
|
|
1615
|
-
if (!files) files = await
|
|
1622
|
+
if (!files) files = await bt();
|
|
1616
1623
|
if (!files || Array.isArray(files) && !files.length) return [];
|
|
1617
1624
|
const url = this.api.url + ("/api/storage/" + (typeof opts == "string" ? opts : opts == null ? void 0 : opts.path)).replaceAll("//", "/");
|
|
1618
|
-
return
|
|
1625
|
+
return Rt({
|
|
1619
1626
|
url,
|
|
1620
1627
|
files: Array.isArray(files) ? files : [files],
|
|
1621
1628
|
headers: this.api.headers
|
|
@@ -1832,7 +1839,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1832
1839
|
}, 1e3);
|
|
1833
1840
|
}
|
|
1834
1841
|
}
|
|
1835
|
-
class Users extends
|
|
1842
|
+
class Users extends H {
|
|
1836
1843
|
constructor(api) {
|
|
1837
1844
|
super();
|
|
1838
1845
|
__publicField(this, "api");
|
|
@@ -1897,7 +1904,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1897
1904
|
});
|
|
1898
1905
|
}
|
|
1899
1906
|
uploadImage(username, file) {
|
|
1900
|
-
return
|
|
1907
|
+
return Rt({
|
|
1901
1908
|
url: this.api.url + `/api/users/${username}/image`,
|
|
1902
1909
|
files: [file],
|
|
1903
1910
|
headers: this.api.headers
|
|
@@ -1907,7 +1914,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1907
1914
|
});
|
|
1908
1915
|
}
|
|
1909
1916
|
}
|
|
1910
|
-
class Settings extends
|
|
1917
|
+
class Settings extends H {
|
|
1911
1918
|
constructor(api) {
|
|
1912
1919
|
super();
|
|
1913
1920
|
__publicField(this, "api");
|
|
@@ -1949,7 +1956,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1949
1956
|
});
|
|
1950
1957
|
}
|
|
1951
1958
|
}
|
|
1952
|
-
class Static extends
|
|
1959
|
+
class Static extends H {
|
|
1953
1960
|
constructor(api) {
|
|
1954
1961
|
super();
|
|
1955
1962
|
__publicField(this, "api");
|
|
@@ -1969,7 +1976,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1969
1976
|
}
|
|
1970
1977
|
upload(files, path = "/") {
|
|
1971
1978
|
return new E(async (res, rej, prog) => {
|
|
1972
|
-
return
|
|
1979
|
+
return Rt({
|
|
1973
1980
|
url: this.api.url + ("/api/static/" + path).replaceAll("//", "/"),
|
|
1974
1981
|
files: Array.isArray(files) ? files : [files],
|
|
1975
1982
|
headers: this.api.headers
|
|
@@ -1982,7 +1989,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1982
1989
|
});
|
|
1983
1990
|
}
|
|
1984
1991
|
}
|
|
1985
|
-
class Momentum extends
|
|
1992
|
+
class Momentum extends H {
|
|
1986
1993
|
constructor(url, opts) {
|
|
1987
1994
|
super();
|
|
1988
1995
|
__publicField(this, "api");
|
package/dist/index.mjs
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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 F = (n, e, t) => e in n ?
|
|
4
|
+
var v = Object.defineProperty;
|
|
5
|
+
var F = (n, e, t) => e in n ? v(n, e, { enumerable: true, configurable: true, writable: true, value: t }) : n[e] = t;
|
|
6
6
|
var a = (n, e, t) => (F(n, typeof e != "symbol" ? e + "" : e, t), t);
|
|
7
|
-
function
|
|
7
|
+
function W(n, e = false) {
|
|
8
8
|
if (n == null)
|
|
9
9
|
throw new Error("Cannot clean a NULL value");
|
|
10
10
|
return Array.isArray(n) ? n = n.filter((t) => t != null) : Object.entries(n).forEach(([t, r]) => {
|
|
@@ -15,6 +15,13 @@ function b(n, e) {
|
|
|
15
15
|
const t = typeof n, r = typeof e;
|
|
16
16
|
return t != "object" || n == null || r != "object" || e == null ? t == "function" && r == "function" ? n.toString() == e.toString() : n === e : Object.keys(n).length != Object.keys(e).length ? false : Object.keys(n).every((s) => b(n[s], e[s]));
|
|
17
17
|
}
|
|
18
|
+
function q(n) {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(n);
|
|
21
|
+
} catch {
|
|
22
|
+
return n;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
18
25
|
class E extends Promise {
|
|
19
26
|
constructor(t) {
|
|
20
27
|
super((r, o) => t(
|
|
@@ -52,15 +59,15 @@ class E extends Promise {
|
|
|
52
59
|
return this.from(super.finally(t));
|
|
53
60
|
}
|
|
54
61
|
}
|
|
55
|
-
function
|
|
62
|
+
function Z(n, e) {
|
|
56
63
|
const t = document.createElement("a");
|
|
57
64
|
t.href = n, t.download = e, document.body.appendChild(t), t.click(), document.body.removeChild(t);
|
|
58
65
|
}
|
|
59
|
-
function
|
|
66
|
+
function Bt(n, e) {
|
|
60
67
|
const t = URL.createObjectURL(n);
|
|
61
|
-
|
|
68
|
+
Z(t, e), URL.revokeObjectURL(t);
|
|
62
69
|
}
|
|
63
|
-
function
|
|
70
|
+
function bt(n = {}) {
|
|
64
71
|
return new Promise((e) => {
|
|
65
72
|
const t = document.createElement("input");
|
|
66
73
|
t.type = "file", t.accept = n.accept || "*", t.style.display = "none", t.multiple = !!n.multiple, t.onblur = t.onchange = async () => {
|
|
@@ -68,13 +75,13 @@ function Bt(n = {}) {
|
|
|
68
75
|
}, document.body.appendChild(t), t.click();
|
|
69
76
|
});
|
|
70
77
|
}
|
|
71
|
-
function
|
|
78
|
+
function Rt(n) {
|
|
72
79
|
return new E((e, t, r) => {
|
|
73
80
|
const o = new XMLHttpRequest(), s = new FormData();
|
|
74
|
-
n.files.forEach((i) => s.append("file", i)), o.withCredentials = !!n.withCredentials, o.upload.addEventListener("progress", (i) => i.lengthComputable ? r(i.loaded / i.total) : null), o.
|
|
81
|
+
n.files.forEach((i) => s.append("file", i)), o.withCredentials = !!n.withCredentials, o.upload.addEventListener("progress", (i) => i.lengthComputable ? r(i.loaded / i.total) : null), o.addEventListener("loadend", () => e(q(o.responseText))), o.addEventListener("error", () => t(q(o.responseText))), o.addEventListener("timeout", () => t({ error: "Request timed out" })), o.open("POST", n.url), Object.entries(n.headers || {}).forEach(([i, p]) => o.setRequestHeader(i, p)), o.send(s);
|
|
75
82
|
});
|
|
76
83
|
}
|
|
77
|
-
class
|
|
84
|
+
class H {
|
|
78
85
|
constructor() {
|
|
79
86
|
a(this, "listeners", {});
|
|
80
87
|
}
|
|
@@ -115,7 +122,7 @@ class P {
|
|
|
115
122
|
});
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
|
-
a(
|
|
125
|
+
a(H, "listeners", {});
|
|
119
126
|
class w extends Error {
|
|
120
127
|
constructor(t, r) {
|
|
121
128
|
super(t);
|
|
@@ -144,7 +151,7 @@ class w extends Error {
|
|
|
144
151
|
}
|
|
145
152
|
}
|
|
146
153
|
a(w, "code", 500);
|
|
147
|
-
class
|
|
154
|
+
class X extends w {
|
|
148
155
|
constructor(e = "Bad Request") {
|
|
149
156
|
super(e);
|
|
150
157
|
}
|
|
@@ -152,8 +159,8 @@ class Z extends w {
|
|
|
152
159
|
return e.constructor.code == this.code;
|
|
153
160
|
}
|
|
154
161
|
}
|
|
155
|
-
a(
|
|
156
|
-
class
|
|
162
|
+
a(X, "code", 400);
|
|
163
|
+
class Q extends w {
|
|
157
164
|
constructor(e = "Unauthorized") {
|
|
158
165
|
super(e);
|
|
159
166
|
}
|
|
@@ -161,8 +168,8 @@ class X extends w {
|
|
|
161
168
|
return e.constructor.code == this.code;
|
|
162
169
|
}
|
|
163
170
|
}
|
|
164
|
-
a(
|
|
165
|
-
class
|
|
171
|
+
a(Q, "code", 401);
|
|
172
|
+
class _ extends w {
|
|
166
173
|
constructor(e = "Forbidden") {
|
|
167
174
|
super(e);
|
|
168
175
|
}
|
|
@@ -170,8 +177,8 @@ class Q extends w {
|
|
|
170
177
|
return e.constructor.code == this.code;
|
|
171
178
|
}
|
|
172
179
|
}
|
|
173
|
-
a(
|
|
174
|
-
class
|
|
180
|
+
a(_, "code", 403);
|
|
181
|
+
class tt extends w {
|
|
175
182
|
constructor(e = "Not Found") {
|
|
176
183
|
super(e);
|
|
177
184
|
}
|
|
@@ -179,8 +186,8 @@ class _ extends w {
|
|
|
179
186
|
return e.constructor.code == this.code;
|
|
180
187
|
}
|
|
181
188
|
}
|
|
182
|
-
a(
|
|
183
|
-
class
|
|
189
|
+
a(tt, "code", 404);
|
|
190
|
+
class et extends w {
|
|
184
191
|
constructor(e = "Internal Server Error") {
|
|
185
192
|
super(e);
|
|
186
193
|
}
|
|
@@ -188,7 +195,7 @@ class tt extends w {
|
|
|
188
195
|
return e.constructor.code == this.code;
|
|
189
196
|
}
|
|
190
197
|
}
|
|
191
|
-
a(
|
|
198
|
+
a(et, "code", 500);
|
|
192
199
|
const g = class g2 {
|
|
193
200
|
constructor(e = {}) {
|
|
194
201
|
a(this, "interceptors", {});
|
|
@@ -217,7 +224,7 @@ const g = class g2 {
|
|
|
217
224
|
const s = Array.isArray(e.query) ? e.query : Object.keys(e.query).map((i) => ({ key: i, value: e.query[i] }));
|
|
218
225
|
t += (t.includes("?") ? "&" : "?") + s.map((i) => `${i.key}=${i.value}`).join("&");
|
|
219
226
|
}
|
|
220
|
-
const r =
|
|
227
|
+
const r = W({
|
|
221
228
|
"Content-Type": e.body ? e.body instanceof FormData ? "multipart/form-data" : "application/json" : void 0,
|
|
222
229
|
...g2.headers,
|
|
223
230
|
...this.headers,
|
|
@@ -229,24 +236,24 @@ const g = class g2 {
|
|
|
229
236
|
method: e.method || (e.body ? "POST" : "GET"),
|
|
230
237
|
body: e.body
|
|
231
238
|
}).then(async (c) => {
|
|
232
|
-
var
|
|
239
|
+
var j, G;
|
|
233
240
|
for (let u of [...Object.values(g2.interceptors), ...Object.values(this.interceptors)])
|
|
234
241
|
await new Promise((O) => u(c, () => O()));
|
|
235
242
|
const R = c.headers.get("Content-Length"), N = R ? parseInt(R, 10) : 0;
|
|
236
|
-
let
|
|
237
|
-
const
|
|
243
|
+
let k = 0;
|
|
244
|
+
const T = (j = c.body) == null ? void 0 : j.getReader(), Y = new ReadableStream({
|
|
238
245
|
start(u) {
|
|
239
246
|
function O() {
|
|
240
|
-
|
|
247
|
+
T == null || T.read().then((x) => {
|
|
241
248
|
if (x.done)
|
|
242
249
|
return u.close();
|
|
243
|
-
|
|
250
|
+
k += x.value.byteLength, p(k / N), u.enqueue(x.value), O();
|
|
244
251
|
}).catch((x) => u.error(x));
|
|
245
252
|
}
|
|
246
253
|
O();
|
|
247
254
|
}
|
|
248
255
|
});
|
|
249
|
-
if (c.data = new Response(
|
|
256
|
+
if (c.data = new Response(Y), e.decode == null || e.decode) {
|
|
250
257
|
const u = (G = c.headers.get("Content-Type")) == null ? void 0 : G.toLowerCase();
|
|
251
258
|
u != null && u.includes("form") ? c.data = await c.data.formData() : u != null && u.includes("json") ? c.data = await c.data.json() : u != null && u.includes("text") ? c.data = await c.data.text() : u != null && u.includes("application") && (c.data = await c.data.blob());
|
|
252
259
|
}
|
|
@@ -283,8 +290,8 @@ const A = {
|
|
|
283
290
|
LIGHT_CYAN: "\x1B[96m",
|
|
284
291
|
WHITE: "\x1B[97m"
|
|
285
292
|
};
|
|
286
|
-
var
|
|
287
|
-
const y = class y2 extends
|
|
293
|
+
var nt = /* @__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))(nt || {});
|
|
294
|
+
const y = class y2 extends H {
|
|
288
295
|
constructor(e) {
|
|
289
296
|
super(), this.namespace = e;
|
|
290
297
|
}
|
|
@@ -335,7 +342,7 @@ class Api extends M {
|
|
|
335
342
|
constructor(url = location.origin, opts = {}) {
|
|
336
343
|
opts.url = url;
|
|
337
344
|
super(opts);
|
|
338
|
-
__publicField(this, "emitter", new
|
|
345
|
+
__publicField(this, "emitter", new H());
|
|
339
346
|
__publicField(this, "_token", null);
|
|
340
347
|
__publicField(this, "emit", this.emitter.emit.bind(this.emitter));
|
|
341
348
|
__publicField(this, "off", this.emitter.off.bind(this.emitter));
|
|
@@ -1085,7 +1092,7 @@ var ActionType = /* @__PURE__ */ ((ActionType2) => {
|
|
|
1085
1092
|
ActionType2[ActionType2["PUT"] = 6] = "PUT";
|
|
1086
1093
|
return ActionType2;
|
|
1087
1094
|
})(ActionType || {});
|
|
1088
|
-
class Actions extends
|
|
1095
|
+
class Actions extends H {
|
|
1089
1096
|
constructor(api) {
|
|
1090
1097
|
super();
|
|
1091
1098
|
__publicField(this, "api");
|
|
@@ -1151,13 +1158,13 @@ class Totp {
|
|
|
1151
1158
|
return this.api.request({ url: `/api/auth/totp/${username}`, method: "POST" });
|
|
1152
1159
|
}
|
|
1153
1160
|
setup(username, method = "app", totp) {
|
|
1154
|
-
return this.api.request({ url: `/api/auth/totp/${username}`, body:
|
|
1161
|
+
return this.api.request({ url: `/api/auth/totp/${username}`, body: W({
|
|
1155
1162
|
method,
|
|
1156
1163
|
totp
|
|
1157
1164
|
}) });
|
|
1158
1165
|
}
|
|
1159
1166
|
}
|
|
1160
|
-
class Auth extends
|
|
1167
|
+
class Auth extends H {
|
|
1161
1168
|
constructor(api, opts) {
|
|
1162
1169
|
var _a;
|
|
1163
1170
|
super();
|
|
@@ -1288,7 +1295,7 @@ class Auth extends P {
|
|
|
1288
1295
|
});
|
|
1289
1296
|
}
|
|
1290
1297
|
}
|
|
1291
|
-
class Data extends
|
|
1298
|
+
class Data extends H {
|
|
1292
1299
|
constructor(api) {
|
|
1293
1300
|
super();
|
|
1294
1301
|
__publicField(this, "api");
|
|
@@ -1330,7 +1337,7 @@ class Data extends P {
|
|
|
1330
1337
|
});
|
|
1331
1338
|
}
|
|
1332
1339
|
}
|
|
1333
|
-
class Email extends
|
|
1340
|
+
class Email extends H {
|
|
1334
1341
|
constructor(api) {
|
|
1335
1342
|
super();
|
|
1336
1343
|
__publicField(this, "api");
|
|
@@ -1345,7 +1352,7 @@ class Email extends P {
|
|
|
1345
1352
|
});
|
|
1346
1353
|
}
|
|
1347
1354
|
}
|
|
1348
|
-
class Groups extends
|
|
1355
|
+
class Groups extends H {
|
|
1349
1356
|
constructor(api) {
|
|
1350
1357
|
super();
|
|
1351
1358
|
__publicField(this, "api");
|
|
@@ -1427,32 +1434,32 @@ class Logger {
|
|
|
1427
1434
|
return this.api.request({ url: `/api/logs/server${query ? `?${query}` : ""}` }).then((resp) => resp);
|
|
1428
1435
|
}
|
|
1429
1436
|
debug(...logs) {
|
|
1430
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1437
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.DEBUG, logs) }).then(() => {
|
|
1431
1438
|
}).catch(() => {
|
|
1432
1439
|
});
|
|
1433
1440
|
}
|
|
1434
1441
|
log(...logs) {
|
|
1435
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1442
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.LOG, logs) }).then(() => {
|
|
1436
1443
|
}).catch(() => {
|
|
1437
1444
|
});
|
|
1438
1445
|
}
|
|
1439
1446
|
info(...logs) {
|
|
1440
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1447
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.INFO, logs) }).then(() => {
|
|
1441
1448
|
}).catch(() => {
|
|
1442
1449
|
});
|
|
1443
1450
|
}
|
|
1444
1451
|
warn(...logs) {
|
|
1445
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1452
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.WARN, logs) }).then(() => {
|
|
1446
1453
|
}).catch(() => {
|
|
1447
1454
|
});
|
|
1448
1455
|
}
|
|
1449
1456
|
error(...logs) {
|
|
1450
|
-
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(
|
|
1457
|
+
return this.api.request({ url: `/api/logs/client`, body: this.buildLog(nt.ERROR, logs) }).then(() => {
|
|
1451
1458
|
}).catch(() => {
|
|
1452
1459
|
});
|
|
1453
1460
|
}
|
|
1454
1461
|
}
|
|
1455
|
-
class Payments extends
|
|
1462
|
+
class Payments extends H {
|
|
1456
1463
|
constructor(api, secret) {
|
|
1457
1464
|
super();
|
|
1458
1465
|
__publicField(this, "api");
|
|
@@ -1493,7 +1500,7 @@ class Payments extends P {
|
|
|
1493
1500
|
return history;
|
|
1494
1501
|
}
|
|
1495
1502
|
}
|
|
1496
|
-
class Pdf extends
|
|
1503
|
+
class Pdf extends H {
|
|
1497
1504
|
constructor(api) {
|
|
1498
1505
|
super();
|
|
1499
1506
|
__publicField(this, "api");
|
|
@@ -1503,7 +1510,7 @@ class Pdf extends P {
|
|
|
1503
1510
|
const blob = await resp.blob();
|
|
1504
1511
|
if (fileName) {
|
|
1505
1512
|
const url = URL.createObjectURL(blob);
|
|
1506
|
-
|
|
1513
|
+
Z(url, fileName.endsWith(".pdf") ? fileName : fileName + ".pdf");
|
|
1507
1514
|
URL.revokeObjectURL(url);
|
|
1508
1515
|
}
|
|
1509
1516
|
this.emit("CREATE", blob);
|
|
@@ -1566,7 +1573,7 @@ const _Socket = class _Socket {
|
|
|
1566
1573
|
};
|
|
1567
1574
|
__publicField(_Socket, "timeout", 1e4);
|
|
1568
1575
|
let Socket = _Socket;
|
|
1569
|
-
class Storage extends
|
|
1576
|
+
class Storage extends H {
|
|
1570
1577
|
constructor(api) {
|
|
1571
1578
|
super();
|
|
1572
1579
|
__publicField(this, "api");
|
|
@@ -1602,16 +1609,16 @@ class Storage extends P {
|
|
|
1602
1609
|
const blob = await response.blob();
|
|
1603
1610
|
const name = opts.downloadAs || new URL(path).pathname.split("/").pop();
|
|
1604
1611
|
this.emit("DOWNLOAD", path, blob);
|
|
1605
|
-
|
|
1612
|
+
Bt(blob, name);
|
|
1606
1613
|
return response;
|
|
1607
1614
|
});
|
|
1608
1615
|
}
|
|
1609
1616
|
upload(files, opts = "") {
|
|
1610
1617
|
return new E(async (res, rej, prog) => {
|
|
1611
|
-
if (!files) files = await
|
|
1618
|
+
if (!files) files = await bt();
|
|
1612
1619
|
if (!files || Array.isArray(files) && !files.length) return [];
|
|
1613
1620
|
const url = this.api.url + ("/api/storage/" + (typeof opts == "string" ? opts : opts == null ? void 0 : opts.path)).replaceAll("//", "/");
|
|
1614
|
-
return
|
|
1621
|
+
return Rt({
|
|
1615
1622
|
url,
|
|
1616
1623
|
files: Array.isArray(files) ? files : [files],
|
|
1617
1624
|
headers: this.api.headers
|
|
@@ -1828,7 +1835,7 @@ class UI {
|
|
|
1828
1835
|
}, 1e3);
|
|
1829
1836
|
}
|
|
1830
1837
|
}
|
|
1831
|
-
class Users extends
|
|
1838
|
+
class Users extends H {
|
|
1832
1839
|
constructor(api) {
|
|
1833
1840
|
super();
|
|
1834
1841
|
__publicField(this, "api");
|
|
@@ -1893,7 +1900,7 @@ class Users extends P {
|
|
|
1893
1900
|
});
|
|
1894
1901
|
}
|
|
1895
1902
|
uploadImage(username, file) {
|
|
1896
|
-
return
|
|
1903
|
+
return Rt({
|
|
1897
1904
|
url: this.api.url + `/api/users/${username}/image`,
|
|
1898
1905
|
files: [file],
|
|
1899
1906
|
headers: this.api.headers
|
|
@@ -1903,7 +1910,7 @@ class Users extends P {
|
|
|
1903
1910
|
});
|
|
1904
1911
|
}
|
|
1905
1912
|
}
|
|
1906
|
-
class Settings extends
|
|
1913
|
+
class Settings extends H {
|
|
1907
1914
|
constructor(api) {
|
|
1908
1915
|
super();
|
|
1909
1916
|
__publicField(this, "api");
|
|
@@ -1945,7 +1952,7 @@ class Settings extends P {
|
|
|
1945
1952
|
});
|
|
1946
1953
|
}
|
|
1947
1954
|
}
|
|
1948
|
-
class Static extends
|
|
1955
|
+
class Static extends H {
|
|
1949
1956
|
constructor(api) {
|
|
1950
1957
|
super();
|
|
1951
1958
|
__publicField(this, "api");
|
|
@@ -1965,7 +1972,7 @@ class Static extends P {
|
|
|
1965
1972
|
}
|
|
1966
1973
|
upload(files, path = "/") {
|
|
1967
1974
|
return new E(async (res, rej, prog) => {
|
|
1968
|
-
return
|
|
1975
|
+
return Rt({
|
|
1969
1976
|
url: this.api.url + ("/api/static/" + path).replaceAll("//", "/"),
|
|
1970
1977
|
files: Array.isArray(files) ? files : [files],
|
|
1971
1978
|
headers: this.api.headers
|
|
@@ -1978,7 +1985,7 @@ class Static extends P {
|
|
|
1978
1985
|
});
|
|
1979
1986
|
}
|
|
1980
1987
|
}
|
|
1981
|
-
class Momentum extends
|
|
1988
|
+
class Momentum extends H {
|
|
1982
1989
|
constructor(url, opts) {
|
|
1983
1990
|
super();
|
|
1984
1991
|
__publicField(this, "api");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ztimson/momentum",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.5",
|
|
4
4
|
"description": "Client library for momentum",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Momentum"
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"watch": "vite build --watch"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@ztimson/utils": "
|
|
29
|
+
"@ztimson/utils": "0.15.1",
|
|
30
30
|
"rxjs": "^7.8.1"
|
|
31
31
|
},
|
|
32
32
|
"devDependencies": {
|