warqadui 0.0.301 → 0.0.303

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.mts CHANGED
@@ -447,6 +447,7 @@ type EnumsConfig = {
447
447
  };
448
448
  interface WarqadConfig {
449
449
  api?: string;
450
+ apiHeaders?: Record<string, any>;
450
451
  socketUrl?: string;
451
452
  apiConfig?: apiConfig;
452
453
  theme?: ThemeConfig;
@@ -481,6 +482,7 @@ interface WarqadConfig {
481
482
  interface WarqadConfigContextType {
482
483
  config: WarqadConfig & {
483
484
  api: string;
485
+ apiHeaders?: Record<string, any>;
484
486
  apiConfig: Required<apiConfig>;
485
487
  theme: Required<ThemeConfig>;
486
488
  store: Required<StoreConfig>;
@@ -496,6 +498,7 @@ interface WarqadConfigContextType {
496
498
  */
497
499
  declare const useWarqadConfig: () => WarqadConfig & {
498
500
  api: string;
501
+ apiHeaders?: Record<string, any>;
499
502
  apiConfig: Required<apiConfig>;
500
503
  theme: Required<ThemeConfig>;
501
504
  store: Required<StoreConfig>;
@@ -911,6 +914,7 @@ interface FetchProps {
911
914
  }) => void;
912
915
  };
913
916
  multipart?: boolean;
917
+ headers?: Record<string, any>;
914
918
  }
915
919
  type FetchFunction = (props: Omit<FetchProps, "body">) => Promise<any>;
916
920
  type PostFunction = (props: FetchProps) => Promise<any>;
@@ -925,7 +929,7 @@ declare const useApi: () => {
925
929
  post: PostFunction;
926
930
  put: PutFunction;
927
931
  remove: DeleteFunction;
928
- fetchPdf: ({ url, v, method, body, }: FetchProps & {
932
+ fetchPdf: ({ url, v, method, body, headers, }: FetchProps & {
929
933
  method: "GET" | "POST";
930
934
  }) => Promise<{
931
935
  ok: boolean;
package/dist/index.d.ts CHANGED
@@ -447,6 +447,7 @@ type EnumsConfig = {
447
447
  };
448
448
  interface WarqadConfig {
449
449
  api?: string;
450
+ apiHeaders?: Record<string, any>;
450
451
  socketUrl?: string;
451
452
  apiConfig?: apiConfig;
452
453
  theme?: ThemeConfig;
@@ -481,6 +482,7 @@ interface WarqadConfig {
481
482
  interface WarqadConfigContextType {
482
483
  config: WarqadConfig & {
483
484
  api: string;
485
+ apiHeaders?: Record<string, any>;
484
486
  apiConfig: Required<apiConfig>;
485
487
  theme: Required<ThemeConfig>;
486
488
  store: Required<StoreConfig>;
@@ -496,6 +498,7 @@ interface WarqadConfigContextType {
496
498
  */
497
499
  declare const useWarqadConfig: () => WarqadConfig & {
498
500
  api: string;
501
+ apiHeaders?: Record<string, any>;
499
502
  apiConfig: Required<apiConfig>;
500
503
  theme: Required<ThemeConfig>;
501
504
  store: Required<StoreConfig>;
@@ -911,6 +914,7 @@ interface FetchProps {
911
914
  }) => void;
912
915
  };
913
916
  multipart?: boolean;
917
+ headers?: Record<string, any>;
914
918
  }
915
919
  type FetchFunction = (props: Omit<FetchProps, "body">) => Promise<any>;
916
920
  type PostFunction = (props: FetchProps) => Promise<any>;
@@ -925,7 +929,7 @@ declare const useApi: () => {
925
929
  post: PostFunction;
926
930
  put: PutFunction;
927
931
  remove: DeleteFunction;
928
- fetchPdf: ({ url, v, method, body, }: FetchProps & {
932
+ fetchPdf: ({ url, v, method, body, headers, }: FetchProps & {
929
933
  method: "GET" | "POST";
930
934
  }) => Promise<{
931
935
  ok: boolean;
package/dist/index.js CHANGED
@@ -415,6 +415,7 @@ var WarqadProvider = ({ children, config }) => {
415
415
  const mergedConfig = (0, import_react2.useMemo)(
416
416
  () => ({
417
417
  api: config?.api || DEFAULT_API,
418
+ apiHeaders: config?.apiHeaders,
418
419
  socketUrl: config?.socketUrl,
419
420
  apiConfig: {
420
421
  ...DEFAULT_API_CONFIG,
@@ -733,7 +734,7 @@ var getToken = () => {
733
734
  return localStorage.getItem("token");
734
735
  };
735
736
  var useApi = () => {
736
- const { api: configApi } = useWarqadConfig();
737
+ const { api: configApi, apiHeaders } = useWarqadConfig();
737
738
  const api = (0, import_react5.useMemo)(() => {
738
739
  const baseURL = configApi || "/api";
739
740
  return import_axios.default.create({
@@ -745,14 +746,18 @@ var useApi = () => {
745
746
  const [isLoading, setIsLoading] = (0, import_react5.useState)(false);
746
747
  const [pdfLoading, setPdfLoading] = (0, import_react5.useState)(false);
747
748
  const [error, setError] = (0, import_react5.useState)(null);
748
- const get = async ({ url, v = 1, params, delay }) => {
749
+ const get = async ({ url, v = 1, params, delay, headers }) => {
749
750
  setIsLoading(true);
750
751
  try {
751
752
  if (delay) await new Promise((r) => setTimeout(r, delay));
752
753
  const prefix = v === 0 ? "" : `/v${v}`;
753
754
  const response = await api.get(`${prefix}${url}`, {
754
755
  params,
755
- headers: { Authorization: `Bearer ${getToken()}` }
756
+ headers: {
757
+ Authorization: `Bearer ${getToken()}`,
758
+ ...apiHeaders,
759
+ ...headers
760
+ }
756
761
  });
757
762
  setData(response.data);
758
763
  setError(null);
@@ -771,7 +776,8 @@ var useApi = () => {
771
776
  v = 1,
772
777
  body,
773
778
  form,
774
- multipart = false
779
+ multipart = false,
780
+ headers
775
781
  }) => {
776
782
  setIsLoading(true);
777
783
  try {
@@ -799,13 +805,19 @@ var useApi = () => {
799
805
  response = await api.post(`${prefix}${url}`, formData, {
800
806
  headers: {
801
807
  "Content-Type": "multipart/form-data",
802
- Authorization: `Bearer ${getToken()}`
808
+ Authorization: `Bearer ${getToken()}`,
809
+ ...apiHeaders,
810
+ ...headers
803
811
  }
804
812
  });
805
813
  } else {
806
814
  const prefix = v === 0 ? "" : `/v${v}`;
807
815
  response = await api.post(`${prefix}${url}`, body, {
808
- headers: { Authorization: `Bearer ${getToken()}` }
816
+ headers: {
817
+ Authorization: `Bearer ${getToken()}`,
818
+ ...apiHeaders,
819
+ ...headers
820
+ }
809
821
  });
810
822
  }
811
823
  setData(response.data);
@@ -828,12 +840,16 @@ var useApi = () => {
828
840
  setIsLoading(false);
829
841
  }
830
842
  };
831
- const put = async ({ url, v = 1, body }) => {
843
+ const put = async ({ url, v = 1, body, headers }) => {
832
844
  setIsLoading(true);
833
845
  try {
834
846
  const prefix = v === 0 ? "" : `/v${v}`;
835
847
  const response = await api.put(`${prefix}${url}`, body, {
836
- headers: { Authorization: `Bearer ${getToken()}` }
848
+ headers: {
849
+ Authorization: `Bearer ${getToken()}`,
850
+ ...apiHeaders,
851
+ ...headers
852
+ }
837
853
  });
838
854
  setData(response.data);
839
855
  return response.data;
@@ -845,13 +861,17 @@ var useApi = () => {
845
861
  setIsLoading(false);
846
862
  }
847
863
  };
848
- const remove = async ({ url, v = 1, params }) => {
864
+ const remove = async ({ url, v = 1, params, headers }) => {
849
865
  setIsLoading(true);
850
866
  try {
851
867
  const prefix = v === 0 ? "" : `/v${v}`;
852
868
  const response = await api.delete(`${prefix}${url}`, {
853
869
  params,
854
- headers: { Authorization: `Bearer ${getToken()}` }
870
+ headers: {
871
+ Authorization: `Bearer ${getToken()}`,
872
+ ...apiHeaders,
873
+ ...headers
874
+ }
855
875
  });
856
876
  setData(response.data);
857
877
  setError(null);
@@ -869,7 +889,8 @@ var useApi = () => {
869
889
  url,
870
890
  v = 1,
871
891
  method,
872
- body
892
+ body,
893
+ headers
873
894
  }) => {
874
895
  setPdfLoading(true);
875
896
  try {
@@ -878,7 +899,11 @@ var useApi = () => {
878
899
  method,
879
900
  data: body,
880
901
  responseType: "blob",
881
- headers: { Authorization: `Bearer ${getToken()}` }
902
+ headers: {
903
+ Authorization: `Bearer ${getToken()}`,
904
+ ...apiHeaders,
905
+ ...headers
906
+ }
882
907
  });
883
908
  if (!response.data || response.data.size === 0) {
884
909
  return { ok: false, message: "Received empty PDF file", errors: [] };
package/dist/index.mjs CHANGED
@@ -196,6 +196,7 @@ var WarqadProvider = ({ children, config }) => {
196
196
  const mergedConfig = useMemo(
197
197
  () => ({
198
198
  api: config?.api || DEFAULT_API,
199
+ apiHeaders: config?.apiHeaders,
199
200
  socketUrl: config?.socketUrl,
200
201
  apiConfig: {
201
202
  ...DEFAULT_API_CONFIG,
@@ -514,7 +515,7 @@ var getToken = () => {
514
515
  return localStorage.getItem("token");
515
516
  };
516
517
  var useApi = () => {
517
- const { api: configApi } = useWarqadConfig();
518
+ const { api: configApi, apiHeaders } = useWarqadConfig();
518
519
  const api = useMemo2(() => {
519
520
  const baseURL = configApi || "/api";
520
521
  return axios.create({
@@ -526,14 +527,18 @@ var useApi = () => {
526
527
  const [isLoading, setIsLoading] = useState3(false);
527
528
  const [pdfLoading, setPdfLoading] = useState3(false);
528
529
  const [error, setError] = useState3(null);
529
- const get = async ({ url, v = 1, params, delay }) => {
530
+ const get = async ({ url, v = 1, params, delay, headers }) => {
530
531
  setIsLoading(true);
531
532
  try {
532
533
  if (delay) await new Promise((r) => setTimeout(r, delay));
533
534
  const prefix = v === 0 ? "" : `/v${v}`;
534
535
  const response = await api.get(`${prefix}${url}`, {
535
536
  params,
536
- headers: { Authorization: `Bearer ${getToken()}` }
537
+ headers: {
538
+ Authorization: `Bearer ${getToken()}`,
539
+ ...apiHeaders,
540
+ ...headers
541
+ }
537
542
  });
538
543
  setData(response.data);
539
544
  setError(null);
@@ -552,7 +557,8 @@ var useApi = () => {
552
557
  v = 1,
553
558
  body,
554
559
  form,
555
- multipart = false
560
+ multipart = false,
561
+ headers
556
562
  }) => {
557
563
  setIsLoading(true);
558
564
  try {
@@ -580,13 +586,19 @@ var useApi = () => {
580
586
  response = await api.post(`${prefix}${url}`, formData, {
581
587
  headers: {
582
588
  "Content-Type": "multipart/form-data",
583
- Authorization: `Bearer ${getToken()}`
589
+ Authorization: `Bearer ${getToken()}`,
590
+ ...apiHeaders,
591
+ ...headers
584
592
  }
585
593
  });
586
594
  } else {
587
595
  const prefix = v === 0 ? "" : `/v${v}`;
588
596
  response = await api.post(`${prefix}${url}`, body, {
589
- headers: { Authorization: `Bearer ${getToken()}` }
597
+ headers: {
598
+ Authorization: `Bearer ${getToken()}`,
599
+ ...apiHeaders,
600
+ ...headers
601
+ }
590
602
  });
591
603
  }
592
604
  setData(response.data);
@@ -609,12 +621,16 @@ var useApi = () => {
609
621
  setIsLoading(false);
610
622
  }
611
623
  };
612
- const put = async ({ url, v = 1, body }) => {
624
+ const put = async ({ url, v = 1, body, headers }) => {
613
625
  setIsLoading(true);
614
626
  try {
615
627
  const prefix = v === 0 ? "" : `/v${v}`;
616
628
  const response = await api.put(`${prefix}${url}`, body, {
617
- headers: { Authorization: `Bearer ${getToken()}` }
629
+ headers: {
630
+ Authorization: `Bearer ${getToken()}`,
631
+ ...apiHeaders,
632
+ ...headers
633
+ }
618
634
  });
619
635
  setData(response.data);
620
636
  return response.data;
@@ -626,13 +642,17 @@ var useApi = () => {
626
642
  setIsLoading(false);
627
643
  }
628
644
  };
629
- const remove = async ({ url, v = 1, params }) => {
645
+ const remove = async ({ url, v = 1, params, headers }) => {
630
646
  setIsLoading(true);
631
647
  try {
632
648
  const prefix = v === 0 ? "" : `/v${v}`;
633
649
  const response = await api.delete(`${prefix}${url}`, {
634
650
  params,
635
- headers: { Authorization: `Bearer ${getToken()}` }
651
+ headers: {
652
+ Authorization: `Bearer ${getToken()}`,
653
+ ...apiHeaders,
654
+ ...headers
655
+ }
636
656
  });
637
657
  setData(response.data);
638
658
  setError(null);
@@ -650,7 +670,8 @@ var useApi = () => {
650
670
  url,
651
671
  v = 1,
652
672
  method,
653
- body
673
+ body,
674
+ headers
654
675
  }) => {
655
676
  setPdfLoading(true);
656
677
  try {
@@ -659,7 +680,11 @@ var useApi = () => {
659
680
  method,
660
681
  data: body,
661
682
  responseType: "blob",
662
- headers: { Authorization: `Bearer ${getToken()}` }
683
+ headers: {
684
+ Authorization: `Bearer ${getToken()}`,
685
+ ...apiHeaders,
686
+ ...headers
687
+ }
663
688
  });
664
689
  if (!response.data || response.data.size === 0) {
665
690
  return { ok: false, message: "Received empty PDF file", errors: [] };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "warqadui",
3
- "version": "0.0.301",
3
+ "version": "0.0.303",
4
4
  "main": "./dist/index.js",
5
5
  "module": "./dist/index.mjs",
6
6
  "types": "./dist/index.d.ts",