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