@axcode/axcloud-sdk 0.1.3 → 0.1.5

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.mjs CHANGED
@@ -704,6 +704,7 @@ function useNews(options = {}) {
704
704
  };
705
705
  }
706
706
  var MEMBER_ENDPOINT_TYPES = ["news", "pages", "events"];
707
+ var PAGE_CONTENT_TYPES = ["page", "pages"];
707
708
  function useContent(contentType, options = {}) {
708
709
  const { client, orgId, isPublicMode } = useAxCloudContext();
709
710
  const {
@@ -715,7 +716,8 @@ function useContent(contentType, options = {}) {
715
716
  sectionId,
716
717
  search,
717
718
  sortBy = "createdAt",
718
- sortOrder = "desc"
719
+ sortOrder = "desc",
720
+ lang
719
721
  } = options;
720
722
  const query = useQuery({
721
723
  queryKey: [
@@ -732,7 +734,8 @@ function useContent(contentType, options = {}) {
732
734
  sectionId,
733
735
  search,
734
736
  sortBy,
735
- sortOrder
737
+ sortOrder,
738
+ lang
736
739
  ],
737
740
  queryFn: async () => {
738
741
  const useMemberEndpoint = !isPublicMode && !publicOnly && MEMBER_ENDPOINT_TYPES.includes(contentType);
@@ -745,7 +748,8 @@ function useContent(contentType, options = {}) {
745
748
  sectionId,
746
749
  search,
747
750
  sortBy,
748
- sortOrder
751
+ sortOrder,
752
+ lang
749
753
  });
750
754
  },
751
755
  staleTime: 1e3 * 60 * 5
@@ -763,13 +767,15 @@ function useContent(contentType, options = {}) {
763
767
  }
764
768
  function useContentItem(contentType, idOrSlug, options = {}) {
765
769
  const { client, orgId, isPublicMode } = useAxCloudContext();
766
- const { publicOnly = false } = options;
767
- const useMemberEndpoint = !isPublicMode && !publicOnly && MEMBER_ENDPOINT_TYPES.includes(contentType);
770
+ const { publicOnly = false, lang } = options;
771
+ const useMemberEndpoint = !isPublicMode && !publicOnly && (MEMBER_ENDPOINT_TYPES.includes(contentType) || PAGE_CONTENT_TYPES.includes(contentType));
768
772
  const query = useQuery({
769
- queryKey: ["axcloud", "content", orgId, contentType, idOrSlug, useMemberEndpoint],
773
+ queryKey: ["axcloud", "content", orgId, contentType, idOrSlug, useMemberEndpoint, lang],
770
774
  queryFn: async () => {
771
775
  const basePath = useMemberEndpoint ? "members" : "public";
772
- return client.get(`/content/${basePath}/${orgId}/${contentType}/${idOrSlug}`);
776
+ const encodedIdOrSlug = encodeURIComponent(idOrSlug);
777
+ const endpoint = PAGE_CONTENT_TYPES.includes(contentType) ? `/content/${basePath}/${orgId}/page/${encodedIdOrSlug}` : `/content/${basePath}/${orgId}/${contentType}/${encodedIdOrSlug}`;
778
+ return lang ? client.get(endpoint, { lang }) : client.get(endpoint);
773
779
  },
774
780
  enabled: !!idOrSlug,
775
781
  staleTime: 1e3 * 60 * 5
@@ -794,11 +800,11 @@ function useMySection(options = {}) {
794
800
  if (!sectionId) {
795
801
  throw new Error("User is not assigned to a section");
796
802
  }
797
- const section = await client.get(
803
+ const response = await client.get(
798
804
  `/orgs/api/organizations/${orgId}/sections/${sectionId}`,
799
805
  { includeMembers: includeMembers ? "true" : void 0 }
800
806
  );
801
- return section;
807
+ return "success" in response && response.success === true && response.data ? response.data : response;
802
808
  },
803
809
  enabled: isAuthenticated && !isUserLoading && !!sectionId,
804
810
  staleTime: 1e3 * 60 * 5
@@ -824,7 +830,8 @@ function useSections() {
824
830
  const query = useQuery({
825
831
  queryKey: ["axcloud", "sections", orgId, stage],
826
832
  queryFn: async () => {
827
- return client.get(`/orgs/api/organizations/${orgId}/sections`);
833
+ const response = await client.get(`/orgs/api/organizations/${orgId}/sections`);
834
+ return "success" in response && response.success === true && response.data ? response.data : response;
828
835
  },
829
836
  staleTime: 1e3 * 60 * 10
830
837
  // 10 minutes