@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.mjs CHANGED
@@ -4237,7 +4237,14 @@ import {
4237
4237
  useQueryClient
4238
4238
  } from "@tanstack/react-query";
4239
4239
  var useConnectedMutation = (mutation, options) => {
4240
- const { locale, apiUrl, getToken, organizationId, getExecuteAs } = useConnectedXM();
4240
+ const {
4241
+ locale,
4242
+ apiUrl,
4243
+ getToken,
4244
+ organizationId,
4245
+ getExecuteAs,
4246
+ onMutationError
4247
+ } = useConnectedXM();
4241
4248
  const queryClient = useQueryClient();
4242
4249
  return useMutation({
4243
4250
  mutationFn: (data) => mutation({
@@ -4251,7 +4258,13 @@ var useConnectedMutation = (mutation, options) => {
4251
4258
  },
4252
4259
  ...data
4253
4260
  }),
4254
- ...options
4261
+ ...options,
4262
+ onError: (error, variables, context) => {
4263
+ if (onMutationError)
4264
+ onMutationError(error, variables, context);
4265
+ if (options?.onError)
4266
+ options.onError(error, variables, context);
4267
+ }
4255
4268
  });
4256
4269
  };
4257
4270
  var useConnectedMutation_default = useConnectedMutation;
@@ -4311,58 +4324,36 @@ var useUnfollowAccount = (options = {}) => {
4311
4324
  };
4312
4325
 
4313
4326
  // src/mutations/activities/optimistic/UpdateReshares.ts
4327
+ import { produce as produce2 } from "immer";
4314
4328
  var UpdateResharesSingle = (increment, queryClient, KEY) => {
4315
- queryClient.setQueryData(KEY, (data) => {
4316
- if (!data?.data) {
4317
- return data;
4318
- }
4319
- data = data.data;
4320
- if (typeof data?._count != "undefined") {
4321
- return {
4322
- data: {
4323
- ...data,
4324
- _count: {
4325
- ...data._count,
4326
- reshares: increment ? data._count.reshares + 1 : data._count.reshares - 1
4327
- },
4328
- reshares: increment ? [{}] : void 0
4329
- }
4330
- };
4331
- }
4332
- });
4329
+ queryClient.setQueryData(
4330
+ KEY,
4331
+ (originalData) => produce2(originalData, (draft) => {
4332
+ if (!draft?.data) {
4333
+ return;
4334
+ }
4335
+ draft.data._count.reshares += increment ? 1 : -1;
4336
+ draft.data.reshares = increment ? [{ id: Date.now().toString() }] : [];
4337
+ })
4338
+ );
4333
4339
  };
4334
4340
  var UpdateResharesInfinite = (increment, queryClient, KEY, activityId) => {
4335
- queryClient.setQueriesData({ queryKey: KEY, exact: false }, (data) => {
4336
- if (!data?.pages || data?.pages?.length === 0) {
4337
- return data;
4338
- }
4339
- const pages = data.pages;
4340
- let activityIndex;
4341
- let pageIndex;
4342
- let reshareActivityIndex;
4343
- let resharePageIndex;
4344
- for (let x = 0; x < pages?.length; x++) {
4345
- for (let y = 0; y < pages?.[x]?.data?.length; y++) {
4346
- if (pages?.[x]?.data?.[y]?.id === activityId) {
4347
- pageIndex = x;
4348
- activityIndex = y;
4349
- }
4350
- if (pages?.[x]?.data?.[y]?.reshared?.id === activityId) {
4351
- resharePageIndex = x;
4352
- reshareActivityIndex = y;
4341
+ queryClient.setQueriesData(
4342
+ { queryKey: KEY, exact: false },
4343
+ (originalData) => produce2(originalData, (draft) => {
4344
+ if (!draft?.pages || draft.pages.length === 0) {
4345
+ return;
4346
+ }
4347
+ for (const page of draft.pages) {
4348
+ for (const activity of page.data) {
4349
+ if (activity.id === activityId) {
4350
+ activity._count.reshares += increment ? 1 : -1;
4351
+ activity.reshares = increment ? [{ id: Date.now().toString() }] : [];
4352
+ }
4353
4353
  }
4354
4354
  }
4355
- }
4356
- if (typeof pageIndex != "undefined" && typeof activityIndex != "undefined") {
4357
- pages[pageIndex].data[activityIndex]._count.reshares = increment ? pages?.[pageIndex]?.data[activityIndex]._count.reshares + 1 : pages?.[pageIndex]?.data[activityIndex]._count.reshares - 1;
4358
- pages[pageIndex].data[activityIndex].reshares = increment ? [{}] : void 0;
4359
- }
4360
- if (typeof resharePageIndex != "undefined" && typeof reshareActivityIndex != "undefined") {
4361
- pages[resharePageIndex].data[reshareActivityIndex].reshared._count.reshares = increment ? pages?.[resharePageIndex]?.data[reshareActivityIndex].reshared._count.reshares + 1 : pages?.[resharePageIndex]?.data[reshareActivityIndex].reshared._count.reshares - 1;
4362
- pages[resharePageIndex].data[reshareActivityIndex].reshared.reshares = increment ? [{}] : void 0;
4363
- }
4364
- return { ...data, pages };
4365
- });
4355
+ })
4356
+ );
4366
4357
  };
4367
4358
 
4368
4359
  // src/mutations/activities/useDeleteReshare.ts
@@ -4372,7 +4363,10 @@ var DeleteReshare = async ({
4372
4363
  queryClient
4373
4364
  }) => {
4374
4365
  if (queryClient) {
4375
- UpdateResharesSingle(false, queryClient, ACTIVITY_QUERY_KEY(activityId));
4366
+ UpdateResharesSingle(false, queryClient, [
4367
+ ...ACTIVITY_QUERY_KEY(activityId),
4368
+ ...GetBaseSingleQueryKeys(clientApiParams.locale)
4369
+ ]);
4376
4370
  UpdateResharesInfinite(
4377
4371
  false,
4378
4372
  queryClient,
@@ -4391,58 +4385,36 @@ var useDeleteReshare = (options = {}) => {
4391
4385
  };
4392
4386
 
4393
4387
  // src/mutations/activities/optimistic/UpdateLikes.ts
4388
+ import { produce as produce3 } from "immer";
4394
4389
  var UpdateLikesSingle = (increment, queryClient, KEY) => {
4395
- queryClient.setQueryData(KEY, (data) => {
4396
- if (!data?.data) {
4397
- return data;
4398
- }
4399
- data = data.data;
4400
- if (typeof data?._count != "undefined") {
4401
- return {
4402
- data: {
4403
- ...data,
4404
- _count: {
4405
- ...data._count,
4406
- likes: increment ? data._count.likes + 1 : data._count.likes - 1
4407
- },
4408
- likes: increment ? [{}] : void 0
4409
- }
4410
- };
4411
- }
4412
- });
4390
+ queryClient.setQueryData(
4391
+ KEY,
4392
+ (originalData) => produce3(originalData, (draft) => {
4393
+ if (!draft?.data) {
4394
+ return;
4395
+ }
4396
+ draft.data._count.likes += increment ? 1 : -1;
4397
+ draft.data.likes = increment ? [{ createdAt: (/* @__PURE__ */ new Date()).toISOString() }] : [];
4398
+ })
4399
+ );
4413
4400
  };
4414
4401
  var UpdateLikesInfinite = (increment, queryClient, KEY, activityId) => {
4415
- queryClient.setQueriesData({ queryKey: KEY, exact: false }, (data) => {
4416
- if (!data?.pages || data?.pages?.length === 0) {
4417
- return data;
4418
- }
4419
- const pages = data.pages;
4420
- let activityIndex;
4421
- let pageIndex;
4422
- let reshareActivityIndex;
4423
- let resharePageIndex;
4424
- for (let x = 0; x < pages?.length; x++) {
4425
- for (let y = 0; y < pages?.[x]?.data?.length; y++) {
4426
- if (pages?.[x]?.data?.[y]?.id === activityId) {
4427
- pageIndex = x;
4428
- activityIndex = y;
4429
- }
4430
- if (pages?.[x]?.data?.[y]?.reshared?.id === activityId) {
4431
- resharePageIndex = x;
4432
- reshareActivityIndex = y;
4402
+ queryClient.setQueriesData(
4403
+ { queryKey: KEY, exact: false },
4404
+ (originalData) => produce3(originalData, (draft) => {
4405
+ if (!draft?.pages || draft.pages.length === 0) {
4406
+ return;
4407
+ }
4408
+ for (const page of draft.pages) {
4409
+ for (const activity of page.data) {
4410
+ if (activity.id === activityId) {
4411
+ activity._count.likes += increment ? 1 : -1;
4412
+ activity.likes = increment ? [{ createdAt: (/* @__PURE__ */ new Date()).toISOString() }] : [];
4413
+ }
4433
4414
  }
4434
4415
  }
4435
- }
4436
- if (typeof pageIndex != "undefined" && typeof activityIndex != "undefined") {
4437
- pages[pageIndex].data[activityIndex]._count.likes = increment ? pages?.[pageIndex]?.data[activityIndex]._count.likes + 1 : pages?.[pageIndex]?.data[activityIndex]._count.likes - 1;
4438
- pages[pageIndex].data[activityIndex].likes = increment ? [{}] : void 0;
4439
- }
4440
- if (typeof resharePageIndex != "undefined" && typeof reshareActivityIndex != "undefined") {
4441
- pages[resharePageIndex].data[reshareActivityIndex].reshared._count.likes = increment ? pages?.[resharePageIndex]?.data[reshareActivityIndex].reshared._count.likes + 1 : pages?.[resharePageIndex]?.data[reshareActivityIndex].reshared._count.likes - 1;
4442
- pages[resharePageIndex].data[reshareActivityIndex].reshared.likes = increment ? [{}] : void 0;
4443
- }
4444
- return { ...data, pages };
4445
- });
4416
+ })
4417
+ );
4446
4418
  };
4447
4419
 
4448
4420
  // src/mutations/activities/useLikeActivity.ts
@@ -4452,7 +4424,10 @@ var LikeActivity = async ({
4452
4424
  queryClient
4453
4425
  }) => {
4454
4426
  if (queryClient) {
4455
- UpdateLikesSingle(true, queryClient, ACTIVITY_QUERY_KEY(activityId));
4427
+ UpdateLikesSingle(true, queryClient, [
4428
+ ...ACTIVITY_QUERY_KEY(activityId),
4429
+ ...GetBaseSingleQueryKeys(clientApiParams.locale)
4430
+ ]);
4456
4431
  UpdateLikesInfinite(true, queryClient, ACTIVITIES_QUERY_KEY(), activityId);
4457
4432
  }
4458
4433
  const clientApi = await GetClientAPI(clientApiParams);
@@ -4472,7 +4447,10 @@ var ReshareActivity = async ({
4472
4447
  clientApiParams
4473
4448
  }) => {
4474
4449
  if (queryClient) {
4475
- UpdateResharesSingle(true, queryClient, ACTIVITY_QUERY_KEY(activityId));
4450
+ UpdateResharesSingle(true, queryClient, [
4451
+ ...ACTIVITY_QUERY_KEY(activityId),
4452
+ ...GetBaseSingleQueryKeys(clientApiParams.locale)
4453
+ ]);
4476
4454
  UpdateResharesInfinite(
4477
4455
  true,
4478
4456
  queryClient,
@@ -4500,7 +4478,10 @@ var UnlikeActivity = async ({
4500
4478
  queryClient
4501
4479
  }) => {
4502
4480
  if (queryClient) {
4503
- UpdateLikesSingle(false, queryClient, ACTIVITY_QUERY_KEY(activityId));
4481
+ UpdateLikesSingle(false, queryClient, [
4482
+ ...ACTIVITY_QUERY_KEY(activityId),
4483
+ ...GetBaseSingleQueryKeys(clientApiParams.locale)
4484
+ ]);
4504
4485
  UpdateLikesInfinite(false, queryClient, ACTIVITIES_QUERY_KEY(), activityId);
4505
4486
  }
4506
4487
  const clientApi = await GetClientAPI(clientApiParams);
@@ -6017,63 +5998,35 @@ var useSelfCheckinRegistration = (options = {}) => {
6017
5998
  };
6018
5999
 
6019
6000
  // src/mutations/activities/optimistic/UpdateComments.ts
6001
+ import { produce as produce4 } from "immer";
6020
6002
  var UpdateCommentsSingle = (increment, queryClient, KEY) => {
6021
- queryClient.setQueryData(KEY, (data) => {
6022
- if (!data?.data) {
6023
- return data;
6024
- }
6025
- data = data.data;
6026
- if (typeof data?._count != "undefined") {
6027
- return {
6028
- data: {
6029
- ...data,
6030
- _count: {
6031
- ...data._count,
6032
- comments: increment ? data._count.comments + 1 : data._count.comments - 1
6033
- },
6034
- comments: increment ? [{}] : void 0
6035
- }
6036
- };
6037
- }
6038
- });
6003
+ queryClient.setQueryData(
6004
+ KEY,
6005
+ (originalData) => produce4(originalData, (draft) => {
6006
+ if (!draft?.data) {
6007
+ return;
6008
+ }
6009
+ draft.data._count.comments += increment ? 1 : -1;
6010
+ draft.data.comments = increment ? [{ id: Date.now().toString() }] : [];
6011
+ })
6012
+ );
6039
6013
  };
6040
6014
  var UpdateCommentsInfinite = (increment, queryClient, KEY, activityId) => {
6041
6015
  queryClient.setQueriesData(
6042
- {
6043
- queryKey: KEY,
6044
- exact: false
6045
- },
6046
- (data) => {
6047
- if (!data?.pages || data?.pages?.length === 0) {
6048
- return data;
6016
+ { queryKey: KEY, exact: false },
6017
+ (originalData) => produce4(originalData, (draft) => {
6018
+ if (!draft?.pages || draft.pages.length === 0) {
6019
+ return;
6049
6020
  }
6050
- const pages = data.pages;
6051
- let activityIndex;
6052
- let pageIndex;
6053
- let reshareActivityIndex;
6054
- let resharePageIndex;
6055
- for (let x = 0; x < pages?.length; x++) {
6056
- for (let y = 0; y < pages?.[x]?.data?.length; y++) {
6057
- if (pages?.[x]?.data?.[y]?.id === activityId) {
6058
- pageIndex = x;
6059
- activityIndex = y;
6060
- }
6061
- if (pages?.[x]?.data?.[y]?.reshared?.id === activityId) {
6062
- resharePageIndex = x;
6063
- reshareActivityIndex = y;
6021
+ for (const page of draft.pages) {
6022
+ for (const activity of page.data) {
6023
+ if (activity.id === activityId) {
6024
+ activity._count.comments += increment ? 1 : -1;
6025
+ activity.comments = increment ? [{ id: Date.now().toString() }] : [];
6064
6026
  }
6065
6027
  }
6066
6028
  }
6067
- if (typeof pageIndex != "undefined" && typeof activityIndex != "undefined") {
6068
- pages[pageIndex].data[activityIndex]._count.comments = increment ? pages?.[pageIndex]?.data[activityIndex]._count.comments + 1 : pages?.[pageIndex]?.data[activityIndex]._count.comments - 1;
6069
- pages[pageIndex].data[activityIndex].comments = increment ? [{}] : void 0;
6070
- }
6071
- if (typeof resharePageIndex != "undefined" && typeof reshareActivityIndex != "undefined") {
6072
- pages[resharePageIndex].data[reshareActivityIndex].reshared._count.comments = increment ? pages?.[resharePageIndex]?.data[reshareActivityIndex].reshared._count.comments + 1 : pages?.[resharePageIndex]?.data[reshareActivityIndex].reshared._count.comments - 1;
6073
- pages[resharePageIndex].data[reshareActivityIndex].reshared.comments = increment ? [{}] : void 0;
6074
- }
6075
- return { ...data, pages };
6076
- }
6029
+ })
6077
6030
  );
6078
6031
  };
6079
6032
 
@@ -6089,7 +6042,7 @@ var SelfCreateActivity = async ({
6089
6042
  if (activity.commentedId) {
6090
6043
  UpdateCommentsSingle(true, queryClient, [
6091
6044
  ...ACTIVITY_QUERY_KEY(activity.commentedId),
6092
- clientApiParams.locale
6045
+ ...GetBaseSingleQueryKeys(clientApiParams.locale)
6093
6046
  ]);
6094
6047
  UpdateCommentsInfinite(
6095
6048
  true,
@@ -6104,51 +6057,51 @@ var SelfCreateActivity = async ({
6104
6057
  `/self/activities`,
6105
6058
  {
6106
6059
  activity,
6107
- buffer: base64Image ? `data:image/jpeg;base64,${base64Image}` : void 0,
6108
- videoUri: videoUri || void 0
6060
+ imageUri: base64Image ?? void 0,
6061
+ videoUri: videoUri ?? void 0
6109
6062
  }
6110
6063
  );
6111
6064
  if (queryClient && data.status === "ok") {
6112
6065
  let nested = false;
6113
- if (data.data?.commented?.id) {
6066
+ if (activity.commentedId) {
6114
6067
  nested = true;
6115
6068
  AppendInfiniteQuery(
6116
6069
  queryClient,
6117
6070
  [
6118
- ...ACTIVITY_COMMENTS_QUERY_KEY(data.data.commented.id),
6071
+ ...ACTIVITY_COMMENTS_QUERY_KEY(activity.commentedId),
6119
6072
  ...GetBaseInfiniteQueryKeys(clientApiParams.locale)
6120
6073
  ],
6121
6074
  data.data
6122
6075
  );
6123
6076
  }
6124
- if (data.data?.content?.id) {
6077
+ if (activity.contentId) {
6125
6078
  nested = true;
6126
6079
  AppendInfiniteQuery(
6127
6080
  queryClient,
6128
6081
  [
6129
- ...CONTENT_ACTIVITIES_QUERY_KEY(data.data.content.id),
6082
+ ...CONTENT_ACTIVITIES_QUERY_KEY(activity.contentId),
6130
6083
  ...GetBaseInfiniteQueryKeys(clientApiParams.locale)
6131
6084
  ],
6132
6085
  data.data
6133
6086
  );
6134
6087
  }
6135
- if (data.data?.event?.id) {
6088
+ if (activity.eventId) {
6136
6089
  nested = true;
6137
6090
  AppendInfiniteQuery(
6138
6091
  queryClient,
6139
6092
  [
6140
- ...EVENT_ACTIVITIES_QUERY_KEY(data.data.event.id),
6093
+ ...EVENT_ACTIVITIES_QUERY_KEY(activity.eventId),
6141
6094
  ...GetBaseInfiniteQueryKeys(clientApiParams.locale)
6142
6095
  ],
6143
6096
  data.data
6144
6097
  );
6145
6098
  }
6146
- if (data.data?.community?.id) {
6099
+ if (activity.communityId) {
6147
6100
  nested = true;
6148
6101
  AppendInfiniteQuery(
6149
6102
  queryClient,
6150
6103
  [
6151
- ...COMMUNITY_ACTIVITIES_QUERY_KEY(data.data.community.id),
6104
+ ...COMMUNITY_ACTIVITIES_QUERY_KEY(activity.communityId),
6152
6105
  ...GetBaseInfiniteQueryKeys(clientApiParams.locale)
6153
6106
  ],
6154
6107
  data.data
@@ -6313,7 +6266,7 @@ var UpdateSelfEventListing = async ({
6313
6266
  `/self/events/listings/${eventId}`,
6314
6267
  {
6315
6268
  event,
6316
- image: base64 ? `data:image/jpeg;base64,${base64}` : void 0
6269
+ image: base64 ?? void 0
6317
6270
  }
6318
6271
  );
6319
6272
  if (queryClient && data.status === "ok") {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@connectedxm/client",
3
- "version": "0.1.8",
3
+ "version": "0.1.20",
4
4
  "description": "Client API javascript SDK",
5
5
  "author": "ConnectedXM Inc.",
6
6
  "repository": {