@amityco/ts-sdk 6.4.6-e12bdf9.0 → 6.5.1-24920fb.0

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 (125) hide show
  1. package/dist/@types/core/events.d.ts +4 -4
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +3 -1
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +1 -1
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/post.d.ts +1 -1
  8. package/dist/@types/domains/post.d.ts.map +1 -1
  9. package/dist/@types/domains/reaction.d.ts +4 -5
  10. package/dist/@types/domains/reaction.d.ts.map +1 -1
  11. package/dist/channelRepsitory/channelMembership/observers/getMembers.d.ts +1 -0
  12. package/dist/channelRepsitory/channelMembership/observers/getMembers.d.ts.map +1 -1
  13. package/dist/client/observers/getTotalUnreadCount.d.ts.map +1 -1
  14. package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
  15. package/dist/commentRepository/observers/getComment.d.ts +2 -2
  16. package/dist/communityRepository/api/getCommunity.d.ts +4 -4
  17. package/dist/communityRepository/api/getRecommendedCommunities.d.ts +4 -19
  18. package/dist/communityRepository/api/getRecommendedCommunities.d.ts.map +1 -1
  19. package/dist/communityRepository/api/getTopTrendingCommunities.d.ts +5 -2
  20. package/dist/communityRepository/api/getTopTrendingCommunities.d.ts.map +1 -1
  21. package/dist/communityRepository/api/getTrendingCommunities.d.ts +17 -0
  22. package/dist/communityRepository/api/getTrendingCommunities.d.ts.map +1 -0
  23. package/dist/communityRepository/api/index.d.ts +0 -1
  24. package/dist/communityRepository/api/index.d.ts.map +1 -1
  25. package/dist/communityRepository/api/test/getTrendingCommunities.test.d.ts +2 -0
  26. package/dist/communityRepository/api/test/getTrendingCommunities.test.d.ts.map +1 -0
  27. package/dist/communityRepository/communityMembership/observers/getMembers.d.ts +1 -0
  28. package/dist/communityRepository/communityMembership/observers/getMembers.d.ts.map +1 -1
  29. package/dist/communityRepository/observers/getCommunities.d.ts +2 -2
  30. package/dist/communityRepository/observers/getCommunity.d.ts +2 -2
  31. package/dist/communityRepository/observers/getRecommendedCommunities.d.ts +20 -0
  32. package/dist/communityRepository/observers/getRecommendedCommunities.d.ts.map +1 -0
  33. package/dist/communityRepository/observers/getTrendingCommunities.d.ts +20 -0
  34. package/dist/communityRepository/observers/getTrendingCommunities.d.ts.map +1 -0
  35. package/dist/communityRepository/observers/index.d.ts +2 -0
  36. package/dist/communityRepository/observers/index.d.ts.map +1 -1
  37. package/dist/communityRepository/utils/communityQueryFilter.d.ts +2 -0
  38. package/dist/communityRepository/utils/communityQueryFilter.d.ts.map +1 -0
  39. package/dist/core/model/idResolvers.d.ts.map +1 -1
  40. package/dist/core/model/identifyModel.d.ts.map +1 -1
  41. package/dist/index.cjs.js +554 -237
  42. package/dist/index.esm.js +554 -237
  43. package/dist/index.umd.js +4 -4
  44. package/dist/pollRepository/api/index.d.ts +0 -1
  45. package/dist/pollRepository/api/index.d.ts.map +1 -1
  46. package/dist/pollRepository/observers/getPoll.d.ts +21 -0
  47. package/dist/pollRepository/observers/getPoll.d.ts.map +1 -0
  48. package/dist/pollRepository/observers/index.d.ts +1 -0
  49. package/dist/pollRepository/observers/index.d.ts.map +1 -1
  50. package/dist/postRepository/observers/getPost.d.ts +2 -2
  51. package/dist/reactionRepository/api/addReaction.d.ts +2 -2
  52. package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  53. package/dist/reactionRepository/api/queryReactions.d.ts +2 -2
  54. package/dist/reactionRepository/api/queryReactions.d.ts.map +1 -1
  55. package/dist/reactionRepository/api/queryReactor.d.ts +19 -0
  56. package/dist/reactionRepository/api/queryReactor.d.ts.map +1 -0
  57. package/dist/reactionRepository/api/removeReaction.d.ts +2 -2
  58. package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  59. package/dist/reactionRepository/observers/getReactions.d.ts +3 -3
  60. package/dist/reactionRepository/observers/getReactions.d.ts.map +1 -1
  61. package/dist/streamRepository/observers/getStreamById.d.ts +19 -2
  62. package/dist/streamRepository/observers/getStreamById.d.ts.map +1 -1
  63. package/dist/streamRepository/observers/getStreams.d.ts.map +1 -1
  64. package/dist/streamRepository/observers/tests/getStreamById.test.d.ts +2 -0
  65. package/dist/streamRepository/observers/tests/getStreamById.test.d.ts.map +1 -0
  66. package/dist/userRepository/observers/getUsers.d.ts +1 -0
  67. package/dist/userRepository/observers/getUsers.d.ts.map +1 -1
  68. package/dist/utils/tests/dummy/reaction.d.ts +1 -1
  69. package/dist/utils/tests/dummy/reaction.d.ts.map +1 -1
  70. package/dist/utils/tests/dummy/stream.d.ts +22 -0
  71. package/dist/utils/tests/dummy/stream.d.ts.map +1 -1
  72. package/package.json +1 -1
  73. package/src/@types/core/events.ts +4 -4
  74. package/src/@types/core/model.ts +3 -1
  75. package/src/@types/core/payload.ts +1 -1
  76. package/src/@types/domains/post.ts +1 -1
  77. package/src/@types/domains/reaction.ts +8 -9
  78. package/src/categoryRepository/api/queryCategories.ts +1 -1
  79. package/src/channelRepsitory/channelMembership/observers/getMembers.ts +47 -39
  80. package/src/channelRepsitory/channelMembership/observers/tests/getMembers.test.ts +82 -5
  81. package/src/client/observers/getTotalUnreadCount.ts +1 -7
  82. package/src/client/observers/tests/getTotalUnreadCount.test.ts +3 -10
  83. package/src/client/utils/markerSyncEngine.ts +13 -2
  84. package/src/commentRepository/events/onCommentReactionAdded.ts +1 -1
  85. package/src/commentRepository/events/onCommentReactionRemoved.ts +1 -1
  86. package/src/commentRepository/observers/getComment.ts +2 -2
  87. package/src/commentRepository/observers/tests/getComment.test.ts +1 -3
  88. package/src/communityRepository/api/getCommunity.ts +4 -4
  89. package/src/communityRepository/api/getRecommendedCommunities.ts +7 -48
  90. package/src/communityRepository/api/getTopTrendingCommunities.ts +5 -2
  91. package/src/communityRepository/api/getTrendingCommunities.ts +50 -0
  92. package/src/communityRepository/api/index.ts +1 -1
  93. package/src/communityRepository/api/test/getTrendingCommunities.test.ts +102 -0
  94. package/src/communityRepository/communityMembership/observers/getMembers.ts +31 -23
  95. package/src/communityRepository/communityMembership/observers/tests/getMembers.test.ts +80 -2
  96. package/src/communityRepository/observers/getCommunities.ts +2 -2
  97. package/src/communityRepository/observers/getCommunity.ts +2 -2
  98. package/src/communityRepository/observers/getRecommendedCommunities.ts +130 -0
  99. package/src/communityRepository/observers/getTrendingCommunities.ts +130 -0
  100. package/src/communityRepository/observers/index.ts +2 -0
  101. package/src/communityRepository/utils/communityQueryFilter.ts +55 -0
  102. package/src/core/model/idResolvers.ts +2 -1
  103. package/src/core/model/identifyModel.ts +5 -4
  104. package/src/pollRepository/api/index.ts +0 -2
  105. package/src/pollRepository/observers/getPoll.ts +33 -0
  106. package/src/pollRepository/observers/index.ts +1 -0
  107. package/src/pollRepository/observers/observePoll.ts +2 -2
  108. package/src/postRepository/events/tests/onPostReactionAdded.test.ts +6 -5
  109. package/src/postRepository/events/tests/onPostReactionRemoved.test.ts +5 -4
  110. package/src/postRepository/observers/getPost.ts +2 -2
  111. package/src/postRepository/observers/getPosts.ts +1 -1
  112. package/src/postRepository/observers/tests/getPost.test.ts +1 -3
  113. package/src/postRepository/observers/tests/getPosts.test.ts +1 -5
  114. package/src/reactionRepository/api/addReaction.ts +2 -2
  115. package/src/reactionRepository/api/queryReactions.ts +2 -2
  116. package/src/reactionRepository/api/queryReactor.ts +31 -0
  117. package/src/reactionRepository/api/removeReaction.ts +2 -2
  118. package/src/reactionRepository/observers/getReactions.ts +6 -8
  119. package/src/streamRepository/observers/getStreamById.ts +35 -1
  120. package/src/streamRepository/observers/getStreams.ts +6 -5
  121. package/src/streamRepository/observers/tests/getStreamById.test.ts +44 -0
  122. package/src/userRepository/observers/getUsers.ts +32 -24
  123. package/src/userRepository/observers/tests/getUsers.test.ts +46 -1
  124. package/src/utils/tests/dummy/reaction.ts +6 -10
  125. package/src/utils/tests/dummy/stream.ts +47 -0
package/dist/index.cjs.js CHANGED
@@ -96,8 +96,8 @@ const PostContentType = Object.freeze({
96
96
 
97
97
  function getVersion() {
98
98
  try {
99
- // the string ''v6.4.5-cjs'' should be replaced by actual value by @rollup/plugin-replace
100
- return 'v6.4.5-cjs';
99
+ // the string ''v6.5.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
100
+ return 'v6.5.0-cjs';
101
101
  }
102
102
  catch (error) {
103
103
  return '__dev__';
@@ -524,7 +524,8 @@ const idResolvers = {
524
524
  post: ({ postId }) => postId,
525
525
  comment: ({ commentId }) => commentId,
526
526
  poll: ({ pollId }) => pollId,
527
- reaction: ({ reactionId }) => reactionId,
527
+ reaction: ({ referenceType, referenceId }) => `${referenceType}#${referenceId}`,
528
+ reactor: ({ reactionId }) => reactionId,
528
529
  stream: ({ streamId }) => streamId,
529
530
  follow: ({ from, to }) => `${from}#${to}`,
530
531
  followInfo: ({ userId }) => userId,
@@ -551,10 +552,10 @@ const getResolver = (name) => idResolvers[name];
551
552
  */
552
553
  const CRITERIAS = {
553
554
  file: ['fileId', 'attributes'],
554
- user: ['userId', 'avatarFileId'],
555
+ user: ['userId', 'avatarFileId', 'roles', 'permissions'],
555
556
  role: ['roleId'],
556
- channel: ['channelId', 'rateLimit'],
557
- subChannel: ['subChannelId'],
557
+ channel: ['channelId', 'defaultSubChannelId'],
558
+ subChannel: ['subChannelId', 'latestMessageId'],
558
559
  channelUsers: ['channelId', 'userId', 'membership'],
559
560
  message: ['messageId'],
560
561
  community: ['communityId', 'postSetting'],
@@ -563,7 +564,8 @@ const CRITERIAS = {
563
564
  post: ['postId', 'feedId'],
564
565
  comment: ['commentId', 'referenceId'],
565
566
  poll: ['pollId'],
566
- reaction: ['reactionId'],
567
+ reaction: ['referenceId', 'referenceType', 'reactors'],
568
+ reactor: ['reactionId'],
567
569
  stream: ['streamId'],
568
570
  follow: ['from', 'to'],
569
571
  feed: ['feedId', 'feedType'],
@@ -22564,12 +22566,8 @@ const getTotalUnreadCount = (callback) => {
22564
22566
  if (!userId)
22565
22567
  throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
22566
22568
  const callbackDataSelector = (data) => { var _a; return (_a = data === null || data === void 0 ? void 0 : data.unreadCount) !== null && _a !== void 0 ? _a : 0; };
22567
- // based on the mobile specs, unreadCount will not trigger observer when userMarker
22568
- // is re-fetched, so apply this filter to ensure the behavior is the same.
22569
- const callbackFilter = (newModel, oldModel) => (newModel === null || newModel === void 0 ? void 0 : newModel.unreadCount) !== (oldModel === null || oldModel === void 0 ? void 0 : oldModel.unreadCount);
22570
22569
  return liveObject(userId, callback, 'userId', getUserMarker, [onUserMarkerFetched], {
22571
22570
  callbackDataSelector,
22572
- callbackFilter,
22573
22571
  });
22574
22572
  };
22575
22573
 
@@ -23616,6 +23614,38 @@ queryChannelMembers.locally = (query) => {
23616
23614
  : undefined;
23617
23615
  };
23618
23616
 
23617
+ /*
23618
+ * Exported for testing
23619
+ * @hidden
23620
+ */
23621
+ const applyFilter$2 = (data, params) => {
23622
+ let channelMembers = filterByPropIntersection(data, 'roles', params.roles);
23623
+ if (params.memberships) {
23624
+ /*
23625
+ * even though membership includes muted as a possible value
23626
+ * when querying the server.
23627
+ * Muted is specified under seperarte property namely isMuted
23628
+ * Hence why I've seperately checked for it's equality
23629
+ */
23630
+ channelMembers = channelMembers.filter(member => {
23631
+ // @ts-ignore
23632
+ if (params.memberships.includes('muted') && member.isMuted) {
23633
+ return true;
23634
+ }
23635
+ // @ts-ignore
23636
+ return params.memberships.includes(member.membership);
23637
+ });
23638
+ }
23639
+ if (params.search) {
23640
+ // eslint-disable-next-line no-console
23641
+ console.warn('`search` param will be deprecated in the next major release. If you want to search channel members by displayName, Please use `searchMembers()` instead.');
23642
+ channelMembers = filterBySearchTerm(channelMembers, params.search);
23643
+ }
23644
+ // sort, 'lastCreated' is the default sort order
23645
+ const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
23646
+ channelMembers = channelMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
23647
+ return channelMembers;
23648
+ };
23619
23649
  /* begin_public_function
23620
23650
  id: channel.member.query
23621
23651
  */
@@ -23640,6 +23670,7 @@ queryChannelMembers.locally = (query) => {
23640
23670
  const getMembers$1 = (params, callback, config) => {
23641
23671
  const { log, cache } = getActiveClient();
23642
23672
  if (!cache) {
23673
+ // eslint-disable-next-line no-console
23643
23674
  console.log(ENABLE_CACHE_MESSAGE);
23644
23675
  }
23645
23676
  const timestamp = Date.now();
@@ -23649,34 +23680,6 @@ const getMembers$1 = (params, callback, config) => {
23649
23680
  const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
23650
23681
  const disposers = [];
23651
23682
  const cacheKey = ['channelUsers', 'collection', { channelId: params.channelId }];
23652
- const applyFilter = (data) => {
23653
- let channelMembers = filterByPropIntersection(data, 'roles', params.roles);
23654
- if (params.memberships) {
23655
- /*
23656
- * even though membership includes muted as a possible value
23657
- * when querying the server.
23658
- * Muted is specified under seperarte property namely isMuted
23659
- * Hence why I've seperately checked for it's equality
23660
- */
23661
- channelMembers = channelMembers.filter(member => {
23662
- // @ts-ignore
23663
- if (params.memberships.includes('muted') && member.isMuted) {
23664
- return true;
23665
- }
23666
- // @ts-ignore
23667
- return params.memberships.includes(member.membership);
23668
- });
23669
- }
23670
- if (params.search) {
23671
- // eslint-disable-next-line no-console
23672
- console.warn('`search` param will be deprecated in the next major release. If you want to search channel members by displayName, Please use `searchMembers()` instead.');
23673
- channelMembers = filterBySearchTerm(channelMembers, params.search);
23674
- }
23675
- // sort, 'lastCreated' is the default sort order
23676
- const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
23677
- channelMembers = channelMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
23678
- return channelMembers;
23679
- };
23680
23683
  const responder = (data, isEventModel = false) => {
23681
23684
  var _a, _b;
23682
23685
  const channelMembers = (_a = data.data
@@ -23688,7 +23691,7 @@ const getMembers$1 = (params, callback, config) => {
23688
23691
  /*
23689
23692
  * Only apply filter to RTE Model
23690
23693
  */
23691
- data: isEventModel ? applyFilter(channelMembers) : channelMembers,
23694
+ data: isEventModel ? applyFilter$2(channelMembers, params) : channelMembers,
23692
23695
  hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
23693
23696
  loading: data.loading,
23694
23697
  error: data.error,
@@ -23776,6 +23779,7 @@ var index$i = /*#__PURE__*/Object.freeze({
23776
23779
  __proto__: null,
23777
23780
  addMembers: addMembers$1,
23778
23781
  removeMembers: removeMembers$1,
23782
+ applyFilter: applyFilter$2,
23779
23783
  getMembers: getMembers$1,
23780
23784
  searchMembers: searchMembers
23781
23785
  });
@@ -24313,6 +24317,7 @@ const onSubChannelDeleted = (callback) => {
24313
24317
  };
24314
24318
 
24315
24319
  const SYNC_TRIGGER_INTERVAL_TIME = 2000;
24320
+ const ON_SUB_CHANNEL_DELETE_SYNC_TRIGGER_DELAY = 2000;
24316
24321
  let clearSyncTrigger;
24317
24322
  let disposers = [];
24318
24323
  let isWaitingForResponse = false;
@@ -24403,7 +24408,13 @@ const registerEventListeners = () => {
24403
24408
  },
24404
24409
  // only trigger sync from remote events to prevent an unread count equal `-1`
24405
24410
  // when an optimistic message creation is performed.
24406
- false), onChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.CHANNEL_CREATED */)), onChannelDeleted(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.CHANNEL_DELETED */)), onChannelJoined(() => events.push("subchannel is joined" /* Amity.MarkerSyncEvent.CHANNEL_JOINED */)), onChannelLeft(() => events.push("subchannel is left" /* Amity.MarkerSyncEvent.CHANNEL_LEFT */)), onSubChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.SUB_CHANNEL_CREATED */)), onSubChannelDeleted(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.SUBCHANNEL_IS_DELETED */)), onFeedMarkerUpdated(() => events.push("feed marker updated" /* Amity.MarkerSyncEvent.MARKER_UPDATED */)), onUserMarkerSync(() => events.push("feed marker updated" /* Amity.MarkerSyncEvent.MARKER_UPDATED */)));
24411
+ false), onChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.CHANNEL_CREATED */)), onChannelDeleted(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.CHANNEL_DELETED */)), onChannelJoined(() => events.push("subchannel is joined" /* Amity.MarkerSyncEvent.CHANNEL_JOINED */)), onChannelLeft(() => events.push("subchannel is left" /* Amity.MarkerSyncEvent.CHANNEL_LEFT */)), onSubChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.SUB_CHANNEL_CREATED */)), onSubChannelDeleted(() =>
24412
+ /*
24413
+ workaround: when receiving the event for sub-channel deletion,
24414
+ before triggering marker update, the SDK will have to add a 2-second delay.
24415
+ so that the unread count is calculated correctly.
24416
+ */
24417
+ setTimeout(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.SUBCHANNEL_IS_DELETED */), ON_SUB_CHANNEL_DELETE_SYNC_TRIGGER_DELAY)), onFeedMarkerUpdated(() => events.push("feed marker updated" /* Amity.MarkerSyncEvent.MARKER_UPDATED */)), onUserMarkerSync(() => events.push("feed marker updated" /* Amity.MarkerSyncEvent.MARKER_UPDATED */)));
24407
24418
  };
24408
24419
  const unRegisterEventListeners = () => {
24409
24420
  disposers.forEach(fn => fn());
@@ -26092,6 +26103,28 @@ queryUsers.locally = (query = {}) => {
26092
26103
  : undefined;
26093
26104
  };
26094
26105
 
26106
+ /*
26107
+ * Exported for testing
26108
+ * @hidden
26109
+ */
26110
+ const applyFilter$1 = (data, params) => {
26111
+ let users = filterByPropEquality(data, 'displayName', params.displayName);
26112
+ switch (params.sortBy) {
26113
+ case 'firstCreated':
26114
+ users = users.sort(sortByFirstCreated);
26115
+ break;
26116
+ case 'lastCreated':
26117
+ users = users.sort(sortByLastCreated);
26118
+ break;
26119
+ default:
26120
+ users = users
26121
+ // this needs to be aligned with the backend data type
26122
+ .map(u => (u.displayName ? u : Object.assign(Object.assign({}, u), { displayName: '' })))
26123
+ // @ts-ignore
26124
+ .sort(sortByDisplayName);
26125
+ }
26126
+ return users;
26127
+ };
26095
26128
  /* begin_public_function
26096
26129
  id: user.query
26097
26130
  */
@@ -26114,6 +26147,7 @@ queryUsers.locally = (query = {}) => {
26114
26147
  const getUsers = (params, callback, config) => {
26115
26148
  const { log, cache } = getActiveClient();
26116
26149
  if (!cache) {
26150
+ // eslint-disable-next-line no-console
26117
26151
  console.log(ENABLE_CACHE_MESSAGE);
26118
26152
  }
26119
26153
  const timestamp = Date.now();
@@ -26123,24 +26157,6 @@ const getUsers = (params, callback, config) => {
26123
26157
  const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
26124
26158
  const disposers = [];
26125
26159
  const cacheKey = ['user', 'collection', {}];
26126
- const applyFilter = (data) => {
26127
- let users = filterByPropEquality(data, 'displayName', params.displayName);
26128
- switch (params.sortBy) {
26129
- case 'firstCreated':
26130
- users = users.sort(sortByFirstCreated);
26131
- break;
26132
- case 'lastCreated':
26133
- users = users.sort(sortByLastCreated);
26134
- break;
26135
- default:
26136
- users = users
26137
- // this needs to be aligned with the backend data type
26138
- .map(u => (u.displayName ? u : Object.assign(Object.assign({}, u), { displayName: '' })))
26139
- // @ts-ignore
26140
- .sort(sortByDisplayName);
26141
- }
26142
- return users;
26143
- };
26144
26160
  const responder = (data, isEventModel = false) => {
26145
26161
  var _a, _b;
26146
26162
  const users = (_a = data.data
@@ -26152,7 +26168,7 @@ const getUsers = (params, callback, config) => {
26152
26168
  /*
26153
26169
  * Only apply filter to RTE Model
26154
26170
  */
26155
- data: isEventModel ? applyFilter(users) : users,
26171
+ data: isEventModel ? applyFilter$1(users, params) : users,
26156
26172
  hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
26157
26173
  loading: data.loading,
26158
26174
  error: data.error,
@@ -27856,7 +27872,7 @@ const onReactorRemoved = (referenceType, referenceId, callback) => {
27856
27872
  * })
27857
27873
  * ```
27858
27874
  *
27859
- * Queries a paginable list of {@link Amity.ReactionQuery} objects
27875
+ * Queries a paginable list of {@link Amity.Reaction} objects
27860
27876
  *
27861
27877
  * @param query The query parameters
27862
27878
  * @returns A page of {@link Amity.Reaction} objects
@@ -27883,6 +27899,30 @@ const queryReactions = async (query) => {
27883
27899
  return { data: reactions, prevPage, nextPage };
27884
27900
  };
27885
27901
 
27902
+ /**
27903
+ * ```js
27904
+ * import { queryReactor } from '@amityco/ts-sdk'
27905
+ * const { data: reactions, prevPage, nextPage } = await queryReactor({
27906
+ * referenceId: 'postId',
27907
+ * referenceType: 'post',
27908
+ * })
27909
+ * ```
27910
+ *
27911
+ * Queries a paginable list of {@link Amity.Reactor} objects
27912
+ *
27913
+ * @param query The query parameters
27914
+ * @returns A page of {@link Amity.Reactor} objects
27915
+ *
27916
+ * @reaction Reaction API
27917
+ * @async
27918
+ * */
27919
+ const queryReactor = async (query) => {
27920
+ const client = getActiveClient();
27921
+ client.log('reaction/queryReactor', query);
27922
+ const _a = await queryReactions(query), { data } = _a, response = __rest(_a, ["data"]);
27923
+ return Object.assign(Object.assign({}, response), { data: data[0].reactors });
27924
+ };
27925
+
27886
27926
  /* begin_public_function
27887
27927
  id: reaction.query
27888
27928
  */
@@ -27897,11 +27937,11 @@ const queryReactions = async (query) => {
27897
27937
  * }, response => merge(reactions, response.data))
27898
27938
  * ```
27899
27939
  *
27900
- * Observe all mutations on a list of {@link Amity.Reaction} for a given target object
27940
+ * Observe all mutations on a list of {@link Amity.Reactor} for a given target object
27901
27941
  *
27902
- * @param params.referenceType the type of the target
27903
- * @param params.referenceId the ID of the target
27942
+ * @param params for querying reactions
27904
27943
  * @param callback the function to call when new data are available
27944
+ * @param config the live collection configuration
27905
27945
  * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
27906
27946
  *
27907
27947
  * @category Reactions Live Collection
@@ -27956,7 +27996,7 @@ const getReactions = (params, callback, config) => {
27956
27996
  const reactions = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
27957
27997
  if (!initial && reactions.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
27958
27998
  return;
27959
- const query = createQuery(queryReactions, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
27999
+ const query = createQuery(queryReactor, Object.assign(Object.assign({}, queryParams), { page: (_d = (!initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined)) !== null && _d !== void 0 ? _d : { limit } }));
27960
28000
  runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
27961
28001
  const data = {
27962
28002
  loading,
@@ -27965,9 +28005,7 @@ const getReactions = (params, callback, config) => {
27965
28005
  data: reactions,
27966
28006
  };
27967
28007
  if (result) {
27968
- data.data = [
27969
- ...new Set([...reactions, ...result[0].reactors.map(getResolver('reaction'))]),
27970
- ];
28008
+ data.data = [...new Set([...reactions, ...result.map(getResolver('reactor'))])];
27971
28009
  }
27972
28010
  pushToCache(cacheKey, data);
27973
28011
  responder(data);
@@ -29727,8 +29765,8 @@ const updateCommunity = async (communityId, patch) => {
29727
29765
 
29728
29766
  /**
29729
29767
  * ```js
29730
- * import { getCommunity } from '@amityco/ts-sdk'
29731
- * const community = await getCommunity('foobar')
29768
+ * import { CommunityRepository } from '@amityco/ts-sdk'
29769
+ * const community = await CommunityRepository.getCommunity('foobar')
29732
29770
  * ```
29733
29771
  *
29734
29772
  * Fetches a {@link Amity.Community} object
@@ -29756,8 +29794,8 @@ const getCommunity$1 = async (communityId) => {
29756
29794
  };
29757
29795
  /**
29758
29796
  * ```js
29759
- * import { getCommunity } from '@amityco/ts-sdk'
29760
- * const community = getCommunity.locally('foobar')
29797
+ * import { CommunityRepository } from '@amityco/ts-sdk'
29798
+ * const community = CommunityRepository.getCommunity.locally('foobar')
29761
29799
  * ```
29762
29800
  *
29763
29801
  * Fetches a {@link Amity.Community} object from cache
@@ -29882,9 +29920,12 @@ const leaveCommunity = async (communityId) => {
29882
29920
  id: community.query.trending_communities
29883
29921
  */
29884
29922
  /**
29923
+ * @deprecated This API renamed to `getTrendingCommunities()`.
29924
+ * Please use getTrendingCommunities() instead.
29925
+ *
29885
29926
  * ```js
29886
- * import { getTopTrendingCommunities } from '@amityco/ts-sdk'
29887
- * const trendingCommunities = await getTopTrendingCommunities()
29927
+ * import { CommunityRepository } from '@amityco/ts-sdk'
29928
+ * const trendingCommunities = await CommunityRepository.getTrendingCommunities()
29888
29929
  * ```
29889
29930
  *
29890
29931
  * Gets a list of top trending {@link Amity.Community} objects
@@ -29946,74 +29987,6 @@ getTopTrendingCommunities.locally = (query) => {
29946
29987
  : undefined;
29947
29988
  };
29948
29989
 
29949
- /* begin_public_function
29950
- id: community.query.recommended_communities
29951
- */
29952
- /**
29953
- * ```js
29954
- * import { getRecommendedCommunities } from '@amityco/ts-sdk'
29955
- * const communities = await getRecommendedCommunities()
29956
- * ```
29957
- *
29958
- * Gets a list of recommended {@link Amity.Community} objects
29959
- *
29960
- * @param query The query parameters
29961
- * @returns A list of {@link Amity.Community} objects
29962
- *
29963
- * @category Community API
29964
- * @async
29965
- */
29966
- const getRecommendedCommunities = async (query) => {
29967
- const client = getActiveClient();
29968
- client.log('channel/getRecommendedCommunities', query);
29969
- const { limit = 5 } = query !== null && query !== void 0 ? query : {};
29970
- // API-FIX: backend doesnt answer Amity.Response
29971
- // const { data: payload } = await client.http.get<Amity.Response<CommunityPayload>>(
29972
- const { data: payload } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
29973
- const data = prepareCommunityPayload(payload);
29974
- const { communities } = data;
29975
- const cachedAt = client.cache && Date.now();
29976
- if (client.cache) {
29977
- ingestInCache(data, { cachedAt });
29978
- const cacheKey = ['community', 'recommended', { params: { options: { limit } } }];
29979
- pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
29980
- }
29981
- return { data: communities, cachedAt };
29982
- };
29983
- /* end_public_function */
29984
- /**
29985
- * ```js
29986
- * import { getRecommendedCommunities } from '@amityco/ts-sdk'
29987
- * const communities = getRecommendedCommunities.locally()
29988
- * ```
29989
- *
29990
- * Gets a list of recommended {@link Amity.Community} objects from cache
29991
- *
29992
- * @param query The query parameters
29993
- * @returns communities
29994
- *
29995
- * @category Community API
29996
- */
29997
- getRecommendedCommunities.locally = (query) => {
29998
- var _a, _b;
29999
- const client = getActiveClient();
30000
- client.log('community/getRecommendedCommunities.locally', query);
30001
- if (!client.cache)
30002
- return;
30003
- const { limit = 5 } = query !== null && query !== void 0 ? query : {};
30004
- const queryKey = ['community', 'recommended', { params: { options: { limit } } }];
30005
- const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
30006
- if (!(data === null || data === void 0 ? void 0 : data.communities.length))
30007
- return;
30008
- const communities = data.communities
30009
- .map(communityId => pullFromCache(['community', 'get', communityId]))
30010
- .filter(Boolean)
30011
- .map(({ data }) => data);
30012
- return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
30013
- ? { data: communities, cachedAt }
30014
- : undefined;
30015
- };
30016
-
30017
29990
  const createCommunityEventSubscriber = (event, callback) => {
30018
29991
  const client = getActiveClient();
30019
29992
  const filter = (payload) => {
@@ -30418,10 +30391,10 @@ const queryCommunities = async (query) => {
30418
30391
  */
30419
30392
  /**
30420
30393
  * ```js
30421
- * import { getCommunities } from '@amityco/ts-sdk'
30394
+ * import { CommunityRepository } from '@amityco/ts-sdk'
30422
30395
  *
30423
30396
  * let communities = []
30424
- * const unsub = getCommunities({
30397
+ * const unsub = CommunityRepository.getCommunities({
30425
30398
  * displayName: Amity.Community['displayName'],
30426
30399
  * }, response => merge(communities, response.data))
30427
30400
  * ```
@@ -30538,11 +30511,11 @@ const getCommunities = (params, callback, config) => {
30538
30511
  */
30539
30512
  /**
30540
30513
  * ```js
30541
- * import { getCommunity } from '@amityco/ts-sdk';
30514
+ * import { CommunityRepository } from '@amityco/ts-sdk';
30542
30515
  *
30543
30516
  * let community;
30544
30517
  *
30545
- * const unsubscribe = getCommunity(communityId, response => {
30518
+ * const unsub = CommunityRepository.getCommunity(communityId, response => {
30546
30519
  * community = response.data;
30547
30520
  * });
30548
30521
  * ```
@@ -30568,6 +30541,287 @@ const getCommunity = (communityId, callback) => {
30568
30541
  };
30569
30542
  /* end_public_function */
30570
30543
 
30544
+ /**
30545
+ * ```js
30546
+ * import { CommunityRepository } from '@amityco/ts-sdk'
30547
+ * const trendingCommunities = await CommunityRepository.getTrendingCommunities()
30548
+ * ```
30549
+ *
30550
+ * Gets a list of top trending {@link Amity.Community} objects
30551
+ *
30552
+ * @param query The query parameters
30553
+ * @returns A list of {@link Amity.Community} objects
30554
+ *
30555
+ * @category Community API
30556
+ * @async
30557
+ * @private
30558
+ */
30559
+ const getTrendingCommunities$1 = async (query) => {
30560
+ const client = getActiveClient();
30561
+ client.log('community/getTrendingCommunities', query);
30562
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = query !== null && query !== void 0 ? query : {};
30563
+ // API-FIX: backend doesnt answer Amity.Response
30564
+ // const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
30565
+ const { data: payload } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
30566
+ const data = prepareCommunityPayload(payload);
30567
+ const { communities } = data;
30568
+ const cachedAt = client.cache && Date.now();
30569
+ if (client.cache) {
30570
+ ingestInCache(data, { cachedAt });
30571
+ }
30572
+ return { data: communities, cachedAt };
30573
+ };
30574
+
30575
+ const communityQueryFilter = (data, params, userId) => {
30576
+ let communities = data;
30577
+ communities = filterByPropEquality(communities, 'displayName', params.displayName);
30578
+ if (!params.includeDeleted) {
30579
+ communities = filterByPropEquality(communities, 'isDeleted', false);
30580
+ }
30581
+ if (params.categoryId) {
30582
+ communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(params.categoryId); });
30583
+ }
30584
+ if (params.tags) {
30585
+ 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); }); });
30586
+ }
30587
+ if (params.membership && userId) {
30588
+ communities = filterByCommunityMembership(communities, params.membership, userId);
30589
+ }
30590
+ const sortBy = params.sortBy || 'lastCreated';
30591
+ if (sortBy === 'lastCreated' || sortBy === 'firstCreated') {
30592
+ communities = communities.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
30593
+ }
30594
+ /*
30595
+ * The server returns communities with empty | null displayName's first before
30596
+ * returning sorted list of communities with displayNames
30597
+ *
30598
+ * This section needs to be updated as displayNames can be null as well
30599
+ */
30600
+ if (sortBy === 'displayName') {
30601
+ communities = communities
30602
+ // this needs to be aligned with the backend data type
30603
+ .map(c => (c.displayName ? c : Object.assign(Object.assign({}, c), { displayName: '' })))
30604
+ // @ts-ignore
30605
+ .sort(sortByDisplayName);
30606
+ }
30607
+ return communities;
30608
+ };
30609
+
30610
+ /* eslint-disable no-use-before-define */
30611
+ /* begin_public_function
30612
+ id: community.query.trending_communities
30613
+ */
30614
+ /**
30615
+ * ```js
30616
+ * import { CommunityRepository } from '@amityco/ts-sdk'
30617
+ *
30618
+ * let communities = []
30619
+ * const unsub = CommunityRepository.getCommunities({
30620
+ * displayName: Amity.Community['displayName'],
30621
+ * }, response => merge(communities, response.data))
30622
+ * ```
30623
+ *
30624
+ * Observe all mutations on a list of {@link Amity.Community}s
30625
+ *
30626
+ * @param params for querying communities
30627
+ * @param callback the function to call when new data are available
30628
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
30629
+ *
30630
+ * @category Community Live Collection
30631
+ */
30632
+ const getTrendingCommunities = (params, callback, config) => {
30633
+ const { log, cache, userId } = getActiveClient();
30634
+ if (!cache) {
30635
+ console.log(ENABLE_CACHE_MESSAGE);
30636
+ }
30637
+ const timestamp = Date.now();
30638
+ log(`getTrendingCommunities(tmpid: ${timestamp}) > listen`);
30639
+ const { limit: queryLimit } = params;
30640
+ const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
30641
+ const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
30642
+ const disposers = [];
30643
+ const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
30644
+ const responder = (data, isEventModel = false) => {
30645
+ var _a, _b;
30646
+ const communities = (_a = data.data
30647
+ .map(communityId => pullFromCache(['community', 'get', communityId]))
30648
+ .filter(Boolean)
30649
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
30650
+ callback({
30651
+ onNextPage: onFetch,
30652
+ data: isEventModel ? communityQueryFilter(communities, params, userId) : communities,
30653
+ hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
30654
+ loading: data.loading,
30655
+ error: data.error,
30656
+ });
30657
+ };
30658
+ const realtimeRouter = (_) => (community) => {
30659
+ var _a;
30660
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30661
+ if (!collection)
30662
+ return;
30663
+ /*
30664
+ * Simply update collection and let responder decide what to do with data
30665
+ */
30666
+ collection.data = [...new Set([community.communityId, ...collection.data])];
30667
+ pushToCache(cacheKey, collection);
30668
+ responder(collection);
30669
+ };
30670
+ const onFetch = (initial = false) => {
30671
+ var _a, _b;
30672
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30673
+ const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
30674
+ if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
30675
+ return;
30676
+ const query = createQuery(getTrendingCommunities$1, params);
30677
+ runQuery(query, ({ data: result, error, loading }) => {
30678
+ const data = {
30679
+ loading,
30680
+ error,
30681
+ params,
30682
+ data: communities,
30683
+ };
30684
+ if (result) {
30685
+ data.data = [...new Set([...communities, ...result.map(getResolver('community'))])];
30686
+ }
30687
+ pushToCache(cacheKey, data);
30688
+ responder(data);
30689
+ }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
30690
+ };
30691
+ disposers.push(onCommunityUserChanged(realtimeRouter()));
30692
+ onFetch(true);
30693
+ disposers.push(() => dropFromCache(cacheKey));
30694
+ return () => {
30695
+ log(`getTrendingCommunities(tmpid: ${timestamp}) > dispose`);
30696
+ disposers.forEach(fn => fn());
30697
+ };
30698
+ };
30699
+ /* end_public_function */
30700
+
30701
+ /* begin_public_function
30702
+ id: community.query.recommended_communities
30703
+ */
30704
+ /**
30705
+ * ```js
30706
+ * import { CommunityRepository } from '@amityco/ts-sdk'
30707
+ * const communities = await CommunityRepository.getRecommendedCommunities()
30708
+ * ```
30709
+ *
30710
+ * Gets a list of recommended {@link Amity.Community} objects
30711
+ *
30712
+ * @param query The query parameters
30713
+ * @returns A list of {@link Amity.Community} objects
30714
+ *
30715
+ * @category Community API
30716
+ * @async
30717
+ * @private
30718
+ */
30719
+ const getRecommendedCommunities$1 = async (query) => {
30720
+ const client = getActiveClient();
30721
+ client.log('community/getRecommendedCommunities', query);
30722
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = query !== null && query !== void 0 ? query : {};
30723
+ // API-FIX: backend doesnt answer Amity.Response
30724
+ // const { data: payload } = await client.http.get<Amity.Response<CommunityPayload>>(
30725
+ const { data: payload } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
30726
+ const data = prepareCommunityPayload(payload);
30727
+ const { communities } = data;
30728
+ const cachedAt = client.cache && Date.now();
30729
+ if (client.cache) {
30730
+ ingestInCache(data, { cachedAt });
30731
+ }
30732
+ return { data: communities, cachedAt };
30733
+ };
30734
+
30735
+ /* begin_public_function
30736
+ id: community.query.recommended_communities
30737
+ */
30738
+ /**
30739
+ * ```js
30740
+ * import { CommunityRepository } from '@amityco/ts-sdk'
30741
+ *
30742
+ * let communities = []
30743
+ * const unsub = CommunityRepository.getCommunities({
30744
+ * displayName: Amity.Community['displayName'],
30745
+ * }, response => merge(communities, response.data))
30746
+ * ```
30747
+ *
30748
+ * Observe all mutations on a list of {@link Amity.Community}s
30749
+ *
30750
+ * @param params for querying communities
30751
+ * @param callback the function to call when new data are available
30752
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
30753
+ *
30754
+ * @category Community Live Collection
30755
+ */
30756
+ const getRecommendedCommunities = (params, callback, config) => {
30757
+ const { log, cache, userId } = getActiveClient();
30758
+ if (!cache) {
30759
+ console.log(ENABLE_CACHE_MESSAGE);
30760
+ }
30761
+ const timestamp = Date.now();
30762
+ log(`getRecommendedCommunities(tmpid: ${timestamp}) > listen`);
30763
+ const { limit: queryLimit } = params; __rest(params, ["limit"]);
30764
+ const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
30765
+ const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
30766
+ const disposers = [];
30767
+ const cacheKey = ['community', 'recommended', { params: { options: { limit } } }];
30768
+ const responder = (data, isEventModel = false) => {
30769
+ var _a, _b;
30770
+ const communities = (_a = data.data
30771
+ .map(communityId => pullFromCache(['community', 'get', communityId]))
30772
+ .filter(Boolean)
30773
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
30774
+ callback({
30775
+ onNextPage: onFetch,
30776
+ data: isEventModel ? communityQueryFilter(communities, params, userId) : communities,
30777
+ hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
30778
+ loading: data.loading,
30779
+ error: data.error,
30780
+ });
30781
+ };
30782
+ const realtimeRouter = (_) => (community) => {
30783
+ var _a;
30784
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30785
+ if (!collection)
30786
+ return;
30787
+ /*
30788
+ * Simply update collection and let responder decide what to do with data
30789
+ */
30790
+ collection.data = [...new Set([community.communityId, ...collection.data])];
30791
+ pushToCache(cacheKey, collection);
30792
+ responder(collection);
30793
+ };
30794
+ const onFetch = (initial = false) => {
30795
+ var _a, _b;
30796
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30797
+ const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
30798
+ if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
30799
+ return;
30800
+ const query = createQuery(getRecommendedCommunities$1, params);
30801
+ runQuery(query, ({ data: result, error, loading }) => {
30802
+ const data = {
30803
+ loading,
30804
+ error,
30805
+ params,
30806
+ data: communities,
30807
+ };
30808
+ if (result) {
30809
+ data.data = [...new Set([...communities, ...result.map(getResolver('community'))])];
30810
+ }
30811
+ pushToCache(cacheKey, data);
30812
+ responder(data);
30813
+ }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
30814
+ };
30815
+ disposers.push(onCommunityUserChanged(realtimeRouter()));
30816
+ onFetch(true);
30817
+ disposers.push(() => dropFromCache(cacheKey));
30818
+ return () => {
30819
+ log(`getRecommendedCommunities(tmpid: ${timestamp}) > dispose`);
30820
+ disposers.forEach(fn => fn());
30821
+ };
30822
+ };
30823
+ /* end_public_function */
30824
+
30571
30825
  /* begin_public_function
30572
30826
  id: community.moderation.add_roles
30573
30827
  */
@@ -30854,6 +31108,24 @@ queryCommunityMembers.locally = (query) => {
30854
31108
  : undefined;
30855
31109
  };
30856
31110
 
31111
+ /*
31112
+ * Exported for testing
31113
+ * @hidden
31114
+ */
31115
+ const applyFilter = (data, params) => {
31116
+ let communityMembers = filterByPropIntersection(data, 'roles', params.roles);
31117
+ if (params.membership) {
31118
+ communityMembers = communityMembers.filter(({ communityMembership }) =>
31119
+ // @ts-ignore
31120
+ params.membership.includes(communityMembership));
31121
+ }
31122
+ if (params.search) {
31123
+ communityMembers = filterBySearchTerm(communityMembers, params.search);
31124
+ }
31125
+ const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
31126
+ communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
31127
+ return communityMembers;
31128
+ };
30857
31129
  /* begin_public_function
30858
31130
  id: community.membership.query
30859
31131
  */
@@ -30878,6 +31150,7 @@ queryCommunityMembers.locally = (query) => {
30878
31150
  const getMembers = (params, callback, config) => {
30879
31151
  const { log, cache } = getActiveClient();
30880
31152
  if (!cache) {
31153
+ // eslint-disable-next-line no-console
30881
31154
  console.log(ENABLE_CACHE_MESSAGE);
30882
31155
  }
30883
31156
  const timestamp = Date.now();
@@ -30887,20 +31160,6 @@ const getMembers = (params, callback, config) => {
30887
31160
  const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
30888
31161
  const disposers = [];
30889
31162
  const cacheKey = ['communityUsers', 'collection', { communityId: params.communityId }];
30890
- const applyFilter = (data) => {
30891
- let communityMembers = filterByPropIntersection(data, 'roles', params.roles);
30892
- if (params.membership) {
30893
- communityMembers = communityMembers.filter(({ communityMembership }) =>
30894
- // @ts-ignore
30895
- params.membership.includes(communityMembership));
30896
- }
30897
- if (params.search) {
30898
- communityMembers = filterBySearchTerm(communityMembers, params.search);
30899
- }
30900
- const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
30901
- communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
30902
- return communityMembers;
30903
- };
30904
31163
  const responder = (data, isEventModel = false) => {
30905
31164
  var _a, _b;
30906
31165
  const communityMembers = (_a = data.data
@@ -30909,7 +31168,7 @@ const getMembers = (params, callback, config) => {
30909
31168
  .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
30910
31169
  callback({
30911
31170
  onNextPage: onFetch,
30912
- data: isEventModel ? applyFilter(communityMembers) : communityMembers,
31171
+ data: isEventModel ? applyFilter(communityMembers, params) : communityMembers,
30913
31172
  hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
30914
31173
  loading: data.loading,
30915
31174
  error: data.error,
@@ -30967,6 +31226,7 @@ var index$7 = /*#__PURE__*/Object.freeze({
30967
31226
  __proto__: null,
30968
31227
  addMembers: addMembers,
30969
31228
  removeMembers: removeMembers,
31229
+ applyFilter: applyFilter,
30970
31230
  getMembers: getMembers,
30971
31231
  onCommunityUserAdded: onCommunityUserAdded,
30972
31232
  onCommunityUserRemoved: onCommunityUserRemoved,
@@ -30990,13 +31250,14 @@ var index$6 = /*#__PURE__*/Object.freeze({
30990
31250
  joinCommunity: joinCommunity,
30991
31251
  leaveCommunity: leaveCommunity,
30992
31252
  getTopTrendingCommunities: getTopTrendingCommunities,
30993
- getRecommendedCommunities: getRecommendedCommunities,
30994
31253
  onCommunityCreated: onCommunityCreated,
30995
31254
  onCommunityUpdated: onCommunityUpdated,
30996
31255
  onCommunityDeleted: onCommunityDeleted,
30997
31256
  observeCommunity: observeCommunity,
30998
31257
  getCommunities: getCommunities,
30999
- getCommunity: getCommunity
31258
+ getCommunity: getCommunity,
31259
+ getTrendingCommunities: getTrendingCommunities,
31260
+ getRecommendedCommunities: getRecommendedCommunities
31000
31261
  });
31001
31262
 
31002
31263
  /* begin_public_function
@@ -31088,7 +31349,7 @@ const queryCategories = async (query) => {
31088
31349
  const cacheKey = [
31089
31350
  'category',
31090
31351
  'query',
31091
- Object.assign(Object.assign({}, params), { options: Object.assign({}, page) }),
31352
+ Object.assign(Object.assign({}, params), { includeDeleted, options: Object.assign({}, page) }),
31092
31353
  ];
31093
31354
  pushToCache(cacheKey, { categories: categories.map(getResolver('category')), paging });
31094
31355
  }
@@ -31967,11 +32228,11 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
31967
32228
  */
31968
32229
  /**
31969
32230
  * ```js
31970
- * import { getPost } from '@amityco/ts-sdk';
32231
+ * import { PostRepository } from '@amityco/ts-sdk';
31971
32232
  *
31972
32233
  * let post;
31973
32234
  *
31974
- * const unsubscribe = getPost(postId, response => {
32235
+ * const unsub = PostRepository.getPost(postId, response => {
31975
32236
  * post = response.data;
31976
32237
  * });
31977
32238
  * ```
@@ -32051,7 +32312,7 @@ const queryPosts = async (query) => {
32051
32312
  };
32052
32313
 
32053
32314
  /* begin_public_function
32054
- id: post.query, feed.query.community_feed, feed.query.user_feed
32315
+ id: post.query
32055
32316
  */
32056
32317
  /**
32057
32318
  * ```js
@@ -32627,11 +32888,11 @@ const observeComment = (commentId, callback, policy = 'cache_then_server') => {
32627
32888
  */
32628
32889
  /**
32629
32890
  * ```js
32630
- * import { getComment } from '@amityco/ts-sdk';
32891
+ * import { CommentRepository } from '@amityco/ts-sdk';
32631
32892
  *
32632
32893
  * let comment;
32633
32894
  *
32634
- * const unsubscribe = getComment(commentId, response => {
32895
+ * const unsub = CommentRepository.getComment(commentId, response => {
32635
32896
  * comment = response.data;
32636
32897
  * });
32637
32898
  * ```
@@ -33140,7 +33401,8 @@ const onStreamRecorded = (callback) => {
33140
33401
  /**
33141
33402
  * ```js
33142
33403
  * import { StreamRepository } from '@amityco/ts-sdk'
33143
- * const stream = await StreamRepository.getStreamById('foobar')
33404
+ * const unsub = StreamRepository.getStreamById('foobar')
33405
+ * unsub()
33144
33406
  * ```
33145
33407
  *
33146
33408
  * Fetches a {@link Amity.Stream} object
@@ -33157,7 +33419,33 @@ const getStreamById = (streamId, callback) => {
33157
33419
  onStreamStopped,
33158
33420
  ]);
33159
33421
  };
33160
- /* end_public_function */
33422
+ /* end_public_function */
33423
+ /**
33424
+ * ```js
33425
+ * import { StreamRepository } from '@amityco/ts-sdk'
33426
+ * const stream = StreamRepository.getStreamById.locally('foobar')
33427
+ * ```
33428
+ *
33429
+ * Fetches a {@link Amity.Stream} live object
33430
+ *
33431
+ * @param streamId the ID of the {@link Amity.Stream} to fetch
33432
+ * @returns the associated {@link Amity.Stream} live object
33433
+ *
33434
+ * @category Stream API
33435
+ */
33436
+ getStreamById.locally = (streamId) => {
33437
+ const client = getActiveClient();
33438
+ client.log('stream/getStreamById', streamId);
33439
+ if (!client.cache)
33440
+ return;
33441
+ const cached = pullFromCache(['stream', 'get', streamId]);
33442
+ if (!cached)
33443
+ return;
33444
+ return {
33445
+ data: cached.data,
33446
+ cachedAt: cached.cachedAt,
33447
+ };
33448
+ };
33161
33449
 
33162
33450
  /* begin_public_function
33163
33451
  id: stream.query
@@ -33182,12 +33470,12 @@ const getStreams = (params, callback, config) => {
33182
33470
  console.log(ENABLE_CACHE_MESSAGE);
33183
33471
  }
33184
33472
  const timestamp = Date.now();
33185
- log(`queryStreams(tmpid: ${timestamp}) > listen`);
33473
+ log(`getStreams(tmpid: ${timestamp}) > listen`);
33186
33474
  const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
33187
33475
  const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
33188
33476
  const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
33189
33477
  const disposers = [];
33190
- const cacheKey = ['streams', 'collection', {}];
33478
+ const cacheKey = ['streams', 'collection', params];
33191
33479
  const applyFilter = (data) => {
33192
33480
  let streams = filterByPropEquality(data, 'isDeleted', params.isDeleted);
33193
33481
  streams = streams.sort(params.sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
@@ -33196,7 +33484,9 @@ const getStreams = (params, callback, config) => {
33196
33484
  const responder = (data, isEventModel = false) => {
33197
33485
  var _a, _b;
33198
33486
  const streams = (_a = data.data
33199
- .map(streamId => pullFromCache(['streams', 'get', streamId]))
33487
+ .map(streamId => {
33488
+ return pullFromCache(['stream', 'get', streamId]);
33489
+ })
33200
33490
  .filter(Boolean)
33201
33491
  .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
33202
33492
  callback({
@@ -33243,7 +33533,7 @@ const getStreams = (params, callback, config) => {
33243
33533
  disposers.push(onStreamRecorded(realtimeRouter()), onStreamStarted(realtimeRouter()), onStreamStopped(realtimeRouter()));
33244
33534
  onFetch(true);
33245
33535
  return () => {
33246
- log(`queryStreams(tmpid: ${timestamp}) > dispose`);
33536
+ log(`getStreams(tmpid: ${timestamp}) > dispose`);
33247
33537
  disposers.forEach(fn => fn());
33248
33538
  };
33249
33539
  };
@@ -33264,64 +33554,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
33264
33554
  getStreams: getStreams
33265
33555
  });
33266
33556
 
33267
- /* begin_public_function
33268
- id: poll.get
33269
- */
33270
- /**
33271
- * ```js
33272
- * import { getPoll } from '@amityco/ts-sdk'
33273
- * const poll = await getPoll('foobar')
33274
- * ```
33275
- *
33276
- * Fetches a {@link Amity.Poll} object
33277
- *
33278
- * @param pollId the ID of the {@link Amity.Poll} to fetch
33279
- * @returns the associated {@link Amity.Poll} object
33280
- *
33281
- * @category Poll API
33282
- * @async
33283
- */
33284
- const getPoll = async (pollId) => {
33285
- const client = getActiveClient();
33286
- client.log('poll/getPoll', pollId);
33287
- const { data } = await client.http.get(`/api/v3/polls/${pollId}`);
33288
- const cachedAt = client.cache && Date.now();
33289
- if (client.cache)
33290
- ingestInCache(data, { cachedAt });
33291
- const { polls } = data;
33292
- return {
33293
- data: polls.find(poll => poll.pollId === pollId),
33294
- cachedAt,
33295
- };
33296
- };
33297
- /* end_public_function */
33298
- /**
33299
- * ```js
33300
- * import { getPoll } from '@amityco/ts-sdk'
33301
- * const poll = getPoll.locally('foobar')
33302
- * ```
33303
- *
33304
- * Fetches a {@link Amity.Poll} object
33305
- *
33306
- * @param pollId the ID of the {@link Amity.Poll} to fetch
33307
- * @returns the associated {@link Amity.Poll} object
33308
- *
33309
- * @category Poll API
33310
- */
33311
- getPoll.locally = (pollId) => {
33312
- const client = getActiveClient();
33313
- client.log('poll/getPoll', pollId);
33314
- if (!client.cache)
33315
- return;
33316
- const cached = pullFromCache(['poll', 'get', pollId]);
33317
- if (!cached)
33318
- return;
33319
- return {
33320
- data: cached.data,
33321
- cachedAt: cached.cachedAt,
33322
- };
33323
- };
33324
-
33325
33557
  /* begin_public_function
33326
33558
  id: poll.create
33327
33559
  */
@@ -33394,6 +33626,64 @@ const closePoll = async (pollId) => {
33394
33626
  };
33395
33627
  /* end_public_function */
33396
33628
 
33629
+ /* begin_public_function
33630
+ id: poll.get
33631
+ */
33632
+ /**
33633
+ * ```js
33634
+ * import { getPoll } from '@amityco/ts-sdk'
33635
+ * const poll = await getPoll('foobar')
33636
+ * ```
33637
+ *
33638
+ * Fetches a {@link Amity.Poll} object
33639
+ *
33640
+ * @param pollId the ID of the {@link Amity.Poll} to fetch
33641
+ * @returns the associated {@link Amity.Poll} object
33642
+ *
33643
+ * @category Poll API
33644
+ * @async
33645
+ */
33646
+ const getPoll$1 = async (pollId) => {
33647
+ const client = getActiveClient();
33648
+ client.log('poll/getPoll', pollId);
33649
+ const { data } = await client.http.get(`/api/v3/polls/${pollId}`);
33650
+ const cachedAt = client.cache && Date.now();
33651
+ if (client.cache)
33652
+ ingestInCache(data, { cachedAt });
33653
+ const { polls } = data;
33654
+ return {
33655
+ data: polls.find(poll => poll.pollId === pollId),
33656
+ cachedAt,
33657
+ };
33658
+ };
33659
+ /* end_public_function */
33660
+ /**
33661
+ * ```js
33662
+ * import { getPoll } from '@amityco/ts-sdk'
33663
+ * const poll = getPoll.locally('foobar')
33664
+ * ```
33665
+ *
33666
+ * Fetches a {@link Amity.Poll} object
33667
+ *
33668
+ * @param pollId the ID of the {@link Amity.Poll} to fetch
33669
+ * @returns the associated {@link Amity.Poll} object
33670
+ *
33671
+ * @category Poll API
33672
+ */
33673
+ getPoll$1.locally = (pollId) => {
33674
+ const client = getActiveClient();
33675
+ client.log('poll/getPoll', pollId);
33676
+ if (!client.cache)
33677
+ return;
33678
+ const cached = pullFromCache(['poll', 'get', pollId]);
33679
+ if (!cached)
33680
+ return;
33681
+ return {
33682
+ data: cached.data,
33683
+ cachedAt: cached.cachedAt,
33684
+ };
33685
+ };
33686
+
33397
33687
  /* begin_public_function
33398
33688
  id: poll.delete
33399
33689
  */
@@ -33414,7 +33704,7 @@ const closePoll = async (pollId) => {
33414
33704
  const deletePoll = async (pollId) => {
33415
33705
  const client = getActiveClient();
33416
33706
  client.log('poll/deletePoll', pollId);
33417
- const poll = await getPoll(pollId);
33707
+ const poll = await getPoll$1(pollId);
33418
33708
  // API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
33419
33709
  const { data } = await client.http.delete(`/api/v3/polls/${pollId}`);
33420
33710
  const { success } = data; // unwrapPayload(data)
@@ -33546,23 +33836,50 @@ const observePoll = (pollId, callback, policy = 'cache_then_server') => {
33546
33836
  };
33547
33837
  const disposers = [];
33548
33838
  disposers.push(onPollUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')), onPollDeleted(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onDelete')));
33549
- runQuery(createQuery(getPoll, pollId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
33839
+ runQuery(createQuery(getPoll$1, pollId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
33550
33840
  return () => {
33551
33841
  log(`observePoll(tmpid: ${timestamp}) > dispose`);
33552
33842
  disposers.forEach(fn => fn());
33553
33843
  };
33554
33844
  };
33555
33845
 
33846
+ /* begin_public_function
33847
+ id: poll.get
33848
+ */
33849
+ /**
33850
+ * ```js
33851
+ * import { PollRepository } from '@amityco/ts-sdk';
33852
+ *
33853
+ * let poll;
33854
+ *
33855
+ * const unsub = PollRepository.getPoll(commentId, response => {
33856
+ * poll = response.data;
33857
+ * });
33858
+ * ```
33859
+ *
33860
+ * Observe all mutation on a given {@link Amity.Poll}
33861
+ *
33862
+ * @param pollId the ID of the poll to observe
33863
+ * @param callback the function to call when new data are available
33864
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
33865
+ *
33866
+ * @category Poll Live Object
33867
+ */
33868
+ const getPoll = (pollId, callback) => {
33869
+ return liveObject(pollId, callback, 'pollId', getPoll$1, [onPollUpdated, onPollDeleted]);
33870
+ };
33871
+ /* end_public_function */
33872
+
33556
33873
  var index = /*#__PURE__*/Object.freeze({
33557
33874
  __proto__: null,
33558
- getPoll: getPoll,
33559
33875
  createPoll: createPoll,
33560
33876
  closePoll: closePoll,
33561
33877
  deletePoll: deletePoll,
33562
33878
  votePoll: votePoll,
33563
33879
  onPollUpdated: onPollUpdated,
33564
33880
  onPollDeleted: onPollDeleted,
33565
- observePoll: observePoll
33881
+ observePoll: observePoll,
33882
+ getPoll: getPoll
33566
33883
  });
33567
33884
 
33568
33885
  /**