@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.
@@ -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
- get: (url: string) => Promise<any>;
6
- post: (url: string, data?: any) => Promise<any>;
7
- put: (url: string, data: any) => Promise<any>;
8
- delete: (url: string) => Promise<any>;
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
- get = async (t) => {
857
- const i = {
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.headers
866
+ headers: this.mergeHeaders(i)
860
867
  };
861
- return fetch(`${this.endpoint}${t}`, i).then((n) => {
862
- if (n.ok)
863
- return n.text();
864
- throw n;
865
- }).then((n) => n.length ? JSON.parse(n) : {}).then((n) => n).catch((n) => {
866
- throw Ei.notify(n), n;
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 n = i ? JSON.stringify(i) : void 0, r = {
876
+ post = async (t, i, n = {}) => {
877
+ const r = i ? JSON.stringify(i) : void 0, o = {
871
878
  method: "POST",
872
- headers: this.headers,
873
- body: n
879
+ headers: this.mergeHeaders(n),
880
+ body: r
874
881
  };
875
- return fetch(`${this.endpoint}${t}`, r).then((o) => {
876
- if (!o.ok)
877
- throw o;
878
- return o.text();
879
- }).then((o) => o.length ? JSON.parse(o) : {}).then((o) => o).catch((o) => {
880
- throw Ei.notify(o), o;
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 n = JSON.stringify(i), r = {
890
+ put = async (t, i, n = {}) => {
891
+ const r = JSON.stringify(i), o = {
885
892
  method: "PUT",
886
- headers: this.headers,
887
- body: n
893
+ headers: this.mergeHeaders(n),
894
+ body: r
888
895
  };
889
- return fetch(`${this.endpoint}${t}`, r).then((o) => o.ok ? o.text() : o.text().then((a) => {
890
- throw new Error(a);
891
- })).then((o) => o.length ? JSON.parse(o) : {}).then((o) => o).catch((o) => {
892
- throw Ei.notify(o), o;
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 i = {
902
+ delete = async (t, i = {}) => {
903
+ const n = {
897
904
  method: "DELETE",
898
- headers: this.headers
905
+ headers: this.mergeHeaders(i)
899
906
  };
900
- return fetch(`${this.endpoint}${t}`, i).then((n) => n.ok ? n.text() : n.text().then((r) => {
901
- throw new Error(r);
902
- })).then((n) => n.length ? JSON.parse(n) : {}).then((n) => n).catch((n) => {
903
- throw Ei.notify(n), n;
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
- return this.fetchInstance?.get(i).then((n) => n.banner) ?? {};
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
  }