@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.mjs CHANGED
@@ -421,21 +421,24 @@ class Api extends q {
421
421
  if (token == this._token) return;
422
422
  this._token = token;
423
423
  this.headers["Authorization"] = token ? `Bearer ${token}` : void 0;
424
- this.emit("TOKEN", token);
424
+ this.emit("token", token);
425
425
  }
426
426
  healthcheck() {
427
427
  return this.request({ url: "/api/healthcheck" });
428
428
  }
429
+ path(...children) {
430
+ return children.filter((p2) => !!p2).join("/").replaceAll("//", "/");
431
+ }
429
432
  request(options) {
430
433
  const req = super.request(options).then((resp) => {
431
- this.emit("RESPONSE", resp, options);
434
+ this.emit("response", resp, options);
432
435
  return resp.data;
433
436
  }).catch((err) => {
434
437
  const e = (err == null ? void 0 : err.data) || err;
435
- this.emit("REJECTED", e, options);
438
+ this.emit("rejected", e, options);
436
439
  throw e;
437
440
  });
438
- this.emit("REQUEST", req, options);
441
+ this.emit("request", req, options);
439
442
  return req;
440
443
  }
441
444
  }
@@ -1171,13 +1174,13 @@ class Actions extends F {
1171
1174
  delete(id) {
1172
1175
  return this.api.request({ url: `/api/actions/${id}`, method: "DELETE" }).then(() => {
1173
1176
  this.cache = this.cache.filter((a) => a._id != id);
1174
- this.emit("DELETE", id);
1177
+ this.emit("delete", id);
1175
1178
  });
1176
1179
  }
1177
- list() {
1180
+ all() {
1178
1181
  return this.api.request({ url: `/api/actions` }).then((resp) => {
1179
1182
  if (resp) this.cache = resp;
1180
- this.emit("LIST", resp || []);
1183
+ this.emit("all", resp || []);
1181
1184
  return resp;
1182
1185
  });
1183
1186
  }
@@ -1186,16 +1189,22 @@ class Actions extends F {
1186
1189
  if (!reload && cached) return Promise.resolve(cached);
1187
1190
  return this.api.request({ url: `/api/actions/${id}` }).then((action) => {
1188
1191
  if (action) this.cache = this.cache.filter((a) => a._id != id).concat([action]);
1189
- this.emit("READ", action);
1192
+ this.emit("read", action);
1190
1193
  return action;
1191
1194
  });
1192
1195
  }
1193
1196
  run(path, opts = {}) {
1194
- return this.api.request({ url: (`/api/actions/run/` + path).replaceAll("//", "/"), ...opts });
1197
+ return this.api.request({ url: (`/api/actions/run/` + path).replaceAll("//", "/"), ...opts }).then((resp) => {
1198
+ this.emit("execute", path, resp);
1199
+ return resp;
1200
+ });
1195
1201
  }
1196
1202
  runById(action, opts = {}) {
1197
1203
  const id = typeof action == "string" ? action : action._id;
1198
- return this.api.request({ url: "/api/actions/run-by-id/" + id, method: "POST", ...opts });
1204
+ return this.api.request({ url: "/api/actions/run-by-id/" + id, method: "POST", ...opts }).then((resp) => {
1205
+ this.emit("execute", typeof action == "string" ? action : action._id, resp);
1206
+ return resp;
1207
+ });
1199
1208
  }
1200
1209
  update(action) {
1201
1210
  return this.api.request({
@@ -1204,7 +1213,7 @@ class Actions extends F {
1204
1213
  body: action
1205
1214
  }).then((action2) => {
1206
1215
  if (action2) this.cache = this.cache.filter((a) => a._id != (action2 == null ? void 0 : action2._id)).concat([action2]);
1207
- this.emit("UPDATE", action2);
1216
+ this.emit("update", action2);
1208
1217
  return action2;
1209
1218
  });
1210
1219
  }
@@ -1220,7 +1229,7 @@ class Ai extends F {
1220
1229
  question,
1221
1230
  context
1222
1231
  } }).then((resp) => {
1223
- this.emit("QUESTION", question, context, resp);
1232
+ this.emit("ask", question, context, resp);
1224
1233
  return resp;
1225
1234
  });
1226
1235
  }
@@ -1231,9 +1240,9 @@ class Analytics extends F {
1231
1240
  __publicField(this, "api");
1232
1241
  this.api = typeof api == "string" ? new Api(api) : api;
1233
1242
  }
1234
- traceIp(ip) {
1243
+ ipTrace(ip) {
1235
1244
  return this.api.request({ url: `/api/analytics/trace?ip=${ip}` }).then((resp) => {
1236
- this.emit("IP_TRACE", ip, resp);
1245
+ this.emit("ipTrace", ip, resp);
1237
1246
  return resp;
1238
1247
  });
1239
1248
  }
@@ -1279,10 +1288,10 @@ class Auth extends F {
1279
1288
  "/api/auth/totp"
1280
1289
  ];
1281
1290
  if (resp.status == 401 && !blacklist.find((url) => resp.url.includes(url)))
1282
- this.emit("SESSION_EXPIRED");
1291
+ this.emit("sessionExpired");
1283
1292
  next();
1284
1293
  });
1285
- this.api.on("TOKEN", (token) => {
1294
+ this.api.on("token", (token) => {
1286
1295
  var _a;
1287
1296
  if ((_a = this.opts) == null ? void 0 : _a.persist) {
1288
1297
  if (token) localStorage.setItem(this.storageKey, token);
@@ -1307,7 +1316,7 @@ class Auth extends F {
1307
1316
  if (!b(this.user, user)) {
1308
1317
  const u = user ? user : null;
1309
1318
  this.$user.next(u);
1310
- this.emit("USER", u);
1319
+ this.emit("user", u);
1311
1320
  }
1312
1321
  }
1313
1322
  knownHost(host = location.origin) {
@@ -1327,7 +1336,9 @@ class Auth extends F {
1327
1336
  }
1328
1337
  }).then(async (resp) => {
1329
1338
  this.api.token = (resp == null ? void 0 : resp.token) || null;
1330
- return await this.once("USER");
1339
+ const user = await this.once("user");
1340
+ this.emit("login", user);
1341
+ return user;
1331
1342
  });
1332
1343
  }
1333
1344
  loginRedirect(host = location.origin) {
@@ -1349,13 +1360,13 @@ class Auth extends F {
1349
1360
  logout() {
1350
1361
  this.api.token = null;
1351
1362
  this.user = null;
1352
- this.emit("LOGOUT");
1363
+ this.emit("logout");
1353
1364
  }
1354
1365
  async register(u) {
1355
1366
  var _a;
1356
1367
  const user = await this.api.request({ url: "/api/auth/register", body: { ...u } });
1357
1368
  if ((_a = user == null ? void 0 : user.image) == null ? void 0 : _a.startsWith("/")) user.image = `${this.api.url}${user.image}?token=${this.api.token}`;
1358
- this.emit("REGISTER", user);
1369
+ this.emit("register", user);
1359
1370
  return user;
1360
1371
  }
1361
1372
  reset(emailOrPass, token) {
@@ -1367,6 +1378,8 @@ class Auth extends F {
1367
1378
  password: token ? emailOrPass : void 0
1368
1379
  }
1369
1380
  }).then(() => {
1381
+ if (token) this.emit("reset", token);
1382
+ else this.emit("resetRequest", emailOrPass);
1370
1383
  });
1371
1384
  }
1372
1385
  async session(token, set = false) {
@@ -1379,7 +1392,7 @@ class Auth extends F {
1379
1392
  this.api.token = token;
1380
1393
  if (session == null ? void 0 : session.user) session.user.image = `${this.api.url}${session.user.image}?token=${this.api.token}`;
1381
1394
  this.user = (session == null ? void 0 : session.user) || null;
1382
- if (session) this.emit("LOGIN", session.user);
1395
+ if (session) this.emit("login", session.user);
1383
1396
  }
1384
1397
  return session;
1385
1398
  }
@@ -1398,41 +1411,40 @@ class Data extends F {
1398
1411
  __publicField(this, "api");
1399
1412
  this.api = typeof api == "string" ? new Api(api) : api;
1400
1413
  }
1401
- delete(collection, document2) {
1414
+ create(collection, document2) {
1402
1415
  return this.api.request({
1403
- url: `/api/data/${collection}/${document2}`,
1404
- method: "DELETE"
1405
- }).then(() => this.emit("DELETE", collection, document2));
1416
+ url: `/api/data/${collection}`,
1417
+ method: "POST"
1418
+ }).then((resp) => {
1419
+ this.emit("create", collection, resp);
1420
+ return resp;
1421
+ });
1406
1422
  }
1407
- get(collection, document2) {
1423
+ read(collection, document2) {
1408
1424
  return this.api.request({ url: `/api/data/${collection}${document2 ? `/${document2}` : ""}` }).then((resp) => {
1409
- this.emit("GET", collection, resp);
1425
+ this.emit("read", collection, resp);
1410
1426
  return resp;
1411
1427
  });
1412
1428
  }
1413
- getSchema() {
1414
- return this.api.request({ url: `/api/data/schema` });
1415
- }
1416
- raw(collection, operand, query, options) {
1429
+ update(collection, document2, append = true) {
1417
1430
  return this.api.request({
1418
1431
  url: `/api/data/${collection}`,
1419
- body: {
1420
- operand,
1421
- query,
1422
- options
1423
- }
1432
+ method: append ? "PATCH" : "PUT",
1433
+ body: document2
1424
1434
  }).then((resp) => {
1425
- this.emit("RAW", collection, resp);
1435
+ this.emit("update", collection, resp);
1426
1436
  return resp;
1427
1437
  });
1428
1438
  }
1429
- set(collection, document2, append = false) {
1439
+ delete(collection, document2) {
1430
1440
  return this.api.request({
1431
- url: `/api/data/${collection}/${document2._id || ""}`,
1432
- method: append ? "PATCH" : "POST",
1433
- body: document2
1434
- }).then((resp) => {
1435
- this.emit("SET", collection, resp);
1441
+ url: `/api/data/${collection}/${document2}`,
1442
+ method: "DELETE"
1443
+ }).then(() => this.emit("delete", collection, document2));
1444
+ }
1445
+ raw(collection, query) {
1446
+ return this.api.request({ url: `/api/data/${collection}`, body: query }).then((resp) => {
1447
+ this.emit("raw", collection, query, resp);
1436
1448
  return resp;
1437
1449
  });
1438
1450
  }
@@ -1447,7 +1459,7 @@ class Email extends F {
1447
1459
  let url = "/api/email";
1448
1460
  if (typeof email.body == "object") url += `/${email.body.template}`;
1449
1461
  return this.api.request({ url, body: email }).then((resp) => {
1450
- this.emit("SENT", email);
1462
+ this.emit("sent", email, resp);
1451
1463
  return resp;
1452
1464
  });
1453
1465
  }
@@ -1458,25 +1470,25 @@ class Groups extends F {
1458
1470
  __publicField(this, "api");
1459
1471
  this.api = typeof api == "string" ? new Api(api) : api;
1460
1472
  }
1473
+ all() {
1474
+ return this.api.request({ url: `/api/groups` }).then((resp) => {
1475
+ this.emit("all", resp || []);
1476
+ return resp;
1477
+ });
1478
+ }
1461
1479
  create(group) {
1462
1480
  return this.api.request({
1463
1481
  url: `/api/groups/${group.name}`,
1464
1482
  method: "POST",
1465
1483
  body: group
1466
1484
  }).then((resp) => {
1467
- this.emit("CREATE", resp);
1468
- return resp;
1469
- });
1470
- }
1471
- list() {
1472
- return this.api.request({ url: `/api/groups` }).then((resp) => {
1473
- this.emit("LIST", resp || []);
1485
+ this.emit("create", resp);
1474
1486
  return resp;
1475
1487
  });
1476
1488
  }
1477
1489
  read(name) {
1478
1490
  return this.api.request({ url: `/api/groups/${name}` }).then((resp) => {
1479
- this.emit("READ", resp);
1491
+ this.emit("read", resp);
1480
1492
  return resp;
1481
1493
  });
1482
1494
  }
@@ -1486,7 +1498,7 @@ class Groups extends F {
1486
1498
  method: "PATCH",
1487
1499
  body: group
1488
1500
  }).then((resp) => {
1489
- this.emit("UPDATE", resp);
1501
+ this.emit("update", resp);
1490
1502
  return resp;
1491
1503
  });
1492
1504
  }
@@ -1494,7 +1506,7 @@ class Groups extends F {
1494
1506
  return this.api.request({
1495
1507
  url: `/api/groups/${name}`,
1496
1508
  method: "DELETE"
1497
- }).then(() => this.emit("DELETE", name));
1509
+ }).then(() => this.emit("delete", name));
1498
1510
  }
1499
1511
  }
1500
1512
  class Logger {
@@ -1502,8 +1514,19 @@ class Logger {
1502
1514
  __publicField(this, "api");
1503
1515
  this.api = typeof api == "string" ? new Api(api) : api;
1504
1516
  if (logLevel != null && logLevel != "NONE") {
1505
- window.addEventListener("error", (event) => this.error(event.error.stack));
1506
- window.addEventListener("unhandledrejection", async (event) => this.error(event.reason.stack));
1517
+ window.addEventListener("error", (event) => {
1518
+ var _a, _b;
1519
+ return this.error(((_a = event.error) == null ? void 0 : _a.stack) || ((_b = event.error) == null ? void 0 : _b.message) || event.error);
1520
+ });
1521
+ window.addEventListener("unhandledrejection", async (event) => {
1522
+ var _a, _b, _c, _d;
1523
+ let log = ((_a = event.reason) == null ? void 0 : _a.stack) || event.reason;
1524
+ if ((_b = event.reason) == null ? void 0 : _b.url)
1525
+ log = `${event.reason.method} ${event.reason.url} -> ${event.reason.code}
1526
+
1527
+ ${log}`;
1528
+ ((_c = event.reason) == null ? void 0 : _c.code) == null || ((_d = event.reason) == null ? void 0 : _d.code) >= 500 ? this.error(log) : this.warn(log);
1529
+ });
1507
1530
  }
1508
1531
  }
1509
1532
  buildLog(level, log) {
@@ -1576,16 +1599,16 @@ class Payments extends F {
1576
1599
  };
1577
1600
  setup();
1578
1601
  }
1579
- async charge(amount, custom = {}) {
1580
- this.emit("CHECKOUT", amount, custom);
1602
+ async create(amount, custom = {}) {
1581
1603
  const request = await this.api.request({ url: "/api/payments", body: {
1582
1604
  amount,
1583
1605
  custom
1584
1606
  } });
1607
+ this.emit("create", amount, custom, request.data.clientSecret);
1585
1608
  return request.data.clientSecret;
1586
1609
  }
1587
1610
  async createForm(element, amount, custom) {
1588
- const token = await this.charge(amount, custom);
1611
+ const token = await this.create(amount, custom);
1589
1612
  const form = this.stripe.elements({ clientSecret: token });
1590
1613
  form.create("payment").mount(element);
1591
1614
  return () => this.stripe.confirmPayment({
@@ -1596,7 +1619,7 @@ class Payments extends F {
1596
1619
  }
1597
1620
  async history(username) {
1598
1621
  const history = await this.api.request({ url: `/api/payments${username ? `/${username}` : ""}` });
1599
- this.emit("LIST", username || null, history);
1622
+ this.emit("history", username || null, history);
1600
1623
  return history;
1601
1624
  }
1602
1625
  }
@@ -1613,7 +1636,7 @@ class Pdf extends F {
1613
1636
  at(url, fileName.endsWith(".pdf") ? fileName : fileName + ".pdf");
1614
1637
  URL.revokeObjectURL(url);
1615
1638
  }
1616
- this.emit("CREATE", blob);
1639
+ this.emit("create", blob);
1617
1640
  return blob;
1618
1641
  }
1619
1642
  fromHtml(content, opts = {}) {
@@ -1634,7 +1657,7 @@ const _Socket = class _Socket {
1634
1657
  __publicField(this, "open", false);
1635
1658
  this.api = typeof api == "string" ? new Api(api) : api;
1636
1659
  this.url = this.api.url.replace("http", "ws");
1637
- this.api.on("TOKEN", () => this.connect());
1660
+ this.api.on("token", () => this.connect());
1638
1661
  this.connect();
1639
1662
  }
1640
1663
  close() {
@@ -1680,59 +1703,70 @@ class Storage extends F {
1680
1703
  this.api = typeof api == "string" ? new Api(api) : api;
1681
1704
  }
1682
1705
  copy(path) {
1683
- return this.api.request({ url: `/api/storage${path.startsWith("/") ? "" : "/"}${path}`, method: "PUT" });
1706
+ const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
1707
+ return this.api.request({ url, method: "PUT" }).then((resp) => {
1708
+ this.emit("copy", path, resp);
1709
+ return resp;
1710
+ });
1684
1711
  }
1685
1712
  delete(path) {
1686
- const url = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll("//", "/");
1713
+ const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
1687
1714
  return this.api.request({ url, method: "DELETE" }).then(() => {
1688
- this.emit("DELETE", url);
1715
+ this.emit("delete", url);
1716
+ });
1717
+ }
1718
+ download(path, opts = {}) {
1719
+ const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
1720
+ return this.api.request({ ...opts, url, decode: false }).then(async (response) => {
1721
+ const blob = await response.blob();
1722
+ const name = opts.downloadAs || path.split("/").pop();
1723
+ this.emit("download", path, blob);
1724
+ Tt(blob, name);
1725
+ return response;
1689
1726
  });
1690
1727
  }
1691
1728
  list(path) {
1692
- const url = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll("//", "/");
1729
+ const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
1693
1730
  return this.api.request({ url: url + "?list" }).then((resp) => {
1694
- this.emit("LIST", path, resp);
1731
+ this.emit("list", path, resp);
1695
1732
  return resp;
1696
1733
  });
1697
1734
  }
1698
1735
  open(path, target = "_blank") {
1699
- const p2 = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll(/\/{2,}/g, "/");
1700
- const link = `${this.api.url}${p2}${this.api.token ? `?token=${this.api.token}` : ""}`;
1736
+ const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
1737
+ const link = `${this.api.url}${url}${this.api.token ? `?token=${this.api.token}` : ""}`;
1701
1738
  if (!target) return link;
1702
- this.emit("OPEN", path);
1739
+ this.emit("open", path);
1703
1740
  return window.open(link, target);
1704
1741
  }
1705
1742
  mkdir(path) {
1706
- const p2 = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll(/\/{2,}/g, "/");
1707
- return this.api.request({ url: p2 + "?directory", method: "POST" });
1743
+ const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
1744
+ return this.api.request({ url: url + "?directory", method: "POST" }).then((resp) => {
1745
+ this.emit("mkdir", path, resp);
1746
+ return resp;
1747
+ });
1708
1748
  }
1709
1749
  move(from, to) {
1710
1750
  if (from == to) return this.list(to);
1711
- return this.api.request({ url: `/api/storage${from.startsWith("/") ? "" : "/"}${from}`, method: "PATCH", body: { move: to } });
1712
- }
1713
- download(path, opts = {}) {
1714
- const p2 = ("/api/storage/" + path).replaceAll("//", "/");
1715
- return this.api.request({ ...opts, url: p2, decode: false }).then(async (response) => {
1716
- const blob = await response.blob();
1717
- const name = opts.downloadAs || path.split("/").pop();
1718
- this.emit("DOWNLOAD", path, blob);
1719
- Tt(blob, name);
1720
- return response;
1751
+ const url = this.api.path(from.startsWith("/api/storage/") ? "" : "/api/storage/", from);
1752
+ return this.api.request({ url, method: "PATCH", body: { move: to } }).then((resp) => {
1753
+ this.emit("move", from, to, resp);
1754
+ return resp;
1721
1755
  });
1722
1756
  }
1723
1757
  upload(files, opts = "") {
1724
1758
  return new m(async (res, rej, prog) => {
1725
1759
  if (!files) files = await It(typeof opts == "object" ? opts : void 0);
1726
1760
  if (!files || Array.isArray(files) && !files.length) return [];
1727
- const url = this.api.url + ("/api/storage/" + ((typeof opts == "string" ? opts : opts == null ? void 0 : opts.path) || "")).replaceAll("//", "/");
1761
+ const path = this.api.path("/api/storage/", typeof opts == "string" ? opts : opts.path || "");
1728
1762
  return $t({
1729
- url,
1763
+ url: `${this.api.url}${path}`,
1730
1764
  files: Array.isArray(files) ? files : [files],
1731
1765
  headers: this.api.headers
1732
1766
  }).onProgress((p2) => {
1733
1767
  prog(p2);
1734
1768
  }).then((resp) => {
1735
- this.emit("UPLOAD", resp);
1769
+ this.emit("upload", resp);
1736
1770
  res(resp);
1737
1771
  }).catch((err) => rej(err));
1738
1772
  });
@@ -1962,7 +1996,7 @@ class Users extends F {
1962
1996
  method: "DELETE"
1963
1997
  }).then(() => {
1964
1998
  this.cache = this.cache.filter((u) => u.username != username);
1965
- this.emit("DELETE", username);
1999
+ this.emit("delete", username);
1966
2000
  });
1967
2001
  }
1968
2002
  list(reload = false) {
@@ -1974,7 +2008,7 @@ class Users extends F {
1974
2008
  });
1975
2009
  this.cache = resp || [];
1976
2010
  this.listed = true;
1977
- this.emit("LIST", resp || []);
2011
+ this.emit("all", resp || []);
1978
2012
  return resp;
1979
2013
  });
1980
2014
  }
@@ -1988,7 +2022,7 @@ class Users extends F {
1988
2022
  resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
1989
2023
  this.cache = [...this.cache.filter((u) => u.username != username), resp];
1990
2024
  }
1991
- this.emit("READ", resp);
2025
+ this.emit("read", resp);
1992
2026
  return resp;
1993
2027
  });
1994
2028
  }
@@ -2002,7 +2036,7 @@ class Users extends F {
2002
2036
  resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
2003
2037
  this.cache = this.cache.filter((u) => u.username != user.username).concat([resp]);
2004
2038
  }
2005
- this.emit(user._id ? "UPDATE" : "CREATE", resp);
2039
+ this.emit(user._id ? "update" : "create", resp);
2006
2040
  return resp;
2007
2041
  });
2008
2042
  }
@@ -2012,7 +2046,7 @@ class Users extends F {
2012
2046
  files: [file],
2013
2047
  headers: this.api.headers
2014
2048
  }).then((resp) => {
2015
- this.emit("UPLOAD_IMAGE", username, file);
2049
+ this.emit("image", username, file);
2016
2050
  return resp;
2017
2051
  });
2018
2052
  }
@@ -2033,28 +2067,28 @@ class Settings extends F {
2033
2067
  list(detailed = false) {
2034
2068
  return this.api.request({ url: `/api/settings` + (detailed ? "?detailed" : "") }).then((resp) => {
2035
2069
  this.cache = !detailed ? resp : Object.values(resp).reduce((acc, v2) => ({ ...acc, [v2.key]: v2.value }), {});
2036
- this.emit("LIST", resp || []);
2070
+ this.emit("list", resp || []);
2037
2071
  return resp;
2038
2072
  });
2039
2073
  }
2040
2074
  delete(key) {
2041
2075
  return this.api.request({ url: `/api/settings/${key}`, method: "DELETE" }).then(() => {
2042
2076
  this.cache = { ...this.cache, [key]: void 0 };
2043
- this.emit("DELETE", key);
2077
+ this.emit("delete", key);
2044
2078
  });
2045
2079
  }
2046
2080
  read(key, reload = false) {
2047
2081
  if (!reload && this.cache[key]) return Promise.resolve(this.cache[key]);
2048
2082
  return this.api.request({ url: `/api/settings/${key}` }).then((variable) => {
2049
2083
  if (variable) this.cache = { ...this.cache, [variable.key]: variable };
2050
- this.emit("READ", variable);
2084
+ this.emit("read", variable);
2051
2085
  return variable;
2052
2086
  });
2053
2087
  }
2054
2088
  update(variable) {
2055
2089
  return this.api.request({ url: `/api/settings/${variable.key}`, body: variable }).then((variable2) => {
2056
2090
  if (variable2) this.cache = { ...this.cache, [variable2.key]: variable2.value };
2057
- this.emit("UPDATE", variable2);
2091
+ this.emit("update", variable2);
2058
2092
  return variable2;
2059
2093
  });
2060
2094
  }
@@ -2067,14 +2101,7 @@ class Static extends F {
2067
2101
  }
2068
2102
  delete(path) {
2069
2103
  return this.api.request({ url: `/api/static/${path}`, method: "DELETE" }).then(() => {
2070
- this.emit("DELETE", path);
2071
- });
2072
- }
2073
- list(path) {
2074
- const url = ("/api/static/" + path).replaceAll("//", "/");
2075
- return this.api.request({ url }).then((resp) => {
2076
- this.emit("LIST", path, resp || []);
2077
- return resp;
2104
+ this.emit("delete", path);
2078
2105
  });
2079
2106
  }
2080
2107
  upload(files, path = "/") {
@@ -2086,7 +2113,7 @@ class Static extends F {
2086
2113
  }).onProgress((p2) => {
2087
2114
  prog(p2);
2088
2115
  }).then((resp) => {
2089
- this.emit("UPLOAD", resp);
2116
+ this.emit("upload", resp);
2090
2117
  res(resp);
2091
2118
  }).catch((err) => rej(err));
2092
2119
  });
@@ -2132,18 +2159,18 @@ class Momentum extends F {
2132
2159
  this.storage = new Storage(this.api);
2133
2160
  this.ui = new UI(this.settings);
2134
2161
  this.users = new Users(this.api);
2135
- this.api.on("*", (event, ...args) => this.emit(`API::${event}`, ...args));
2136
- this.actions.on("*", (event, ...args) => this.emit(`ACTIONS::${event}`, ...args));
2137
- this.auth.on("*", (event, ...args) => this.emit(`AUTH::${event}`, ...args));
2138
- this.data.on("*", (event, ...args) => this.emit(`DATA::${event}`, ...args));
2139
- this.email.on("*", (event, ...args) => this.emit(`EMAIL::${event}`, ...args));
2140
- this.groups.on("*", (event, ...args) => this.emit(`GROUPS::${event}`, ...args));
2141
- if (this.payments) this.payments.on("*", (event, ...args) => this.emit(`PAYMENT::${event}`, ...args));
2142
- this.pdf.on("*", (event, ...args) => this.emit(`PDF::${event}`, ...args));
2143
- this.settings.on("*", (event, ...args) => this.emit(`SETTINGS::${event}`, ...args));
2144
- this.static.on("*", (event, ...args) => this.emit(`STATIC::${event}`, ...args));
2145
- this.storage.on("*", (event, ...args) => this.emit(`STORAGE::${event}`, ...args));
2146
- this.users.on("*", (event, ...args) => this.emit(`USERS::${event}`, ...args));
2162
+ this.api.on("*", (event, ...args) => this.emit(`Api:${event}`, ...args));
2163
+ this.actions.on("*", (event, ...args) => this.emit(`Actions:${event}`, ...args));
2164
+ this.auth.on("*", (event, ...args) => this.emit(`Auth:${event}`, ...args));
2165
+ this.data.on("*", (event, ...args) => this.emit(`Data:${event}`, ...args));
2166
+ this.email.on("*", (event, ...args) => this.emit(`Email:${event}`, ...args));
2167
+ this.groups.on("*", (event, ...args) => this.emit(`Groups:${event}`, ...args));
2168
+ if (this.payments) this.payments.on("*", (event, ...args) => this.emit(`Payments:${event}`, ...args));
2169
+ this.pdf.on("*", (event, ...args) => this.emit(`Pdf:${event}`, ...args));
2170
+ this.settings.on("*", (event, ...args) => this.emit(`Settings:${event}`, ...args));
2171
+ this.static.on("*", (event, ...args) => this.emit(`Static:${event}`, ...args));
2172
+ this.storage.on("*", (event, ...args) => this.emit(`Storage:${event}`, ...args));
2173
+ this.users.on("*", (event, ...args) => this.emit(`Users:${event}`, ...args));
2147
2174
  this.users.on("*", (event, ...args) => {
2148
2175
  var _a;
2149
2176
  if (Array.isArray(args[0])) {
@@ -1 +1 @@
1
- {"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,SAAS,EAAC,MAAM,gBAAgB,CAAC;AAEzC,MAAM,MAAM,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GAAG,IAAI,EAAE,GAAG,EAAE;CAGpB"}
@@ -1,14 +1,15 @@
1
1
  import { TypedEmitter, TypedEvents } from '@ztimson/utils';
2
2
  import { Api } from './api';
3
3
  export type PaymentEvents = TypedEvents & {
4
- 'CHECKOUT': (amount: number, custom: any) => any;
5
- 'LIST': (username: string | null, history: any[]) => void;
4
+ 'create': (amount: number, custom: any, token: string) => any;
5
+ 'complete': (token: string, response: any) => any;
6
+ 'history': (username: string | null, history: any[]) => void;
6
7
  };
7
8
  export declare class Payments extends TypedEmitter<PaymentEvents> {
8
9
  private readonly api;
9
10
  stripe: any;
10
11
  constructor(api: Api | string, secret: string);
11
- private charge;
12
+ private create;
12
13
  createForm(element: string, amount: number, custom?: any): Promise<() => Promise<any>>;
13
14
  history(username?: string): Promise<any[]>;
14
15
  }
@@ -1 +1 @@
1
- {"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAI1B,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG;IACzC,UAAU,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IACjD,MAAM,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CAC1D,CAAC;AAEF,qBAAa,QAAS,SAAQ,YAAY,CAAC,aAAa,CAAC;IACxD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;IAE3B,MAAM,EAAG,GAAG,CAAC;gBAED,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM;YAgB/B,MAAM;IASd,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;IAWtF,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM;CAK/B"}
1
+ {"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../src/payments.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,YAAY,EAAE,KAAK,WAAW,EAAC,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAI1B,MAAM,MAAM,aAAa,GAAG,WAAW,GAAG;IACzC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,MAAM,KAAK,GAAG,CAAC;IAC9D,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,KAAK,GAAG,CAAC;IAClD,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,KAAK,IAAI,CAAC;CAC7D,CAAC;AAEF,qBAAa,QAAS,SAAQ,YAAY,CAAC,aAAa,CAAC;IACxD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;IAE3B,MAAM,EAAG,GAAG,CAAC;gBAED,GAAG,EAAE,GAAG,GAAG,MAAM,EAAE,MAAM,EAAE,MAAM;YAgB/B,MAAM;IASd,UAAU,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,GAAG,GAAG,OAAO,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,CAAC;IAWtF,OAAO,CAAC,QAAQ,CAAC,EAAE,MAAM;CAK/B"}
package/dist/pdf.d.ts CHANGED
@@ -5,7 +5,7 @@ export type PdfOptions = {
5
5
  fileName?: string;
6
6
  };
7
7
  export type PdfEvents = TypedEvents & {
8
- CREATE: (pdf: Blob) => any;
8
+ create: (pdf: Blob) => any;
9
9
  };
10
10
  export declare class Pdf extends TypedEmitter<PdfEvents> {
11
11
  private readonly api;
@@ -15,12 +15,12 @@ export type Setting<T> = {
15
15
  system?: boolean;
16
16
  };
17
17
  export type SettingEvents = TypedEvents & {
18
- LIST: (variables: {
18
+ list: (variables: {
19
19
  [key: string]: any;
20
20
  }) => any;
21
- DELETE: (key: string) => any;
22
- READ: (variable: Setting<any> | null) => any;
23
- UPDATE: (variable: Setting<any>) => any;
21
+ delete: (key: string) => any;
22
+ read: (variable: Setting<any> | null) => any;
23
+ update: (variable: Setting<any>) => any;
24
24
  };
25
25
  export declare class Settings extends TypedEmitter<SettingEvents> {
26
26
  readonly api: Api;