@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/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 {
@@ -1587,16 +1599,16 @@ class Payments extends F {
1587
1599
  };
1588
1600
  setup();
1589
1601
  }
1590
- async charge(amount, custom = {}) {
1591
- this.emit("CHECKOUT", amount, custom);
1602
+ async create(amount, custom = {}) {
1592
1603
  const request = await this.api.request({ url: "/api/payments", body: {
1593
1604
  amount,
1594
1605
  custom
1595
1606
  } });
1607
+ this.emit("create", amount, custom, request.data.clientSecret);
1596
1608
  return request.data.clientSecret;
1597
1609
  }
1598
1610
  async createForm(element, amount, custom) {
1599
- const token = await this.charge(amount, custom);
1611
+ const token = await this.create(amount, custom);
1600
1612
  const form = this.stripe.elements({ clientSecret: token });
1601
1613
  form.create("payment").mount(element);
1602
1614
  return () => this.stripe.confirmPayment({
@@ -1607,7 +1619,7 @@ class Payments extends F {
1607
1619
  }
1608
1620
  async history(username) {
1609
1621
  const history = await this.api.request({ url: `/api/payments${username ? `/${username}` : ""}` });
1610
- this.emit("LIST", username || null, history);
1622
+ this.emit("history", username || null, history);
1611
1623
  return history;
1612
1624
  }
1613
1625
  }
@@ -1624,7 +1636,7 @@ class Pdf extends F {
1624
1636
  at(url, fileName.endsWith(".pdf") ? fileName : fileName + ".pdf");
1625
1637
  URL.revokeObjectURL(url);
1626
1638
  }
1627
- this.emit("CREATE", blob);
1639
+ this.emit("create", blob);
1628
1640
  return blob;
1629
1641
  }
1630
1642
  fromHtml(content, opts = {}) {
@@ -1645,7 +1657,7 @@ const _Socket = class _Socket {
1645
1657
  __publicField(this, "open", false);
1646
1658
  this.api = typeof api == "string" ? new Api(api) : api;
1647
1659
  this.url = this.api.url.replace("http", "ws");
1648
- this.api.on("TOKEN", () => this.connect());
1660
+ this.api.on("token", () => this.connect());
1649
1661
  this.connect();
1650
1662
  }
1651
1663
  close() {
@@ -1691,59 +1703,70 @@ class Storage extends F {
1691
1703
  this.api = typeof api == "string" ? new Api(api) : api;
1692
1704
  }
1693
1705
  copy(path) {
1694
- 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
+ });
1695
1711
  }
1696
1712
  delete(path) {
1697
- const url = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll("//", "/");
1713
+ const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
1698
1714
  return this.api.request({ url, method: "DELETE" }).then(() => {
1699
- 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;
1700
1726
  });
1701
1727
  }
1702
1728
  list(path) {
1703
- const url = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll("//", "/");
1729
+ const url = this.api.path(path.startsWith("/api/storage/") ? "" : "/api/storage/", path);
1704
1730
  return this.api.request({ url: url + "?list" }).then((resp) => {
1705
- this.emit("LIST", path, resp);
1731
+ this.emit("list", path, resp);
1706
1732
  return resp;
1707
1733
  });
1708
1734
  }
1709
1735
  open(path, target = "_blank") {
1710
- const p2 = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll(/\/{2,}/g, "/");
1711
- 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}` : ""}`;
1712
1738
  if (!target) return link;
1713
- this.emit("OPEN", path);
1739
+ this.emit("open", path);
1714
1740
  return window.open(link, target);
1715
1741
  }
1716
1742
  mkdir(path) {
1717
- const p2 = (path.startsWith("/api/storage/") ? path : "/api/storage/" + path).replaceAll(/\/{2,}/g, "/");
1718
- 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
+ });
1719
1748
  }
1720
1749
  move(from, to) {
1721
1750
  if (from == to) return this.list(to);
1722
- return this.api.request({ url: `/api/storage${from.startsWith("/") ? "" : "/"}${from}`, method: "PATCH", body: { move: to } });
1723
- }
1724
- download(path, opts = {}) {
1725
- const p2 = ("/api/storage/" + path).replaceAll("//", "/");
1726
- return this.api.request({ ...opts, url: p2, decode: false }).then(async (response) => {
1727
- const blob = await response.blob();
1728
- const name = opts.downloadAs || path.split("/").pop();
1729
- this.emit("DOWNLOAD", path, blob);
1730
- Tt(blob, name);
1731
- 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;
1732
1755
  });
1733
1756
  }
1734
1757
  upload(files, opts = "") {
1735
1758
  return new m(async (res, rej, prog) => {
1736
1759
  if (!files) files = await It(typeof opts == "object" ? opts : void 0);
1737
1760
  if (!files || Array.isArray(files) && !files.length) return [];
1738
- 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 || "");
1739
1762
  return $t({
1740
- url,
1763
+ url: `${this.api.url}${path}`,
1741
1764
  files: Array.isArray(files) ? files : [files],
1742
1765
  headers: this.api.headers
1743
1766
  }).onProgress((p2) => {
1744
1767
  prog(p2);
1745
1768
  }).then((resp) => {
1746
- this.emit("UPLOAD", resp);
1769
+ this.emit("upload", resp);
1747
1770
  res(resp);
1748
1771
  }).catch((err) => rej(err));
1749
1772
  });
@@ -1973,7 +1996,7 @@ class Users extends F {
1973
1996
  method: "DELETE"
1974
1997
  }).then(() => {
1975
1998
  this.cache = this.cache.filter((u) => u.username != username);
1976
- this.emit("DELETE", username);
1999
+ this.emit("delete", username);
1977
2000
  });
1978
2001
  }
1979
2002
  list(reload = false) {
@@ -1985,7 +2008,7 @@ class Users extends F {
1985
2008
  });
1986
2009
  this.cache = resp || [];
1987
2010
  this.listed = true;
1988
- this.emit("LIST", resp || []);
2011
+ this.emit("all", resp || []);
1989
2012
  return resp;
1990
2013
  });
1991
2014
  }
@@ -1999,7 +2022,7 @@ class Users extends F {
1999
2022
  resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
2000
2023
  this.cache = [...this.cache.filter((u) => u.username != username), resp];
2001
2024
  }
2002
- this.emit("READ", resp);
2025
+ this.emit("read", resp);
2003
2026
  return resp;
2004
2027
  });
2005
2028
  }
@@ -2013,7 +2036,7 @@ class Users extends F {
2013
2036
  resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
2014
2037
  this.cache = this.cache.filter((u) => u.username != user.username).concat([resp]);
2015
2038
  }
2016
- this.emit(user._id ? "UPDATE" : "CREATE", resp);
2039
+ this.emit(user._id ? "update" : "create", resp);
2017
2040
  return resp;
2018
2041
  });
2019
2042
  }
@@ -2023,7 +2046,7 @@ class Users extends F {
2023
2046
  files: [file],
2024
2047
  headers: this.api.headers
2025
2048
  }).then((resp) => {
2026
- this.emit("UPLOAD_IMAGE", username, file);
2049
+ this.emit("image", username, file);
2027
2050
  return resp;
2028
2051
  });
2029
2052
  }
@@ -2044,28 +2067,28 @@ class Settings extends F {
2044
2067
  list(detailed = false) {
2045
2068
  return this.api.request({ url: `/api/settings` + (detailed ? "?detailed" : "") }).then((resp) => {
2046
2069
  this.cache = !detailed ? resp : Object.values(resp).reduce((acc, v2) => ({ ...acc, [v2.key]: v2.value }), {});
2047
- this.emit("LIST", resp || []);
2070
+ this.emit("list", resp || []);
2048
2071
  return resp;
2049
2072
  });
2050
2073
  }
2051
2074
  delete(key) {
2052
2075
  return this.api.request({ url: `/api/settings/${key}`, method: "DELETE" }).then(() => {
2053
2076
  this.cache = { ...this.cache, [key]: void 0 };
2054
- this.emit("DELETE", key);
2077
+ this.emit("delete", key);
2055
2078
  });
2056
2079
  }
2057
2080
  read(key, reload = false) {
2058
2081
  if (!reload && this.cache[key]) return Promise.resolve(this.cache[key]);
2059
2082
  return this.api.request({ url: `/api/settings/${key}` }).then((variable) => {
2060
2083
  if (variable) this.cache = { ...this.cache, [variable.key]: variable };
2061
- this.emit("READ", variable);
2084
+ this.emit("read", variable);
2062
2085
  return variable;
2063
2086
  });
2064
2087
  }
2065
2088
  update(variable) {
2066
2089
  return this.api.request({ url: `/api/settings/${variable.key}`, body: variable }).then((variable2) => {
2067
2090
  if (variable2) this.cache = { ...this.cache, [variable2.key]: variable2.value };
2068
- this.emit("UPDATE", variable2);
2091
+ this.emit("update", variable2);
2069
2092
  return variable2;
2070
2093
  });
2071
2094
  }
@@ -2078,14 +2101,7 @@ class Static extends F {
2078
2101
  }
2079
2102
  delete(path) {
2080
2103
  return this.api.request({ url: `/api/static/${path}`, method: "DELETE" }).then(() => {
2081
- this.emit("DELETE", path);
2082
- });
2083
- }
2084
- list(path) {
2085
- const url = ("/api/static/" + path).replaceAll("//", "/");
2086
- return this.api.request({ url }).then((resp) => {
2087
- this.emit("LIST", path, resp || []);
2088
- return resp;
2104
+ this.emit("delete", path);
2089
2105
  });
2090
2106
  }
2091
2107
  upload(files, path = "/") {
@@ -2097,7 +2113,7 @@ class Static extends F {
2097
2113
  }).onProgress((p2) => {
2098
2114
  prog(p2);
2099
2115
  }).then((resp) => {
2100
- this.emit("UPLOAD", resp);
2116
+ this.emit("upload", resp);
2101
2117
  res(resp);
2102
2118
  }).catch((err) => rej(err));
2103
2119
  });
@@ -2143,18 +2159,18 @@ class Momentum extends F {
2143
2159
  this.storage = new Storage(this.api);
2144
2160
  this.ui = new UI(this.settings);
2145
2161
  this.users = new Users(this.api);
2146
- this.api.on("*", (event, ...args) => this.emit(`API::${event}`, ...args));
2147
- this.actions.on("*", (event, ...args) => this.emit(`ACTIONS::${event}`, ...args));
2148
- this.auth.on("*", (event, ...args) => this.emit(`AUTH::${event}`, ...args));
2149
- this.data.on("*", (event, ...args) => this.emit(`DATA::${event}`, ...args));
2150
- this.email.on("*", (event, ...args) => this.emit(`EMAIL::${event}`, ...args));
2151
- this.groups.on("*", (event, ...args) => this.emit(`GROUPS::${event}`, ...args));
2152
- if (this.payments) this.payments.on("*", (event, ...args) => this.emit(`PAYMENT::${event}`, ...args));
2153
- this.pdf.on("*", (event, ...args) => this.emit(`PDF::${event}`, ...args));
2154
- this.settings.on("*", (event, ...args) => this.emit(`SETTINGS::${event}`, ...args));
2155
- this.static.on("*", (event, ...args) => this.emit(`STATIC::${event}`, ...args));
2156
- this.storage.on("*", (event, ...args) => this.emit(`STORAGE::${event}`, ...args));
2157
- 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));
2158
2174
  this.users.on("*", (event, ...args) => {
2159
2175
  var _a;
2160
2176
  if (Array.isArray(args[0])) {
@@ -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;
package/dist/static.d.ts CHANGED
@@ -1,16 +1,13 @@
1
1
  import { Api } from './api';
2
- import { TypedEmitter, TypedEvents } from '@ztimson/utils';
3
- import { FileMeta } from './storage';
2
+ import { PromiseProgress, TypedEmitter, TypedEvents } from '@ztimson/utils';
4
3
  export type StaticEvents = TypedEvents & {
5
- LIST: (path: string, response: string[] | FileMeta) => any;
6
- DELETE: (path: string) => any;
7
- UPLOAD: (files: string[]) => any;
4
+ delete: (path: string) => any;
5
+ upload: (files: string[]) => any;
8
6
  };
9
7
  export declare class Static extends TypedEmitter<StaticEvents> {
10
8
  private readonly api;
11
9
  constructor(api: Api | string);
12
10
  delete(path: string): Promise<void>;
13
- list(path: string): Promise<string[] | FileMeta>;
14
- upload(files: File | File[], path?: string): Promise<string[]>;
11
+ upload(files: File | File[], path?: string): PromiseProgress<string[]>;
15
12
  }
16
13
  //# sourceMappingURL=static.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../src/static.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAA+B,YAAY,EAAE,KAAK,WAAW,EAAqB,MAAM,gBAAgB,CAAC;AAChH,OAAO,EAAC,KAAK,QAAQ,EAAC,MAAM,WAAW,CAAC;AAExC,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG;IACxC,IAAI,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,QAAQ,KAAK,GAAG,CAAC;IAC3D,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;IAC9B,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,CAAC;CACjC,CAAC;AAEF,qBAAa,MAAO,SAAQ,YAAY,CAAC,YAAY,CAAC;IACrD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;gBAEf,GAAG,EAAE,GAAG,GAAG,MAAM;IAK7B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMnC,IAAI,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,GAAG,QAAQ,CAAC;IAQhD,MAAM,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,EAAE,IAAI,SAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;CAc3D"}
1
+ {"version":3,"file":"static.d.ts","sourceRoot":"","sources":["../src/static.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,EAAC,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAC,eAAe,EAAE,YAAY,EAAE,KAAK,WAAW,EAAqB,MAAM,gBAAgB,CAAC;AAEnG,MAAM,MAAM,YAAY,GAAG,WAAW,GAAG;IACxC,MAAM,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,GAAG,CAAC;IAC9B,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,GAAG,CAAC;CACjC,CAAC;AAEF,qBAAa,MAAO,SAAQ,YAAY,CAAC,YAAY,CAAC;IACrD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAO;gBAEf,GAAG,EAAE,GAAG,GAAG,MAAM;IAK7B,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMnC,MAAM,CAAC,KAAK,EAAE,IAAI,GAAG,IAAI,EAAE,EAAE,IAAI,SAAM,GAAG,eAAe,CAAC,MAAM,EAAE,CAAC;CAcnE"}