@amityco/ts-sdk 0.0.1-beta.41.1 → 0.0.1-beta.42.2

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 (122) hide show
  1. package/dist/@types/core/model.d.ts +3 -1
  2. package/dist/@types/core/model.d.ts.map +1 -1
  3. package/dist/@types/domains/category.d.ts +1 -1
  4. package/dist/@types/domains/category.d.ts.map +1 -1
  5. package/dist/@types/domains/comment.d.ts +1 -1
  6. package/dist/@types/domains/comment.d.ts.map +1 -1
  7. package/dist/@types/domains/community.d.ts +1 -1
  8. package/dist/@types/domains/community.d.ts.map +1 -1
  9. package/dist/@types/domains/message.d.ts +1 -1
  10. package/dist/@types/domains/message.d.ts.map +1 -1
  11. package/dist/@types/domains/post.d.ts +1 -1
  12. package/dist/@types/domains/post.d.ts.map +1 -1
  13. package/dist/@types/domains/subChannel.d.ts +1 -1
  14. package/dist/@types/domains/subChannel.d.ts.map +1 -1
  15. package/dist/cache/utils/index.d.ts +1 -0
  16. package/dist/cache/utils/index.d.ts.map +1 -1
  17. package/dist/category/api/queryCategories.d.ts.map +1 -1
  18. package/dist/category/observers/liveCategories.d.ts.map +1 -1
  19. package/dist/channel/observers/liveChannel.d.ts.map +1 -1
  20. package/dist/channel/observers/liveChannels.d.ts.map +1 -1
  21. package/dist/comment/api/queryComments.d.ts.map +1 -1
  22. package/dist/comment/api/tests/queryComments.test.d.ts +2 -0
  23. package/dist/comment/api/tests/queryComments.test.d.ts.map +1 -0
  24. package/dist/comment/observers/liveComments.d.ts.map +1 -1
  25. package/dist/community/api/queryCommunities.d.ts.map +1 -1
  26. package/dist/community/observers/liveCommunities.d.ts.map +1 -1
  27. package/dist/core/model/idResolvers.d.ts.map +1 -1
  28. package/dist/core/model/identifyModel.d.ts.map +1 -1
  29. package/dist/core/model/index.d.ts +1 -1
  30. package/dist/core/model/index.d.ts.map +1 -1
  31. package/dist/follow/api/getFollowInfo.d.ts.map +1 -1
  32. package/dist/follow/observers/index.d.ts +1 -0
  33. package/dist/follow/observers/index.d.ts.map +1 -1
  34. package/dist/follow/observers/liveFollowInfo.d.ts +21 -0
  35. package/dist/follow/observers/liveFollowInfo.d.ts.map +1 -0
  36. package/dist/follow/observers/tests/liveFollowInfo.test.d.ts +2 -0
  37. package/dist/follow/observers/tests/liveFollowInfo.test.d.ts.map +1 -0
  38. package/dist/index.cjs.js +112 -63
  39. package/dist/index.esm.js +112 -64
  40. package/dist/index.umd.js +4 -4
  41. package/dist/message/api/createMessage.d.ts +2 -1
  42. package/dist/message/api/createMessage.d.ts.map +1 -1
  43. package/dist/message/observers/liveMessages.d.ts.map +1 -1
  44. package/dist/message/utils/index.d.ts +3 -2
  45. package/dist/message/utils/index.d.ts.map +1 -1
  46. package/dist/post/api/queryPosts.d.ts.map +1 -1
  47. package/dist/post/observers/livePosts.d.ts.map +1 -1
  48. package/dist/subChannel/api/querySubChannels.d.ts.map +1 -1
  49. package/dist/subChannel/observers/liveSubChannels.d.ts.map +1 -1
  50. package/dist/utils/constants.d.ts +1 -0
  51. package/dist/utils/constants.d.ts.map +1 -1
  52. package/dist/utils/liveObject.d.ts +1 -1
  53. package/dist/utils/liveObject.d.ts.map +1 -1
  54. package/dist/utils/tests/dummy/comment.d.ts +77 -0
  55. package/dist/utils/tests/dummy/comment.d.ts.map +1 -0
  56. package/dist/utils/tests/dummy/community.d.ts +1 -1
  57. package/dist/utils/tests/dummy/index.d.ts +1 -0
  58. package/dist/utils/tests/dummy/index.d.ts.map +1 -1
  59. package/dist/utils/tests/dummy/post.d.ts +0 -12
  60. package/dist/utils/tests/dummy/post.d.ts.map +1 -1
  61. package/package.json +1 -1
  62. package/src/@types/core/model.ts +3 -1
  63. package/src/@types/domains/category.ts +1 -1
  64. package/src/@types/domains/comment.ts +1 -1
  65. package/src/@types/domains/community.ts +1 -1
  66. package/src/@types/domains/message.ts +1 -1
  67. package/src/@types/domains/post.ts +1 -1
  68. package/src/@types/domains/subChannel.ts +1 -1
  69. package/src/cache/utils/index.ts +5 -2
  70. package/src/category/api/queryCategories.ts +2 -1
  71. package/src/category/observers/liveCategories.ts +3 -1
  72. package/src/category/observers/tests/liveCategories.test.ts +1 -3
  73. package/src/channel/api/tests/addChannelMembers.test.ts +13 -0
  74. package/src/channel/api/tests/queryChannelMembers.test.ts +1 -0
  75. package/src/channel/api/tests/removeChannelMembers.test.ts +9 -2
  76. package/src/channel/observers/liveChannel.ts +16 -1
  77. package/src/channel/observers/liveChannels.ts +11 -9
  78. package/src/comment/api/queryComments.ts +2 -1
  79. package/src/comment/api/tests/createComment.test.ts +17 -112
  80. package/src/comment/api/tests/queryComments.test.ts +147 -0
  81. package/src/comment/api/tests/updateComment.test.ts +14 -85
  82. package/src/comment/observers/liveComments.ts +12 -7
  83. package/src/community/api/queryCommunities.ts +2 -1
  84. package/src/community/api/test/queryCommunity.test.ts +30 -0
  85. package/src/community/observers/liveCommunities.ts +13 -7
  86. package/src/community/observers/tests/liveCommunities.test.ts +2 -2
  87. package/src/core/model/idResolvers.ts +1 -0
  88. package/src/core/model/identifyModel.ts +2 -1
  89. package/src/core/model/index.ts +11 -2
  90. package/src/follow/api/getFollowInfo.ts +4 -8
  91. package/src/follow/observers/index.ts +1 -0
  92. package/src/follow/observers/liveFollowInfo.ts +29 -0
  93. package/src/follow/observers/tests/liveFollowInfo.test.ts +198 -0
  94. package/src/message/api/createMessage.ts +17 -5
  95. package/src/message/api/tests/createMessage.test.ts +36 -5
  96. package/src/message/api/tests/deleteMessage.test.ts +10 -3
  97. package/src/message/api/tests/getMessage.test.ts +9 -3
  98. package/src/message/api/tests/queryMessages.test.ts +30 -0
  99. package/src/message/api/tests/updateMessage.test.ts +9 -2
  100. package/src/message/observers/liveMessages.ts +15 -15
  101. package/src/message/tests/observers/liveMessages.test.ts +2 -2
  102. package/src/message/utils/index.ts +10 -1
  103. package/src/post/api/queryPosts.ts +2 -1
  104. package/src/post/api/tests/queryPosts.test.ts +30 -0
  105. package/src/post/observers/livePosts.ts +16 -11
  106. package/src/post/observers/tests/livePosts.test.ts +4 -5
  107. package/src/reaction/api/tests/addReaction.test.ts +13 -0
  108. package/src/reaction/api/tests/removeReaction.test.ts +13 -0
  109. package/src/subChannel/api/querySubChannels.ts +2 -1
  110. package/src/subChannel/observers/liveSubChannels.ts +6 -5
  111. package/src/subChannel/observers/tests/liveSubChannels.test.ts +5 -2
  112. package/src/utils/constants.ts +2 -1
  113. package/src/utils/liveObject.ts +1 -4
  114. package/src/utils/tests/dummy/comment.ts +268 -0
  115. package/src/utils/tests/dummy/index.ts +1 -0
  116. package/src/utils/tests/dummy/post.ts +0 -114
  117. package/dist/post/tests/api/getPost.test.d.ts +0 -2
  118. package/dist/post/tests/api/getPost.test.d.ts.map +0 -1
  119. package/dist/post/tests/api/queryPosts.test.d.ts +0 -2
  120. package/dist/post/tests/api/queryPosts.test.d.ts.map +0 -1
  121. package/src/post/tests/api/getPost.test.ts +0 -98
  122. package/src/post/tests/api/queryPosts.test.ts +0 -123
package/dist/index.cjs.js CHANGED
@@ -95,8 +95,8 @@ const PostContentType = Object.freeze({
95
95
 
96
96
  function getVersion() {
97
97
  try {
98
- // the string ''v0.0.1-beta.41.1-cjs'' should be replaced by actual value by @rollup/plugin-replace
99
- return 'v0.0.1-beta.41.1-cjs';
98
+ // the string ''v0.0.1-beta.42.2-cjs'' should be replaced by actual value by @rollup/plugin-replace
99
+ return 'v0.0.1-beta.42.2-cjs';
100
100
  }
101
101
  catch (error) {
102
102
  return '__dev__';
@@ -104,11 +104,22 @@ function getVersion() {
104
104
  }
105
105
  const VERSION = getVersion();
106
106
 
107
+ const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
108
+ const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
109
+ const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
110
+ const LIVE_OBJECT_ENABLE_CACHE_MESSAGE = 'For using Live Object feature you need to enable Cache!';
111
+ const UNSYNCED_OBJECT_CACHED_AT_MESSAGE = 'Observing unsynced object is not supported by Live Object.';
112
+ const UNSYNCED_OBJECT_CACHED_AT_VALUE = -5;
113
+ const SECOND = 1000;
114
+ const MINUTE = 60 * SECOND;
115
+ const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
116
+
107
117
  // cache constants
108
118
  const CACHE_KEY_GET = 'get';
109
119
  const CACHE_KEY_TOMBSTONE = 'dead';
110
- const CACHE_LIFESPAN = 1 * 60 * 1000; // 1 minute
111
- const CACHE_LIFESPAN_TOMBSTONE = 3 * 60 * 1000; // 3 minutes
120
+ const CACHE_SHORTEN_LIFESPAN = 2 * SECOND;
121
+ const CACHE_LIFESPAN = 1 * MINUTE; // 1 minute
122
+ const CACHE_LIFESPAN_TOMBSTONE = 3 * MINUTE; // 3 minutes
112
123
  /**
113
124
  * Shallow-clones an object and sort its keys
114
125
  *
@@ -512,6 +523,7 @@ const idResolvers = {
512
523
  reaction: ({ reactionId }) => reactionId,
513
524
  stream: ({ streamId }) => streamId,
514
525
  follow: ({ from, to }) => `${from}#${to}`,
526
+ followInfo: ({ userId }) => userId,
515
527
  followCount: ({ userId }) => userId,
516
528
  feed: ({ targetId, feedId }) => `${targetId}#${feedId}`,
517
529
  };
@@ -550,8 +562,9 @@ const CRITERIAS = {
550
562
  reaction: ['reactionId'],
551
563
  stream: ['streamId'],
552
564
  follow: ['from', 'to'],
553
- followCount: ['userId', 'followerCount'],
554
565
  feed: ['feedId', 'feedType'],
566
+ followInfo: ['userId', 'status'],
567
+ followCount: ['userId', 'followerCount'],
555
568
  };
556
569
  /** @hidden */
557
570
  const hasKeys = (object, needles) => {
@@ -616,7 +629,15 @@ const PAYLOAD2MODEL = {
616
629
  };
617
630
  /** hidden */
618
631
  const hasUpdates = (prevData, nextData) => {
619
- return new Date(prevData.updatedAt) < new Date(nextData.updatedAt);
632
+ if ('updatedAt' in prevData && 'updatedAt' in nextData) {
633
+ return new Date(prevData.updatedAt) < new Date(nextData.updatedAt);
634
+ }
635
+ /*
636
+ * hasUpdates is used to identify the latest object among many. If the object
637
+ * does not extend ${Amity.UpdatedAt}, then there is no way to differentiate.
638
+ * So it is considered by default that the object hasUpdates
639
+ */
640
+ return true;
620
641
  };
621
642
  /** hidden */
622
643
  function getFutureDate(date = new Date().toISOString()) {
@@ -20371,15 +20392,6 @@ const getFeedSettings = async () => {
20371
20392
  }));
20372
20393
  };
20373
20394
 
20374
- const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
20375
- const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
20376
- const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
20377
- const LIVE_OBJECT_ENABLE_CACHE_MESSAGE = 'For using Live Object feature you need to enable Cache!';
20378
- const UNSYNCED_OBJECT_CACHED_AT_MESSAGE = 'Observing unsynced object is not supported by Live Object.';
20379
- const UNSYNCED_OBJECT_CACHED_AT_VALUE = -5;
20380
- const MINUTE = 60 * 1000;
20381
- const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
20382
-
20383
20395
  // TODO: find a way to uniquely identify the device
20384
20396
  /** @hidden */
20385
20397
  const getDeviceId = () => {
@@ -22191,8 +22203,8 @@ function convertParams(_a) {
22191
22203
  return Object.assign({ messageFeedId: subChannelId, mentionedUsers: mentionees }, rest);
22192
22204
  }
22193
22205
  function convertQueryParams$1(_a) {
22194
- var { page, sortBy, subChannelId, tags } = _a, rest = __rest(_a, ["page", "sortBy", "subChannelId", "tags"]);
22195
- const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, options: { token: toToken(page || { limit: 10 }, 'afterbeforeraw') } });
22206
+ var { page, sortBy, subChannelId, tags, includeDeleted } = _a, rest = __rest(_a, ["page", "sortBy", "subChannelId", "tags", "includeDeleted"]);
22207
+ const out = Object.assign(Object.assign({}, rest), { messageFeedId: subChannelId, isDeleted: includeDeleted === false ? false : undefined, options: { token: toToken(page || { limit: 10 }, 'afterbeforeraw') } });
22196
22208
  if (sortBy !== undefined) {
22197
22209
  out.options.sortBy = sortBy;
22198
22210
  }
@@ -22454,7 +22466,7 @@ let uniqueId;
22454
22466
  const createMessage = async (bundle) => {
22455
22467
  const client = getActiveClient();
22456
22468
  client.log('message/createMessage', bundle);
22457
- const referenceId = uniqueId || getLocalId();
22469
+ const referenceId = bundle.referenceId || uniqueId || getLocalId();
22458
22470
  uniqueId = undefined;
22459
22471
  const { data: payload } = await client.http.post('/api/v5/messages', Object.assign(Object.assign({}, convertParams(bundle)), { referenceId }));
22460
22472
  const data = prepareMessagePayload(payload);
@@ -22487,8 +22499,9 @@ const createMessage = async (bundle) => {
22487
22499
  *
22488
22500
  * @category Message API
22489
22501
  */
22490
- createMessage.optimistically = (bundle) => {
22491
- var _a, _b;
22502
+ createMessage.optimistically = (_a) => {
22503
+ var _b, _c;
22504
+ var { referenceId } = _a, bundle = __rest(_a, ["referenceId"]);
22492
22505
  const client = getActiveClient();
22493
22506
  if (!client.cache)
22494
22507
  return;
@@ -22499,7 +22512,7 @@ createMessage.optimistically = (bundle) => {
22499
22512
  * Updated to handle client requirement to add messageId while uploading
22500
22513
  * message with image. Temporary!
22501
22514
  */
22502
- uniqueId = getLocalId();
22515
+ uniqueId = referenceId || getLocalId();
22503
22516
  const bundleWithMessageId = Object.assign({ messageId: uniqueId, uniqueId }, bundle);
22504
22517
  client.log('message/createMessage.optimistically', bundleWithMessageId);
22505
22518
  const subChannel = pullFromCache(['subChannel', 'get', bundle.subChannelId]);
@@ -22508,13 +22521,13 @@ createMessage.optimistically = (bundle) => {
22508
22521
  if (subChannel.data.channelId === subChannel.data.subChannelId) {
22509
22522
  const channel = pullFromCache(['channel', 'get', subChannel.data.channelId]);
22510
22523
  if (channel === null || channel === void 0 ? void 0 : channel.data) {
22511
- upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_a = channel.data.messageCount) !== null && _a !== void 0 ? _a : 0) + 1 }));
22524
+ upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_b = channel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1 }));
22512
22525
  }
22513
22526
  }
22514
22527
  }
22515
22528
  // as reused to update created and updated time, which should be the same
22516
22529
  const createdTime = new Date().toISOString();
22517
- const message = Object.assign({ creatorId: client.userId, channelSegment: ((_b = subChannel === null || subChannel === void 0 ? void 0 : subChannel.data.messageCount) !== null && _b !== void 0 ? _b : 0) + 1, childrenNumber: 0, createdAt: createdTime, updatedAt: createdTime }, bundleWithMessageId);
22530
+ const message = Object.assign({ creatorId: client.userId, channelSegment: ((_c = subChannel === null || subChannel === void 0 ? void 0 : subChannel.data.messageCount) !== null && _c !== void 0 ? _c : 0) + 1, childrenNumber: 0, createdAt: createdTime, updatedAt: createdTime }, bundleWithMessageId);
22518
22531
  const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
22519
22532
  pushToCache(['message', 'get', message.messageId], message, { cachedAt });
22520
22533
  fireEvent('local.message.created', { messages: [message] });
@@ -22732,13 +22745,13 @@ const prepareMembershipPayload = (payload, memberProp, userIdProp = 'userId', us
22732
22745
  const queryPosts = async (query) => {
22733
22746
  const client = getActiveClient();
22734
22747
  client.log('post/queryPosts', query);
22735
- const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
22748
+ const { page = { limit: 10 }, includeDeleted } = query, params = __rest(query, ["page", "includeDeleted"]);
22736
22749
  const { dataTypes, matchingOnlyParentPost } = params;
22737
22750
  // API-FIX: parameters should be querystring. (1)
22738
22751
  // API-FIX: backend should answer Amity.Response (2)
22739
22752
  // const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
22740
22753
  const { data } = await client.http.get(`/api/v4/posts`, {
22741
- params: Object.assign(Object.assign({}, params), {
22754
+ params: Object.assign(Object.assign({}, params), { isDeleted: includeDeleted === false ? false : undefined,
22742
22755
  /*
22743
22756
  * when creating post like image, file, video BE will create 2 posts
22744
22757
  * 1. parent post to store text with dataType=text
@@ -23066,12 +23079,12 @@ const queryCommunities = async (query) => {
23066
23079
  client.log('channel/queryCommunities', query);
23067
23080
  // safe decapsulation
23068
23081
  const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
23069
- const _b = params !== null && params !== void 0 ? params : {}, { displayName, membership } = _b, restParams = __rest(_b, ["displayName", "membership"]);
23082
+ const _b = params !== null && params !== void 0 ? params : {}, { displayName, membership, includeDeleted } = _b, restParams = __rest(_b, ["displayName", "membership", "includeDeleted"]);
23070
23083
  // API-FIX: parameters should be querystring.
23071
23084
  // API-FIX: backend doesnt answer Amity.Response
23072
23085
  // const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<CommunityPayload>>>(
23073
23086
  const { data } = await client.http.get(`/api/v3/communities`, {
23074
- params: Object.assign(Object.assign({}, restParams), { keyword: displayName, filter: membership, options: {
23087
+ params: Object.assign(Object.assign({}, restParams), { isDeleted: includeDeleted === false ? false : undefined, keyword: displayName, filter: membership, options: {
23075
23088
  token: toToken(page, 'skiplimit'),
23076
23089
  } }),
23077
23090
  });
@@ -23912,7 +23925,7 @@ const declinePost = async (postId) => {
23912
23925
  const queryComments = async (query) => {
23913
23926
  const client = getActiveClient();
23914
23927
  client.log('comment/queryComments', query);
23915
- const { page = { limit: 10 } } = query, params = __rest(query, ["page"]);
23928
+ const { page = { limit: 10 }, includeDeleted } = query, params = __rest(query, ["page", "includeDeleted"]);
23916
23929
  const options = {
23917
23930
  type: params.sortBy ? 'pagination' : undefined,
23918
23931
  token: toToken(page, params.sortBy ? 'skiplimit' : 'afterbefore'),
@@ -23922,7 +23935,7 @@ const queryComments = async (query) => {
23922
23935
  // API-FIX: backend should answer Amity.Response (2)
23923
23936
  // const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.CommentPayload>>>(
23924
23937
  const { data } = await client.http.get(`/api/v3/comments`, {
23925
- params: Object.assign(Object.assign({}, params), {
23938
+ params: Object.assign(Object.assign({}, params), { isDeleted: includeDeleted === false ? false : undefined,
23926
23939
  // filterByParentId, API-FIX: backend does not support this boolean LOL. what the hell seriously.
23927
23940
  options }),
23928
23941
  });
@@ -26779,6 +26792,11 @@ const liveChannel = (channelId, callback) => {
26779
26792
  onChannelUpdated,
26780
26793
  onChannelDeleted,
26781
26794
  onChannelJoined,
26795
+ onChannelLeft,
26796
+ onChannelMemberAdded,
26797
+ onChannelMemberRemoved,
26798
+ onChannelMemberBanned,
26799
+ onChannelMemberUnbanned,
26782
26800
  onChannelMuted,
26783
26801
  () => onMessageCreated(() => null), // watch unread count
26784
26802
  ]);
@@ -26895,13 +26913,14 @@ const liveChannels = (params, callback, config) => {
26895
26913
  }
26896
26914
  pushToCache(cacheKey, data);
26897
26915
  responder(data);
26898
- }, queryOptions(policy));
26916
+ }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
26899
26917
  };
26900
26918
  disposers.push(onChannelCreated(realtimeRouter()), onChannelDeleted(realtimeRouter()), onChannelUpdated(realtimeRouter()), onChannelMuted(realtimeRouter()), onChannelJoined(realtimeRouter()), onChannelLeft(realtimeRouter()), onChannelMemberAdded(realtimeRouter()), onChannelMemberRemoved(realtimeRouter()), onMessageCreated(() => null));
26901
26919
  onFetch();
26902
26920
  return () => {
26903
26921
  log(`liveChannels(tmpid: ${timestamp}) > dispose`);
26904
26922
  disposers.forEach(fn => fn());
26923
+ dropFromCache(cacheKey);
26905
26924
  };
26906
26925
  };
26907
26926
 
@@ -27059,9 +27078,9 @@ function convertQueryParams(_a) {
27059
27078
  const querySubChannels = async (query) => {
27060
27079
  const client = getActiveClient();
27061
27080
  client.log('channel/querySubChannels', query);
27062
- const _a = convertQueryParams(query), { page = { limit: 10 }, channelId } = _a, params = __rest(_a, ["page", "channelId"]);
27081
+ const _a = convertQueryParams(query), { page = { limit: 10 }, channelId, includeDeleted } = _a, params = __rest(_a, ["page", "channelId", "includeDeleted"]);
27063
27082
  const response = await client.http.get(`/api/v5/message-feeds/channel/${channelId}`, {
27064
- params: Object.assign(Object.assign({}, params), { options: {
27083
+ params: Object.assign(Object.assign({}, params), { isDeleted: includeDeleted === false ? false : undefined, options: {
27065
27084
  token: toToken(page, 'skiplimit'),
27066
27085
  } }),
27067
27086
  });
@@ -27504,8 +27523,8 @@ const liveSubChannels = (params, callback, config) => {
27504
27523
  const responder = (data) => {
27505
27524
  var _a;
27506
27525
  let subChannels = data.data;
27507
- if (params.isDeleted !== undefined) {
27508
- subChannels = filterByPropEquality(subChannels, 'isDeleted', params.isDeleted);
27526
+ if (params.includeDeleted === false) {
27527
+ subChannels = filterByPropEquality(subChannels, 'isDeleted', false);
27509
27528
  }
27510
27529
  subChannels.sort(sortByLastActivity);
27511
27530
  callback({
@@ -27545,7 +27564,7 @@ const liveSubChannels = (params, callback, config) => {
27545
27564
  data: result ? merge(subChannels, result) : subChannels,
27546
27565
  };
27547
27566
  responder(snapshot);
27548
- }, queryOptions(policy));
27567
+ }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
27549
27568
  };
27550
27569
  disposers.push(onSubChannelCreated(realtimeRouter('onCreate')), onSubChannelDeleted(realtimeRouter('onDelete')), onSubChannelFetched(realtimeRouter('onFetch')), onSubChannelUpdated(realtimeRouter('onUpdate')));
27551
27570
  onFetch();
@@ -27650,9 +27669,11 @@ const liveMessages = (params, callback, config) => {
27650
27669
  .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
27651
27670
  /*
27652
27671
  * for cases when message is deleted via RTE, this flag is used to get
27653
- * items fro cache that are deleted | !deleted
27672
+ * items from cache that are !deleted
27654
27673
  */
27655
- messages = filterByPropEquality(messages, 'isDeleted', params.isDeleted);
27674
+ if (params.includeDeleted === false) {
27675
+ messages = filterByPropEquality(messages, 'isDeleted', false);
27676
+ }
27656
27677
  callback({
27657
27678
  onNextPage: onFetch,
27658
27679
  data: messages,
@@ -27661,17 +27682,12 @@ const liveMessages = (params, callback, config) => {
27661
27682
  error: data.error,
27662
27683
  });
27663
27684
  };
27664
- const realtimeRouter = (action) => (message) => {
27685
+ const realtimeRouter = (_) => (message) => {
27665
27686
  var _a;
27666
27687
  const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
27667
- if (params.subChannelId !== message.subChannelId || !collection)
27688
+ if (params.subChannelId !== (message === null || message === void 0 ? void 0 : message.subChannelId) || !collection)
27668
27689
  return;
27669
- if (action === 'onCreate') {
27670
- collection.data = [...new Set([message.messageId, ...collection.data])];
27671
- }
27672
- else if (['onDelete'].includes(action)) {
27673
- collection.data = collection.data.filter(m => m !== message.messageId);
27674
- }
27690
+ collection.data = [...new Set([message.messageId, ...collection.data])];
27675
27691
  pushToCache(cacheKey, collection);
27676
27692
  responder(collection);
27677
27693
  };
@@ -27694,13 +27710,14 @@ const liveMessages = (params, callback, config) => {
27694
27710
  }
27695
27711
  pushToCache(cacheKey, data);
27696
27712
  responder(data);
27697
- }, queryOptions(policy));
27713
+ }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
27698
27714
  };
27699
- disposers.push(onMessageFetched(realtimeRouter('onFetch')), onMessageCreated(realtimeRouter('onCreate')), onMessageUpdated(realtimeRouter('onUpdate')), onMessageDeleted(realtimeRouter('onDelete')), onMessageFlagged(realtimeRouter('onFlagged')), onMessageUnflagged(realtimeRouter('onUnflagged')), onMessageFlagCleared(realtimeRouter('onFlagCleared')), onMessageReactionAdded(realtimeRouter('onReactionAdded')), onMessageReactionRemoved(realtimeRouter('onReactionRemoved')));
27715
+ disposers.push(onMessageFetched(realtimeRouter()), onMessageCreated(realtimeRouter()), onMessageUpdated(realtimeRouter()), onMessageDeleted(realtimeRouter()), onMessageFlagged(realtimeRouter()), onMessageUnflagged(realtimeRouter()), onMessageFlagCleared(realtimeRouter()), onMessageReactionAdded(realtimeRouter()), onMessageReactionRemoved(realtimeRouter()));
27700
27716
  onFetch();
27701
27717
  return () => {
27702
27718
  log(`liveMessages(tmpid: ${timestamp}) > dispose`);
27703
27719
  disposers.forEach(fn => fn());
27720
+ dropFromCache(cacheKey);
27704
27721
  };
27705
27722
  };
27706
27723
 
@@ -28176,8 +28193,10 @@ const liveCommunities = (params, callback, config) => {
28176
28193
  .map(communityId => pullFromCache(['community', 'get', communityId]))
28177
28194
  .filter(Boolean)
28178
28195
  .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
28179
- communities = filterByPropEquality(communities, 'isDeleted', params.isDeleted);
28180
28196
  communities = filterByPropEquality(communities, 'displayName', params.displayName);
28197
+ if (params.includeDeleted === false) {
28198
+ communities = filterByPropEquality(communities, 'isDeleted', false);
28199
+ }
28181
28200
  if (params.categoryId) {
28182
28201
  communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(params.categoryId); });
28183
28202
  }
@@ -28246,13 +28265,14 @@ const liveCommunities = (params, callback, config) => {
28246
28265
  }
28247
28266
  pushToCache(cacheKey, data);
28248
28267
  responder(data);
28249
- }, queryOptions(policy));
28268
+ }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
28250
28269
  };
28251
28270
  disposers.push(onCommunityCreated(realtimeRouter()), onCommunityDeleted(realtimeRouter()), onCommunityUpdated(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityLeft(realtimeRouter()), onCommunityUserChanged(realtimeRouter()));
28252
28271
  onFetch();
28253
28272
  return () => {
28254
28273
  log(`liveCommunities(tmpid: ${timestamp}) > dispose`);
28255
28274
  disposers.forEach(fn => fn());
28275
+ dropFromCache(cacheKey);
28256
28276
  };
28257
28277
  };
28258
28278
 
@@ -28419,9 +28439,9 @@ const liveCommunityMembers = (params, callback, config) => {
28419
28439
  const queryCategories = async (query) => {
28420
28440
  const client = getActiveClient();
28421
28441
  client.log('category/queryCategories', query);
28422
- const _a = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 } } = _a, params = __rest(_a, ["page"]);
28442
+ const _a = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 }, includeDeleted } = _a, params = __rest(_a, ["page", "includeDeleted"]);
28423
28443
  const { data } = await client.http.get(`/api/v3/community-categories`, {
28424
- params: Object.assign(Object.assign({}, params), { options: {
28444
+ params: Object.assign(Object.assign({}, params), { isDeleted: includeDeleted === false ? false : undefined, options: {
28425
28445
  token: toToken(page, 'skiplimit'),
28426
28446
  } }),
28427
28447
  });
@@ -28564,7 +28584,9 @@ const liveCategories = (params, callback, config) => {
28564
28584
  .map(categoryId => pullFromCache(['category', 'get', categoryId]))
28565
28585
  .filter(Boolean)
28566
28586
  .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
28567
- categories = filterByPropEquality(categories, 'isDeleted', params.isDeleted);
28587
+ if (params.includeDeleted === false) {
28588
+ categories = filterByPropEquality(categories, 'isDeleted', false);
28589
+ }
28568
28590
  switch (params.sortBy) {
28569
28591
  case 'firstCreated':
28570
28592
  categories = categories.sort(sortByFirstCreated);
@@ -28822,11 +28844,6 @@ const queryFollowings = async (query) => queryFollows('following', query);
28822
28844
  */
28823
28845
  queryFollowings.locally = (query) => queryFollows.locally('following', query);
28824
28846
 
28825
- const getCacheKey = (userId) => [
28826
- 'followInfo',
28827
- 'get',
28828
- `${getActiveClient().userId}#${userId}`,
28829
- ];
28830
28847
  /* begin_public_function
28831
28848
  id: user.relationship.get_follow_info, user.relationship.get_my_follow_info
28832
28849
  */
@@ -28853,7 +28870,9 @@ const getFollowInfo = async (userId) => {
28853
28870
  const followInfo = 'follows' in data
28854
28871
  ? Object.assign(Object.assign({}, data.followCounts[0]), { status: (_b = (_a = data.follows) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.status }) : data.followCounts[0];
28855
28872
  if (client.cache) {
28856
- pushToCache(getCacheKey(userId), followInfo, { cachedAt });
28873
+ pushToCache(['followInfo', 'get', userId], followInfo, {
28874
+ cachedAt,
28875
+ });
28857
28876
  }
28858
28877
  return {
28859
28878
  data: followInfo,
@@ -28880,7 +28899,7 @@ getFollowInfo.locally = (userId) => {
28880
28899
  if (!client.cache) {
28881
28900
  return;
28882
28901
  }
28883
- const cached = pullFromCache(getCacheKey(userId));
28902
+ const cached = pullFromCache(['followInfo', 'get', userId]);
28884
28903
  if (!cached) {
28885
28904
  return;
28886
28905
  }
@@ -29492,6 +29511,29 @@ const liveFollowings = (params, callback, config) => {
29492
29511
  };
29493
29512
  };
29494
29513
 
29514
+ /**
29515
+ * ```js
29516
+ * import { liveFollowInfo } from '@amityco/ts-sdk';
29517
+ *
29518
+ * let followInfo;
29519
+ *
29520
+ * const unsubscribe = liveFollowInfo(userId, response => {
29521
+ * followInfo = response.data;
29522
+ * });
29523
+ * ```
29524
+ *
29525
+ * Observe all mutation on a given {@link Amity.FollowCount} object
29526
+ *
29527
+ * @param userId the ID of the current user
29528
+ * @param callback the function to call when new data are available
29529
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing
29530
+ *
29531
+ * @category FollowInfo Live Object
29532
+ */
29533
+ const liveFollowInfo = (userId, callback) => {
29534
+ return liveObject(userId, callback, 'userId', getFollowInfo, [onFollowInfoUpdated]);
29535
+ };
29536
+
29495
29537
  /**
29496
29538
  * ```js
29497
29539
  * import { observePosts } from '@amityco/ts-sdk'
@@ -29651,9 +29693,11 @@ const livePosts = (params, callback, config) => {
29651
29693
  .map(postId => pullFromCache(['post', 'get', postId]))
29652
29694
  .filter(Boolean)
29653
29695
  .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
29654
- posts = filterByPropEquality(posts, 'isDeleted', params.isDeleted);
29655
29696
  const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
29656
29697
  posts = posts.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
29698
+ if (params.includeDeleted === false) {
29699
+ posts = filterByPropEquality(posts, 'isDeleted', false);
29700
+ }
29657
29701
  if (params.tags) {
29658
29702
  posts = posts.filter(p => { var _a; return (_a = p.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); }); });
29659
29703
  }
@@ -29705,13 +29749,14 @@ const livePosts = (params, callback, config) => {
29705
29749
  }
29706
29750
  pushToCache(cacheKey, data);
29707
29751
  responder(data);
29708
- }, queryOptions(policy));
29752
+ }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
29709
29753
  };
29710
29754
  disposers.push(onPostCreated(realtimeRouter('onCreate')), onPostApproved(realtimeRouter('onApproved')), onPostDeclined(realtimeRouter('onDeclined')), onPostDeleted(realtimeRouter('onDelete')), onPostUpdated(realtimeRouter('onUpdate')), onPostFlagged(realtimeRouter('onFlagged')), onPostUnflagged(realtimeRouter('onUnflagged')), onPostReactionAdded(realtimeRouter('onReactionAdded')), onPostReactionRemoved(realtimeRouter('onReactionRemoved')));
29711
29755
  onFetch();
29712
29756
  return () => {
29713
29757
  log(`livePosts(tmpid: ${timestamp}) > dispose`);
29714
29758
  disposers.forEach(fn => fn());
29759
+ dropFromCache(cacheKey);
29715
29760
  };
29716
29761
  };
29717
29762
 
@@ -29868,7 +29913,9 @@ const liveComments = (params, callback, config) => {
29868
29913
  .map(commentId => pullFromCache(['comment', 'get', commentId]))
29869
29914
  .filter(Boolean)
29870
29915
  .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
29871
- comments = filterByPropEquality(comments, 'isDeleted', params.isDeleted);
29916
+ if (params.includeDeleted === false) {
29917
+ comments = filterByPropEquality(comments, 'isDeleted', false);
29918
+ }
29872
29919
  const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
29873
29920
  comments = comments.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
29874
29921
  callback({
@@ -29916,13 +29963,14 @@ const liveComments = (params, callback, config) => {
29916
29963
  }
29917
29964
  pushToCache(cacheKey, data);
29918
29965
  responder(data);
29919
- }, queryOptions(policy));
29966
+ }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
29920
29967
  };
29921
29968
  disposers.push(onCommentCreated(realtimeRouter('onCreate')), onCommentUpdated(realtimeRouter('onUpdate')), onCommentDeleted(realtimeRouter('onDelete')), onCommentFlagged(realtimeRouter('onFlagged')), onCommentUnflagged(realtimeRouter('onUnflagged')), onCommentReactionAdded(realtimeRouter('onReactionAdded')), onCommentReactionRemoved(realtimeRouter('onReactionRemoved')));
29922
29969
  onFetch();
29923
29970
  return () => {
29924
29971
  log(`liveComments(tmpid: ${timestamp}) > dispose`);
29925
29972
  disposers.forEach(fn => fn());
29973
+ dropFromCache(cacheKey);
29926
29974
  };
29927
29975
  };
29928
29976
 
@@ -30671,6 +30719,7 @@ exports.liveComments = liveComments;
30671
30719
  exports.liveCommunities = liveCommunities;
30672
30720
  exports.liveCommunity = liveCommunity;
30673
30721
  exports.liveCommunityMembers = liveCommunityMembers;
30722
+ exports.liveFollowInfo = liveFollowInfo;
30674
30723
  exports.liveFollowers = liveFollowers;
30675
30724
  exports.liveFollowings = liveFollowings;
30676
30725
  exports.liveMessage = liveMessage;