@amityco/ts-sdk 0.0.1-beta.37 → 0.0.1-beta.38

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.
Files changed (179) hide show
  1. package/.eslintrc.json +3 -5
  2. package/dist/@types/core/events.d.ts +1 -0
  3. package/dist/@types/core/events.d.ts.map +1 -1
  4. package/dist/@types/domains/category.d.ts +7 -0
  5. package/dist/@types/domains/category.d.ts.map +1 -1
  6. package/dist/@types/domains/community.d.ts +12 -0
  7. package/dist/@types/domains/community.d.ts.map +1 -1
  8. package/dist/@types/global.d.ts +5 -0
  9. package/dist/@types/global.d.ts.map +1 -1
  10. package/dist/category/api/queryCategories.d.ts +1 -5
  11. package/dist/category/api/queryCategories.d.ts.map +1 -1
  12. package/dist/category/observers/index.d.ts +2 -0
  13. package/dist/category/observers/index.d.ts.map +1 -0
  14. package/dist/category/observers/liveCategories.d.ts +18 -0
  15. package/dist/category/observers/liveCategories.d.ts.map +1 -0
  16. package/dist/category/observers/tests/liveCategories.test.d.ts +2 -0
  17. package/dist/category/observers/tests/liveCategories.test.d.ts.map +1 -0
  18. package/dist/channel/api/tests/getChannels.test.d.ts +2 -0
  19. package/dist/channel/api/tests/getChannels.test.d.ts.map +1 -0
  20. package/dist/channel/api/tests/leaveChannel.test.d.ts +2 -0
  21. package/dist/channel/api/tests/leaveChannel.test.d.ts.map +1 -0
  22. package/dist/channel/observers/liveChannel.d.ts.map +1 -1
  23. package/dist/client/api/accessTokenExpiryWatcher.d.ts +4 -1
  24. package/dist/client/api/accessTokenExpiryWatcher.d.ts.map +1 -1
  25. package/dist/client/api/getToken.d.ts +3 -1
  26. package/dist/client/api/getToken.d.ts.map +1 -1
  27. package/dist/client/utils/setClientToken.d.ts +3 -3
  28. package/dist/comment/api/deleteComment.d.ts.map +1 -1
  29. package/dist/comment/api/getComment.d.ts.map +1 -1
  30. package/dist/comment/observers/index.d.ts +1 -0
  31. package/dist/comment/observers/index.d.ts.map +1 -1
  32. package/dist/comment/observers/liveComment.d.ts +21 -0
  33. package/dist/comment/observers/liveComment.d.ts.map +1 -0
  34. package/dist/comment/observers/tests/liveComment.test.d.ts +2 -0
  35. package/dist/comment/observers/tests/liveComment.test.d.ts.map +1 -0
  36. package/dist/community/api/queryCommunities.d.ts +1 -10
  37. package/dist/community/api/queryCommunities.d.ts.map +1 -1
  38. package/dist/community/events/index.d.ts +1 -0
  39. package/dist/community/events/index.d.ts.map +1 -1
  40. package/dist/community/events/onCommunityUserChanged.d.ts +17 -0
  41. package/dist/community/events/onCommunityUserChanged.d.ts.map +1 -0
  42. package/dist/community/events/utils.d.ts +1 -0
  43. package/dist/community/events/utils.d.ts.map +1 -1
  44. package/dist/community/observers/index.d.ts +1 -0
  45. package/dist/community/observers/index.d.ts.map +1 -1
  46. package/dist/community/observers/liveCommunities.d.ts +20 -0
  47. package/dist/community/observers/liveCommunities.d.ts.map +1 -0
  48. package/dist/community/observers/tests/liveCommunities.test.d.ts +2 -0
  49. package/dist/community/observers/tests/liveCommunities.test.d.ts.map +1 -0
  50. package/dist/core/events.d.ts +3 -3
  51. package/dist/core/events.d.ts.map +1 -1
  52. package/dist/core/query/sorting.d.ts +6 -0
  53. package/dist/core/query/sorting.d.ts.map +1 -1
  54. package/dist/core/transports/http.d.ts +0 -5
  55. package/dist/core/transports/http.d.ts.map +1 -1
  56. package/dist/file/api/test/createImage.test.d.ts +2 -0
  57. package/dist/file/api/test/createImage.test.d.ts.map +1 -0
  58. package/dist/file/api/test/createVideo.test.d.ts +2 -0
  59. package/dist/file/api/test/createVideo.test.d.ts.map +1 -0
  60. package/dist/index.cjs.js +441 -195
  61. package/dist/index.d.ts +1 -0
  62. package/dist/index.d.ts.map +1 -1
  63. package/dist/index.esm.js +436 -195
  64. package/dist/index.umd.js +4 -4
  65. package/dist/message/observers/liveMessage.d.ts.map +1 -1
  66. package/dist/post/observers/index.d.ts +1 -0
  67. package/dist/post/observers/index.d.ts.map +1 -1
  68. package/dist/post/observers/livePost.d.ts +21 -0
  69. package/dist/post/observers/livePost.d.ts.map +1 -0
  70. package/dist/post/observers/tests/livePost.test.d.ts +2 -0
  71. package/dist/post/observers/tests/livePost.test.d.ts.map +1 -0
  72. package/dist/subChannel/api/tests/deleteSubChannel.test.d.ts +2 -0
  73. package/dist/subChannel/api/tests/deleteSubChannel.test.d.ts.map +1 -0
  74. package/dist/subChannel/api/tests/getSubChannel.test.d.ts +2 -0
  75. package/dist/subChannel/api/tests/getSubChannel.test.d.ts.map +1 -0
  76. package/dist/subChannel/api/tests/getSubChannels.test.d.ts +2 -0
  77. package/dist/subChannel/api/tests/getSubChannels.test.d.ts.map +1 -0
  78. package/dist/subChannel/api/tests/updateSubChannel.test.d.ts +2 -0
  79. package/dist/subChannel/api/tests/updateSubChannel.test.d.ts.map +1 -0
  80. package/dist/subChannel/observers/liveSubChannel.d.ts.map +1 -1
  81. package/dist/user/api/tests/updateUser.test.d.ts +2 -0
  82. package/dist/user/api/tests/updateUser.test.d.ts.map +1 -0
  83. package/dist/user/observers/liveUser.d.ts.map +1 -1
  84. package/dist/utils/liveObject.d.ts +2 -0
  85. package/dist/utils/liveObject.d.ts.map +1 -0
  86. package/dist/utils/tests/dummy/category.d.ts +64 -0
  87. package/dist/utils/tests/dummy/category.d.ts.map +1 -0
  88. package/dist/utils/tests/dummy/channel.d.ts +50 -0
  89. package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
  90. package/dist/utils/tests/dummy/community.d.ts +132 -0
  91. package/dist/utils/tests/dummy/community.d.ts.map +1 -1
  92. package/dist/utils/tests/dummy/file.d.ts +3 -0
  93. package/dist/utils/tests/dummy/file.d.ts.map +1 -1
  94. package/dist/utils/tests/dummy/index.d.ts +1 -0
  95. package/dist/utils/tests/dummy/index.d.ts.map +1 -1
  96. package/dist/utils/tests/dummy/post.d.ts +2 -0
  97. package/dist/utils/tests/dummy/post.d.ts.map +1 -1
  98. package/dist/utils/tests/dummy/subChannel.d.ts +0 -20
  99. package/dist/utils/tests/dummy/subChannel.d.ts.map +1 -1
  100. package/dist/utils/tests/dummy/user.d.ts +18 -0
  101. package/dist/utils/tests/dummy/user.d.ts.map +1 -1
  102. package/dist/utils/tests/liveObject.test.d.ts +2 -0
  103. package/dist/utils/tests/liveObject.test.d.ts.map +1 -0
  104. package/package.json +4 -4
  105. package/src/@types/core/events.ts +1 -0
  106. package/src/@types/domains/category.ts +13 -0
  107. package/src/@types/domains/community.ts +25 -0
  108. package/src/@types/global.ts +5 -0
  109. package/src/category/api/queryCategories.ts +3 -5
  110. package/src/category/observers/index.ts +1 -0
  111. package/src/category/observers/liveCategories.ts +141 -0
  112. package/src/category/observers/tests/liveCategories.test.ts +147 -0
  113. package/src/channel/api/tests/createChannel.test.ts +30 -6
  114. package/src/channel/api/tests/getChannel.test.ts +3 -1
  115. package/src/channel/api/tests/getChannels.test.ts +97 -0
  116. package/src/channel/api/tests/joinChannel.test.ts +62 -3
  117. package/src/channel/api/tests/leaveChannel.test.ts +90 -0
  118. package/src/channel/api/tests/queryChannels.test.ts +38 -1
  119. package/src/channel/observers/liveChannel.ts +8 -80
  120. package/src/client/api/accessTokenExpiryWatcher.ts +7 -5
  121. package/src/client/api/tests/accessTokenExpiryWatcher.test.ts +8 -5
  122. package/src/comment/api/deleteComment.ts +5 -5
  123. package/src/comment/api/getComment.ts +8 -3
  124. package/src/comment/observers/index.ts +1 -0
  125. package/src/comment/observers/liveComment.ts +43 -0
  126. package/src/comment/observers/tests/liveComment.test.ts +95 -0
  127. package/src/community/api/queryCommunities.ts +3 -10
  128. package/src/community/api/test/addCommunityMember.test.ts +14 -2
  129. package/src/community/api/test/joinCommunity.test.ts +14 -2
  130. package/src/community/api/test/leaveCommunity.test.ts +11 -1
  131. package/src/community/api/test/removeCommunityMembers.test.ts +11 -1
  132. package/src/community/events/index.ts +1 -0
  133. package/src/community/events/onCommunityUserChanged.ts +20 -0
  134. package/src/community/events/test/onCommunityJoined.test.ts +1 -1
  135. package/src/community/events/test/onCommunityUserAdded.test.ts +1 -1
  136. package/src/community/events/test/onCommunityUserBanned.test.ts +1 -1
  137. package/src/community/events/test/onCommunityUserUnbaned.test.ts +1 -1
  138. package/src/community/events/test/utils.test.ts +52 -3
  139. package/src/community/events/utils.ts +49 -0
  140. package/src/community/observers/index.ts +1 -0
  141. package/src/community/observers/liveCommunities.ts +188 -0
  142. package/src/community/observers/tests/liveCommunities.test.ts +284 -0
  143. package/src/core/query/sorting.ts +8 -0
  144. package/src/core/transports/http.ts +17 -13
  145. package/src/core/transports/test/http.test.ts +49 -60
  146. package/src/file/api/createFile.ts +1 -1
  147. package/src/file/api/createImage.ts +1 -1
  148. package/src/file/api/createVideo.ts +1 -1
  149. package/src/file/api/test/createImage.test.ts +69 -0
  150. package/src/file/api/test/createVideo.test.ts +81 -0
  151. package/src/index.ts +1 -0
  152. package/src/message/observers/liveMessage.ts +11 -83
  153. package/src/message/tests/observers/liveMessage.test.ts +1 -143
  154. package/src/post/observers/index.ts +1 -0
  155. package/src/post/observers/livePost.ts +47 -0
  156. package/src/post/observers/tests/livePost.test.ts +97 -0
  157. package/src/stream/api/tests/createStream.test.ts +3 -11
  158. package/src/stream/api/tests/deleteStream.test.ts +5 -3
  159. package/src/subChannel/api/tests/createSubChannel.test.ts +21 -14
  160. package/src/subChannel/api/tests/deleteSubChannel.test.ts +112 -0
  161. package/src/subChannel/api/tests/getSubChannel.test.ts +97 -0
  162. package/src/subChannel/api/tests/getSubChannels.test.ts +97 -0
  163. package/src/subChannel/api/tests/updateSubChannel.test.ts +86 -0
  164. package/src/subChannel/observers/liveSubChannel.ts +6 -56
  165. package/src/subChannel/observers/tests/liveSubChannel.test.ts +0 -82
  166. package/src/user/api/tests/updateUser.test.ts +60 -0
  167. package/src/user/observers/liveUser.ts +9 -61
  168. package/src/user/tests/observers/liveUser.test.ts +1 -154
  169. package/src/utils/liveObject.ts +86 -0
  170. package/src/utils/tests/dummy/category.ts +57 -0
  171. package/src/utils/tests/dummy/channel.ts +51 -1
  172. package/src/utils/tests/dummy/community.ts +94 -0
  173. package/src/utils/tests/dummy/file.ts +32 -0
  174. package/src/utils/tests/dummy/index.ts +1 -0
  175. package/src/utils/tests/dummy/post.ts +56 -45
  176. package/src/utils/tests/dummy/stream.ts +73 -73
  177. package/src/utils/tests/dummy/subChannel.ts +0 -22
  178. package/src/utils/tests/dummy/user.ts +21 -0
  179. package/src/utils/tests/liveObject.test.ts +172 -0
package/dist/index.esm.js CHANGED
@@ -3,7 +3,6 @@ import AsyncStorage from '@react-native-async-storage/async-storage';
3
3
  import mitt from 'mitt';
4
4
  import debug from 'debug';
5
5
  import axios from 'axios';
6
- import qs from 'qs';
7
6
  import HttpAgent, { HttpsAgent } from 'agentkeepalive';
8
7
  import io from 'socket.io-client';
9
8
  import nativeIdGenerator from 'react-native-uuid';
@@ -1079,6 +1078,14 @@ const sortByDisplayName = ({ displayName: a }, { displayName: b }) => {
1079
1078
  return 0;
1080
1079
  return a < b ? -1 : 1;
1081
1080
  };
1081
+ /**
1082
+ * Alphabetic sorting of objects having a name
1083
+ */
1084
+ const sortByName = ({ name: a }, { name: b }) => {
1085
+ if (a === b)
1086
+ return 0;
1087
+ return a < b ? -1 : 1;
1088
+ };
1082
1089
  /**
1083
1090
  * Sorting a collection by their apparition order (oldest first)
1084
1091
  */
@@ -1382,13 +1389,6 @@ const unwrapPayload = (response) => {
1382
1389
  return undefined;
1383
1390
  };
1384
1391
 
1385
- /**
1386
- * Axios param serializer (for querystring)
1387
- * @hidden
1388
- */
1389
- const stringify = (params) => {
1390
- return qs.stringify(params, { arrayFormat: 'brackets' });
1391
- };
1392
1392
  /**
1393
1393
  * Creates a pre-configured axios instance
1394
1394
  *
@@ -1409,7 +1409,14 @@ const createHttpTransport = (endpoint) => {
1409
1409
  baseURL: endpoint,
1410
1410
  httpAgent: new HttpAgent(options),
1411
1411
  httpsAgent: new HttpsAgent(options),
1412
- paramsSerializer: stringify,
1412
+ /*
1413
+ * If paramSerializer is required, use the serialize option to stringify
1414
+ * params. The encode option will pass complex params as string only whereas
1415
+ * the serialize option will pass params in the format Record<string, any>
1416
+ *
1417
+ * For more details:
1418
+ * https://github.com/axios/axios#request-config
1419
+ */
1413
1420
  });
1414
1421
  instance.interceptors.request.use(config => {
1415
1422
  var _a;
@@ -1423,10 +1430,8 @@ const createHttpTransport = (endpoint) => {
1423
1430
  return config;
1424
1431
  });
1425
1432
  instance.interceptors.response.use(response => response, error => {
1426
- var _a;
1433
+ var _a, _b;
1427
1434
  const { response } = error;
1428
- // eslint-disable-next-line no-console
1429
- console.error((_a = response === null || response === void 0 ? void 0 : response.data) !== null && _a !== void 0 ? _a : error);
1430
1435
  // handle unauthorized request
1431
1436
  if (response.data.code === 400100 /* Amity.ServerError.UNAUTHORIZED */) {
1432
1437
  fireEvent('tokenTerminated', "terminated" /* Amity.SessionStates.TERMINATED */);
@@ -1436,8 +1441,15 @@ const createHttpTransport = (endpoint) => {
1436
1441
  fireEvent('tokenExpired', "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */);
1437
1442
  throw new ASCError('Token expired', 800403 /* Amity.ClientError.TOKEN_EXPIRED */, "fatal" /* Amity.ErrorLevel.FATAL */);
1438
1443
  }
1439
- if (response === null || response === void 0 ? void 0 : response.data)
1440
- unwrapPayload(response.data);
1444
+ // if it's an error with status in the response payload,
1445
+ // then it's an expected error.
1446
+ if ((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.status) {
1447
+ unwrapPayload(response === null || response === void 0 ? void 0 : response.data);
1448
+ }
1449
+ // unexpected error.
1450
+ else {
1451
+ throw new Error((_b = response === null || response === void 0 ? void 0 : response.data) !== null && _b !== void 0 ? _b : error);
1452
+ }
1441
1453
  });
1442
1454
  return instance;
1443
1455
  };
@@ -20877,7 +20889,8 @@ const isExpired = (expiresAt) => Date.now() > Date.parse(expiresAt) - COMPENSATE
20877
20889
  *
20878
20890
  * @category private
20879
20891
  */
20880
- const isAboutToExpire = (expiresAt, issuedAt) => {
20892
+ const isAboutToExpire = (params) => {
20893
+ const { expiresAt, issuedAt } = params;
20881
20894
  const expires = Date.parse(expiresAt);
20882
20895
  const issued = Date.parse(issuedAt);
20883
20896
  const now = Date.now();
@@ -20912,7 +20925,7 @@ const accessTokenExpiryWatcher = (expiresAt, issuedAt, sessionHandler) => {
20912
20925
  scheduleTask(() => sessionHandler.sessionWillRenewAccessToken(renewal()));
20913
20926
  return;
20914
20927
  }
20915
- if (isAboutToExpire(issuedAt, expiresAt)) {
20928
+ if (isAboutToExpire({ expiresAt, issuedAt })) {
20916
20929
  sessionHandler.sessionWillRenewAccessToken(renewal());
20917
20930
  }
20918
20931
  }, ACCESS_TOKEN_WATCHER_INTERVAL);
@@ -21383,6 +21396,58 @@ const onUserUnflagged = (callback) => createUserEventSubscriber('user.unflagged'
21383
21396
  */
21384
21397
  const onUserFlagCleared = (callback) => createUserEventSubscriber('user.flagCleared', callback);
21385
21398
 
21399
+ const liveObject = (id, callback, key, fetcher, eventHandlers) => {
21400
+ const { cache } = getActiveClient();
21401
+ if (!cache) {
21402
+ console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
21403
+ }
21404
+ let model;
21405
+ let isUnsyncedModel = false; // for messages
21406
+ const disposers = [];
21407
+ const dispatcher = (data) => {
21408
+ model = data.data;
21409
+ callback(data);
21410
+ };
21411
+ const realtimeRouter = (eventModel) => {
21412
+ if (id !== eventModel[key]) {
21413
+ return;
21414
+ }
21415
+ if (model && !hasUpdates(model, eventModel)) {
21416
+ return;
21417
+ }
21418
+ dispatcher({ loading: false, data: eventModel, origin: 'event' });
21419
+ };
21420
+ const onFetch = () => {
21421
+ // @ts-ignore
21422
+ const query = createQuery(fetcher, id, true);
21423
+ runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
21424
+ if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
21425
+ dispatcher({
21426
+ // @ts-ignore
21427
+ data,
21428
+ origin,
21429
+ loading: false,
21430
+ error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
21431
+ });
21432
+ isUnsyncedModel = true;
21433
+ disposers.forEach(fn => fn());
21434
+ }
21435
+ else if (!isUnsyncedModel) {
21436
+ // @ts-ignore
21437
+ dispatcher({ loading, data, origin, error });
21438
+ }
21439
+ if (error) {
21440
+ disposers.forEach(fn => fn());
21441
+ }
21442
+ });
21443
+ };
21444
+ disposers.push(...eventHandlers.map(fn => fn(realtimeRouter)));
21445
+ onFetch();
21446
+ return () => {
21447
+ disposers.forEach(fn => fn());
21448
+ };
21449
+ };
21450
+
21386
21451
  /**
21387
21452
  * ```js
21388
21453
  * import { onUserFetched } from '@amityco/ts-sdk'
@@ -21420,42 +21485,14 @@ const onUserFetched = (callback) => createUserEventSubscriber('user.fetched', ca
21420
21485
  * @category Message Live Object
21421
21486
  */
21422
21487
  const liveUser = (userId, callback) => {
21423
- const { log, cache } = getActiveClient();
21424
- const timestamp = Date.now();
21425
- log(`liveUser(tmpid: ${timestamp}) > listen`);
21426
- if (!cache) {
21427
- console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
21428
- }
21429
- let user;
21430
- const disposers = [];
21431
- const dispatcher = (data) => {
21432
- user = data.data;
21433
- callback(data);
21434
- };
21435
- const realtimeRouter = (eventUser) => {
21436
- if (userId !== eventUser.userId) {
21437
- return;
21438
- }
21439
- if (user && !hasUpdates(user, eventUser)) {
21440
- return;
21441
- }
21442
- dispatcher({ loading: false, data: eventUser, origin: 'event' });
21443
- };
21444
- const onFetch = () => {
21445
- const query = createQuery(getUser, userId, true);
21446
- runQuery(query, ({ loading, data, error, origin }) => {
21447
- dispatcher({ loading, data, origin, error });
21448
- if (error) {
21449
- disposers.forEach(fn => fn());
21450
- }
21451
- });
21452
- };
21453
- disposers.push(onUserFetched(realtimeRouter), onUserUpdated(realtimeRouter), onUserDeleted(realtimeRouter), onUserFlagged(realtimeRouter), onUserUnflagged(realtimeRouter), onUserFlagCleared(realtimeRouter));
21454
- onFetch();
21455
- return () => {
21456
- log(`liveUser(tmpid: ${timestamp}) > dispose`);
21457
- disposers.forEach(fn => fn());
21458
- };
21488
+ return liveObject(userId, callback, 'userId', getUser, [
21489
+ onUserFetched,
21490
+ onUserUpdated,
21491
+ onUserDeleted,
21492
+ onUserFlagged,
21493
+ onUserUnflagged,
21494
+ onUserFlagCleared,
21495
+ ]);
21459
21496
  };
21460
21497
 
21461
21498
  /**
@@ -21579,7 +21616,7 @@ const createFile = async (formData, onProgress) => {
21579
21616
  : { 'content-type': 'multipart/form-data' };
21580
21617
  const { data } = await client.http.post('/api/v4/files', formData, {
21581
21618
  headers,
21582
- onUploadProgress({ loaded, total }) {
21619
+ onUploadProgress({ loaded, total = 100 }) {
21583
21620
  onProgress && onProgress(Math.round((loaded * 100) / total));
21584
21621
  },
21585
21622
  });
@@ -21658,7 +21695,7 @@ const createVideo = async (formData, feedType, onProgress) => {
21658
21695
  : { 'content-type': 'multipart/form-data' };
21659
21696
  const { data } = await client.http.post('/api/v4/videos', formData, {
21660
21697
  headers,
21661
- onUploadProgress({ loaded, total }) {
21698
+ onUploadProgress({ loaded, total = 100 }) {
21662
21699
  onProgress && onProgress(Math.round((loaded * 100) / total));
21663
21700
  },
21664
21701
  });
@@ -21699,7 +21736,7 @@ const createImage = async (formData, onProgress) => {
21699
21736
  : { 'content-type': 'multipart/form-data' };
21700
21737
  const { data } = await client.http.post('/api/v4/images', formData, {
21701
21738
  headers,
21702
- onUploadProgress({ loaded, total }) {
21739
+ onUploadProgress({ loaded, total = 100 }) {
21703
21740
  onProgress && onProgress(Math.round((loaded * 100) / total));
21704
21741
  },
21705
21742
  });
@@ -23678,6 +23715,7 @@ getComments.locally = (commentIds) => {
23678
23715
  const getComment = async (commentId) => {
23679
23716
  const client = getActiveClient();
23680
23717
  client.log('comment/getComment', commentId);
23718
+ isInTombstone('comment', commentId);
23681
23719
  let data;
23682
23720
  try {
23683
23721
  // API-FIX: endpoint should not be /list, parameters should be querystring.
@@ -23685,8 +23723,8 @@ const getComment = async (commentId) => {
23685
23723
  data = response.data;
23686
23724
  }
23687
23725
  catch (error) {
23688
- if ((error === null || error === void 0 ? void 0 : error.code) === 400400 /* Amity.ServerError.ITEM_NOT_FOUND */) {
23689
- dropFromCache(['comment', 'get', commentId], true);
23726
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23727
+ pushToTombstone('comment', commentId);
23690
23728
  }
23691
23729
  throw error;
23692
23730
  }
@@ -23820,9 +23858,7 @@ const deleteComment = async (commentId, permanent = false) => {
23820
23858
  fireEvent('post.updated', { posts: [post.data] });
23821
23859
  fireEvent('comment.deleted', { comments: [deleted] });
23822
23860
  if (permanent) {
23823
- setTimeout(() => {
23824
- dropFromCache(['comment', 'get', commentId], true);
23825
- }, 0);
23861
+ scheduleTask(() => pushToTombstone('comment', commentId));
23826
23862
  }
23827
23863
  else {
23828
23864
  upsertInCache(['comment', 'get', commentId], { isDeleted: true });
@@ -26245,55 +26281,13 @@ const onMessageReactionRemoved = (callback) => {
26245
26281
  * @category Message Live Object
26246
26282
  */
26247
26283
  const liveChannel = (channelId, callback) => {
26248
- const { log, cache } = getActiveClient();
26249
- const timestamp = Date.now();
26250
- log(`liveChannel(tmpid: ${timestamp}) > listen`);
26251
- if (!cache) {
26252
- console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
26253
- }
26254
- let channel;
26255
- let isUnsyncedObject = false;
26256
- const disposers = [];
26257
- const dispatcher = (data) => {
26258
- channel = data.data;
26259
- callback(data);
26260
- };
26261
- const realtimeRouter = (eventChannel) => {
26262
- if (channelId !== eventChannel.channelId) {
26263
- return;
26264
- }
26265
- if (channel && !hasUpdates(channel, eventChannel)) {
26266
- return;
26267
- }
26268
- dispatcher({ loading: false, data: eventChannel, origin: 'event' });
26269
- };
26270
- const onFetch = () => {
26271
- const query = createQuery(getChannel, channelId);
26272
- runQuery(query, ({ loading, data, error, origin, cachedAt }) => {
26273
- if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
26274
- dispatcher({
26275
- data,
26276
- origin,
26277
- loading: false,
26278
- error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
26279
- });
26280
- isUnsyncedObject = true;
26281
- disposers.forEach(fn => fn());
26282
- }
26283
- else if (!isUnsyncedObject) {
26284
- dispatcher({ loading, data, origin, error });
26285
- }
26286
- if (error) {
26287
- disposers.forEach(fn => fn());
26288
- }
26289
- });
26290
- };
26291
- disposers.push(onChannelUpdated(realtimeRouter), onChannelDeleted(realtimeRouter), onChannelJoined(realtimeRouter), onChannelMuted(realtimeRouter), onMessageCreated(() => null));
26292
- onFetch();
26293
- return () => {
26294
- log(`liveChannel(tmpid: ${timestamp}) > dispose`);
26295
- disposers.forEach(fn => fn());
26296
- };
26284
+ return liveObject(channelId, callback, 'channelId', getChannel, [
26285
+ onChannelUpdated,
26286
+ onChannelDeleted,
26287
+ onChannelJoined,
26288
+ onChannelMuted,
26289
+ () => onMessageCreated(() => null), // watch unread count
26290
+ ]);
26297
26291
  };
26298
26292
 
26299
26293
  /**
@@ -26954,42 +26948,11 @@ const onSubChannelFetched = (callback) => {
26954
26948
  * @category SubChannel Live Object
26955
26949
  */
26956
26950
  const liveSubChannel = (subChannelId, callback) => {
26957
- const { log, cache } = getActiveClient();
26958
- const timestamp = Date.now();
26959
- log(`liveSubChannel(tmpid: ${timestamp}) > listen`);
26960
- if (!cache) {
26961
- console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
26962
- }
26963
- let subChannel;
26964
- const disposers = [];
26965
- const dispatcher = (data) => {
26966
- subChannel = data.data;
26967
- callback(data);
26968
- };
26969
- const realtimeRouter = (eventSubChannel) => {
26970
- if (subChannelId !== eventSubChannel.subChannelId) {
26971
- return;
26972
- }
26973
- if (subChannel && !hasUpdates(subChannel, eventSubChannel)) {
26974
- return;
26975
- }
26976
- dispatcher({ loading: false, data: eventSubChannel, origin: 'event' });
26977
- };
26978
- const onFetch = () => {
26979
- const query = createQuery(getSubChannel, subChannelId);
26980
- runQuery(query, ({ error, data, loading, origin }) => {
26981
- dispatcher({ error, data, loading, origin });
26982
- if (error) {
26983
- disposers.forEach(fn => fn());
26984
- }
26985
- });
26986
- };
26987
- disposers.push(onSubChannelFetched(realtimeRouter), onSubChannelUpdated(realtimeRouter), onSubChannelDeleted(realtimeRouter));
26988
- onFetch();
26989
- return () => {
26990
- log(`liveSubChannel(tmpid: ${timestamp}) > dispose`);
26991
- disposers.forEach(fn => fn());
26992
- };
26951
+ return liveObject(subChannelId, callback, 'subChannelId', getSubChannel, [
26952
+ onSubChannelFetched,
26953
+ onSubChannelUpdated,
26954
+ onSubChannelDeleted,
26955
+ ]);
26993
26956
  };
26994
26957
 
26995
26958
  /**
@@ -27120,55 +27083,16 @@ const onMessageFetched = (callback) => {
27120
27083
  * @category Message Live Object
27121
27084
  */
27122
27085
  const liveMessage = (messageId, callback) => {
27123
- const { log, cache } = getActiveClient();
27124
- const timestamp = Date.now();
27125
- log(`liveMessage(tmpid: ${timestamp}) > listen`);
27126
- if (!cache) {
27127
- console.log(LIVE_OBJECT_ENABLE_CACHE_MESSAGE);
27128
- }
27129
- let message;
27130
- let isUnsyncedObject = false;
27131
- const disposers = [];
27132
- const dispatcher = (data) => {
27133
- message = data.data;
27134
- callback(data);
27135
- };
27136
- const realtimeRouter = (eventMessage) => {
27137
- if (messageId !== eventMessage.messageId) {
27138
- return;
27139
- }
27140
- if (message && !hasUpdates(message, eventMessage)) {
27141
- return;
27142
- }
27143
- dispatcher({ loading: false, data: eventMessage, origin: 'event' });
27144
- };
27145
- const onFetch = () => {
27146
- const query = createQuery(getMessage, messageId, true);
27147
- runQuery(query, ({ loading, data, error, origin, cachedAt }) => {
27148
- if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
27149
- dispatcher({
27150
- data,
27151
- origin,
27152
- loading: false,
27153
- error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
27154
- });
27155
- isUnsyncedObject = true;
27156
- disposers.forEach(fn => fn());
27157
- }
27158
- else if (!isUnsyncedObject) {
27159
- dispatcher({ loading, data, origin, error });
27160
- }
27161
- if (error) {
27162
- disposers.forEach(fn => fn());
27163
- }
27164
- });
27165
- };
27166
- disposers.push(onMessageFetched(realtimeRouter), onMessageUpdated(realtimeRouter), onMessageDeleted(realtimeRouter), onMessageFlagged(realtimeRouter), onMessageUnflagged(realtimeRouter), onMessageFlagCleared(realtimeRouter), onMessageReactionAdded(realtimeRouter), onMessageReactionRemoved(realtimeRouter));
27167
- onFetch();
27168
- return () => {
27169
- log(`liveMessage(tmpid: ${timestamp}) > dispose`);
27170
- disposers.forEach(fn => fn());
27171
- };
27086
+ return liveObject(messageId, callback, 'messageId', getMessage, [
27087
+ onMessageFetched,
27088
+ onMessageUpdated,
27089
+ onMessageDeleted,
27090
+ onMessageFlagged,
27091
+ onMessageUnflagged,
27092
+ onMessageFlagCleared,
27093
+ onMessageReactionAdded,
27094
+ onMessageReactionRemoved,
27095
+ ]);
27172
27096
  };
27173
27097
 
27174
27098
  /**
@@ -27369,6 +27293,30 @@ const createCommunityEventSubscriber = (event, callback) => {
27369
27293
  };
27370
27294
  return createEventSubscriber(client, event, event, filter);
27371
27295
  };
27296
+ /*
27297
+ * verifies membership status
27298
+ */
27299
+ function isMember(membership) {
27300
+ return membership !== 'none';
27301
+ }
27302
+ /*
27303
+ * checks if currently logged in user is part of the community
27304
+ */
27305
+ function isCurrentUserPartOfCommunity(c, m) {
27306
+ const { userId } = getActiveUser();
27307
+ return c.communityId === m.communityId && m.userId === userId;
27308
+ }
27309
+ /*
27310
+ * For mqtt events server will not send user specific data as it's broadcasted
27311
+ * to multiple users. Althought this can be calculated, it's not scalable. Hence
27312
+ * the client SDK needs to calculate this info
27313
+ */
27314
+ function updateMembershipStatus(communities, communityUsers) {
27315
+ return communities.map(c => {
27316
+ const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
27317
+ return Object.assign(Object.assign({}, c), { isJoined });
27318
+ });
27319
+ }
27372
27320
  function hasPermission(member, payload, permission) {
27373
27321
  if (member.permissions.some(x => x === permission)) {
27374
27322
  return true;
@@ -27399,7 +27347,15 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
27399
27347
  const client = getActiveClient();
27400
27348
  const filter = (payload) => {
27401
27349
  const communityPayload = unpackCommunityPayload(payload);
27350
+ const { communities } = communityPayload;
27402
27351
  const preparedPayload = prepareMembershipPayload(communityPayload, 'communityUsers');
27352
+ const { communityUsers } = preparedPayload;
27353
+ /*
27354
+ * community.isJoined is not part of the communityMembership payload, and needs
27355
+ * to be calculated based on the communityMembership value
27356
+ */
27357
+ const communitiesWithMembership = updateMembershipStatus(communities, communityUsers);
27358
+ preparedPayload.communities = communitiesWithMembership;
27403
27359
  if (!client.cache) {
27404
27360
  // TODO: here we are missing specific properties here!
27405
27361
  callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
@@ -27541,6 +27497,23 @@ const onCommunityUserAdded = (callback) => createCommunityMemberEventSubscriber(
27541
27497
  */
27542
27498
  const onCommunityUserRemoved = (callback) => createCommunityMemberEventSubscriber('community.userRemoved', callback);
27543
27499
 
27500
+ /**
27501
+ * ```js
27502
+ * import { onCommunityUserChanged } from '@amityco/ts-sdk'
27503
+ * const dispose = onCommunityUserChanged((community, member) => {
27504
+ * // ...
27505
+ * })
27506
+ * ```
27507
+ *
27508
+ * Fired when a user has been added or removed from a {@link Amity.Community}
27509
+ *
27510
+ * @param callback The function to call when the event was fired
27511
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27512
+ *
27513
+ * @category Community Events
27514
+ */
27515
+ const onCommunityUserChanged = (callback) => createCommunityMemberEventSubscriber('community.userChanged', callback);
27516
+
27544
27517
  /**
27545
27518
  * ```js
27546
27519
  * import { onCommunityUserBanned } from '@amityco/ts-sdk'
@@ -27619,6 +27592,122 @@ const observeCommunity = (communityId, callback) => {
27619
27592
  };
27620
27593
  };
27621
27594
 
27595
+ /**
27596
+ * ```js
27597
+ * import { liveCommunities } from '@amityco/ts-sdk'
27598
+ *
27599
+ * let communities = []
27600
+ * const unsub = liveCommunities({
27601
+ * displayName: Amity.Community['displayName'],
27602
+ * }, response => merge(communities, response.data))
27603
+ * ```
27604
+ *
27605
+ * Observe all mutations on a list of {@link Amity.Community}s
27606
+ *
27607
+ * @param params for querying communities
27608
+ * @param callback the function to call when new data are available
27609
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
27610
+ *
27611
+ * @category Community Live Collection
27612
+ */
27613
+ const liveCommunities = (params, callback, config) => {
27614
+ const { log, cache } = getActiveClient();
27615
+ if (!cache) {
27616
+ console.log(ENABLE_CACHE_MESSAGE);
27617
+ }
27618
+ const timestamp = Date.now();
27619
+ log(`liveCommunities(tmpid: ${timestamp}) > listen`);
27620
+ const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
27621
+ const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
27622
+ const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
27623
+ const disposers = [];
27624
+ const cacheKey = ['community', 'collection', {}];
27625
+ const responder = (data) => {
27626
+ var _a, _b;
27627
+ let communities = (_a = data.data
27628
+ .map(communityId => pullFromCache(['community', 'get', communityId]))
27629
+ .filter(Boolean)
27630
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
27631
+ communities = filterByPropEquality(communities, 'isDeleted', params.isDeleted);
27632
+ communities = filterByPropEquality(communities, 'displayName', params.displayName);
27633
+ if (params.categoryId) {
27634
+ communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(params.categoryId); });
27635
+ }
27636
+ if (params.tags) {
27637
+ communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = params.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
27638
+ }
27639
+ if (params.membership === 'member') {
27640
+ communities = filterByPropEquality(communities, 'isJoined', true);
27641
+ }
27642
+ if (params.membership === 'notMember') {
27643
+ communities = filterByPropEquality(communities, 'isJoined', false);
27644
+ }
27645
+ const sortBy = params.sortBy || 'lastCreated';
27646
+ if (sortBy === 'lastCreated' || sortBy === 'firstCreated') {
27647
+ communities = communities.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
27648
+ }
27649
+ /*
27650
+ * The server returns communities with empty | null displayName's first before
27651
+ * returning sorted list of communities with displayNames
27652
+ *
27653
+ * This section needs to be updated as displayNames can be null as well
27654
+ */
27655
+ if (sortBy === 'displayName') {
27656
+ communities = communities
27657
+ // this needs to be aligned with the backend data type
27658
+ .map(c => (c.displayName ? c : Object.assign(Object.assign({}, c), { displayName: '' })))
27659
+ // @ts-ignore
27660
+ .sort(sortByDisplayName);
27661
+ }
27662
+ callback({
27663
+ onNextPage: onFetch,
27664
+ data: communities,
27665
+ hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
27666
+ loading: data.loading,
27667
+ error: data.error,
27668
+ });
27669
+ };
27670
+ const realtimeRouter = (_) => (community) => {
27671
+ var _a;
27672
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
27673
+ if (!collection)
27674
+ return;
27675
+ /*
27676
+ * Simply update collection and let responder decide what to do with data
27677
+ */
27678
+ collection.data = [...new Set([community.communityId, ...collection.data])];
27679
+ pushToCache(cacheKey, collection);
27680
+ responder(collection);
27681
+ };
27682
+ const onFetch = () => {
27683
+ var _a, _b, _c;
27684
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
27685
+ const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
27686
+ if (communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
27687
+ return;
27688
+ const query = createQuery(queryCommunities, Object.assign(Object.assign({}, queryParams), { page: (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) !== null && _c !== void 0 ? _c : { limit } }));
27689
+ runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
27690
+ const data = {
27691
+ loading,
27692
+ error,
27693
+ params: { page },
27694
+ data: communities,
27695
+ };
27696
+ if (result) {
27697
+ data.data = [...new Set([...communities, ...result.map(getResolver('community'))])];
27698
+ }
27699
+ pushToCache(cacheKey, data);
27700
+ responder(data);
27701
+ }, queryOptions(policy));
27702
+ };
27703
+ disposers.push(onCommunityCreated(realtimeRouter()), onCommunityDeleted(realtimeRouter()), onCommunityUpdated(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityLeft(realtimeRouter()), onCommunityUserChanged(realtimeRouter()));
27704
+ onFetch();
27705
+ return () => {
27706
+ log(`liveCommunities(tmpid: ${timestamp}) > dispose`);
27707
+ disposers.forEach(fn => fn());
27708
+ };
27709
+ };
27710
+
27622
27711
  /**
27623
27712
  * ```js
27624
27713
  * import { queryCategories } from '@amityco/ts-sdk'
@@ -27747,6 +27836,96 @@ getCategory.locally = (categoryId) => {
27747
27836
  };
27748
27837
  };
27749
27838
 
27839
+ /**
27840
+ * ```js
27841
+ * import { liveCategories } from '@amityco/ts-sdk'
27842
+ *
27843
+ * let categories = []
27844
+ * const unsub = liveCategories({}, response => merge(categories, response.data))
27845
+ * ```
27846
+ *
27847
+ * Observe all mutations on a list of {@link Amity.Category}s
27848
+ *
27849
+ * @param params for querying categories
27850
+ * @param callback the function to call when new data are available
27851
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the categories
27852
+ *
27853
+ * @category Category Live Collection
27854
+ */
27855
+ const liveCategories = (params, callback, config) => {
27856
+ const { log, cache } = getActiveClient();
27857
+ if (!cache) {
27858
+ console.log(ENABLE_CACHE_MESSAGE);
27859
+ }
27860
+ const timestamp = Date.now();
27861
+ log(`liveCategories(tmpid: ${timestamp}) > listen`);
27862
+ const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
27863
+ const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
27864
+ const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
27865
+ const disposers = [];
27866
+ const cacheKey = ['category', 'collection', {}];
27867
+ const responder = (data) => {
27868
+ var _a, _b;
27869
+ let categories = (_a = data.data
27870
+ .map(categoryId => pullFromCache(['category', 'get', categoryId]))
27871
+ .filter(Boolean)
27872
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
27873
+ categories = filterByPropEquality(categories, 'isDeleted', params.isDeleted);
27874
+ switch (params.sortBy) {
27875
+ case 'firstCreated':
27876
+ categories = categories.sort(sortByFirstCreated);
27877
+ break;
27878
+ case 'lastCreated':
27879
+ categories = categories.sort(sortByLastCreated);
27880
+ break;
27881
+ default:
27882
+ categories = categories.sort(sortByName);
27883
+ }
27884
+ callback({
27885
+ onNextPage: onFetch,
27886
+ data: categories,
27887
+ hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
27888
+ loading: data.loading,
27889
+ error: data.error,
27890
+ });
27891
+ };
27892
+ /*
27893
+ * const realtimeRouter = () => {
27894
+ * @TODO: At the time of creating this method category does not have any
27895
+ * observers
27896
+ *};
27897
+ */
27898
+ const onFetch = () => {
27899
+ var _a, _b, _c;
27900
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
27901
+ const categories = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
27902
+ if (categories.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
27903
+ return;
27904
+ const query = createQuery(queryCategories, Object.assign(Object.assign({}, queryParams), { page: (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) !== null && _c !== void 0 ? _c : { limit } }));
27905
+ runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
27906
+ const data = {
27907
+ loading,
27908
+ error,
27909
+ params: { page },
27910
+ data: categories,
27911
+ };
27912
+ if (result) {
27913
+ data.data = [...new Set([...categories, ...result.map(getResolver('category'))])];
27914
+ }
27915
+ pushToCache(cacheKey, data);
27916
+ responder(data);
27917
+ }, queryOptions(policy));
27918
+ };
27919
+ disposers.push(() => {
27920
+ // @TODO -> update once observers added
27921
+ });
27922
+ onFetch();
27923
+ return () => {
27924
+ log(`liveCategories(tmpid: ${timestamp}) > dispose`);
27925
+ disposers.forEach(fn => fn());
27926
+ };
27927
+ };
27928
+
27750
27929
  /**
27751
27930
  * ```js
27752
27931
  * import { queryGlobalFeed } from '@amityco/ts-sdk'
@@ -28671,6 +28850,38 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
28671
28850
  };
28672
28851
  };
28673
28852
 
28853
+ /**
28854
+ * ```js
28855
+ * import { livePost } from '@amityco/ts-sdk';
28856
+ *
28857
+ * let post;
28858
+ *
28859
+ * const unsubscribe = livePost(postId, response => {
28860
+ * post = response.data;
28861
+ * });
28862
+ * ```
28863
+ *
28864
+ * Observe all mutation on a given {@link Amity.Post}
28865
+ *
28866
+ * @param postId the ID of the message to observe
28867
+ * @param callback the function to call when new data are available
28868
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the sub channel
28869
+ *
28870
+ * @category Post Live Object
28871
+ */
28872
+ const livePost = (postId, callback) => {
28873
+ return liveObject(postId, callback, 'postId', getPost, [
28874
+ onPostApproved,
28875
+ onPostDeclined,
28876
+ onPostDeleted,
28877
+ onPostFlagged,
28878
+ onPostReactionAdded,
28879
+ onPostReactionRemoved,
28880
+ onPostUnflagged,
28881
+ onPostUpdated,
28882
+ ]);
28883
+ };
28884
+
28674
28885
  /**
28675
28886
  * ```js
28676
28887
  * import { livePosts } from '@amityco/ts-sdk'
@@ -28866,6 +29077,36 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
28866
29077
  };
28867
29078
  };
28868
29079
 
29080
+ /**
29081
+ * ```js
29082
+ * import { liveComment } from '@amityco/ts-sdk';
29083
+ *
29084
+ * let comment;
29085
+ *
29086
+ * const unsubscribe = liveComment(commentId, response => {
29087
+ * comment = response.data;
29088
+ * });
29089
+ * ```
29090
+ *
29091
+ * Observe all mutation on a given {@link Amity.Comment}
29092
+ *
29093
+ * @param commentId the ID of the comment to observe
29094
+ * @param callback the function to call when new data are available
29095
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
29096
+ *
29097
+ * @category Comment Live Object
29098
+ */
29099
+ const liveComment = (commentId, callback) => {
29100
+ return liveObject(commentId, callback, 'commentId', getComment, [
29101
+ onCommentDeleted,
29102
+ onCommentFlagged,
29103
+ onCommentReactionAdded,
29104
+ onCommentReactionRemoved,
29105
+ onCommentUnflagged,
29106
+ onCommentUpdated,
29107
+ ]);
29108
+ };
29109
+
28869
29110
  /**
28870
29111
  * ```js
28871
29112
  * import { liveComments } from '@amityco/ts-sdk'
@@ -29550,4 +29791,4 @@ const createUserToken = async (apiKey, apiRegion, params) => {
29550
29791
  return { accessToken: data.accessToken };
29551
29792
  };
29552
29793
 
29553
- export { API_REGIONS, CommunityPostSettingMaps, CommunityPostSettings, ContentFeedType, DefaultCommunityPostSetting, FileType, MessageContentType, PostContentType, SubscriptionLevels, VERSION$1 as VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, acceptFollower, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRoles, addReaction, approvePost, backupCache, banChannelMembers, closePoll, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createImage, createMessage, createPoll, createPost, createQuery, createReport, createStream, createSubChannel, createUserToken, createVideo, declineFollower, declinePost, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePoll, deletePost, deleteReport, deleteStream, deleteSubChannel, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByChannelMembership, filterByPropEquality, filterByPropInclusion, follow, getActiveClient, getCategory, getChannel, getChannelTopic, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFeedSettings, getFile, getFollowInfo, getMessage, getMessageTopic, getMessages, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPoll, getPost, getPostTopic, getPosts, getRecommendedCommunities, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStream, getSubChannel, getSubChannelTopic, getSubChannels, getTopTrendingCommunities, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, liveChannel, liveChannelMembers, liveChannels, liveComments, liveFollowers, liveFollowings, liveMessage, liveMessages, livePosts, liveReactions, liveSubChannel, liveSubChannels, liveUser, mergeInCache, observeChannel, observeChannels, observeComment, observeComments, observeCommunity, observeFile, observeFollowInfo, observeFollowers, observeFollowings, observeMessage, observeMessages, observePoll, observePost, observePosts, observeUser, onChannelCreated, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelMemberAdded, onChannelMemberBanned, onChannelMemberRemoved, onChannelMemberUnbanned, onChannelMuted, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onFollowInfoUpdated, onFollowRequestAccepted, onFollowRequestCanceled, onFollowRequestDeclined, onFollowerDeleted, onFollowerRequested, onMessageCreated, onMessageDeleted, onMessageFlagCleared, onMessageFlagged, onMessageReactionAdded, onMessageReactionRemoved, onMessageUnflagged, onMessageUpdated, onPollDeleted, onPollUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionAdded, onReactionRemoved, onReactorAdded, onReactorRemoved, onSessionStateChange, onStreamRecorded, onStreamStarted, onStreamStopped, onSubChannelCreated, onSubChannelDeleted, onSubChannelUpdated, onUserDeleted, onUserFlagCleared, onUserFlagged, onUserFollowed, onUserUnflagged, onUserUnfollowed, onUserUpdated, pullFromCache, pushToCache, queryCache, queryCategories, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryFollowers, queryFollowings, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryReactions, queryRoles, queryStreams, querySubChannels, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRoles, removeReaction, renewal, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, startReading, stopReading, subscribeTopic, toPage, toPageRaw, toToken, unbanChannelMembers, unfollow, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateSubChannel, updateUser, upsertInCache, votePoll, wipeCache };
29794
+ export { API_REGIONS, CommunityPostSettingMaps, CommunityPostSettings, ContentFeedType, DefaultCommunityPostSetting, FileType, MessageContentType, PostContentType, SubscriptionLevels, VERSION$1 as VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, acceptFollower, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRoles, addReaction, approvePost, backupCache, banChannelMembers, closePoll, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createImage, createMessage, createPoll, createPost, createQuery, createReport, createStream, createSubChannel, createUserToken, createVideo, declineFollower, declinePost, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePoll, deletePost, deleteReport, deleteStream, deleteSubChannel, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByChannelMembership, filterByPropEquality, filterByPropInclusion, follow, getActiveClient, getCategory, getChannel, getChannelTopic, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFeedSettings, getFile, getFollowInfo, getMessage, getMessageTopic, getMessages, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPoll, getPost, getPostTopic, getPosts, getRecommendedCommunities, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStream, getSubChannel, getSubChannelTopic, getSubChannels, getTopTrendingCommunities, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, liveCategories, liveChannel, liveChannelMembers, liveChannels, liveComment, liveComments, liveCommunities, liveFollowers, liveFollowings, liveMessage, liveMessages, livePost, livePosts, liveReactions, liveSubChannel, liveSubChannels, liveUser, mergeInCache, observeChannel, observeChannels, observeComment, observeComments, observeCommunity, observeFile, observeFollowInfo, observeFollowers, observeFollowings, observeMessage, observeMessages, observePoll, observePost, observePosts, observeUser, onChannelCreated, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelMemberAdded, onChannelMemberBanned, onChannelMemberRemoved, onChannelMemberUnbanned, onChannelMuted, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserChanged, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onFollowInfoUpdated, onFollowRequestAccepted, onFollowRequestCanceled, onFollowRequestDeclined, onFollowerDeleted, onFollowerRequested, onMessageCreated, onMessageDeleted, onMessageFlagCleared, onMessageFlagged, onMessageReactionAdded, onMessageReactionRemoved, onMessageUnflagged, onMessageUpdated, onPollDeleted, onPollUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionAdded, onReactionRemoved, onReactorAdded, onReactorRemoved, onSessionStateChange, onStreamRecorded, onStreamStarted, onStreamStopped, onSubChannelCreated, onSubChannelDeleted, onSubChannelUpdated, onUserDeleted, onUserFlagCleared, onUserFlagged, onUserFollowed, onUserUnflagged, onUserUnfollowed, onUserUpdated, pullFromCache, pushToCache, queryCache, queryCategories, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryFollowers, queryFollowings, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryReactions, queryRoles, queryStreams, querySubChannels, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRoles, removeReaction, renewal, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortByName, sortBySegmentNumber, startReading, stopReading, subscribeTopic, toPage, toPageRaw, toToken, unbanChannelMembers, unfollow, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateSubChannel, updateUser, upsertInCache, votePoll, wipeCache };