@ztimson/momentum 0.38.0 → 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/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("TOKEN", token);
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("RESPONSE", resp, options);
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("REJECTED", e, options);
442
+ this.emit("rejected", e, options);
440
443
  throw e;
441
444
  });
442
- this.emit("REQUEST", req, options);
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("DELETE", id);
1181
+ this.emit("delete", id);
1179
1182
  });
1180
1183
  }
1181
- list() {
1184
+ all() {
1182
1185
  return this.api.request({ url: `/api/actions` }).then((resp) => {
1183
1186
  if (resp) this.cache = resp;
1184
- this.emit("LIST", resp || []);
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("READ", action);
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("UPDATE", action2);
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("QUESTION", question, context, resp);
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
- traceIp(ip) {
1247
+ ipTrace(ip) {
1239
1248
  return this.api.request({ url: `/api/analytics/trace?ip=${ip}` }).then((resp) => {
1240
- this.emit("IP_TRACE", ip, resp);
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("SESSION_EXPIRED");
1295
+ this.emit("sessionExpired");
1287
1296
  next();
1288
1297
  });
1289
- this.api.on("TOKEN", (token) => {
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("USER", u);
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
- return await this.once("USER");
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("LOGOUT");
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("REGISTER", user);
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("LOGIN", session.user);
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
- delete(collection, document2) {
1418
+ create(collection, document2) {
1406
1419
  return this.api.request({
1407
- url: `/api/data/${collection}/${document2}`,
1408
- method: "DELETE"
1409
- }).then(() => this.emit("DELETE", collection, document2));
1420
+ url: `/api/data/${collection}`,
1421
+ method: "POST"
1422
+ }).then((resp) => {
1423
+ this.emit("create", collection, resp);
1424
+ return resp;
1425
+ });
1410
1426
  }
1411
- get(collection, document2) {
1427
+ read(collection, document2) {
1412
1428
  return this.api.request({ url: `/api/data/${collection}${document2 ? `/${document2}` : ""}` }).then((resp) => {
1413
- this.emit("GET", collection, resp);
1429
+ this.emit("read", collection, resp);
1414
1430
  return resp;
1415
1431
  });
1416
1432
  }
1417
- getSchema() {
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
- body: {
1424
- operand,
1425
- query,
1426
- options
1427
- }
1436
+ method: append ? "PATCH" : "PUT",
1437
+ body: document2
1428
1438
  }).then((resp) => {
1429
- this.emit("RAW", collection, resp);
1439
+ this.emit("update", collection, resp);
1430
1440
  return resp;
1431
1441
  });
1432
1442
  }
1433
- set(collection, document2, append = false) {
1443
+ delete(collection, document2) {
1434
1444
  return this.api.request({
1435
- url: `/api/data/${collection}/${document2._id || ""}`,
1436
- method: append ? "PATCH" : "POST",
1437
- body: document2
1438
- }).then((resp) => {
1439
- this.emit("SET", collection, resp);
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("SENT", email);
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("CREATE", resp);
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("READ", resp);
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("UPDATE", resp);
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("DELETE", name));
1513
+ }).then(() => this.emit("delete", name));
1502
1514
  }
1503
1515
  }
1504
1516
  class Logger {
@@ -1506,8 +1518,19 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1506
1518
  __publicField(this, "api");
1507
1519
  this.api = typeof api == "string" ? new Api(api) : api;
1508
1520
  if (logLevel != null && logLevel != "NONE") {
1509
- window.addEventListener("error", (event) => this.error(event.error.stack));
1510
- window.addEventListener("unhandledrejection", async (event) => this.error(event.reason.stack));
1521
+ window.addEventListener("error", (event) => {
1522
+ var _a, _b;
1523
+ return this.error(((_a = event.error) == null ? void 0 : _a.stack) || ((_b = event.error) == null ? void 0 : _b.message) || event.error);
1524
+ });
1525
+ window.addEventListener("unhandledrejection", async (event) => {
1526
+ var _a, _b, _c, _d;
1527
+ let log = ((_a = event.reason) == null ? void 0 : _a.stack) || event.reason;
1528
+ if ((_b = event.reason) == null ? void 0 : _b.url)
1529
+ log = `${event.reason.method} ${event.reason.url} -> ${event.reason.code}
1530
+
1531
+ ${log}`;
1532
+ ((_c = event.reason) == null ? void 0 : _c.code) == null || ((_d = event.reason) == null ? void 0 : _d.code) >= 500 ? this.error(log) : this.warn(log);
1533
+ });
1511
1534
  }
1512
1535
  }
1513
1536
  buildLog(level, log) {
@@ -1580,16 +1603,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1580
1603
  };
1581
1604
  setup();
1582
1605
  }
1583
- async charge(amount, custom = {}) {
1584
- this.emit("CHECKOUT", amount, custom);
1606
+ async create(amount, custom = {}) {
1585
1607
  const request = await this.api.request({ url: "/api/payments", body: {
1586
1608
  amount,
1587
1609
  custom
1588
1610
  } });
1611
+ this.emit("create", amount, custom, request.data.clientSecret);
1589
1612
  return request.data.clientSecret;
1590
1613
  }
1591
1614
  async createForm(element, amount, custom) {
1592
- const token = await this.charge(amount, custom);
1615
+ const token = await this.create(amount, custom);
1593
1616
  const form = this.stripe.elements({ clientSecret: token });
1594
1617
  form.create("payment").mount(element);
1595
1618
  return () => this.stripe.confirmPayment({
@@ -1600,7 +1623,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1600
1623
  }
1601
1624
  async history(username) {
1602
1625
  const history = await this.api.request({ url: `/api/payments${username ? `/${username}` : ""}` });
1603
- this.emit("LIST", username || null, history);
1626
+ this.emit("history", username || null, history);
1604
1627
  return history;
1605
1628
  }
1606
1629
  }
@@ -1617,7 +1640,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1617
1640
  at(url, fileName.endsWith(".pdf") ? fileName : fileName + ".pdf");
1618
1641
  URL.revokeObjectURL(url);
1619
1642
  }
1620
- this.emit("CREATE", blob);
1643
+ this.emit("create", blob);
1621
1644
  return blob;
1622
1645
  }
1623
1646
  fromHtml(content, opts = {}) {
@@ -1638,7 +1661,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1638
1661
  __publicField(this, "open", false);
1639
1662
  this.api = typeof api == "string" ? new Api(api) : api;
1640
1663
  this.url = this.api.url.replace("http", "ws");
1641
- this.api.on("TOKEN", () => this.connect());
1664
+ this.api.on("token", () => this.connect());
1642
1665
  this.connect();
1643
1666
  }
1644
1667
  close() {
@@ -1684,59 +1707,70 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1684
1707
  this.api = typeof api == "string" ? new Api(api) : api;
1685
1708
  }
1686
1709
  copy(path) {
1687
- return this.api.request({ url: `/api/storage${path.startsWith("/") ? "" : "/"}${path}`, method: "PUT" });
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
+ });
1688
1715
  }
1689
1716
  delete(path) {
1690
- const url = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll("//", "/");
1717
+ const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
1691
1718
  return this.api.request({ url, method: "DELETE" }).then(() => {
1692
- this.emit("DELETE", url);
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;
1693
1730
  });
1694
1731
  }
1695
1732
  list(path) {
1696
- const url = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll("//", "/");
1733
+ const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
1697
1734
  return this.api.request({ url: url + "?list" }).then((resp) => {
1698
- this.emit("LIST", path, resp);
1735
+ this.emit("list", path, resp);
1699
1736
  return resp;
1700
1737
  });
1701
1738
  }
1702
1739
  open(path, target = "_blank") {
1703
- const p2 = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll(/\/{2,}/g, "/");
1704
- const link = `${this.api.url}${p2}${this.api.token ? `?token=${this.api.token}` : ""}`;
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}` : ""}`;
1705
1742
  if (!target) return link;
1706
- this.emit("OPEN", path);
1743
+ this.emit("open", path);
1707
1744
  return window.open(link, target);
1708
1745
  }
1709
1746
  mkdir(path) {
1710
- const p2 = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll(/\/{2,}/g, "/");
1711
- return this.api.request({ url: p2 + "?directory", method: "POST" });
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
+ });
1712
1752
  }
1713
1753
  move(from, to) {
1714
1754
  if (from == to) return this.list(to);
1715
- return this.api.request({ url: `/api/storage${from.startsWith("/") ? "" : "/"}${from}`, method: "PATCH", body: { move: to } });
1716
- }
1717
- download(path, opts = {}) {
1718
- const p2 = ("/api/storage/" + path).replaceAll("//", "/");
1719
- return this.api.request({ ...opts, url: p2, decode: false }).then(async (response) => {
1720
- const blob = await response.blob();
1721
- const name = opts.downloadAs || path.split("/").pop();
1722
- this.emit("DOWNLOAD", path, blob);
1723
- Tt(blob, name);
1724
- 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;
1725
1759
  });
1726
1760
  }
1727
1761
  upload(files, opts = "") {
1728
1762
  return new m(async (res, rej, prog) => {
1729
1763
  if (!files) files = await It(typeof opts == "object" ? opts : void 0);
1730
1764
  if (!files || Array.isArray(files) && !files.length) return [];
1731
- const url = this.api.url + ("/api/storage/" + ((typeof opts == "string" ? opts : opts == null ? void 0 : opts.path) || "")).replaceAll("//", "/");
1765
+ const path = this.api.path("/api/storage/", typeof opts == "string" ? opts : opts.path || "");
1732
1766
  return $t({
1733
- url,
1767
+ url: `${this.api.url}${path}`,
1734
1768
  files: Array.isArray(files) ? files : [files],
1735
1769
  headers: this.api.headers
1736
1770
  }).onProgress((p2) => {
1737
1771
  prog(p2);
1738
1772
  }).then((resp) => {
1739
- this.emit("UPLOAD", resp);
1773
+ this.emit("upload", resp);
1740
1774
  res(resp);
1741
1775
  }).catch((err) => rej(err));
1742
1776
  });
@@ -1966,7 +2000,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1966
2000
  method: "DELETE"
1967
2001
  }).then(() => {
1968
2002
  this.cache = this.cache.filter((u) => u.username != username);
1969
- this.emit("DELETE", username);
2003
+ this.emit("delete", username);
1970
2004
  });
1971
2005
  }
1972
2006
  list(reload = false) {
@@ -1978,7 +2012,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1978
2012
  });
1979
2013
  this.cache = resp || [];
1980
2014
  this.listed = true;
1981
- this.emit("LIST", resp || []);
2015
+ this.emit("all", resp || []);
1982
2016
  return resp;
1983
2017
  });
1984
2018
  }
@@ -1992,7 +2026,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
1992
2026
  resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
1993
2027
  this.cache = [...this.cache.filter((u) => u.username != username), resp];
1994
2028
  }
1995
- this.emit("READ", resp);
2029
+ this.emit("read", resp);
1996
2030
  return resp;
1997
2031
  });
1998
2032
  }
@@ -2006,7 +2040,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2006
2040
  resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
2007
2041
  this.cache = this.cache.filter((u) => u.username != user.username).concat([resp]);
2008
2042
  }
2009
- this.emit(user._id ? "UPDATE" : "CREATE", resp);
2043
+ this.emit(user._id ? "update" : "create", resp);
2010
2044
  return resp;
2011
2045
  });
2012
2046
  }
@@ -2016,7 +2050,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2016
2050
  files: [file],
2017
2051
  headers: this.api.headers
2018
2052
  }).then((resp) => {
2019
- this.emit("UPLOAD_IMAGE", username, file);
2053
+ this.emit("image", username, file);
2020
2054
  return resp;
2021
2055
  });
2022
2056
  }
@@ -2037,28 +2071,28 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2037
2071
  list(detailed = false) {
2038
2072
  return this.api.request({ url: `/api/settings` + (detailed ? "?detailed" : "") }).then((resp) => {
2039
2073
  this.cache = !detailed ? resp : Object.values(resp).reduce((acc, v2) => ({ ...acc, [v2.key]: v2.value }), {});
2040
- this.emit("LIST", resp || []);
2074
+ this.emit("list", resp || []);
2041
2075
  return resp;
2042
2076
  });
2043
2077
  }
2044
2078
  delete(key) {
2045
2079
  return this.api.request({ url: `/api/settings/${key}`, method: "DELETE" }).then(() => {
2046
2080
  this.cache = { ...this.cache, [key]: void 0 };
2047
- this.emit("DELETE", key);
2081
+ this.emit("delete", key);
2048
2082
  });
2049
2083
  }
2050
2084
  read(key, reload = false) {
2051
2085
  if (!reload && this.cache[key]) return Promise.resolve(this.cache[key]);
2052
2086
  return this.api.request({ url: `/api/settings/${key}` }).then((variable) => {
2053
2087
  if (variable) this.cache = { ...this.cache, [variable.key]: variable };
2054
- this.emit("READ", variable);
2088
+ this.emit("read", variable);
2055
2089
  return variable;
2056
2090
  });
2057
2091
  }
2058
2092
  update(variable) {
2059
2093
  return this.api.request({ url: `/api/settings/${variable.key}`, body: variable }).then((variable2) => {
2060
2094
  if (variable2) this.cache = { ...this.cache, [variable2.key]: variable2.value };
2061
- this.emit("UPDATE", variable2);
2095
+ this.emit("update", variable2);
2062
2096
  return variable2;
2063
2097
  });
2064
2098
  }
@@ -2071,14 +2105,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2071
2105
  }
2072
2106
  delete(path) {
2073
2107
  return this.api.request({ url: `/api/static/${path}`, method: "DELETE" }).then(() => {
2074
- this.emit("DELETE", path);
2075
- });
2076
- }
2077
- list(path) {
2078
- const url = ("/api/static/" + path).replaceAll("//", "/");
2079
- return this.api.request({ url }).then((resp) => {
2080
- this.emit("LIST", path, resp || []);
2081
- return resp;
2108
+ this.emit("delete", path);
2082
2109
  });
2083
2110
  }
2084
2111
  upload(files, path = "/") {
@@ -2090,7 +2117,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2090
2117
  }).onProgress((p2) => {
2091
2118
  prog(p2);
2092
2119
  }).then((resp) => {
2093
- this.emit("UPLOAD", resp);
2120
+ this.emit("upload", resp);
2094
2121
  res(resp);
2095
2122
  }).catch((err) => rej(err));
2096
2123
  });
@@ -2136,18 +2163,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
2136
2163
  this.storage = new Storage(this.api);
2137
2164
  this.ui = new UI(this.settings);
2138
2165
  this.users = new Users(this.api);
2139
- this.api.on("*", (event, ...args) => this.emit(`API::${event}`, ...args));
2140
- this.actions.on("*", (event, ...args) => this.emit(`ACTIONS::${event}`, ...args));
2141
- this.auth.on("*", (event, ...args) => this.emit(`AUTH::${event}`, ...args));
2142
- this.data.on("*", (event, ...args) => this.emit(`DATA::${event}`, ...args));
2143
- this.email.on("*", (event, ...args) => this.emit(`EMAIL::${event}`, ...args));
2144
- this.groups.on("*", (event, ...args) => this.emit(`GROUPS::${event}`, ...args));
2145
- if (this.payments) this.payments.on("*", (event, ...args) => this.emit(`PAYMENT::${event}`, ...args));
2146
- this.pdf.on("*", (event, ...args) => this.emit(`PDF::${event}`, ...args));
2147
- this.settings.on("*", (event, ...args) => this.emit(`SETTINGS::${event}`, ...args));
2148
- this.static.on("*", (event, ...args) => this.emit(`STATIC::${event}`, ...args));
2149
- this.storage.on("*", (event, ...args) => this.emit(`STORAGE::${event}`, ...args));
2150
- this.users.on("*", (event, ...args) => this.emit(`USERS::${event}`, ...args));
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));
2151
2178
  this.users.on("*", (event, ...args) => {
2152
2179
  var _a;
2153
2180
  if (Array.isArray(args[0])) {