@mx-cartographer/experiences 6.0.8 → 6.0.9-alpha.mm1
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/common/utils/Fetch.d.ts +6 -5
- package/dist/index.es.js +45 -36
- package/dist/index.es.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
export declare class Fetch {
|
|
2
2
|
endpoint: string;
|
|
3
|
-
headers:
|
|
3
|
+
headers: Record<string, string>;
|
|
4
4
|
constructor(endpoint: string, token: string);
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
private mergeHeaders;
|
|
6
|
+
get: (url: string, customHeaders?: Record<string, string | null>) => Promise<any>;
|
|
7
|
+
post: (url: string, data?: any, customHeaders?: Record<string, string | null>) => Promise<any>;
|
|
8
|
+
put: (url: string, data: any, customHeaders?: Record<string, string | null>) => Promise<any>;
|
|
9
|
+
delete: (url: string, customHeaders?: Record<string, string | null>) => Promise<any>;
|
|
9
10
|
}
|
|
10
11
|
export default Fetch;
|
package/dist/index.es.js
CHANGED
|
@@ -853,54 +853,61 @@ class Ae {
|
|
|
853
853
|
"MD-Session-Token": i
|
|
854
854
|
};
|
|
855
855
|
}
|
|
856
|
-
|
|
857
|
-
|
|
856
|
+
// Helper to merge headers dynamically
|
|
857
|
+
mergeHeaders = (t = {}) => {
|
|
858
|
+
const i = { ...this.headers };
|
|
859
|
+
return Object.keys(t).forEach((n) => {
|
|
860
|
+
t[n] === null ? delete i[n] : i[n] = t[n];
|
|
861
|
+
}), i;
|
|
862
|
+
};
|
|
863
|
+
get = async (t, i = {}) => {
|
|
864
|
+
const n = {
|
|
858
865
|
method: "GET",
|
|
859
|
-
headers: this.
|
|
866
|
+
headers: this.mergeHeaders(i)
|
|
860
867
|
};
|
|
861
|
-
return fetch(`${this.endpoint}${t}`,
|
|
862
|
-
if (
|
|
863
|
-
return
|
|
864
|
-
throw
|
|
865
|
-
}).then((
|
|
866
|
-
throw Ei.notify(
|
|
868
|
+
return fetch(`${this.endpoint}${t}`, n).then((r) => {
|
|
869
|
+
if (r.ok)
|
|
870
|
+
return r.text();
|
|
871
|
+
throw r;
|
|
872
|
+
}).then((r) => r.length ? JSON.parse(r) : {}).then((r) => r).catch((r) => {
|
|
873
|
+
throw Ei.notify(r), r;
|
|
867
874
|
});
|
|
868
875
|
};
|
|
869
|
-
post = async (t, i) => {
|
|
870
|
-
const
|
|
876
|
+
post = async (t, i, n = {}) => {
|
|
877
|
+
const r = i ? JSON.stringify(i) : void 0, o = {
|
|
871
878
|
method: "POST",
|
|
872
|
-
headers: this.
|
|
873
|
-
body:
|
|
879
|
+
headers: this.mergeHeaders(n),
|
|
880
|
+
body: r
|
|
874
881
|
};
|
|
875
|
-
return fetch(`${this.endpoint}${t}`,
|
|
876
|
-
if (!
|
|
877
|
-
throw
|
|
878
|
-
return
|
|
879
|
-
}).then((
|
|
880
|
-
throw Ei.notify(
|
|
882
|
+
return fetch(`${this.endpoint}${t}`, o).then((a) => {
|
|
883
|
+
if (!a.ok)
|
|
884
|
+
throw a;
|
|
885
|
+
return a.text();
|
|
886
|
+
}).then((a) => a.length ? JSON.parse(a) : {}).then((a) => a).catch((a) => {
|
|
887
|
+
throw Ei.notify(a), a;
|
|
881
888
|
});
|
|
882
889
|
};
|
|
883
|
-
put = async (t, i) => {
|
|
884
|
-
const
|
|
890
|
+
put = async (t, i, n = {}) => {
|
|
891
|
+
const r = JSON.stringify(i), o = {
|
|
885
892
|
method: "PUT",
|
|
886
|
-
headers: this.
|
|
887
|
-
body:
|
|
893
|
+
headers: this.mergeHeaders(n),
|
|
894
|
+
body: r
|
|
888
895
|
};
|
|
889
|
-
return fetch(`${this.endpoint}${t}`,
|
|
890
|
-
throw new Error(
|
|
891
|
-
})).then((
|
|
892
|
-
throw Ei.notify(
|
|
896
|
+
return fetch(`${this.endpoint}${t}`, o).then((a) => a.ok ? a.text() : a.text().then((s) => {
|
|
897
|
+
throw new Error(s);
|
|
898
|
+
})).then((a) => a.length ? JSON.parse(a) : {}).then((a) => a).catch((a) => {
|
|
899
|
+
throw Ei.notify(a), a;
|
|
893
900
|
});
|
|
894
901
|
};
|
|
895
|
-
delete = async (t) => {
|
|
896
|
-
const
|
|
902
|
+
delete = async (t, i = {}) => {
|
|
903
|
+
const n = {
|
|
897
904
|
method: "DELETE",
|
|
898
|
-
headers: this.
|
|
905
|
+
headers: this.mergeHeaders(i)
|
|
899
906
|
};
|
|
900
|
-
return fetch(`${this.endpoint}${t}`,
|
|
901
|
-
throw new Error(
|
|
902
|
-
})).then((
|
|
903
|
-
throw Ei.notify(
|
|
907
|
+
return fetch(`${this.endpoint}${t}`, n).then((r) => r.ok ? r.text() : r.text().then((o) => {
|
|
908
|
+
throw new Error(o);
|
|
909
|
+
})).then((r) => r.length ? JSON.parse(r) : {}).then((r) => r).catch((r) => {
|
|
910
|
+
throw Ei.notify(r), r;
|
|
904
911
|
});
|
|
905
912
|
};
|
|
906
913
|
}
|
|
@@ -994,8 +1001,10 @@ class Cr {
|
|
|
994
1001
|
}
|
|
995
1002
|
getBanner = async (t) => {
|
|
996
1003
|
try {
|
|
997
|
-
const i = `/banner/${t}/account_widget_banner
|
|
998
|
-
|
|
1004
|
+
const i = `/banner/${t}/account_widget_banner`, n = {
|
|
1005
|
+
"MD-Session-Token": null
|
|
1006
|
+
};
|
|
1007
|
+
return this.fetchInstance?.get(i, n).then((r) => r.banner) ?? {};
|
|
999
1008
|
} catch (i) {
|
|
1000
1009
|
return console.error("Error fetching banner:", i), null;
|
|
1001
1010
|
}
|