@ztimson/momentum 0.44.0 → 0.45.1
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 +2 -2
- package/dist/actions.d.ts.map +1 -1
- package/dist/ai.d.ts.map +1 -1
- package/dist/analytics.d.ts.map +1 -1
- package/dist/api.d.ts +1 -1
- package/dist/api.d.ts.map +1 -1
- package/dist/auth.d.ts.map +1 -1
- package/dist/client.d.ts.map +1 -1
- package/dist/core.d.ts +5 -5
- package/dist/core.d.ts.map +1 -1
- package/dist/data.d.ts.map +1 -1
- package/dist/email.d.ts.map +1 -1
- package/dist/groups.d.ts +4 -2
- package/dist/groups.d.ts.map +1 -1
- package/dist/index.cjs +282 -213
- package/dist/index.mjs +283 -214
- package/dist/logger.d.ts.map +1 -1
- package/dist/momentum.d.ts.map +1 -1
- package/dist/pathed-events.d.ts +70 -48
- package/dist/pathed-events.d.ts.map +1 -1
- package/dist/payments.d.ts.map +1 -1
- package/dist/pdf.d.ts.map +1 -1
- package/dist/settings.d.ts.map +1 -1
- package/dist/static.d.ts.map +1 -1
- package/dist/storage.d.ts.map +1 -1
- package/dist/users.d.ts +2 -2
- package/dist/users.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -744,94 +744,165 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
744
744
|
};
|
|
745
745
|
Object.defineProperty(r, "__esModule", { value: true }), e(S, r), e(L, r);
|
|
746
746
|
})(xt);
|
|
747
|
-
function
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
}
|
|
753
|
-
|
|
754
|
-
if (!acc) return p2;
|
|
755
|
-
if (hitNone) return acc;
|
|
756
|
-
if (p2.all) acc.all = true;
|
|
757
|
-
if (p2.all || p2.create) acc.create = true;
|
|
758
|
-
if (p2.all || p2.read) acc.read = true;
|
|
759
|
-
if (p2.all || p2.update) acc.update = true;
|
|
760
|
-
if (p2.all || p2.delete) acc.delete = true;
|
|
761
|
-
if (p2.all || p2.execute) acc.execute = true;
|
|
762
|
-
acc.methods = [...acc.methods, ...p2.methods];
|
|
763
|
-
return acc;
|
|
764
|
-
}, null);
|
|
765
|
-
if (combined.all) combined.methods = ["*"];
|
|
766
|
-
if (combined.none) combined.methods = ["n"];
|
|
767
|
-
combined.methods = new B(combined.methods);
|
|
768
|
-
combined.full = pathedEvent(combined.fullPath, ...combined.methods);
|
|
769
|
-
return combined;
|
|
770
|
-
}
|
|
771
|
-
function hasPath(target, ...anyPath) {
|
|
772
|
-
const parsedRequired = anyPath.map(parsePathedEvent);
|
|
773
|
-
const parsedTarget = ft(target).map(parsePathedEvent);
|
|
774
|
-
return !!parsedRequired.find((r) => {
|
|
775
|
-
if (r.all) return true;
|
|
776
|
-
const filtered = parsedTarget.filter((p2) => r.fullPath.startsWith(p2.fullPath));
|
|
777
|
-
if (!filtered.length) return false;
|
|
778
|
-
const combined = combinePathedEvents(...filtered);
|
|
779
|
-
return !combined.none && (combined.all || new B(combined.methods).intersection(new B(r.methods)).length);
|
|
780
|
-
});
|
|
781
|
-
}
|
|
782
|
-
function hasPathFatal(target, ...paths) {
|
|
783
|
-
if (!hasPath(target, ...paths)) throw new Error(`Missing permission: ${paths.join(", ")}`);
|
|
747
|
+
function PE(str, ...args) {
|
|
748
|
+
const combined = [];
|
|
749
|
+
for (let i = 0; i < str.length || i < args.length; i++) {
|
|
750
|
+
if (str[i]) combined.push(str[i]);
|
|
751
|
+
if (args[i]) combined.push(args[i]);
|
|
752
|
+
}
|
|
753
|
+
return new PathEvent(combined.join(""));
|
|
784
754
|
}
|
|
785
|
-
function
|
|
786
|
-
|
|
787
|
-
let
|
|
788
|
-
|
|
789
|
-
|
|
755
|
+
function PES(str, ...args) {
|
|
756
|
+
let combined = [];
|
|
757
|
+
for (let i = 0; i < str.length || i < args.length; i++) {
|
|
758
|
+
if (str[i]) combined.push(str[i]);
|
|
759
|
+
if (args[i]) combined.push(args[i]);
|
|
760
|
+
}
|
|
761
|
+
const [paths, methods] = combined.join("").split(":");
|
|
762
|
+
return PathEvent.toString(paths, methods == null ? void 0 : methods.split(""));
|
|
790
763
|
}
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
764
|
+
class PathEvent {
|
|
765
|
+
constructor(pathedEvent) {
|
|
766
|
+
/** First directory in path */
|
|
767
|
+
__publicField(this, "module");
|
|
768
|
+
/** Entire path, including the module & name */
|
|
769
|
+
__publicField(this, "fullPath");
|
|
770
|
+
/** Path including the name, excluding the module */
|
|
771
|
+
__publicField(this, "path");
|
|
772
|
+
/** Last sagment of path */
|
|
773
|
+
__publicField(this, "name");
|
|
774
|
+
/** List of methods */
|
|
775
|
+
__publicField(this, "methods");
|
|
776
|
+
/** All/Wildcard specified */
|
|
777
|
+
__publicField(this, "all");
|
|
778
|
+
/** None specified */
|
|
779
|
+
__publicField(this, "none");
|
|
780
|
+
/** Create method specified */
|
|
781
|
+
__publicField(this, "create");
|
|
782
|
+
/** Read method specified */
|
|
783
|
+
__publicField(this, "read");
|
|
784
|
+
/** Update method specified */
|
|
785
|
+
__publicField(this, "update");
|
|
786
|
+
/** Delete method specified */
|
|
787
|
+
__publicField(this, "delete");
|
|
788
|
+
var _a;
|
|
789
|
+
if (typeof pathedEvent == "object") return Object.assign(this, pathedEvent);
|
|
790
|
+
let [p2, scope, method] = pathedEvent.split(":");
|
|
791
|
+
if (!method) method = scope || "*";
|
|
792
|
+
if (p2 == "*" || !p2 && method == "*") {
|
|
793
|
+
p2 = "";
|
|
794
|
+
method = "*";
|
|
795
|
+
}
|
|
796
|
+
let temp = p2.split("/").filter((p22) => !!p22);
|
|
797
|
+
this.module = ((_a = temp.splice(0, 1)[0]) == null ? void 0 : _a.toLowerCase()) || "";
|
|
798
|
+
this.fullPath = p2;
|
|
799
|
+
this.path = temp.join("/");
|
|
800
|
+
this.name = temp.pop() || "";
|
|
801
|
+
this.methods = method.split("");
|
|
802
|
+
this.all = method == null ? void 0 : method.includes("*");
|
|
803
|
+
this.none = method == null ? void 0 : method.includes("n");
|
|
804
|
+
this.create = !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("w")) || (method == null ? void 0 : method.includes("c")));
|
|
805
|
+
this.read = !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("r")));
|
|
806
|
+
this.update = !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("w")) || (method == null ? void 0 : method.includes("u")));
|
|
807
|
+
this.delete = !(method == null ? void 0 : method.includes("n")) && ((method == null ? void 0 : method.includes("*")) || (method == null ? void 0 : method.includes("w")) || (method == null ? void 0 : method.includes("d")));
|
|
808
|
+
}
|
|
809
|
+
/**
|
|
810
|
+
* Combine multiple pathed events into one parsed object. Longest path takes precedent, but all subsequent methods are
|
|
811
|
+
* combined until a "none" is reached
|
|
812
|
+
*
|
|
813
|
+
* @param {string | PathEvent} paths PathedEvents as strings or pre-parsed
|
|
814
|
+
* @return {PathEvent} Final combined permission
|
|
815
|
+
*/
|
|
816
|
+
static combine(paths) {
|
|
817
|
+
let hitNone = false;
|
|
818
|
+
const combined = paths.map((p2) => new PathEvent(p2)).toSorted((p1, p2) => {
|
|
819
|
+
const l1 = p1.fullPath.length, l2 = p2.fullPath.length;
|
|
820
|
+
return l1 < l2 ? 1 : l1 > l2 ? -1 : 0;
|
|
821
|
+
}).reduce((acc, p2) => {
|
|
822
|
+
if (p2.none) hitNone = true;
|
|
823
|
+
if (!acc) return p2;
|
|
824
|
+
if (hitNone) return acc;
|
|
825
|
+
if (p2.all) acc.all = true;
|
|
826
|
+
if (p2.all || p2.create) acc.create = true;
|
|
827
|
+
if (p2.all || p2.read) acc.read = true;
|
|
828
|
+
if (p2.all || p2.update) acc.update = true;
|
|
829
|
+
if (p2.all || p2.delete) acc.delete = true;
|
|
830
|
+
acc.methods = [...acc.methods, ...p2.methods];
|
|
831
|
+
return acc;
|
|
832
|
+
}, null);
|
|
833
|
+
if (combined.all) combined.methods = ["*"];
|
|
834
|
+
if (combined.none) combined.methods = ["n"];
|
|
835
|
+
combined.methods = new B(combined.methods);
|
|
836
|
+
combined.raw = PES`${combined.fullPath}:${combined.methods}`;
|
|
837
|
+
return combined;
|
|
838
|
+
}
|
|
839
|
+
/**
|
|
840
|
+
* Squash 2 sets of paths & return true if any overlap is found
|
|
841
|
+
*
|
|
842
|
+
* @param {string | PathEvent | (string | PathEvent)[]} target Array of PathedEvents as strings or pre-parsed
|
|
843
|
+
* @param has
|
|
844
|
+
* @return {boolean} Whether there is any overlap
|
|
845
|
+
*/
|
|
846
|
+
static has(target, ...has) {
|
|
847
|
+
const parsedRequired = ft(has).map((pe) => new PathEvent(pe));
|
|
848
|
+
const parsedTarget = ft(target).map((pe) => new PathEvent(pe));
|
|
849
|
+
return !!parsedRequired.find((r) => {
|
|
850
|
+
if (!r.fullPath && r.all) return true;
|
|
851
|
+
const filtered = parsedTarget.filter((p2) => r.fullPath.startsWith(p2.fullPath));
|
|
852
|
+
if (!filtered.length) return false;
|
|
853
|
+
const combined = PathEvent.combine(filtered);
|
|
854
|
+
return !combined.none && (combined.all || new B(combined.methods).intersection(new B(r.methods)).length);
|
|
855
|
+
});
|
|
856
|
+
}
|
|
857
|
+
/**
|
|
858
|
+
* Same as `has` but raises an error if there is no overlap
|
|
859
|
+
*
|
|
860
|
+
* @param {string | string[]} target Array of PathedEvents as strings or pre-parsed
|
|
861
|
+
* @param has
|
|
862
|
+
*/
|
|
863
|
+
static hasFatal(target, ...has) {
|
|
864
|
+
if (!PathEvent.has(target, ...has)) throw new Error(`Missing permission: ${ft(has).join(", ")}`);
|
|
865
|
+
}
|
|
866
|
+
/**
|
|
867
|
+
* Create pathed event string from its components
|
|
868
|
+
*
|
|
869
|
+
* @param {string | string[]} path Event path
|
|
870
|
+
* @param {Method} methods Event method
|
|
871
|
+
* @return {string} String representation of PathedEvent
|
|
872
|
+
*/
|
|
873
|
+
static toString(path, methods) {
|
|
874
|
+
let p2 = ft(path).filter((p22) => p22 != null).join("/");
|
|
875
|
+
if (methods == null ? void 0 : methods.length) p2 += `:${ft(methods).map((m) => m.toLowerCase()).join("")}`;
|
|
876
|
+
return p2 == null ? void 0 : p2.trim().replaceAll(/\/{2,}/g, "/").replaceAll(/(^\/|\/$)/g, "");
|
|
877
|
+
}
|
|
878
|
+
/**
|
|
879
|
+
* Create pathed event string from its components
|
|
880
|
+
*
|
|
881
|
+
* @return {string} String representation of PathedEvent
|
|
882
|
+
*/
|
|
883
|
+
toString() {
|
|
884
|
+
return PathEvent.toString(this.fullPath, this.methods);
|
|
885
|
+
}
|
|
815
886
|
}
|
|
816
887
|
class PathedEventEmitter {
|
|
817
888
|
constructor() {
|
|
818
889
|
__publicField(this, "listeners", []);
|
|
819
890
|
}
|
|
820
891
|
emit(event, ...args) {
|
|
821
|
-
const parsed =
|
|
822
|
-
this.listeners.filter((l) =>
|
|
892
|
+
const parsed = new PathEvent(event);
|
|
893
|
+
this.listeners.filter((l) => PathEvent.has(l[0], event)).forEach((l) => l[1](parsed, ...args));
|
|
823
894
|
}
|
|
824
895
|
off(listener) {
|
|
825
896
|
this.listeners = this.listeners.filter((l) => l[1] != listener);
|
|
826
897
|
}
|
|
827
898
|
on(event, listener) {
|
|
828
|
-
ft(event).forEach((e) => this.listeners.push([
|
|
899
|
+
ft(event).forEach((e) => this.listeners.push([new PathEvent(e), listener]));
|
|
829
900
|
return () => this.off(listener);
|
|
830
901
|
}
|
|
831
902
|
once(event, listener) {
|
|
832
903
|
return new Promise((res) => {
|
|
833
904
|
const unsubscribe = this.on(event, (event2, ...args) => {
|
|
834
|
-
res(args);
|
|
905
|
+
res(args.length < 2 ? args[0] : args);
|
|
835
906
|
if (listener) listener(event2, ...args);
|
|
836
907
|
unsubscribe();
|
|
837
908
|
});
|
|
@@ -863,11 +934,11 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
863
934
|
if (token == this._token) return;
|
|
864
935
|
this._token = token;
|
|
865
936
|
this.headers["Authorization"] = token ? `Bearer ${token}` : null;
|
|
866
|
-
this.emit(
|
|
937
|
+
this.emit(PES`api/token:${token ? "u" : "d"}`, token);
|
|
867
938
|
}
|
|
868
939
|
healthcheck() {
|
|
869
940
|
return this.request({ url: "/api/healthcheck" }).then((resp) => {
|
|
870
|
-
this.emit(
|
|
941
|
+
this.emit(PES`api/healthcheck:r`, resp);
|
|
871
942
|
return resp;
|
|
872
943
|
});
|
|
873
944
|
}
|
|
@@ -875,15 +946,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
875
946
|
const key = Lt(options);
|
|
876
947
|
const method = options.method == "GET" ? "r" : options.method == "POST" ? "c" : options.method == "DELETE" ? "d" : "u";
|
|
877
948
|
if (this.pending[key] != null) return this.pending[key];
|
|
878
|
-
this.pending[key] = super.request(options).then((
|
|
879
|
-
this.emit(
|
|
880
|
-
return
|
|
949
|
+
this.pending[key] = super.request(options).then((response) => {
|
|
950
|
+
this.emit(PES`api/response:${method}`, { request: options, response });
|
|
951
|
+
return response.data;
|
|
881
952
|
}).catch((err) => {
|
|
882
953
|
const e = (err == null ? void 0 : err.data) || err;
|
|
883
|
-
this.emit(
|
|
954
|
+
this.emit(PES`api/error:${method}`, { request: options, error: e });
|
|
884
955
|
throw e;
|
|
885
956
|
}).finally(() => delete this.pending[key]);
|
|
886
|
-
this.emit(
|
|
957
|
+
this.emit(PES`api/request:${method}`, { request: options, response: this.pending[key] });
|
|
887
958
|
return this.pending[key];
|
|
888
959
|
}
|
|
889
960
|
}
|
|
@@ -906,15 +977,15 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
906
977
|
}
|
|
907
978
|
delete(id) {
|
|
908
979
|
if (!id) throw new Error("Cannot delete action, missing ID");
|
|
909
|
-
return this.api.request({ url: `/api/` +
|
|
980
|
+
return this.api.request({ url: `/api/` + PES`actions/${id}`, method: "DELETE" }).then(() => {
|
|
910
981
|
this.cache.delete(id);
|
|
911
|
-
this.emit(
|
|
982
|
+
this.emit(PES`actions/${id}:d`, id);
|
|
912
983
|
});
|
|
913
984
|
}
|
|
914
985
|
all() {
|
|
915
|
-
return this.api.request({ url: `/api
|
|
986
|
+
return this.api.request({ url: `/api/` + PES`actions` }).then((resp) => {
|
|
916
987
|
this.cache.addAll(resp);
|
|
917
|
-
this.emit(
|
|
988
|
+
this.emit(PES`actions:r`, resp || []);
|
|
918
989
|
return resp;
|
|
919
990
|
});
|
|
920
991
|
}
|
|
@@ -922,35 +993,29 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
922
993
|
if (!id) throw new Error("Cannot read action, missing ID");
|
|
923
994
|
const cached = this.cache.get(id);
|
|
924
995
|
if (!reload && cached) return Promise.resolve(cached);
|
|
925
|
-
return this.api.request({ url: `/api/` +
|
|
996
|
+
return this.api.request({ url: `/api/` + PES`actions/${id}` }).then((action) => {
|
|
926
997
|
if (action) this.cache.add(action);
|
|
927
|
-
this.emit(
|
|
998
|
+
this.emit(PES`actions/${id}:r`, action);
|
|
928
999
|
return action;
|
|
929
1000
|
});
|
|
930
1001
|
}
|
|
931
1002
|
run(path, opts = {}) {
|
|
932
1003
|
if (!path) throw new Error("Cannot run action, missing path");
|
|
933
|
-
return this.api.request({ url: `/api/` +
|
|
934
|
-
this.emit(pathedEvent(["actions/run", path], "x"), resp);
|
|
935
|
-
return resp;
|
|
936
|
-
});
|
|
1004
|
+
return this.api.request({ url: `/api/` + PES`actions/run/${path}`, ...opts });
|
|
937
1005
|
}
|
|
938
1006
|
runById(action, opts = {}) {
|
|
939
1007
|
const id = typeof action == "string" ? action : action == null ? void 0 : action._id;
|
|
940
1008
|
if (!id) throw new Error("Cannot run action, missing ID");
|
|
941
|
-
return this.api.request({ url: "/api/" +
|
|
942
|
-
this.emit(pathedEvent(["actions/run-by-id", id], "x"), resp);
|
|
943
|
-
return resp;
|
|
944
|
-
});
|
|
1009
|
+
return this.api.request({ url: "/api/" + PES`actions/run-by-id/${id}`, method: "POST", ...opts });
|
|
945
1010
|
}
|
|
946
1011
|
update(action) {
|
|
947
1012
|
return this.api.request({
|
|
948
|
-
url: `/api/` +
|
|
1013
|
+
url: `/api/` + PES`actions/${action._id}`,
|
|
949
1014
|
method: "POST",
|
|
950
1015
|
body: action
|
|
951
1016
|
}).then((action2) => {
|
|
952
1017
|
if (action2) this.cache.add(action2);
|
|
953
|
-
this.emit(
|
|
1018
|
+
this.emit(PES`actions/${action2._id}:u`, action2);
|
|
954
1019
|
return action2;
|
|
955
1020
|
});
|
|
956
1021
|
}
|
|
@@ -963,16 +1028,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
963
1028
|
}
|
|
964
1029
|
ask(question, context) {
|
|
965
1030
|
if (!question) throw new Error("Cannot ask AI, missing question");
|
|
966
|
-
return this.api.request({ url: `/api
|
|
1031
|
+
return this.api.request({ url: `/api/` + PES`ai`, method: "POST", body: {
|
|
967
1032
|
question,
|
|
968
1033
|
context
|
|
969
|
-
} }).then((
|
|
970
|
-
this.emit(
|
|
971
|
-
return
|
|
1034
|
+
} }).then((response) => {
|
|
1035
|
+
this.emit(PES`ai:c`, { question, context, response });
|
|
1036
|
+
return response;
|
|
972
1037
|
});
|
|
973
1038
|
}
|
|
974
1039
|
clear() {
|
|
975
|
-
return this.api.request({ url: "/api/
|
|
1040
|
+
return this.api.request({ url: "/api/" + PES`ai`, method: "DELETE" }).then(() => this.emit(PES`ai:d`, this.api.token));
|
|
976
1041
|
}
|
|
977
1042
|
}
|
|
978
1043
|
class Analytics extends PathedEventEmitter {
|
|
@@ -983,8 +1048,8 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
983
1048
|
}
|
|
984
1049
|
ipTrace(ip) {
|
|
985
1050
|
if (!ip) throw new Error("Cannot trace, missing IP");
|
|
986
|
-
return this.api.request({ url: `/api
|
|
987
|
-
this.emit(
|
|
1051
|
+
return this.api.request({ url: `/api/` + PES`analytics/trace/${ip}` }).then((resp) => {
|
|
1052
|
+
this.emit(PES`analytics/trace/${ip}:r`, resp);
|
|
988
1053
|
return resp;
|
|
989
1054
|
});
|
|
990
1055
|
}
|
|
@@ -1030,11 +1095,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1030
1095
|
"/api/auth/totp"
|
|
1031
1096
|
];
|
|
1032
1097
|
if (resp.status == 401 && !blacklist.find((url) => resp.url.includes(url)))
|
|
1033
|
-
this.emit(
|
|
1098
|
+
this.emit(PES`auth/session-expired:d`, this.api.token);
|
|
1034
1099
|
next();
|
|
1035
1100
|
});
|
|
1036
1101
|
this.api.on("api/token", (event, token) => {
|
|
1037
1102
|
var _a;
|
|
1103
|
+
console.log("loading user...");
|
|
1038
1104
|
if ((_a = this.opts) == null ? void 0 : _a.persist) {
|
|
1039
1105
|
if (token) localStorage.setItem(this.storageKey, token);
|
|
1040
1106
|
else localStorage.removeItem(this.storageKey);
|
|
@@ -1057,15 +1123,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1057
1123
|
set user(user) {
|
|
1058
1124
|
if (!A(this.user, user)) {
|
|
1059
1125
|
this._user = user ? user : null;
|
|
1060
|
-
this.emit(
|
|
1126
|
+
this.emit(PES`auth/user:u`, this._user);
|
|
1061
1127
|
}
|
|
1062
1128
|
}
|
|
1063
1129
|
knownHost(host = location.origin) {
|
|
1064
1130
|
if (host.startsWith("/")) return Promise.resolve();
|
|
1065
|
-
return this.api.request({ url: `/api/auth/known-host?host=${encodeURI(new URL(host).origin)}` })
|
|
1066
|
-
this.emit(pathedEvent("auth/known-host", "r"), host, false);
|
|
1067
|
-
throw err;
|
|
1068
|
-
});
|
|
1131
|
+
return this.api.request({ url: `/api/auth/known-host?host=${encodeURI(new URL(host).origin)}` });
|
|
1069
1132
|
}
|
|
1070
1133
|
login(username, password, totp) {
|
|
1071
1134
|
if (!username || !password) throw new Error("Cannot login, missing username or password");
|
|
@@ -1081,7 +1144,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1081
1144
|
}).then(async (resp) => {
|
|
1082
1145
|
this.api.token = (resp == null ? void 0 : resp.token) || null;
|
|
1083
1146
|
const user = await this.once("auth/user");
|
|
1084
|
-
this.emit(
|
|
1147
|
+
this.emit(PES`auth/login/${username}:u`, user);
|
|
1085
1148
|
return user;
|
|
1086
1149
|
});
|
|
1087
1150
|
}
|
|
@@ -1102,16 +1165,16 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1102
1165
|
});
|
|
1103
1166
|
}
|
|
1104
1167
|
logout() {
|
|
1168
|
+
this.emit(PES`auth/logout:d`, this.user);
|
|
1105
1169
|
this.api.token = null;
|
|
1106
1170
|
this.user = null;
|
|
1107
|
-
this.emit(pathedEvent("auth/logout", "d"));
|
|
1108
1171
|
}
|
|
1109
1172
|
async register(u) {
|
|
1110
1173
|
var _a;
|
|
1111
1174
|
if (!u.username || !u.password) throw new Error("Cannot register user, missing username or password");
|
|
1112
1175
|
const user = await this.api.request({ url: "/api/auth/register", body: { ...u } });
|
|
1113
1176
|
if ((_a = user == null ? void 0 : user.image) == null ? void 0 : _a.startsWith("/")) user.image = `${this.api.url}${user.image}?token=${this.api.token}`;
|
|
1114
|
-
this.emit(
|
|
1177
|
+
this.emit(PES`auth/register:c`, user);
|
|
1115
1178
|
return user;
|
|
1116
1179
|
}
|
|
1117
1180
|
reset(emailOrPass, token) {
|
|
@@ -1124,7 +1187,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1124
1187
|
password: token ? emailOrPass : void 0
|
|
1125
1188
|
}
|
|
1126
1189
|
}).then(() => {
|
|
1127
|
-
this.emit(
|
|
1190
|
+
this.emit(PES`auth/reset:${token ? "u" : "c"}`, token || emailOrPass);
|
|
1128
1191
|
});
|
|
1129
1192
|
}
|
|
1130
1193
|
async session(token, set = false) {
|
|
@@ -1133,12 +1196,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1133
1196
|
url: "/api/auth/session",
|
|
1134
1197
|
headers: token ? { "Authorization": `Bearer ${token}` } : void 0
|
|
1135
1198
|
});
|
|
1136
|
-
this.emit(
|
|
1199
|
+
this.emit(PES`auth/session:r`, session);
|
|
1137
1200
|
if (set) {
|
|
1138
1201
|
this.api.token = token;
|
|
1139
1202
|
if (session == null ? void 0 : session.user) session.user.image = `${this.api.url}${session.user.image}?token=${this.api.token}`;
|
|
1140
1203
|
this.user = (session == null ? void 0 : session.user) || null;
|
|
1141
|
-
if (session) this.emit(
|
|
1204
|
+
if (session) this.emit(PES`auth/login:c`, session.user);
|
|
1142
1205
|
}
|
|
1143
1206
|
return session;
|
|
1144
1207
|
}
|
|
@@ -1148,7 +1211,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1148
1211
|
url: "/api/auth/password",
|
|
1149
1212
|
body: { username, password, oldPassword }
|
|
1150
1213
|
}).then((resp) => {
|
|
1151
|
-
this.emit(
|
|
1214
|
+
this.emit(PES`auth/reset:u`, resp == null ? void 0 : resp.token);
|
|
1152
1215
|
if (resp == null ? void 0 : resp.token) this.api.token = resp.token;
|
|
1153
1216
|
});
|
|
1154
1217
|
}
|
|
@@ -1254,7 +1317,7 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1254
1317
|
if (!dismissed && !this.pwa && this.mobile) this.pwaPrompt();
|
|
1255
1318
|
}, 500);
|
|
1256
1319
|
}
|
|
1257
|
-
this.emit(
|
|
1320
|
+
this.emit(PES`client/inject:c`, this.platform);
|
|
1258
1321
|
}
|
|
1259
1322
|
pwaPrompt(platform) {
|
|
1260
1323
|
const url = this.settings.api.url;
|
|
@@ -1371,13 +1434,13 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1371
1434
|
setTimeout(() => {
|
|
1372
1435
|
prompt.remove();
|
|
1373
1436
|
backdrop.remove();
|
|
1374
|
-
this.emit(
|
|
1437
|
+
this.emit(PES`client/pwa:d`, platform);
|
|
1375
1438
|
}, 500);
|
|
1376
1439
|
};
|
|
1377
1440
|
prompt.append(close);
|
|
1378
1441
|
backdrop.append(prompt);
|
|
1379
1442
|
document.body.append(backdrop);
|
|
1380
|
-
this.emit(
|
|
1443
|
+
this.emit(PES`client/pwa:c`, platform);
|
|
1381
1444
|
}
|
|
1382
1445
|
}
|
|
1383
1446
|
class Data extends PathedEventEmitter {
|
|
@@ -1389,18 +1452,18 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1389
1452
|
create(collection, document2) {
|
|
1390
1453
|
if (!collection || !document2) throw new Error("Cannot create document, missing collection or document");
|
|
1391
1454
|
return this.api.request({
|
|
1392
|
-
url: `/api/` +
|
|
1455
|
+
url: `/api/` + PES`data/${collection}`,
|
|
1393
1456
|
method: "POST",
|
|
1394
1457
|
body: document2
|
|
1395
1458
|
}).then((resp) => {
|
|
1396
|
-
this.emit(
|
|
1459
|
+
this.emit(PES`data/${collection}:c`, resp);
|
|
1397
1460
|
return resp;
|
|
1398
1461
|
});
|
|
1399
1462
|
}
|
|
1400
1463
|
read(collection, id) {
|
|
1401
1464
|
if (!collection) throw new Error("Cannot read documents, missing collection");
|
|
1402
|
-
return this.api.request({ url: `/api/` +
|
|
1403
|
-
this.emit(
|
|
1465
|
+
return this.api.request({ url: `/api/` + PES`data/${collection}/${id}` }).then((resp) => {
|
|
1466
|
+
this.emit(PES`data/${collection}/${id}:r`, collection, resp);
|
|
1404
1467
|
return resp;
|
|
1405
1468
|
});
|
|
1406
1469
|
}
|
|
@@ -1408,43 +1471,43 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1408
1471
|
if (!collection || !document2) throw new Error("Cannot update document, missing collection or document");
|
|
1409
1472
|
if (!document2._id) return this.create(collection, document2);
|
|
1410
1473
|
return this.api.request({
|
|
1411
|
-
url: `/api/` +
|
|
1474
|
+
url: `/api/` + PES`data/${collection}/${document2._id}`,
|
|
1412
1475
|
method: append ? "PATCH" : "PUT",
|
|
1413
1476
|
body: document2
|
|
1414
1477
|
}).then((resp) => {
|
|
1415
|
-
this.emit(
|
|
1478
|
+
this.emit(PES`data/${collection}/${document2._id}:u`, resp);
|
|
1416
1479
|
return resp;
|
|
1417
1480
|
});
|
|
1418
1481
|
}
|
|
1419
1482
|
delete(collection, id) {
|
|
1420
1483
|
if (!collection || !id) throw new Error("Cannot delete document, missing collection or ID");
|
|
1421
1484
|
return this.api.request({
|
|
1422
|
-
url: `/api/` +
|
|
1485
|
+
url: `/api/` + PES`data/${collection}/${id}`,
|
|
1423
1486
|
method: "DELETE"
|
|
1424
|
-
}).then(() => this.emit(
|
|
1487
|
+
}).then(() => this.emit(PES`data/${collection}/${id}:d`, id));
|
|
1425
1488
|
}
|
|
1426
1489
|
raw(collection, query) {
|
|
1427
1490
|
if (!collection || !query) throw new Error("Cannot execute raw query, missing collection or query");
|
|
1428
1491
|
const mode = query.operand.startsWith("find") ? "r" : query.operand == "insert" ? "c" : query.operand.startsWith("delete") ? "d" : "u";
|
|
1429
|
-
return this.api.request({ url: `/api/` +
|
|
1430
|
-
this.emit(
|
|
1492
|
+
return this.api.request({ url: `/api/` + PES`data/${collection}` + "?raw", body: query }).then((resp) => {
|
|
1493
|
+
this.emit(PES`data/${collection}:${mode}`, resp);
|
|
1431
1494
|
return resp;
|
|
1432
1495
|
});
|
|
1433
1496
|
}
|
|
1434
1497
|
deleteSchema(path) {
|
|
1435
1498
|
if (!path) throw new Error("Cannot delete schema, missing collection path");
|
|
1436
|
-
return this.api.request({ url: `/api/` +
|
|
1499
|
+
return this.api.request({ url: `/api/` + PES`schema/${path}`, method: "DELETE" }).then(() => this.emit(PES`schema/${path}:d`, path));
|
|
1437
1500
|
}
|
|
1438
1501
|
getSchema(pathOrTree) {
|
|
1439
|
-
return this.api.request({ url: "/api/" +
|
|
1440
|
-
this.emit(
|
|
1502
|
+
return this.api.request({ url: "/api/" + PES`schema/${typeof pathOrTree == "string" ? pathOrTree : ""}` + (pathOrTree === true ? `?tree=${pathOrTree}` : "") }).then((resp) => {
|
|
1503
|
+
this.emit(PES`schema/${typeof pathOrTree == "string" ? pathOrTree : ""}:r`, resp);
|
|
1441
1504
|
return resp;
|
|
1442
1505
|
});
|
|
1443
1506
|
}
|
|
1444
1507
|
setSchema(schema) {
|
|
1445
1508
|
if (!schema.path) throw new Error("Cannot update schema, missing collection path");
|
|
1446
|
-
return this.api.request({ url: "/api/" +
|
|
1447
|
-
this.emit(
|
|
1509
|
+
return this.api.request({ url: "/api/" + PES`schema/${schema.path}`, body: schema }).then((resp) => {
|
|
1510
|
+
this.emit(PES`schema/${schema.path}:${schema._id ? "u" : "c"}`, resp);
|
|
1448
1511
|
return resp;
|
|
1449
1512
|
});
|
|
1450
1513
|
}
|
|
@@ -1458,10 +1521,10 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1458
1521
|
send(email) {
|
|
1459
1522
|
var _a;
|
|
1460
1523
|
if (!email.to && !email.bcc || !email.body) throw new Error("Cannot send email, missing address or body");
|
|
1461
|
-
return this.api.request({ url: "/api/" +
|
|
1524
|
+
return this.api.request({ url: "/api/" + PES`email/${(_a = email.body) == null ? void 0 : _a.template}`, body: email }).then((response) => {
|
|
1462
1525
|
var _a2;
|
|
1463
|
-
this.emit(
|
|
1464
|
-
return
|
|
1526
|
+
this.emit(PES`email/${(_a2 = email.body) == null ? void 0 : _a2.template}:c`, { email, response });
|
|
1527
|
+
return response;
|
|
1465
1528
|
});
|
|
1466
1529
|
}
|
|
1467
1530
|
}
|
|
@@ -1469,49 +1532,59 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
|
|
|
1469
1532
|
constructor(api) {
|
|
1470
1533
|
super();
|
|
1471
1534
|
__publicField(this, "api");
|
|
1535
|
+
__publicField(this, "cache", new Dt("name"));
|
|
1472
1536
|
this.api = typeof api == "string" ? new Api(api) : api;
|
|
1473
1537
|
}
|
|
1474
|
-
all() {
|
|
1475
|
-
|
|
1476
|
-
|
|
1538
|
+
async all(reload) {
|
|
1539
|
+
if (!reload && this.cache.complete) return this.cache.all();
|
|
1540
|
+
return this.api.request({ url: `/api/` + PES`groups` }).then((resp) => {
|
|
1541
|
+
this.cache.addAll(resp);
|
|
1542
|
+
this.emit(PES`groups:r`, resp || []);
|
|
1477
1543
|
return resp;
|
|
1478
1544
|
});
|
|
1479
1545
|
}
|
|
1480
1546
|
create(group) {
|
|
1481
1547
|
if (!group.name) throw new Error("Cannot create group, missing name");
|
|
1482
1548
|
return this.api.request({
|
|
1483
|
-
url: `/api
|
|
1549
|
+
url: `/api/` + PES`groups/${group.name}`,
|
|
1484
1550
|
method: "POST",
|
|
1485
1551
|
body: group
|
|
1486
1552
|
}).then((resp) => {
|
|
1487
|
-
this.
|
|
1553
|
+
this.cache.add(resp);
|
|
1554
|
+
this.emit(PES`groups/${group.name}:c`, resp);
|
|
1488
1555
|
return resp;
|
|
1489
1556
|
});
|
|
1490
1557
|
}
|
|
1491
|
-
read(name) {
|
|
1558
|
+
async read(name, reload) {
|
|
1492
1559
|
if (!name) throw new Error("Cannot read group, missing name");
|
|
1493
|
-
|
|
1494
|
-
|
|
1560
|
+
if (!reload && this.cache.get(name)) return this.cache.get(name);
|
|
1561
|
+
return this.api.request({ url: `/api/` + PES`groups/${name}` }).then((resp) => {
|
|
1562
|
+
this.cache.add(resp);
|
|
1563
|
+
this.emit(PES`groups/${name}:r`, resp);
|
|
1495
1564
|
return resp;
|
|
1496
1565
|
});
|
|
1497
1566
|
}
|
|
1498
1567
|
update(group) {
|
|
1499
1568
|
if (!group.name) throw new Error("Cannot update group, missing name");
|
|
1500
1569
|
return this.api.request({
|
|
1501
|
-
url: `/api/` +
|
|
1570
|
+
url: `/api/` + PES`groups/${group.name}`,
|
|
1502
1571
|
method: "PATCH",
|
|
1503
1572
|
body: group
|
|
1504
1573
|
}).then((resp) => {
|
|
1505
|
-
this.
|
|
1574
|
+
this.cache.add(resp);
|
|
1575
|
+
this.emit(PES`groups/${group.name}:u`, resp);
|
|
1506
1576
|
return resp;
|
|
1507
1577
|
});
|
|
1508
1578
|
}
|
|
1509
1579
|
delete(name) {
|
|
1510
1580
|
if (!name) throw new Error("Cannot delete group, missing name");
|
|
1511
1581
|
return this.api.request({
|
|
1512
|
-
url: `/api/` +
|
|
1582
|
+
url: `/api/` + PES`groups/${name}`,
|
|
1513
1583
|
method: "DELETE"
|
|
1514
|
-
}).then(() =>
|
|
1584
|
+
}).then(() => {
|
|
1585
|
+
this.cache.delete(name);
|
|
1586
|
+
this.emit(PES`groups/${name}:d`);
|
|
1587
|
+
});
|
|
1515
1588
|
}
|
|
1516
1589
|
}
|
|
1517
1590
|
class Logger extends PathedEventEmitter {
|
|
@@ -1550,11 +1623,11 @@ ${log}`;
|
|
|
1550
1623
|
};
|
|
1551
1624
|
}
|
|
1552
1625
|
createLog(log, namespace = this.namespace) {
|
|
1553
|
-
return this.api.request({ url: `/api/` +
|
|
1626
|
+
return this.api.request({ url: `/api/` + PES`logs/${namespace}`, body: log }).then(() => this.emit(PES`logs/${namespace}:c`, log)).catch(() => {
|
|
1554
1627
|
});
|
|
1555
1628
|
}
|
|
1556
1629
|
clearLogs(namespace = this.namespace) {
|
|
1557
|
-
return this.api.request({ url: `/api/` +
|
|
1630
|
+
return this.api.request({ url: `/api/` + PES`logs/${namespace}`, method: "DELETE" }).then(() => this.emit(PES`logs/${namespace}:d`));
|
|
1558
1631
|
}
|
|
1559
1632
|
clearServerLogs() {
|
|
1560
1633
|
return this.clearLogs("server");
|
|
@@ -1562,8 +1635,8 @@ ${log}`;
|
|
|
1562
1635
|
getLogs(length, page, namespace = this.namespace) {
|
|
1563
1636
|
if (!namespace) throw new Error("Cannot get logs, missing namespace");
|
|
1564
1637
|
const query = [length ? `length=${length}` : void 0, page ? `page=${page}` : void 0].filter((v) => !!v).join("&");
|
|
1565
|
-
return this.api.request({ url: `/api/` +
|
|
1566
|
-
this.emit(
|
|
1638
|
+
return this.api.request({ url: `/api/` + PES`logs/${namespace}` + (query ? `?${query}` : "") }).then((logs) => {
|
|
1639
|
+
this.emit(PES`logs/${namespace}:r`, logs);
|
|
1567
1640
|
return logs;
|
|
1568
1641
|
});
|
|
1569
1642
|
}
|
|
@@ -1609,7 +1682,7 @@ ${log}`;
|
|
|
1609
1682
|
amount,
|
|
1610
1683
|
custom
|
|
1611
1684
|
} });
|
|
1612
|
-
this.emit(
|
|
1685
|
+
this.emit(PES`payments:c`, request.data.clientSecret);
|
|
1613
1686
|
return request.data.clientSecret;
|
|
1614
1687
|
}
|
|
1615
1688
|
async createForm(element, amount, custom) {
|
|
@@ -1623,8 +1696,8 @@ ${log}`;
|
|
|
1623
1696
|
});
|
|
1624
1697
|
}
|
|
1625
1698
|
async history(username) {
|
|
1626
|
-
const history = await this.api.request({ url: `/api/` +
|
|
1627
|
-
this.emit(
|
|
1699
|
+
const history = await this.api.request({ url: `/api/` + PES`payments/${username}` });
|
|
1700
|
+
this.emit(PES`payments/${username}:r`, history);
|
|
1628
1701
|
return history;
|
|
1629
1702
|
}
|
|
1630
1703
|
}
|
|
@@ -1635,7 +1708,7 @@ ${log}`;
|
|
|
1635
1708
|
this.api = typeof api == "string" ? new Api(api) : api;
|
|
1636
1709
|
}
|
|
1637
1710
|
createPdf(body, options) {
|
|
1638
|
-
return this.api.request({ url: `/api
|
|
1711
|
+
return this.api.request({ url: `/api/` + PES`pdf`, body: { ...body, options }, decode: false }).then(async (resp) => {
|
|
1639
1712
|
const blob = await resp.blob();
|
|
1640
1713
|
if (options == null ? void 0 : options.download) {
|
|
1641
1714
|
let filename = (options == null ? void 0 : options.filename) || qt();
|
|
@@ -1644,7 +1717,7 @@ ${log}`;
|
|
|
1644
1717
|
dt(url, filename);
|
|
1645
1718
|
URL.revokeObjectURL(url);
|
|
1646
1719
|
}
|
|
1647
|
-
this.emit(
|
|
1720
|
+
this.emit(PES`pdf:c`, blob);
|
|
1648
1721
|
return blob;
|
|
1649
1722
|
});
|
|
1650
1723
|
}
|
|
@@ -1716,54 +1789,54 @@ ${log}`;
|
|
|
1716
1789
|
}
|
|
1717
1790
|
copy(source, destination) {
|
|
1718
1791
|
if (!source || !destination) throw new Error("Cannot copy file or folder, missing source or destination");
|
|
1719
|
-
return this.api.request({ url: "/api/" +
|
|
1720
|
-
this.emit(
|
|
1721
|
-
return
|
|
1792
|
+
return this.api.request({ url: "/api/" + PES`storage/${destination}`, body: { from: source } }).then((response) => {
|
|
1793
|
+
this.emit(PES`storage/${destination}:c`, response);
|
|
1794
|
+
return response;
|
|
1722
1795
|
});
|
|
1723
1796
|
}
|
|
1724
1797
|
delete(path) {
|
|
1725
1798
|
if (!path) throw new Error("Cannot delete file or folder, missing path");
|
|
1726
|
-
return this.api.request({ url: "/api/" +
|
|
1727
|
-
this.emit(
|
|
1799
|
+
return this.api.request({ url: "/api/" + PES`storage/${path}`, method: "DELETE" }).then(() => {
|
|
1800
|
+
this.emit(PES`storage/${path}:d`, path);
|
|
1728
1801
|
});
|
|
1729
1802
|
}
|
|
1730
1803
|
download(path, opts = {}) {
|
|
1731
1804
|
if (!path) throw new Error("Cannot download file, missing path");
|
|
1732
|
-
return this.api.request({ ...opts, url: "/api/" +
|
|
1805
|
+
return this.api.request({ ...opts, url: "/api/" + PES`storage/${path}`, decode: false }).then(async (response) => {
|
|
1733
1806
|
const blob = await response.blob();
|
|
1734
1807
|
const name = opts.downloadAs || path.split("/").pop();
|
|
1735
|
-
this.emit(
|
|
1808
|
+
this.emit(PES`storage/${path}:r`, blob);
|
|
1736
1809
|
Gt(blob, name);
|
|
1737
1810
|
return response;
|
|
1738
1811
|
});
|
|
1739
1812
|
}
|
|
1740
1813
|
list(path) {
|
|
1741
1814
|
if (!path) path = "/";
|
|
1742
|
-
return this.api.request({ url: "/api/" +
|
|
1743
|
-
this.emit(
|
|
1815
|
+
return this.api.request({ url: "/api/" + PES`storage/${path}` + "?list" }).then((resp) => {
|
|
1816
|
+
this.emit(PES`storage/${path}:r`, resp);
|
|
1744
1817
|
return resp;
|
|
1745
1818
|
});
|
|
1746
1819
|
}
|
|
1747
1820
|
open(path, target = "_blank") {
|
|
1748
1821
|
if (!path) throw new Error("Cannot download file, missing path");
|
|
1749
|
-
const link = `${this.api.url}/api/${
|
|
1822
|
+
const link = `${this.api.url}/api/` + PES`storage/${path}` + (this.api.token ? `?token=${this.api.token}` : "");
|
|
1750
1823
|
if (!target) return link;
|
|
1751
|
-
this.emit(
|
|
1824
|
+
this.emit(PES`storage/${path}:r`, path);
|
|
1752
1825
|
return window.open(link, target);
|
|
1753
1826
|
}
|
|
1754
1827
|
mkdir(path) {
|
|
1755
1828
|
if (!path) throw new Error("Cannot make directory, missing path");
|
|
1756
|
-
return this.api.request({ url: "/api/" +
|
|
1757
|
-
this.emit(
|
|
1829
|
+
return this.api.request({ url: "/api/" + PES`storage/${path}`, body: { directory: true } }).then((resp) => {
|
|
1830
|
+
this.emit(PES`storage/${path}:c`, resp);
|
|
1758
1831
|
return resp;
|
|
1759
1832
|
});
|
|
1760
1833
|
}
|
|
1761
1834
|
move(source, destination) {
|
|
1762
1835
|
if (!source || !destination) throw new Error("Cannot move file or folder, missing source or destination");
|
|
1763
1836
|
if (source == destination) return this.list(destination);
|
|
1764
|
-
return this.api.request({ url: "/api/" +
|
|
1765
|
-
this.emit(
|
|
1766
|
-
return
|
|
1837
|
+
return this.api.request({ url: "/api/" + PES`storage/${source}`, method: "PATCH", body: { move: destination } }).then((response) => {
|
|
1838
|
+
this.emit(PES`storage/${source}:u`, response);
|
|
1839
|
+
return response;
|
|
1767
1840
|
});
|
|
1768
1841
|
}
|
|
1769
1842
|
upload(files, opts) {
|
|
@@ -1772,13 +1845,13 @@ ${log}`;
|
|
|
1772
1845
|
if (!files || Array.isArray(files) && !files.length) return [];
|
|
1773
1846
|
const path = (opts && typeof opts == "object" ? opts == null ? void 0 : opts.path : opts) || "/";
|
|
1774
1847
|
return Ft({
|
|
1775
|
-
url: `${this.api.url}/api/${
|
|
1848
|
+
url: `${this.api.url}/api/` + PES`storage/${path}`,
|
|
1776
1849
|
files: ft(files),
|
|
1777
1850
|
headers: this.api.headers
|
|
1778
1851
|
}).onProgress((p2) => {
|
|
1779
1852
|
prog(p2);
|
|
1780
1853
|
}).then((resp) => {
|
|
1781
|
-
this.emit(
|
|
1854
|
+
this.emit(PES`storage/${path}:c`, resp);
|
|
1782
1855
|
res(resp);
|
|
1783
1856
|
}).catch((err) => rej(err));
|
|
1784
1857
|
});
|
|
@@ -1791,44 +1864,44 @@ ${log}`;
|
|
|
1791
1864
|
__publicField(this, "cache", new Dt("username"));
|
|
1792
1865
|
this.api = typeof api == "string" ? new Api(api) : api;
|
|
1793
1866
|
}
|
|
1794
|
-
|
|
1795
|
-
if (!username) throw new Error("Cannot delete user, missing username");
|
|
1796
|
-
return this.api.request({
|
|
1797
|
-
url: "/api/" + pathedEvent(["users", username]),
|
|
1798
|
-
method: "DELETE"
|
|
1799
|
-
}).then(() => {
|
|
1800
|
-
this.cache.delete(username);
|
|
1801
|
-
this.emit(pathedEvent(["users", username], "d"), username);
|
|
1802
|
-
});
|
|
1803
|
-
}
|
|
1804
|
-
async all(reload = false) {
|
|
1867
|
+
async all(reload) {
|
|
1805
1868
|
if (!reload && this.cache.complete) return this.cache.all();
|
|
1806
|
-
return this.api.request({ url: "/api/" +
|
|
1869
|
+
return this.api.request({ url: "/api/" + PES`users` }).then((resp) => {
|
|
1807
1870
|
resp == null ? void 0 : resp.forEach((r) => {
|
|
1808
1871
|
r.image = this.api.url + r.image + `?token=${this.api.token}`;
|
|
1809
1872
|
return r;
|
|
1810
1873
|
});
|
|
1811
1874
|
this.cache.addAll(resp);
|
|
1812
|
-
this.emit(
|
|
1875
|
+
this.emit(PES`users:r`, resp || []);
|
|
1813
1876
|
return resp;
|
|
1814
1877
|
});
|
|
1815
1878
|
}
|
|
1816
|
-
|
|
1879
|
+
delete(username) {
|
|
1880
|
+
if (!username) throw new Error("Cannot delete user, missing username");
|
|
1881
|
+
return this.api.request({
|
|
1882
|
+
url: "/api/" + PES`users/${username}`,
|
|
1883
|
+
method: "DELETE"
|
|
1884
|
+
}).then(() => {
|
|
1885
|
+
this.cache.delete(username);
|
|
1886
|
+
this.emit(PES`users/${username}:d`, username);
|
|
1887
|
+
});
|
|
1888
|
+
}
|
|
1889
|
+
async read(username, reload) {
|
|
1817
1890
|
if (!username) throw new Error("Cannot read user, missing username");
|
|
1818
1891
|
if (!reload && this.cache.get(username)) return this.cache.get(username);
|
|
1819
|
-
return this.api.request({ url: "/api/" +
|
|
1892
|
+
return this.api.request({ url: "/api/" + PES`users/${username}` }).then((resp) => {
|
|
1820
1893
|
if (resp) {
|
|
1821
1894
|
resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
|
|
1822
1895
|
this.cache.add(resp);
|
|
1823
1896
|
}
|
|
1824
|
-
this.emit(
|
|
1897
|
+
this.emit(PES`users/${username}:r`, resp);
|
|
1825
1898
|
return resp;
|
|
1826
1899
|
});
|
|
1827
1900
|
}
|
|
1828
1901
|
update(user) {
|
|
1829
1902
|
if (!user.username) throw new Error("Cannot update user, missing username");
|
|
1830
1903
|
return this.api.request({
|
|
1831
|
-
url: `/api/` +
|
|
1904
|
+
url: `/api/` + PES`users/${user.username}`,
|
|
1832
1905
|
method: "PATCH",
|
|
1833
1906
|
body: user
|
|
1834
1907
|
}).then((resp) => {
|
|
@@ -1836,19 +1909,16 @@ ${log}`;
|
|
|
1836
1909
|
resp.image = this.api.url + resp.image + `?token=${this.api.token}`;
|
|
1837
1910
|
this.cache.add(resp);
|
|
1838
1911
|
}
|
|
1839
|
-
this.emit(
|
|
1912
|
+
this.emit(PES`users/${user.username}:${resp._id ? "u" : "c"}`, resp);
|
|
1840
1913
|
return resp;
|
|
1841
1914
|
});
|
|
1842
1915
|
}
|
|
1843
1916
|
uploadImage(username, file) {
|
|
1844
1917
|
if (!username || !file) throw new Error("Cannot update user image, missing username or file");
|
|
1845
1918
|
return Ft({
|
|
1846
|
-
url: this.api.url + `/api/` +
|
|
1919
|
+
url: this.api.url + `/api/` + PES`users/${username}/image`,
|
|
1847
1920
|
files: [file],
|
|
1848
1921
|
headers: this.api.headers
|
|
1849
|
-
}).then((resp) => {
|
|
1850
|
-
this.emit(pathedEvent(["users", username, "image"], "u"), username, file);
|
|
1851
|
-
return resp;
|
|
1852
1922
|
});
|
|
1853
1923
|
}
|
|
1854
1924
|
}
|
|
@@ -1861,33 +1931,33 @@ ${log}`;
|
|
|
1861
1931
|
}
|
|
1862
1932
|
async all(detailed = false, reload) {
|
|
1863
1933
|
if (!reload && !detailed && this.cache.complete) return this.cache;
|
|
1864
|
-
return this.api.request({ url: `/api
|
|
1934
|
+
return this.api.request({ url: `/api/` + PES`settings` + (detailed ? "?detailed" : "") }).then((resp) => {
|
|
1865
1935
|
if (resp) Object.keys(resp).forEach((key) => this.cache.set(key, detailed ? resp[key].value : resp[key]));
|
|
1866
|
-
this.emit(
|
|
1936
|
+
this.emit(PES`settings:r`, resp || []);
|
|
1867
1937
|
return resp;
|
|
1868
1938
|
});
|
|
1869
1939
|
}
|
|
1870
1940
|
delete(key) {
|
|
1871
1941
|
if (!key) throw new Error("Cannot delete setting, missing key");
|
|
1872
|
-
return this.api.request({ url: `/api/` +
|
|
1942
|
+
return this.api.request({ url: `/api/` + PES`settings/${key}`, method: "DELETE" }).then(() => {
|
|
1873
1943
|
this.cache.delete(key);
|
|
1874
|
-
this.emit(
|
|
1944
|
+
this.emit(PES`settings/${key}:d`, key);
|
|
1875
1945
|
});
|
|
1876
1946
|
}
|
|
1877
1947
|
read(key, reload = false) {
|
|
1878
1948
|
if (!key) throw new Error("Cannot read setting, missing key");
|
|
1879
1949
|
if (!reload && this.cache.get(key)) return this.cache.get(key);
|
|
1880
|
-
return this.api.request({ url: `/api/` +
|
|
1950
|
+
return this.api.request({ url: `/api/` + PES`settings/${key}` }).then((variable) => {
|
|
1881
1951
|
if (variable) this.cache.set(variable.key, variable.value);
|
|
1882
|
-
this.emit(
|
|
1952
|
+
this.emit(PES`settings/${key}:r`, variable);
|
|
1883
1953
|
return variable;
|
|
1884
1954
|
});
|
|
1885
1955
|
}
|
|
1886
1956
|
update(variable) {
|
|
1887
1957
|
if (!variable.key) throw new Error("Cannot update setting, missing key");
|
|
1888
|
-
return this.api.request({ url: `/api/` +
|
|
1958
|
+
return this.api.request({ url: `/api/` + PES`settings/${variable.key}`, body: variable }).then((variable2) => {
|
|
1889
1959
|
if (variable2) this.cache.set(variable2.key, variable2.value);
|
|
1890
|
-
this.emit(`/api/` +
|
|
1960
|
+
this.emit(`/api/` + PES`settings/${variable2.key}:${variable2._id ? "u" : "c"}`, variable2);
|
|
1891
1961
|
return variable2;
|
|
1892
1962
|
});
|
|
1893
1963
|
}
|
|
@@ -1900,21 +1970,21 @@ ${log}`;
|
|
|
1900
1970
|
}
|
|
1901
1971
|
delete(path) {
|
|
1902
1972
|
if (!path) throw new Error("Cannot delete static asset, missing path");
|
|
1903
|
-
return this.api.request({ url: `/api/` +
|
|
1904
|
-
this.emit(
|
|
1973
|
+
return this.api.request({ url: `/api/` + PES`static/${path}`, method: "DELETE" }).then(() => {
|
|
1974
|
+
this.emit(PES`static/${path}:d`, path);
|
|
1905
1975
|
});
|
|
1906
1976
|
}
|
|
1907
1977
|
upload(files, path = "/") {
|
|
1908
1978
|
if (!files) throw new Error("Cannot upload static assets, missing file");
|
|
1909
1979
|
return new E(async (res, rej, prog) => {
|
|
1910
1980
|
return Ft({
|
|
1911
|
-
url: this.api.url + "/api/" +
|
|
1981
|
+
url: this.api.url + "/api/" + PES`static/${path}`,
|
|
1912
1982
|
files: ft(files),
|
|
1913
1983
|
headers: this.api.headers
|
|
1914
1984
|
}).onProgress((p2) => {
|
|
1915
1985
|
prog(p2);
|
|
1916
1986
|
}).then((resp) => {
|
|
1917
|
-
this.emit(
|
|
1987
|
+
this.emit(PES`static/${path}:c`, resp);
|
|
1918
1988
|
res(resp);
|
|
1919
1989
|
}).catch((err) => rej(err));
|
|
1920
1990
|
});
|
|
@@ -1978,7 +2048,8 @@ ${log}`;
|
|
|
1978
2048
|
this.relayEvents(this.users);
|
|
1979
2049
|
this.users.on(`*`, () => {
|
|
1980
2050
|
if (!this.auth.user) return;
|
|
1981
|
-
|
|
2051
|
+
const cached = this.users.cache.get(this.auth.user.username);
|
|
2052
|
+
if (cached) this.auth.user = cached;
|
|
1982
2053
|
});
|
|
1983
2054
|
}
|
|
1984
2055
|
}
|
|
@@ -1994,6 +2065,9 @@ ${log}`;
|
|
|
1994
2065
|
exports2.Groups = Groups;
|
|
1995
2066
|
exports2.Logger = Logger;
|
|
1996
2067
|
exports2.Momentum = Momentum;
|
|
2068
|
+
exports2.PE = PE;
|
|
2069
|
+
exports2.PES = PES;
|
|
2070
|
+
exports2.PathEvent = PathEvent;
|
|
1997
2071
|
exports2.PathedEventEmitter = PathedEventEmitter;
|
|
1998
2072
|
exports2.Payments = Payments;
|
|
1999
2073
|
exports2.Pdf = Pdf;
|
|
@@ -2003,10 +2077,5 @@ ${log}`;
|
|
|
2003
2077
|
exports2.Storage = Storage;
|
|
2004
2078
|
exports2.Totp = Totp;
|
|
2005
2079
|
exports2.Users = Users;
|
|
2006
|
-
exports2.combinePathedEvents = combinePathedEvents;
|
|
2007
|
-
exports2.hasPath = hasPath;
|
|
2008
|
-
exports2.hasPathFatal = hasPathFatal;
|
|
2009
|
-
exports2.parsePathedEvent = parsePathedEvent;
|
|
2010
|
-
exports2.pathedEvent = pathedEvent;
|
|
2011
2080
|
Object.defineProperty(exports2, Symbol.toStringTag, { value: "Module" });
|
|
2012
2081
|
});
|