@connectedxm/client 0.1.8 → 0.1.20

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.js CHANGED
@@ -4803,7 +4803,14 @@ var useGetLevelSponsors = (levelId = "", params = {}, options = {}) => {
4803
4803
  // src/mutations/useConnectedMutation.ts
4804
4804
  var import_react_query4 = require("@tanstack/react-query");
4805
4805
  var useConnectedMutation = (mutation, options) => {
4806
- const { locale, apiUrl, getToken, organizationId, getExecuteAs } = useConnectedXM();
4806
+ const {
4807
+ locale,
4808
+ apiUrl,
4809
+ getToken,
4810
+ organizationId,
4811
+ getExecuteAs,
4812
+ onMutationError
4813
+ } = useConnectedXM();
4807
4814
  const queryClient = (0, import_react_query4.useQueryClient)();
4808
4815
  return (0, import_react_query4.useMutation)({
4809
4816
  mutationFn: (data) => mutation({
@@ -4817,7 +4824,13 @@ var useConnectedMutation = (mutation, options) => {
4817
4824
  },
4818
4825
  ...data
4819
4826
  }),
4820
- ...options
4827
+ ...options,
4828
+ onError: (error, variables, context) => {
4829
+ if (onMutationError)
4830
+ onMutationError(error, variables, context);
4831
+ if (options?.onError)
4832
+ options.onError(error, variables, context);
4833
+ }
4821
4834
  });
4822
4835
  };
4823
4836
  var useConnectedMutation_default = useConnectedMutation;
@@ -4877,58 +4890,36 @@ var useUnfollowAccount = (options = {}) => {
4877
4890
  };
4878
4891
 
4879
4892
  // src/mutations/activities/optimistic/UpdateReshares.ts
4893
+ var import_immer2 = require("immer");
4880
4894
  var UpdateResharesSingle = (increment, queryClient, KEY) => {
4881
- queryClient.setQueryData(KEY, (data) => {
4882
- if (!data?.data) {
4883
- return data;
4884
- }
4885
- data = data.data;
4886
- if (typeof data?._count != "undefined") {
4887
- return {
4888
- data: {
4889
- ...data,
4890
- _count: {
4891
- ...data._count,
4892
- reshares: increment ? data._count.reshares + 1 : data._count.reshares - 1
4893
- },
4894
- reshares: increment ? [{}] : void 0
4895
- }
4896
- };
4897
- }
4898
- });
4895
+ queryClient.setQueryData(
4896
+ KEY,
4897
+ (originalData) => (0, import_immer2.produce)(originalData, (draft) => {
4898
+ if (!draft?.data) {
4899
+ return;
4900
+ }
4901
+ draft.data._count.reshares += increment ? 1 : -1;
4902
+ draft.data.reshares = increment ? [{ id: Date.now().toString() }] : [];
4903
+ })
4904
+ );
4899
4905
  };
4900
4906
  var UpdateResharesInfinite = (increment, queryClient, KEY, activityId) => {
4901
- queryClient.setQueriesData({ queryKey: KEY, exact: false }, (data) => {
4902
- if (!data?.pages || data?.pages?.length === 0) {
4903
- return data;
4904
- }
4905
- const pages = data.pages;
4906
- let activityIndex;
4907
- let pageIndex;
4908
- let reshareActivityIndex;
4909
- let resharePageIndex;
4910
- for (let x = 0; x < pages?.length; x++) {
4911
- for (let y = 0; y < pages?.[x]?.data?.length; y++) {
4912
- if (pages?.[x]?.data?.[y]?.id === activityId) {
4913
- pageIndex = x;
4914
- activityIndex = y;
4915
- }
4916
- if (pages?.[x]?.data?.[y]?.reshared?.id === activityId) {
4917
- resharePageIndex = x;
4918
- reshareActivityIndex = y;
4907
+ queryClient.setQueriesData(
4908
+ { queryKey: KEY, exact: false },
4909
+ (originalData) => (0, import_immer2.produce)(originalData, (draft) => {
4910
+ if (!draft?.pages || draft.pages.length === 0) {
4911
+ return;
4912
+ }
4913
+ for (const page of draft.pages) {
4914
+ for (const activity of page.data) {
4915
+ if (activity.id === activityId) {
4916
+ activity._count.reshares += increment ? 1 : -1;
4917
+ activity.reshares = increment ? [{ id: Date.now().toString() }] : [];
4918
+ }
4919
4919
  }
4920
4920
  }
4921
- }
4922
- if (typeof pageIndex != "undefined" && typeof activityIndex != "undefined") {
4923
- pages[pageIndex].data[activityIndex]._count.reshares = increment ? pages?.[pageIndex]?.data[activityIndex]._count.reshares + 1 : pages?.[pageIndex]?.data[activityIndex]._count.reshares - 1;
4924
- pages[pageIndex].data[activityIndex].reshares = increment ? [{}] : void 0;
4925
- }
4926
- if (typeof resharePageIndex != "undefined" && typeof reshareActivityIndex != "undefined") {
4927
- pages[resharePageIndex].data[reshareActivityIndex].reshared._count.reshares = increment ? pages?.[resharePageIndex]?.data[reshareActivityIndex].reshared._count.reshares + 1 : pages?.[resharePageIndex]?.data[reshareActivityIndex].reshared._count.reshares - 1;
4928
- pages[resharePageIndex].data[reshareActivityIndex].reshared.reshares = increment ? [{}] : void 0;
4929
- }
4930
- return { ...data, pages };
4931
- });
4921
+ })
4922
+ );
4932
4923
  };
4933
4924
 
4934
4925
  // src/mutations/activities/useDeleteReshare.ts
@@ -4938,7 +4929,10 @@ var DeleteReshare = async ({
4938
4929
  queryClient
4939
4930
  }) => {
4940
4931
  if (queryClient) {
4941
- UpdateResharesSingle(false, queryClient, ACTIVITY_QUERY_KEY(activityId));
4932
+ UpdateResharesSingle(false, queryClient, [
4933
+ ...ACTIVITY_QUERY_KEY(activityId),
4934
+ ...GetBaseSingleQueryKeys(clientApiParams.locale)
4935
+ ]);
4942
4936
  UpdateResharesInfinite(
4943
4937
  false,
4944
4938
  queryClient,
@@ -4957,58 +4951,36 @@ var useDeleteReshare = (options = {}) => {
4957
4951
  };
4958
4952
 
4959
4953
  // src/mutations/activities/optimistic/UpdateLikes.ts
4954
+ var import_immer3 = require("immer");
4960
4955
  var UpdateLikesSingle = (increment, queryClient, KEY) => {
4961
- queryClient.setQueryData(KEY, (data) => {
4962
- if (!data?.data) {
4963
- return data;
4964
- }
4965
- data = data.data;
4966
- if (typeof data?._count != "undefined") {
4967
- return {
4968
- data: {
4969
- ...data,
4970
- _count: {
4971
- ...data._count,
4972
- likes: increment ? data._count.likes + 1 : data._count.likes - 1
4973
- },
4974
- likes: increment ? [{}] : void 0
4975
- }
4976
- };
4977
- }
4978
- });
4956
+ queryClient.setQueryData(
4957
+ KEY,
4958
+ (originalData) => (0, import_immer3.produce)(originalData, (draft) => {
4959
+ if (!draft?.data) {
4960
+ return;
4961
+ }
4962
+ draft.data._count.likes += increment ? 1 : -1;
4963
+ draft.data.likes = increment ? [{ createdAt: (/* @__PURE__ */ new Date()).toISOString() }] : [];
4964
+ })
4965
+ );
4979
4966
  };
4980
4967
  var UpdateLikesInfinite = (increment, queryClient, KEY, activityId) => {
4981
- queryClient.setQueriesData({ queryKey: KEY, exact: false }, (data) => {
4982
- if (!data?.pages || data?.pages?.length === 0) {
4983
- return data;
4984
- }
4985
- const pages = data.pages;
4986
- let activityIndex;
4987
- let pageIndex;
4988
- let reshareActivityIndex;
4989
- let resharePageIndex;
4990
- for (let x = 0; x < pages?.length; x++) {
4991
- for (let y = 0; y < pages?.[x]?.data?.length; y++) {
4992
- if (pages?.[x]?.data?.[y]?.id === activityId) {
4993
- pageIndex = x;
4994
- activityIndex = y;
4995
- }
4996
- if (pages?.[x]?.data?.[y]?.reshared?.id === activityId) {
4997
- resharePageIndex = x;
4998
- reshareActivityIndex = y;
4968
+ queryClient.setQueriesData(
4969
+ { queryKey: KEY, exact: false },
4970
+ (originalData) => (0, import_immer3.produce)(originalData, (draft) => {
4971
+ if (!draft?.pages || draft.pages.length === 0) {
4972
+ return;
4973
+ }
4974
+ for (const page of draft.pages) {
4975
+ for (const activity of page.data) {
4976
+ if (activity.id === activityId) {
4977
+ activity._count.likes += increment ? 1 : -1;
4978
+ activity.likes = increment ? [{ createdAt: (/* @__PURE__ */ new Date()).toISOString() }] : [];
4979
+ }
4999
4980
  }
5000
4981
  }
5001
- }
5002
- if (typeof pageIndex != "undefined" && typeof activityIndex != "undefined") {
5003
- pages[pageIndex].data[activityIndex]._count.likes = increment ? pages?.[pageIndex]?.data[activityIndex]._count.likes + 1 : pages?.[pageIndex]?.data[activityIndex]._count.likes - 1;
5004
- pages[pageIndex].data[activityIndex].likes = increment ? [{}] : void 0;
5005
- }
5006
- if (typeof resharePageIndex != "undefined" && typeof reshareActivityIndex != "undefined") {
5007
- pages[resharePageIndex].data[reshareActivityIndex].reshared._count.likes = increment ? pages?.[resharePageIndex]?.data[reshareActivityIndex].reshared._count.likes + 1 : pages?.[resharePageIndex]?.data[reshareActivityIndex].reshared._count.likes - 1;
5008
- pages[resharePageIndex].data[reshareActivityIndex].reshared.likes = increment ? [{}] : void 0;
5009
- }
5010
- return { ...data, pages };
5011
- });
4982
+ })
4983
+ );
5012
4984
  };
5013
4985
 
5014
4986
  // src/mutations/activities/useLikeActivity.ts
@@ -5018,7 +4990,10 @@ var LikeActivity = async ({
5018
4990
  queryClient
5019
4991
  }) => {
5020
4992
  if (queryClient) {
5021
- UpdateLikesSingle(true, queryClient, ACTIVITY_QUERY_KEY(activityId));
4993
+ UpdateLikesSingle(true, queryClient, [
4994
+ ...ACTIVITY_QUERY_KEY(activityId),
4995
+ ...GetBaseSingleQueryKeys(clientApiParams.locale)
4996
+ ]);
5022
4997
  UpdateLikesInfinite(true, queryClient, ACTIVITIES_QUERY_KEY(), activityId);
5023
4998
  }
5024
4999
  const clientApi = await GetClientAPI(clientApiParams);
@@ -5038,7 +5013,10 @@ var ReshareActivity = async ({
5038
5013
  clientApiParams
5039
5014
  }) => {
5040
5015
  if (queryClient) {
5041
- UpdateResharesSingle(true, queryClient, ACTIVITY_QUERY_KEY(activityId));
5016
+ UpdateResharesSingle(true, queryClient, [
5017
+ ...ACTIVITY_QUERY_KEY(activityId),
5018
+ ...GetBaseSingleQueryKeys(clientApiParams.locale)
5019
+ ]);
5042
5020
  UpdateResharesInfinite(
5043
5021
  true,
5044
5022
  queryClient,
@@ -5066,7 +5044,10 @@ var UnlikeActivity = async ({
5066
5044
  queryClient
5067
5045
  }) => {
5068
5046
  if (queryClient) {
5069
- UpdateLikesSingle(false, queryClient, ACTIVITY_QUERY_KEY(activityId));
5047
+ UpdateLikesSingle(false, queryClient, [
5048
+ ...ACTIVITY_QUERY_KEY(activityId),
5049
+ ...GetBaseSingleQueryKeys(clientApiParams.locale)
5050
+ ]);
5070
5051
  UpdateLikesInfinite(false, queryClient, ACTIVITIES_QUERY_KEY(), activityId);
5071
5052
  }
5072
5053
  const clientApi = await GetClientAPI(clientApiParams);
@@ -6583,63 +6564,35 @@ var useSelfCheckinRegistration = (options = {}) => {
6583
6564
  };
6584
6565
 
6585
6566
  // src/mutations/activities/optimistic/UpdateComments.ts
6567
+ var import_immer4 = require("immer");
6586
6568
  var UpdateCommentsSingle = (increment, queryClient, KEY) => {
6587
- queryClient.setQueryData(KEY, (data) => {
6588
- if (!data?.data) {
6589
- return data;
6590
- }
6591
- data = data.data;
6592
- if (typeof data?._count != "undefined") {
6593
- return {
6594
- data: {
6595
- ...data,
6596
- _count: {
6597
- ...data._count,
6598
- comments: increment ? data._count.comments + 1 : data._count.comments - 1
6599
- },
6600
- comments: increment ? [{}] : void 0
6601
- }
6602
- };
6603
- }
6604
- });
6569
+ queryClient.setQueryData(
6570
+ KEY,
6571
+ (originalData) => (0, import_immer4.produce)(originalData, (draft) => {
6572
+ if (!draft?.data) {
6573
+ return;
6574
+ }
6575
+ draft.data._count.comments += increment ? 1 : -1;
6576
+ draft.data.comments = increment ? [{ id: Date.now().toString() }] : [];
6577
+ })
6578
+ );
6605
6579
  };
6606
6580
  var UpdateCommentsInfinite = (increment, queryClient, KEY, activityId) => {
6607
6581
  queryClient.setQueriesData(
6608
- {
6609
- queryKey: KEY,
6610
- exact: false
6611
- },
6612
- (data) => {
6613
- if (!data?.pages || data?.pages?.length === 0) {
6614
- return data;
6582
+ { queryKey: KEY, exact: false },
6583
+ (originalData) => (0, import_immer4.produce)(originalData, (draft) => {
6584
+ if (!draft?.pages || draft.pages.length === 0) {
6585
+ return;
6615
6586
  }
6616
- const pages = data.pages;
6617
- let activityIndex;
6618
- let pageIndex;
6619
- let reshareActivityIndex;
6620
- let resharePageIndex;
6621
- for (let x = 0; x < pages?.length; x++) {
6622
- for (let y = 0; y < pages?.[x]?.data?.length; y++) {
6623
- if (pages?.[x]?.data?.[y]?.id === activityId) {
6624
- pageIndex = x;
6625
- activityIndex = y;
6626
- }
6627
- if (pages?.[x]?.data?.[y]?.reshared?.id === activityId) {
6628
- resharePageIndex = x;
6629
- reshareActivityIndex = y;
6587
+ for (const page of draft.pages) {
6588
+ for (const activity of page.data) {
6589
+ if (activity.id === activityId) {
6590
+ activity._count.comments += increment ? 1 : -1;
6591
+ activity.comments = increment ? [{ id: Date.now().toString() }] : [];
6630
6592
  }
6631
6593
  }
6632
6594
  }
6633
- if (typeof pageIndex != "undefined" && typeof activityIndex != "undefined") {
6634
- pages[pageIndex].data[activityIndex]._count.comments = increment ? pages?.[pageIndex]?.data[activityIndex]._count.comments + 1 : pages?.[pageIndex]?.data[activityIndex]._count.comments - 1;
6635
- pages[pageIndex].data[activityIndex].comments = increment ? [{}] : void 0;
6636
- }
6637
- if (typeof resharePageIndex != "undefined" && typeof reshareActivityIndex != "undefined") {
6638
- pages[resharePageIndex].data[reshareActivityIndex].reshared._count.comments = increment ? pages?.[resharePageIndex]?.data[reshareActivityIndex].reshared._count.comments + 1 : pages?.[resharePageIndex]?.data[reshareActivityIndex].reshared._count.comments - 1;
6639
- pages[resharePageIndex].data[reshareActivityIndex].reshared.comments = increment ? [{}] : void 0;
6640
- }
6641
- return { ...data, pages };
6642
- }
6595
+ })
6643
6596
  );
6644
6597
  };
6645
6598
 
@@ -6655,7 +6608,7 @@ var SelfCreateActivity = async ({
6655
6608
  if (activity.commentedId) {
6656
6609
  UpdateCommentsSingle(true, queryClient, [
6657
6610
  ...ACTIVITY_QUERY_KEY(activity.commentedId),
6658
- clientApiParams.locale
6611
+ ...GetBaseSingleQueryKeys(clientApiParams.locale)
6659
6612
  ]);
6660
6613
  UpdateCommentsInfinite(
6661
6614
  true,
@@ -6670,51 +6623,51 @@ var SelfCreateActivity = async ({
6670
6623
  `/self/activities`,
6671
6624
  {
6672
6625
  activity,
6673
- buffer: base64Image ? `data:image/jpeg;base64,${base64Image}` : void 0,
6674
- videoUri: videoUri || void 0
6626
+ imageUri: base64Image ?? void 0,
6627
+ videoUri: videoUri ?? void 0
6675
6628
  }
6676
6629
  );
6677
6630
  if (queryClient && data.status === "ok") {
6678
6631
  let nested = false;
6679
- if (data.data?.commented?.id) {
6632
+ if (activity.commentedId) {
6680
6633
  nested = true;
6681
6634
  AppendInfiniteQuery(
6682
6635
  queryClient,
6683
6636
  [
6684
- ...ACTIVITY_COMMENTS_QUERY_KEY(data.data.commented.id),
6637
+ ...ACTIVITY_COMMENTS_QUERY_KEY(activity.commentedId),
6685
6638
  ...GetBaseInfiniteQueryKeys(clientApiParams.locale)
6686
6639
  ],
6687
6640
  data.data
6688
6641
  );
6689
6642
  }
6690
- if (data.data?.content?.id) {
6643
+ if (activity.contentId) {
6691
6644
  nested = true;
6692
6645
  AppendInfiniteQuery(
6693
6646
  queryClient,
6694
6647
  [
6695
- ...CONTENT_ACTIVITIES_QUERY_KEY(data.data.content.id),
6648
+ ...CONTENT_ACTIVITIES_QUERY_KEY(activity.contentId),
6696
6649
  ...GetBaseInfiniteQueryKeys(clientApiParams.locale)
6697
6650
  ],
6698
6651
  data.data
6699
6652
  );
6700
6653
  }
6701
- if (data.data?.event?.id) {
6654
+ if (activity.eventId) {
6702
6655
  nested = true;
6703
6656
  AppendInfiniteQuery(
6704
6657
  queryClient,
6705
6658
  [
6706
- ...EVENT_ACTIVITIES_QUERY_KEY(data.data.event.id),
6659
+ ...EVENT_ACTIVITIES_QUERY_KEY(activity.eventId),
6707
6660
  ...GetBaseInfiniteQueryKeys(clientApiParams.locale)
6708
6661
  ],
6709
6662
  data.data
6710
6663
  );
6711
6664
  }
6712
- if (data.data?.community?.id) {
6665
+ if (activity.communityId) {
6713
6666
  nested = true;
6714
6667
  AppendInfiniteQuery(
6715
6668
  queryClient,
6716
6669
  [
6717
- ...COMMUNITY_ACTIVITIES_QUERY_KEY(data.data.community.id),
6670
+ ...COMMUNITY_ACTIVITIES_QUERY_KEY(activity.communityId),
6718
6671
  ...GetBaseInfiniteQueryKeys(clientApiParams.locale)
6719
6672
  ],
6720
6673
  data.data
@@ -6879,7 +6832,7 @@ var UpdateSelfEventListing = async ({
6879
6832
  `/self/events/listings/${eventId}`,
6880
6833
  {
6881
6834
  event,
6882
- image: base64 ? `data:image/jpeg;base64,${base64}` : void 0
6835
+ image: base64 ?? void 0
6883
6836
  }
6884
6837
  );
6885
6838
  if (queryClient && data.status === "ok") {