@ztimson/momentum 0.38.1 → 0.39.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 +8 -8
- package/dist/actions.d.ts.map +1 -1
- package/dist/ai.d.ts +1 -1
- 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 +5 -4
- package/dist/api.d.ts.map +1 -1
- package/dist/auth.d.ts +7 -5
- package/dist/auth.d.ts.map +1 -1
- package/dist/data.d.ts +22 -11
- package/dist/data.d.ts.map +1 -1
- package/dist/email.d.ts +1 -1
- package/dist/email.d.ts.map +1 -1
- package/dist/groups.d.ts +6 -6
- package/dist/groups.d.ts.map +1 -1
- package/dist/index.cjs +129 -113
- package/dist/index.mjs +129 -113
- package/dist/payments.d.ts +4 -3
- package/dist/payments.d.ts.map +1 -1
- package/dist/pdf.d.ts +1 -1
- package/dist/settings.d.ts +4 -4
- package/dist/static.d.ts +4 -7
- package/dist/static.d.ts.map +1 -1
- package/dist/storage.d.ts +11 -8
- package/dist/storage.d.ts.map +1 -1
- package/dist/users.d.ts +6 -6
- package/dist/users.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -425,21 +425,24 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
425
425
|
if (token == this._token) return;
|
|
426
426
|
this._token = token;
|
|
427
427
|
this.headers["Authorization"] = token ? `Bearer ${token}` : void 0;
|
|
428
|
-
this.emit("
|
|
428
|
+
this.emit("token", token);
|
|
429
429
|
}
|
|
430
430
|
healthcheck() {
|
|
431
431
|
return this.request({ url: "/api/healthcheck" });
|
|
432
432
|
}
|
|
433
|
+
path(...children) {
|
|
434
|
+
return children.filter((p2) => !!p2).join("/").replaceAll("//", "/");
|
|
435
|
+
}
|
|
433
436
|
request(options) {
|
|
434
437
|
const req = super.request(options).then((resp) => {
|
|
435
|
-
this.emit("
|
|
438
|
+
this.emit("response", resp, options);
|
|
436
439
|
return resp.data;
|
|
437
440
|
}).catch((err) => {
|
|
438
441
|
const e = (err == null ? void 0 : err.data) || err;
|
|
439
|
-
this.emit("
|
|
442
|
+
this.emit("rejected", e, options);
|
|
440
443
|
throw e;
|
|
441
444
|
});
|
|
442
|
-
this.emit("
|
|
445
|
+
this.emit("request", req, options);
|
|
443
446
|
return req;
|
|
444
447
|
}
|
|
445
448
|
}
|
|
@@ -1175,13 +1178,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1175
1178
|
delete(id) {
|
|
1176
1179
|
return this.api.request({ url: `/api/actions/${id}`, method: "DELETE" }).then(() => {
|
|
1177
1180
|
this.cache = this.cache.filter((a) => a._id != id);
|
|
1178
|
-
this.emit("
|
|
1181
|
+
this.emit("delete", id);
|
|
1179
1182
|
});
|
|
1180
1183
|
}
|
|
1181
|
-
|
|
1184
|
+
all() {
|
|
1182
1185
|
return this.api.request({ url: `/api/actions` }).then((resp) => {
|
|
1183
1186
|
if (resp) this.cache = resp;
|
|
1184
|
-
this.emit("
|
|
1187
|
+
this.emit("all", resp || []);
|
|
1185
1188
|
return resp;
|
|
1186
1189
|
});
|
|
1187
1190
|
}
|
|
@@ -1190,16 +1193,22 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1190
1193
|
if (!reload && cached) return Promise.resolve(cached);
|
|
1191
1194
|
return this.api.request({ url: `/api/actions/${id}` }).then((action) => {
|
|
1192
1195
|
if (action) this.cache = this.cache.filter((a) => a._id != id).concat([action]);
|
|
1193
|
-
this.emit("
|
|
1196
|
+
this.emit("read", action);
|
|
1194
1197
|
return action;
|
|
1195
1198
|
});
|
|
1196
1199
|
}
|
|
1197
1200
|
run(path, opts = {}) {
|
|
1198
|
-
return this.api.request({ url: (`/api/actions/run/` + path).replaceAll("//", "/"), ...opts })
|
|
1201
|
+
return this.api.request({ url: (`/api/actions/run/` + path).replaceAll("//", "/"), ...opts }).then((resp) => {
|
|
1202
|
+
this.emit("execute", path, resp);
|
|
1203
|
+
return resp;
|
|
1204
|
+
});
|
|
1199
1205
|
}
|
|
1200
1206
|
runById(action, opts = {}) {
|
|
1201
1207
|
const id = typeof action == "string" ? action : action._id;
|
|
1202
|
-
return this.api.request({ url: "/api/actions/run-by-id/" + id, method: "POST", ...opts })
|
|
1208
|
+
return this.api.request({ url: "/api/actions/run-by-id/" + id, method: "POST", ...opts }).then((resp) => {
|
|
1209
|
+
this.emit("execute", typeof action == "string" ? action : action._id, resp);
|
|
1210
|
+
return resp;
|
|
1211
|
+
});
|
|
1203
1212
|
}
|
|
1204
1213
|
update(action) {
|
|
1205
1214
|
return this.api.request({
|
|
@@ -1208,7 +1217,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1208
1217
|
body: action
|
|
1209
1218
|
}).then((action2) => {
|
|
1210
1219
|
if (action2) this.cache = this.cache.filter((a) => a._id != (action2 == null ? void 0 : action2._id)).concat([action2]);
|
|
1211
|
-
this.emit("
|
|
1220
|
+
this.emit("update", action2);
|
|
1212
1221
|
return action2;
|
|
1213
1222
|
});
|
|
1214
1223
|
}
|
|
@@ -1224,7 +1233,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1224
1233
|
question,
|
|
1225
1234
|
context
|
|
1226
1235
|
} }).then((resp) => {
|
|
1227
|
-
this.emit("
|
|
1236
|
+
this.emit("ask", question, context, resp);
|
|
1228
1237
|
return resp;
|
|
1229
1238
|
});
|
|
1230
1239
|
}
|
|
@@ -1235,9 +1244,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1235
1244
|
__publicField(this, "api");
|
|
1236
1245
|
this.api = typeof api == "string" ? new Api(api) : api;
|
|
1237
1246
|
}
|
|
1238
|
-
|
|
1247
|
+
ipTrace(ip) {
|
|
1239
1248
|
return this.api.request({ url: `/api/analytics/trace?ip=${ip}` }).then((resp) => {
|
|
1240
|
-
this.emit("
|
|
1249
|
+
this.emit("ipTrace", ip, resp);
|
|
1241
1250
|
return resp;
|
|
1242
1251
|
});
|
|
1243
1252
|
}
|
|
@@ -1283,10 +1292,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1283
1292
|
"/api/auth/totp"
|
|
1284
1293
|
];
|
|
1285
1294
|
if (resp.status == 401 && !blacklist.find((url) => resp.url.includes(url)))
|
|
1286
|
-
this.emit("
|
|
1295
|
+
this.emit("sessionExpired");
|
|
1287
1296
|
next();
|
|
1288
1297
|
});
|
|
1289
|
-
this.api.on("
|
|
1298
|
+
this.api.on("token", (token) => {
|
|
1290
1299
|
var _a;
|
|
1291
1300
|
if ((_a = this.opts) == null ? void 0 : _a.persist) {
|
|
1292
1301
|
if (token) localStorage.setItem(this.storageKey, token);
|
|
@@ -1311,7 +1320,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1311
1320
|
if (!b(this.user, user)) {
|
|
1312
1321
|
const u = user ? user : null;
|
|
1313
1322
|
this.$user.next(u);
|
|
1314
|
-
this.emit("
|
|
1323
|
+
this.emit("user", u);
|
|
1315
1324
|
}
|
|
1316
1325
|
}
|
|
1317
1326
|
knownHost(host = location.origin) {
|
|
@@ -1331,7 +1340,9 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1331
1340
|
}
|
|
1332
1341
|
}).then(async (resp) => {
|
|
1333
1342
|
this.api.token = (resp == null ? void 0 : resp.token) || null;
|
|
1334
|
-
|
|
1343
|
+
const user = await this.once("user");
|
|
1344
|
+
this.emit("login", user);
|
|
1345
|
+
return user;
|
|
1335
1346
|
});
|
|
1336
1347
|
}
|
|
1337
1348
|
loginRedirect(host = location.origin) {
|
|
@@ -1353,13 +1364,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1353
1364
|
logout() {
|
|
1354
1365
|
this.api.token = null;
|
|
1355
1366
|
this.user = null;
|
|
1356
|
-
this.emit("
|
|
1367
|
+
this.emit("logout");
|
|
1357
1368
|
}
|
|
1358
1369
|
async register(u) {
|
|
1359
1370
|
var _a;
|
|
1360
1371
|
const user = await this.api.request({ url: "/api/auth/register", body: { ...u } });
|
|
1361
1372
|
if ((_a = user == null ? void 0 : user.image) == null ? void 0 : _a.startsWith("/")) user.image = `${this.api.url}${user.image}?token=${this.api.token}`;
|
|
1362
|
-
this.emit("
|
|
1373
|
+
this.emit("register", user);
|
|
1363
1374
|
return user;
|
|
1364
1375
|
}
|
|
1365
1376
|
reset(emailOrPass, token) {
|
|
@@ -1371,6 +1382,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1371
1382
|
password: token ? emailOrPass : void 0
|
|
1372
1383
|
}
|
|
1373
1384
|
}).then(() => {
|
|
1385
|
+
if (token) this.emit("reset", token);
|
|
1386
|
+
else this.emit("resetRequest", emailOrPass);
|
|
1374
1387
|
});
|
|
1375
1388
|
}
|
|
1376
1389
|
async session(token, set = false) {
|
|
@@ -1383,7 +1396,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1383
1396
|
this.api.token = token;
|
|
1384
1397
|
if (session == null ? void 0 : session.user) session.user.image = `${this.api.url}${session.user.image}?token=${this.api.token}`;
|
|
1385
1398
|
this.user = (session == null ? void 0 : session.user) || null;
|
|
1386
|
-
if (session) this.emit("
|
|
1399
|
+
if (session) this.emit("login", session.user);
|
|
1387
1400
|
}
|
|
1388
1401
|
return session;
|
|
1389
1402
|
}
|
|
@@ -1402,41 +1415,40 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1402
1415
|
__publicField(this, "api");
|
|
1403
1416
|
this.api = typeof api == "string" ? new Api(api) : api;
|
|
1404
1417
|
}
|
|
1405
|
-
|
|
1418
|
+
create(collection, document2) {
|
|
1406
1419
|
return this.api.request({
|
|
1407
|
-
url: `/api/data/${collection}
|
|
1408
|
-
method: "
|
|
1409
|
-
}).then(() =>
|
|
1420
|
+
url: `/api/data/${collection}`,
|
|
1421
|
+
method: "POST"
|
|
1422
|
+
}).then((resp) => {
|
|
1423
|
+
this.emit("create", collection, resp);
|
|
1424
|
+
return resp;
|
|
1425
|
+
});
|
|
1410
1426
|
}
|
|
1411
|
-
|
|
1427
|
+
read(collection, document2) {
|
|
1412
1428
|
return this.api.request({ url: `/api/data/${collection}${document2 ? `/${document2}` : ""}` }).then((resp) => {
|
|
1413
|
-
this.emit("
|
|
1429
|
+
this.emit("read", collection, resp);
|
|
1414
1430
|
return resp;
|
|
1415
1431
|
});
|
|
1416
1432
|
}
|
|
1417
|
-
|
|
1418
|
-
return this.api.request({ url: `/api/data/schema` });
|
|
1419
|
-
}
|
|
1420
|
-
raw(collection, operand, query, options) {
|
|
1433
|
+
update(collection, document2, append = true) {
|
|
1421
1434
|
return this.api.request({
|
|
1422
1435
|
url: `/api/data/${collection}`,
|
|
1423
|
-
|
|
1424
|
-
|
|
1425
|
-
query,
|
|
1426
|
-
options
|
|
1427
|
-
}
|
|
1436
|
+
method: append ? "PATCH" : "PUT",
|
|
1437
|
+
body: document2
|
|
1428
1438
|
}).then((resp) => {
|
|
1429
|
-
this.emit("
|
|
1439
|
+
this.emit("update", collection, resp);
|
|
1430
1440
|
return resp;
|
|
1431
1441
|
});
|
|
1432
1442
|
}
|
|
1433
|
-
|
|
1443
|
+
delete(collection, document2) {
|
|
1434
1444
|
return this.api.request({
|
|
1435
|
-
url: `/api/data/${collection}/${document2
|
|
1436
|
-
method:
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1445
|
+
url: `/api/data/${collection}/${document2}`,
|
|
1446
|
+
method: "DELETE"
|
|
1447
|
+
}).then(() => this.emit("delete", collection, document2));
|
|
1448
|
+
}
|
|
1449
|
+
raw(collection, query) {
|
|
1450
|
+
return this.api.request({ url: `/api/data/${collection}`, body: query }).then((resp) => {
|
|
1451
|
+
this.emit("raw", collection, query, resp);
|
|
1440
1452
|
return resp;
|
|
1441
1453
|
});
|
|
1442
1454
|
}
|
|
@@ -1451,7 +1463,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1451
1463
|
let url = "/api/email";
|
|
1452
1464
|
if (typeof email.body == "object") url += `/${email.body.template}`;
|
|
1453
1465
|
return this.api.request({ url, body: email }).then((resp) => {
|
|
1454
|
-
this.emit("
|
|
1466
|
+
this.emit("sent", email, resp);
|
|
1455
1467
|
return resp;
|
|
1456
1468
|
});
|
|
1457
1469
|
}
|
|
@@ -1462,25 +1474,25 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1462
1474
|
__publicField(this, "api");
|
|
1463
1475
|
this.api = typeof api == "string" ? new Api(api) : api;
|
|
1464
1476
|
}
|
|
1477
|
+
all() {
|
|
1478
|
+
return this.api.request({ url: `/api/groups` }).then((resp) => {
|
|
1479
|
+
this.emit("all", resp || []);
|
|
1480
|
+
return resp;
|
|
1481
|
+
});
|
|
1482
|
+
}
|
|
1465
1483
|
create(group) {
|
|
1466
1484
|
return this.api.request({
|
|
1467
1485
|
url: `/api/groups/${group.name}`,
|
|
1468
1486
|
method: "POST",
|
|
1469
1487
|
body: group
|
|
1470
1488
|
}).then((resp) => {
|
|
1471
|
-
this.emit("
|
|
1472
|
-
return resp;
|
|
1473
|
-
});
|
|
1474
|
-
}
|
|
1475
|
-
list() {
|
|
1476
|
-
return this.api.request({ url: `/api/groups` }).then((resp) => {
|
|
1477
|
-
this.emit("LIST", resp || []);
|
|
1489
|
+
this.emit("create", resp);
|
|
1478
1490
|
return resp;
|
|
1479
1491
|
});
|
|
1480
1492
|
}
|
|
1481
1493
|
read(name) {
|
|
1482
1494
|
return this.api.request({ url: `/api/groups/${name}` }).then((resp) => {
|
|
1483
|
-
this.emit("
|
|
1495
|
+
this.emit("read", resp);
|
|
1484
1496
|
return resp;
|
|
1485
1497
|
});
|
|
1486
1498
|
}
|
|
@@ -1490,7 +1502,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1490
1502
|
method: "PATCH",
|
|
1491
1503
|
body: group
|
|
1492
1504
|
}).then((resp) => {
|
|
1493
|
-
this.emit("
|
|
1505
|
+
this.emit("update", resp);
|
|
1494
1506
|
return resp;
|
|
1495
1507
|
});
|
|
1496
1508
|
}
|
|
@@ -1498,7 +1510,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1498
1510
|
return this.api.request({
|
|
1499
1511
|
url: `/api/groups/${name}`,
|
|
1500
1512
|
method: "DELETE"
|
|
1501
|
-
}).then(() => this.emit("
|
|
1513
|
+
}).then(() => this.emit("delete", name));
|
|
1502
1514
|
}
|
|
1503
1515
|
}
|
|
1504
1516
|
class Logger {
|
|
@@ -1591,16 +1603,16 @@ ${log}`;
|
|
|
1591
1603
|
};
|
|
1592
1604
|
setup();
|
|
1593
1605
|
}
|
|
1594
|
-
async
|
|
1595
|
-
this.emit("CHECKOUT", amount, custom);
|
|
1606
|
+
async create(amount, custom = {}) {
|
|
1596
1607
|
const request = await this.api.request({ url: "/api/payments", body: {
|
|
1597
1608
|
amount,
|
|
1598
1609
|
custom
|
|
1599
1610
|
} });
|
|
1611
|
+
this.emit("create", amount, custom, request.data.clientSecret);
|
|
1600
1612
|
return request.data.clientSecret;
|
|
1601
1613
|
}
|
|
1602
1614
|
async createForm(element, amount, custom) {
|
|
1603
|
-
const token = await this.
|
|
1615
|
+
const token = await this.create(amount, custom);
|
|
1604
1616
|
const form = this.stripe.elements({ clientSecret: token });
|
|
1605
1617
|
form.create("payment").mount(element);
|
|
1606
1618
|
return () => this.stripe.confirmPayment({
|
|
@@ -1611,7 +1623,7 @@ ${log}`;
|
|
|
1611
1623
|
}
|
|
1612
1624
|
async history(username) {
|
|
1613
1625
|
const history = await this.api.request({ url: `/api/payments${username ? `/${username}` : ""}` });
|
|
1614
|
-
this.emit("
|
|
1626
|
+
this.emit("history", username || null, history);
|
|
1615
1627
|
return history;
|
|
1616
1628
|
}
|
|
1617
1629
|
}
|
|
@@ -1628,7 +1640,7 @@ ${log}`;
|
|
|
1628
1640
|
at(url, fileName.endsWith(".pdf") ? fileName : fileName + ".pdf");
|
|
1629
1641
|
URL.revokeObjectURL(url);
|
|
1630
1642
|
}
|
|
1631
|
-
this.emit("
|
|
1643
|
+
this.emit("create", blob);
|
|
1632
1644
|
return blob;
|
|
1633
1645
|
}
|
|
1634
1646
|
fromHtml(content, opts = {}) {
|
|
@@ -1649,7 +1661,7 @@ ${log}`;
|
|
|
1649
1661
|
__publicField(this, "open", false);
|
|
1650
1662
|
this.api = typeof api == "string" ? new Api(api) : api;
|
|
1651
1663
|
this.url = this.api.url.replace("http", "ws");
|
|
1652
|
-
this.api.on("
|
|
1664
|
+
this.api.on("token", () => this.connect());
|
|
1653
1665
|
this.connect();
|
|
1654
1666
|
}
|
|
1655
1667
|
close() {
|
|
@@ -1695,59 +1707,70 @@ ${log}`;
|
|
|
1695
1707
|
this.api = typeof api == "string" ? new Api(api) : api;
|
|
1696
1708
|
}
|
|
1697
1709
|
copy(path) {
|
|
1698
|
-
|
|
1710
|
+
const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
|
|
1711
|
+
return this.api.request({ url, method: "PUT" }).then((resp) => {
|
|
1712
|
+
this.emit("copy", path, resp);
|
|
1713
|
+
return resp;
|
|
1714
|
+
});
|
|
1699
1715
|
}
|
|
1700
1716
|
delete(path) {
|
|
1701
|
-
const url = (path.startsWith("/api/storage/") ?
|
|
1717
|
+
const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
|
|
1702
1718
|
return this.api.request({ url, method: "DELETE" }).then(() => {
|
|
1703
|
-
this.emit("
|
|
1719
|
+
this.emit("delete", url);
|
|
1720
|
+
});
|
|
1721
|
+
}
|
|
1722
|
+
download(path, opts = {}) {
|
|
1723
|
+
const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
|
|
1724
|
+
return this.api.request({ ...opts, url, decode: false }).then(async (response) => {
|
|
1725
|
+
const blob = await response.blob();
|
|
1726
|
+
const name = opts.downloadAs || path.split("/").pop();
|
|
1727
|
+
this.emit("download", path, blob);
|
|
1728
|
+
Tt(blob, name);
|
|
1729
|
+
return response;
|
|
1704
1730
|
});
|
|
1705
1731
|
}
|
|
1706
1732
|
list(path) {
|
|
1707
|
-
const url = (path.startsWith("/api/storage/") ?
|
|
1733
|
+
const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
|
|
1708
1734
|
return this.api.request({ url: url + "?list" }).then((resp) => {
|
|
1709
|
-
this.emit("
|
|
1735
|
+
this.emit("list", path, resp);
|
|
1710
1736
|
return resp;
|
|
1711
1737
|
});
|
|
1712
1738
|
}
|
|
1713
1739
|
open(path, target = "_blank") {
|
|
1714
|
-
const
|
|
1715
|
-
const link = `${this.api.url}${
|
|
1740
|
+
const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
|
|
1741
|
+
const link = `${this.api.url}${url}${this.api.token ? `?token=${this.api.token}` : ""}`;
|
|
1716
1742
|
if (!target) return link;
|
|
1717
|
-
this.emit("
|
|
1743
|
+
this.emit("open", path);
|
|
1718
1744
|
return window.open(link, target);
|
|
1719
1745
|
}
|
|
1720
1746
|
mkdir(path) {
|
|
1721
|
-
const
|
|
1722
|
-
return this.api.request({ url:
|
|
1747
|
+
const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
|
|
1748
|
+
return this.api.request({ url: url + "?directory", method: "POST" }).then((resp) => {
|
|
1749
|
+
this.emit("mkdir", path, resp);
|
|
1750
|
+
return resp;
|
|
1751
|
+
});
|
|
1723
1752
|
}
|
|
1724
1753
|
move(from, to) {
|
|
1725
1754
|
if (from == to) return this.list(to);
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
return this.api.request({ ...opts, url: p2, decode: false }).then(async (response) => {
|
|
1731
|
-
const blob = await response.blob();
|
|
1732
|
-
const name = opts.downloadAs || path.split("/").pop();
|
|
1733
|
-
this.emit("DOWNLOAD", path, blob);
|
|
1734
|
-
Tt(blob, name);
|
|
1735
|
-
return response;
|
|
1755
|
+
const url = this.api.path(from.startsWith("/api/storage/") ? "" : "/api/storage/", from);
|
|
1756
|
+
return this.api.request({ url, method: "PATCH", body: { move: to } }).then((resp) => {
|
|
1757
|
+
this.emit("move", from, to, resp);
|
|
1758
|
+
return resp;
|
|
1736
1759
|
});
|
|
1737
1760
|
}
|
|
1738
1761
|
upload(files, opts = "") {
|
|
1739
1762
|
return new m(async (res, rej, prog) => {
|
|
1740
1763
|
if (!files) files = await It(typeof opts == "object" ? opts : void 0);
|
|
1741
1764
|
if (!files || Array.isArray(files) && !files.length) return [];
|
|
1742
|
-
const
|
|
1765
|
+
const path = this.api.path("/api/storage/", typeof opts == "string" ? opts : opts.path || "");
|
|
1743
1766
|
return $t({
|
|
1744
|
-
url
|
|
1767
|
+
url: `${this.api.url}${path}`,
|
|
1745
1768
|
files: Array.isArray(files) ? files : [files],
|
|
1746
1769
|
headers: this.api.headers
|
|
1747
1770
|
}).onProgress((p2) => {
|
|
1748
1771
|
prog(p2);
|
|
1749
1772
|
}).then((resp) => {
|
|
1750
|
-
this.emit("
|
|
1773
|
+
this.emit("upload", resp);
|
|
1751
1774
|
res(resp);
|
|
1752
1775
|
}).catch((err) => rej(err));
|
|
1753
1776
|
});
|
|
@@ -1977,7 +2000,7 @@ ${log}`;
|
|
|
1977
2000
|
method: "DELETE"
|
|
1978
2001
|
}).then(() => {
|
|
1979
2002
|
this.cache = this.cache.filter((u) => u.username != username);
|
|
1980
|
-
this.emit("
|
|
2003
|
+
this.emit("delete", username);
|
|
1981
2004
|
});
|
|
1982
2005
|
}
|
|
1983
2006
|
list(reload = false) {
|
|
@@ -1989,7 +2012,7 @@ ${log}`;
|
|
|
1989
2012
|
});
|
|
1990
2013
|
this.cache = resp || [];
|
|
1991
2014
|
this.listed = true;
|
|
1992
|
-
this.emit("
|
|
2015
|
+
this.emit("all", resp || []);
|
|
1993
2016
|
return resp;
|
|
1994
2017
|
});
|
|
1995
2018
|
}
|
|
@@ -2003,7 +2026,7 @@ ${log}`;
|
|
|
2003
2026
|
resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
|
|
2004
2027
|
this.cache = [...this.cache.filter((u) => u.username != username), resp];
|
|
2005
2028
|
}
|
|
2006
|
-
this.emit("
|
|
2029
|
+
this.emit("read", resp);
|
|
2007
2030
|
return resp;
|
|
2008
2031
|
});
|
|
2009
2032
|
}
|
|
@@ -2017,7 +2040,7 @@ ${log}`;
|
|
|
2017
2040
|
resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
|
|
2018
2041
|
this.cache = this.cache.filter((u) => u.username != user.username).concat([resp]);
|
|
2019
2042
|
}
|
|
2020
|
-
this.emit(user._id ? "
|
|
2043
|
+
this.emit(user._id ? "update" : "create", resp);
|
|
2021
2044
|
return resp;
|
|
2022
2045
|
});
|
|
2023
2046
|
}
|
|
@@ -2027,7 +2050,7 @@ ${log}`;
|
|
|
2027
2050
|
files: [file],
|
|
2028
2051
|
headers: this.api.headers
|
|
2029
2052
|
}).then((resp) => {
|
|
2030
|
-
this.emit("
|
|
2053
|
+
this.emit("image", username, file);
|
|
2031
2054
|
return resp;
|
|
2032
2055
|
});
|
|
2033
2056
|
}
|
|
@@ -2048,28 +2071,28 @@ ${log}`;
|
|
|
2048
2071
|
list(detailed = false) {
|
|
2049
2072
|
return this.api.request({ url: `/api/settings` + (detailed ? "?detailed" : "") }).then((resp) => {
|
|
2050
2073
|
this.cache = !detailed ? resp : Object.values(resp).reduce((acc, v2) => ({ ...acc, [v2.key]: v2.value }), {});
|
|
2051
|
-
this.emit("
|
|
2074
|
+
this.emit("list", resp || []);
|
|
2052
2075
|
return resp;
|
|
2053
2076
|
});
|
|
2054
2077
|
}
|
|
2055
2078
|
delete(key) {
|
|
2056
2079
|
return this.api.request({ url: `/api/settings/${key}`, method: "DELETE" }).then(() => {
|
|
2057
2080
|
this.cache = { ...this.cache, [key]: void 0 };
|
|
2058
|
-
this.emit("
|
|
2081
|
+
this.emit("delete", key);
|
|
2059
2082
|
});
|
|
2060
2083
|
}
|
|
2061
2084
|
read(key, reload = false) {
|
|
2062
2085
|
if (!reload && this.cache[key]) return Promise.resolve(this.cache[key]);
|
|
2063
2086
|
return this.api.request({ url: `/api/settings/${key}` }).then((variable) => {
|
|
2064
2087
|
if (variable) this.cache = { ...this.cache, [variable.key]: variable };
|
|
2065
|
-
this.emit("
|
|
2088
|
+
this.emit("read", variable);
|
|
2066
2089
|
return variable;
|
|
2067
2090
|
});
|
|
2068
2091
|
}
|
|
2069
2092
|
update(variable) {
|
|
2070
2093
|
return this.api.request({ url: `/api/settings/${variable.key}`, body: variable }).then((variable2) => {
|
|
2071
2094
|
if (variable2) this.cache = { ...this.cache, [variable2.key]: variable2.value };
|
|
2072
|
-
this.emit("
|
|
2095
|
+
this.emit("update", variable2);
|
|
2073
2096
|
return variable2;
|
|
2074
2097
|
});
|
|
2075
2098
|
}
|
|
@@ -2082,14 +2105,7 @@ ${log}`;
|
|
|
2082
2105
|
}
|
|
2083
2106
|
delete(path) {
|
|
2084
2107
|
return this.api.request({ url: `/api/static/${path}`, method: "DELETE" }).then(() => {
|
|
2085
|
-
this.emit("
|
|
2086
|
-
});
|
|
2087
|
-
}
|
|
2088
|
-
list(path) {
|
|
2089
|
-
const url = ("/api/static/" + path).replaceAll("//", "/");
|
|
2090
|
-
return this.api.request({ url }).then((resp) => {
|
|
2091
|
-
this.emit("LIST", path, resp || []);
|
|
2092
|
-
return resp;
|
|
2108
|
+
this.emit("delete", path);
|
|
2093
2109
|
});
|
|
2094
2110
|
}
|
|
2095
2111
|
upload(files, path = "/") {
|
|
@@ -2101,7 +2117,7 @@ ${log}`;
|
|
|
2101
2117
|
}).onProgress((p2) => {
|
|
2102
2118
|
prog(p2);
|
|
2103
2119
|
}).then((resp) => {
|
|
2104
|
-
this.emit("
|
|
2120
|
+
this.emit("upload", resp);
|
|
2105
2121
|
res(resp);
|
|
2106
2122
|
}).catch((err) => rej(err));
|
|
2107
2123
|
});
|
|
@@ -2147,18 +2163,18 @@ ${log}`;
|
|
|
2147
2163
|
this.storage = new Storage(this.api);
|
|
2148
2164
|
this.ui = new UI(this.settings);
|
|
2149
2165
|
this.users = new Users(this.api);
|
|
2150
|
-
this.api.on("*", (event, ...args) => this.emit(`
|
|
2151
|
-
this.actions.on("*", (event, ...args) => this.emit(`
|
|
2152
|
-
this.auth.on("*", (event, ...args) => this.emit(`
|
|
2153
|
-
this.data.on("*", (event, ...args) => this.emit(`
|
|
2154
|
-
this.email.on("*", (event, ...args) => this.emit(`
|
|
2155
|
-
this.groups.on("*", (event, ...args) => this.emit(`
|
|
2156
|
-
if (this.payments) this.payments.on("*", (event, ...args) => this.emit(`
|
|
2157
|
-
this.pdf.on("*", (event, ...args) => this.emit(`
|
|
2158
|
-
this.settings.on("*", (event, ...args) => this.emit(`
|
|
2159
|
-
this.static.on("*", (event, ...args) => this.emit(`
|
|
2160
|
-
this.storage.on("*", (event, ...args) => this.emit(`
|
|
2161
|
-
this.users.on("*", (event, ...args) => this.emit(`
|
|
2166
|
+
this.api.on("*", (event, ...args) => this.emit(`Api:${event}`, ...args));
|
|
2167
|
+
this.actions.on("*", (event, ...args) => this.emit(`Actions:${event}`, ...args));
|
|
2168
|
+
this.auth.on("*", (event, ...args) => this.emit(`Auth:${event}`, ...args));
|
|
2169
|
+
this.data.on("*", (event, ...args) => this.emit(`Data:${event}`, ...args));
|
|
2170
|
+
this.email.on("*", (event, ...args) => this.emit(`Email:${event}`, ...args));
|
|
2171
|
+
this.groups.on("*", (event, ...args) => this.emit(`Groups:${event}`, ...args));
|
|
2172
|
+
if (this.payments) this.payments.on("*", (event, ...args) => this.emit(`Payments:${event}`, ...args));
|
|
2173
|
+
this.pdf.on("*", (event, ...args) => this.emit(`Pdf:${event}`, ...args));
|
|
2174
|
+
this.settings.on("*", (event, ...args) => this.emit(`Settings:${event}`, ...args));
|
|
2175
|
+
this.static.on("*", (event, ...args) => this.emit(`Static:${event}`, ...args));
|
|
2176
|
+
this.storage.on("*", (event, ...args) => this.emit(`Storage:${event}`, ...args));
|
|
2177
|
+
this.users.on("*", (event, ...args) => this.emit(`Users:${event}`, ...args));
|
|
2162
2178
|
this.users.on("*", (event, ...args) => {
|
|
2163
2179
|
var _a;
|
|
2164
2180
|
if (Array.isArray(args[0])) {
|