@amityco/ts-sdk 0.0.1-beta.26 → 0.0.1-beta.27

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 (66) hide show
  1. package/dist/@types/core/events.d.ts +7 -7
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/payload.d.ts +3 -5
  4. package/dist/@types/core/payload.d.ts.map +1 -1
  5. package/dist/@types/domains/follow.d.ts +2 -1
  6. package/dist/@types/domains/follow.d.ts.map +1 -1
  7. package/dist/@types/domains/reaction.d.ts +10 -0
  8. package/dist/@types/domains/reaction.d.ts.map +1 -1
  9. package/dist/channel/api/banChannelMembers.d.ts +16 -0
  10. package/dist/channel/api/banChannelMembers.d.ts.map +1 -0
  11. package/dist/channel/api/index.d.ts +2 -0
  12. package/dist/channel/api/index.d.ts.map +1 -1
  13. package/dist/channel/api/unbanChannelMembers.d.ts +16 -0
  14. package/dist/channel/api/unbanChannelMembers.d.ts.map +1 -0
  15. package/dist/comment/observers/liveComments.d.ts.map +1 -1
  16. package/dist/follow/api/follow.d.ts.map +1 -1
  17. package/dist/follow/api/getFollowInfo.d.ts.map +1 -1
  18. package/dist/follow/api/queryFollowers.d.ts +4 -4
  19. package/dist/follow/api/queryFollowers.d.ts.map +1 -1
  20. package/dist/follow/api/queryFollowings.d.ts +4 -4
  21. package/dist/follow/api/queryFollowings.d.ts.map +1 -1
  22. package/dist/follow/api/utils.d.ts +4 -4
  23. package/dist/follow/api/utils.d.ts.map +1 -1
  24. package/dist/follow/events/utils.d.ts.map +1 -1
  25. package/dist/index.cjs.js +345 -19
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.esm.js +340 -20
  29. package/dist/index.umd.js +4 -4
  30. package/dist/reaction/api/queryReactions.d.ts +1 -6
  31. package/dist/reaction/api/queryReactions.d.ts.map +1 -1
  32. package/dist/reaction/events/index.d.ts +3 -0
  33. package/dist/reaction/events/index.d.ts.map +1 -1
  34. package/dist/reaction/events/onReactorAdded.d.ts +19 -0
  35. package/dist/reaction/events/onReactorAdded.d.ts.map +1 -0
  36. package/dist/reaction/events/onReactorRemoved.d.ts +19 -0
  37. package/dist/reaction/events/onReactorRemoved.d.ts.map +1 -0
  38. package/dist/reaction/observers/index.d.ts +2 -0
  39. package/dist/reaction/observers/index.d.ts.map +1 -0
  40. package/dist/reaction/observers/liveReactions.d.ts +22 -0
  41. package/dist/reaction/observers/liveReactions.d.ts.map +1 -0
  42. package/package.json +1 -1
  43. package/src/@types/core/events.ts +7 -7
  44. package/src/@types/core/payload.ts +5 -6
  45. package/src/@types/domains/follow.ts +3 -1
  46. package/src/@types/domains/reaction.ts +17 -0
  47. package/src/channel/api/banChannelMembers.ts +41 -0
  48. package/src/channel/api/index.ts +3 -0
  49. package/src/channel/api/unbanChannelMembers.ts +41 -0
  50. package/src/comment/observers/liveComments.ts +4 -1
  51. package/src/follow/api/acceptFollower.ts +1 -1
  52. package/src/follow/api/declineFollower.ts +1 -1
  53. package/src/follow/api/follow.ts +1 -4
  54. package/src/follow/api/getFollowInfo.ts +8 -5
  55. package/src/follow/api/queryFollowers.ts +5 -4
  56. package/src/follow/api/queryFollowings.ts +5 -4
  57. package/src/follow/api/unfollow.ts +1 -1
  58. package/src/follow/api/utils.ts +10 -10
  59. package/src/follow/events/utils.ts +9 -6
  60. package/src/index.ts +1 -0
  61. package/src/reaction/api/queryReactions.ts +6 -6
  62. package/src/reaction/events/index.ts +4 -0
  63. package/src/reaction/events/onReactorAdded.ts +80 -0
  64. package/src/reaction/events/onReactorRemoved.ts +85 -0
  65. package/src/reaction/observers/index.ts +1 -0
  66. package/src/reaction/observers/liveReactions.ts +142 -0
package/dist/index.esm.js CHANGED
@@ -23141,6 +23141,7 @@ const queryReactions = async (query) => {
23141
23141
  });
23142
23142
  const { paging } = data, payload = __rest(data, ["paging"]);
23143
23143
  const { reactions } = payload;
23144
+ ingestInCache(Object.assign(Object.assign({}, payload), { reactions: reactions[0].reactors }));
23144
23145
  const nextPage = toPageRaw(paging.next);
23145
23146
  const prevPage = toPageRaw(paging.previous);
23146
23147
  return { data: reactions, prevPage, nextPage };
@@ -23543,6 +23544,56 @@ const onCommentReactionRemoved = (callback) => {
23543
23544
  return createEventSubscriber(client, 'comment.removeReaction', 'comment.removeReaction', filter);
23544
23545
  };
23545
23546
 
23547
+ /**
23548
+ * ```js
23549
+ * import { onReactionAdded } from '@amityco/ts-sdk'
23550
+ * const dispose = onReactionAdded('post', postId, post => {
23551
+ * // ...
23552
+ * })
23553
+ * ```
23554
+ *
23555
+ * Fired when an {@link Amity.Reaction} has been added
23556
+ *
23557
+ * @param {@link Amity.ReactableType} referenceType
23558
+ * @param {string} referenceId
23559
+ * @param callback The function to call when the event was fired
23560
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
23561
+ *
23562
+ * @category Message Events
23563
+ * */
23564
+ const onReactionAdded = (referenceType, referenceId, callback) => {
23565
+ const callbackWrapper = (model) => {
23566
+ if (getResolver(referenceType)(model) === referenceId) {
23567
+ callback(model);
23568
+ }
23569
+ };
23570
+ /*
23571
+ * Important: Want to point out that reference type will never be 'message'
23572
+ * for onReactionAdded
23573
+ */
23574
+ if (referenceType === 'message') {
23575
+ const client = getActiveClient();
23576
+ const filter = (payload) => {
23577
+ var _a;
23578
+ const cached = pullFromCache([
23579
+ 'message',
23580
+ 'get',
23581
+ payload.messages[0].messageId,
23582
+ ]);
23583
+ const isReactionEvent = ((_a = cached === null || cached === void 0 ? void 0 : cached.data) === null || _a === void 0 ? void 0 : _a.reactionsCount) !== payload.messages[0].reactionsCount;
23584
+ ingestInCache(payload);
23585
+ if (isReactionEvent) {
23586
+ callbackWrapper(payload.messages[0]);
23587
+ }
23588
+ };
23589
+ return createEventSubscriber(client, 'reaction/onReactionAdded', 'v3.message.didUpdate', filter);
23590
+ }
23591
+ if (referenceType === 'post') {
23592
+ return onPostReactionAdded(callbackWrapper);
23593
+ }
23594
+ return onCommentReactionAdded(callbackWrapper);
23595
+ };
23596
+
23546
23597
  /**
23547
23598
  * ```js
23548
23599
  * import { onReactionRemoved } from '@amityco/ts-sdk'
@@ -23589,6 +23640,214 @@ const onReactionRemoved = (referenceType, referenceId, callback) => {
23589
23640
  return onCommentReactionRemoved(callbackWrapper);
23590
23641
  };
23591
23642
 
23643
+ /**
23644
+ * ```js
23645
+ * import { onReactorAdded } from '@amityco/ts-sdk'
23646
+ * const dispose = onReactorAdded('post', postId, reactor => {
23647
+ * // ...
23648
+ * })
23649
+ * ```
23650
+ *
23651
+ * Fired when an {@link Amity.Reactor} has been added
23652
+ *
23653
+ * @param {@link Amity.ReactableType} referenceType
23654
+ * @param {string} referenceId
23655
+ * @param callback The function to call when the event was fired
23656
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
23657
+ *
23658
+ * @category Events
23659
+ * */
23660
+ const onReactorAdded = (referenceType, referenceId, callback) => {
23661
+ const client = getActiveClient();
23662
+ const callbackWrapper = (referenceType_, referenceId_, reaction) => {
23663
+ if (referenceType_ === referenceType && referenceId_ === referenceId) {
23664
+ callback(reaction);
23665
+ }
23666
+ };
23667
+ if (referenceType === 'message') {
23668
+ const filter = (payload) => {
23669
+ if (!payload.messages[0].latestReaction)
23670
+ return;
23671
+ const _a = payload.messages[0].latestReaction, { eventName, referenceId, referenceType, userDisplayName } = _a, reactor = __rest(_a, ["eventName", "referenceId", "referenceType", "userDisplayName"]);
23672
+ if (eventName !== 'add')
23673
+ return;
23674
+ ingestInCache(payload);
23675
+ ingestInCache({ reactions: [reactor] });
23676
+ callbackWrapper('message', payload.messages[0].messageId, reactor);
23677
+ };
23678
+ return createEventSubscriber(client, 'reaction/onReactorAdded', 'v3.message.didUpdate', filter);
23679
+ }
23680
+ if (referenceType === 'post') {
23681
+ const filter = (payload) => {
23682
+ const { reactor } = payload, rest = __rest(payload, ["reactor"]);
23683
+ ingestInCache(rest);
23684
+ ingestInCache({ reactions: [reactor] });
23685
+ callbackWrapper('post', payload.posts[0].postId, reactor);
23686
+ };
23687
+ return createEventSubscriber(client, 'post.addReaction', 'post.addReaction', filter);
23688
+ }
23689
+ const filter = (payload) => {
23690
+ const { reactor } = payload, rest = __rest(payload, ["reactor"]);
23691
+ ingestInCache(rest);
23692
+ ingestInCache({ reactions: [reactor] });
23693
+ callbackWrapper('comment', payload.comments[0].commentId, reactor);
23694
+ };
23695
+ return createEventSubscriber(client, 'comment.addReaction', 'comment.addReaction', filter);
23696
+ };
23697
+
23698
+ /**
23699
+ * ```js
23700
+ * import { onReactorRemoved } from '@amityco/ts-sdk'
23701
+ * const dispose = onReactorRemoved('post', postId, reactor => {
23702
+ * // ...
23703
+ * })
23704
+ * ```
23705
+ *
23706
+ * Fired when an {@link Amity.Reactor} has been removed
23707
+ *
23708
+ * @param {@link Amity.ReactableType} referenceType
23709
+ * @param {string} referenceId
23710
+ * @param callback The function to call when the event was fired
23711
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
23712
+ *
23713
+ * @category Events
23714
+ * */
23715
+ const onReactorRemoved = (referenceType, referenceId, callback) => {
23716
+ const client = getActiveClient();
23717
+ const callbackWrapper = (referenceType_, referenceId_, reaction) => {
23718
+ if (referenceType_ === referenceType && referenceId_ === referenceId) {
23719
+ callback(reaction);
23720
+ }
23721
+ };
23722
+ if (referenceType === 'message') {
23723
+ const filter = (payload) => {
23724
+ if (!payload.messages[0].latestReaction)
23725
+ return;
23726
+ const _a = payload.messages[0].latestReaction, { eventName, referenceId, referenceType } = _a, reactor = __rest(_a, ["eventName", "referenceId", "referenceType"]);
23727
+ if (eventName !== 'remove')
23728
+ return;
23729
+ ingestInCache(payload);
23730
+ ingestInCache({ reactions: [reactor] });
23731
+ callbackWrapper('message', payload.messages[0].messageId, reactor);
23732
+ };
23733
+ return createEventSubscriber(client, 'reaction/onReactorRemoved', 'v3.message.didUpdate', filter);
23734
+ }
23735
+ if (referenceType === 'post') {
23736
+ const filter = (payload) => {
23737
+ const { reactor } = payload, rest = __rest(payload, ["reactor"]);
23738
+ ingestInCache(rest);
23739
+ ingestInCache({ reactions: [reactor] });
23740
+ callbackWrapper('post', payload.posts[0].postId, reactor);
23741
+ };
23742
+ return createEventSubscriber(client, 'post.removeReaction', 'post.removeReaction', filter);
23743
+ }
23744
+ const filter = (payload) => {
23745
+ const { reactor } = payload, rest = __rest(payload, ["reactor"]);
23746
+ ingestInCache(rest);
23747
+ ingestInCache({ reactions: [reactor] });
23748
+ callbackWrapper('comment', payload.comments[0].commentId, reactor);
23749
+ };
23750
+ return createEventSubscriber(client, 'comment.removeReaction', 'comment.removeReaction', filter);
23751
+ };
23752
+
23753
+ const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
23754
+ const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
23755
+
23756
+ /**
23757
+ * ```js
23758
+ * import { liveReactions } from '@amityco/ts-sdk'
23759
+ *
23760
+ * let reactions = []
23761
+ * const unsub = liveReactions({
23762
+ * referenceId: Amity.Reaction['referenceId'],
23763
+ * referenceType: Amity.Reaction['referenceType'],
23764
+ * }, response => merge(reactions, response.data))
23765
+ * ```
23766
+ *
23767
+ * Observe all mutations on a list of {@link Amity.Reaction} for a given target object
23768
+ *
23769
+ * @param referenceType the type of the target
23770
+ * @param referenceId the ID of the target
23771
+ * @param callback the function to call when new data are available
23772
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
23773
+ *
23774
+ * @category Reactions Live Collection
23775
+ */
23776
+ const liveReactions = (params, callback, config) => {
23777
+ const { log, cache } = getActiveClient();
23778
+ if (!cache) {
23779
+ console.log('For using Live Collection feature you need to enable Cache!');
23780
+ }
23781
+ const timestamp = Date.now();
23782
+ log(`liveReactions(tmpid: ${timestamp}) > listen`);
23783
+ const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
23784
+ const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
23785
+ const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
23786
+ const disposers = [];
23787
+ const cacheKey = [
23788
+ 'reaction',
23789
+ 'collection',
23790
+ { referenceId: params.referenceId, referenceType: params.referenceType },
23791
+ ];
23792
+ const responder = (data) => {
23793
+ var _a, _b;
23794
+ const reactions = (_a = data.data
23795
+ .map(reactorId => pullFromCache(['reaction', 'get', reactorId]))
23796
+ .filter(Boolean)
23797
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
23798
+ callback({
23799
+ onNextPage: onFetch,
23800
+ data: reactions,
23801
+ hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
23802
+ loading: data.loading,
23803
+ error: data.error,
23804
+ });
23805
+ };
23806
+ const realtimeRouter = (reaction, action) => {
23807
+ var _a;
23808
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23809
+ if (!collection)
23810
+ return;
23811
+ if (action === 'onAdded') {
23812
+ collection.data = [...new Set([reaction.reactionId, ...collection.data])];
23813
+ }
23814
+ else if (action === 'onRemoved') {
23815
+ collection.data = collection.data.filter(p => p !== reaction.reactionId);
23816
+ }
23817
+ pushToCache(cacheKey, collection);
23818
+ responder(collection);
23819
+ };
23820
+ const onFetch = () => {
23821
+ var _a, _b, _c, _d, _e;
23822
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23823
+ const reactions = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
23824
+ if (reactions.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
23825
+ return;
23826
+ const query = createQuery(queryReactions, Object.assign(Object.assign({}, queryParams), { page: (_e = (_d = collection === null || collection === void 0 ? void 0 : collection.params) === null || _d === void 0 ? void 0 : _d.page) !== null && _e !== void 0 ? _e : { limit } }));
23827
+ runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
23828
+ const data = {
23829
+ loading,
23830
+ error,
23831
+ params: { page },
23832
+ data: reactions,
23833
+ };
23834
+ if (result) {
23835
+ data.data = [
23836
+ ...new Set([...reactions, ...result[0].reactors.map(getResolver('reaction'))]),
23837
+ ];
23838
+ }
23839
+ pushToCache(cacheKey, data);
23840
+ responder(data);
23841
+ }, queryOptions(policy));
23842
+ };
23843
+ disposers.push(onReactorAdded(queryParams.referenceType, queryParams.referenceId, reaction => realtimeRouter(reaction, 'onAdded')), onReactorRemoved(queryParams.referenceType, queryParams.referenceId, reaction => realtimeRouter(reaction, 'onRemoved')));
23844
+ onFetch();
23845
+ return () => {
23846
+ log(`liveReactions(tmpid: ${timestamp}) > dispose`);
23847
+ disposers.forEach(fn => fn());
23848
+ };
23849
+ };
23850
+
23592
23851
  var REFERENCE_TYPES = {
23593
23852
  post: {
23594
23853
  domainName: 'posts',
@@ -24170,6 +24429,66 @@ const removeChannelMembersRole = async (channelId, roleId, userIds) => {
24170
24429
  return !!channelUsers.find(channelUser => channelUser.channelId === channelId && !channelUser.roles.includes(roleId));
24171
24430
  };
24172
24431
 
24432
+ /**
24433
+ * ```js
24434
+ * import { banChannelMembers } from '@amityco/ts-sdk'
24435
+ *
24436
+ * await banChannelMembers('channel-id-1', ['userId1', 'userId2'])
24437
+ * ```
24438
+ *
24439
+ * @param channelId of {@link Amity.Channel} from which the users should be banned
24440
+ * @param userIds of the {@link Amity.User}'s to be banned
24441
+ * @returns the updated {@link Amity.Membership}'s object
24442
+ *
24443
+ * @category Channel API
24444
+ * @async
24445
+ * */
24446
+ const banChannelMembers = async (channelId, userIds) => {
24447
+ const client = getActiveClient();
24448
+ client.log('channel/banChannelMembers', { userIds, channelId });
24449
+ const payload = await client.http.put(`/api/v3/channels/${channelId}/users/ban`, {
24450
+ userIds,
24451
+ });
24452
+ const cachedAt = client.cache && Date.now();
24453
+ if (client.cache)
24454
+ ingestInCache(payload.data, { cachedAt });
24455
+ const { channelUsers } = payload.data;
24456
+ return {
24457
+ data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
24458
+ cachedAt,
24459
+ };
24460
+ };
24461
+
24462
+ /**
24463
+ * ```js
24464
+ * import { unbanChannelMembers } from '@amityco/ts-sdk'
24465
+ *
24466
+ * await unbanChannelMembers('channel-id-1', ['userId1', 'userId2'])
24467
+ * ```
24468
+ *
24469
+ * @param channelId of {@link Amity.Channel} where the users should be unbanned
24470
+ * @param userIds of the {@link Amity.User}'s to be unbanned
24471
+ * @returns the updated {@link Amity.Membership}'s object
24472
+ *
24473
+ * @category Channel API
24474
+ * @async
24475
+ * */
24476
+ const unbanChannelMembers = async (channelId, userIds) => {
24477
+ const client = getActiveClient();
24478
+ client.log('channel/unbanChannelMembers', { userIds, channelId });
24479
+ const payload = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`, {
24480
+ userIds,
24481
+ });
24482
+ const cachedAt = client.cache && Date.now();
24483
+ if (client.cache)
24484
+ ingestInCache(payload.data, { cachedAt });
24485
+ const { channelUsers } = payload.data;
24486
+ return {
24487
+ data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
24488
+ cachedAt,
24489
+ };
24490
+ };
24491
+
24173
24492
  /**
24174
24493
  * ```js
24175
24494
  * import { onChannelUpdated } from '@amityco/ts-sdk'
@@ -24994,7 +25313,7 @@ const queryFollows = async (key, query) => {
24994
25313
  client.log(`follow/queryF${key.substring(1)}`, query);
24995
25314
  const { userId, page } = query, params = __rest(query, ["userId", "page"]);
24996
25315
  const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/${key}` : `/api/v4/users/${userId}/${key}`, {
24997
- params: Object.assign(Object.assign({}, params), { token: toToken(page, 'skiplimit') }),
25316
+ params: Object.assign(Object.assign({}, params), { token: toToken(page, 'afterbeforeraw') }),
24998
25317
  });
24999
25318
  const { paging } = data, payload = __rest(data, ["paging"]);
25000
25319
  const { follows } = payload;
@@ -25008,8 +25327,8 @@ const queryFollows = async (key, query) => {
25008
25327
  ];
25009
25328
  pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
25010
25329
  }
25011
- const nextPage = toPage(paging.next);
25012
- const prevPage = toPage(paging.previous);
25330
+ const nextPage = toPageRaw(paging.next);
25331
+ const prevPage = toPageRaw(paging.previous);
25013
25332
  return { data: follows, cachedAt, prevPage, nextPage };
25014
25333
  };
25015
25334
  queryFollows.locally = (key, query) => {
@@ -25028,8 +25347,8 @@ queryFollows.locally = (key, query) => {
25028
25347
  .map(key => pullFromCache(['follow', 'get', key]))
25029
25348
  .filter(Boolean)
25030
25349
  .map(({ data }) => data);
25031
- const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
25032
- const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
25350
+ const prevPage = toPageRaw(data === null || data === void 0 ? void 0 : data.paging.previous);
25351
+ const nextPage = toPageRaw(data === null || data === void 0 ? void 0 : data.paging.next);
25033
25352
  return follows.length === ((_b = data === null || data === void 0 ? void 0 : data.follows) === null || _b === void 0 ? void 0 : _b.length)
25034
25353
  ? { data: follows, cachedAt, prevPage, nextPage }
25035
25354
  : undefined;
@@ -25120,7 +25439,8 @@ const getFollowInfo = async (userId) => {
25120
25439
  client.log('follow/getFollowInfo', userId);
25121
25440
  const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/followInfo` : `/api/v4/users/${userId}/followInfo`);
25122
25441
  const cachedAt = client.cache && Date.now();
25123
- const followInfo = 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 });
25442
+ const followInfo = 'follows' in data
25443
+ ? 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];
25124
25444
  if (client.cache) {
25125
25445
  pushToCache(getCacheKey(userId), followInfo, { cachedAt });
25126
25446
  }
@@ -25180,7 +25500,7 @@ const follow = async (userId) => {
25180
25500
  if (client.cache) {
25181
25501
  ingestInCache(data, { cachedAt });
25182
25502
  }
25183
- fireEvent(data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested', data.follows[0]);
25503
+ fireEvent(data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested', data);
25184
25504
  return {
25185
25505
  data: data.follows[0],
25186
25506
  cachedAt,
@@ -25208,7 +25528,7 @@ const unfollow = async (userId) => {
25208
25528
  if (client.cache) {
25209
25529
  ingestInCache(data);
25210
25530
  }
25211
- fireEvent('follow.unfollowed', data.follows[0]);
25531
+ fireEvent('follow.unfollowed', data);
25212
25532
  return true;
25213
25533
  };
25214
25534
 
@@ -25233,7 +25553,7 @@ const acceptFollower = async (userId) => {
25233
25553
  if (client.cache) {
25234
25554
  ingestInCache(data);
25235
25555
  }
25236
- fireEvent('follow.accepted', data.follows[0]);
25556
+ fireEvent('follow.accepted', data);
25237
25557
  return true;
25238
25558
  };
25239
25559
 
@@ -25258,7 +25578,7 @@ const declineFollower = async (userId) => {
25258
25578
  if (client.cache) {
25259
25579
  ingestInCache(data);
25260
25580
  }
25261
- fireEvent('follow.requestDeclined', data.follows[0]);
25581
+ fireEvent('follow.requestDeclined', data);
25262
25582
  return true;
25263
25583
  };
25264
25584
 
@@ -25267,19 +25587,20 @@ const createFollowEventSubscriber = (event, callback) => {
25267
25587
  const filter = (payload) => {
25268
25588
  var _a, _b;
25269
25589
  if (!client.cache) {
25270
- callback(payload);
25590
+ callback(payload.follows[0]);
25271
25591
  }
25272
25592
  else {
25273
- ingestInCache({ follows: [payload] });
25593
+ ingestInCache(payload);
25274
25594
  const queries = [
25275
25595
  ...((_a = queryCache(['followers', 'query'])) !== null && _a !== void 0 ? _a : []),
25276
25596
  ...((_b = queryCache(['followings', 'query'])) !== null && _b !== void 0 ? _b : []),
25277
25597
  ];
25278
25598
  queries
25279
- // @ts-ignore
25280
- .filter(({ key }) => key[2].userId === payload.from || key[2].userId === payload.to)
25599
+ .filter(({ key }) =>
25600
+ // @ts-ignore
25601
+ key[2].userId === payload.follows[0].from || key[2].userId === payload.follows[0].to)
25281
25602
  .forEach(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
25282
- callback(payload);
25603
+ callback(payload.follows[0]);
25283
25604
  }
25284
25605
  };
25285
25606
  return createEventSubscriber(client, event, event, filter);
@@ -25648,9 +25969,6 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
25648
25969
  };
25649
25970
  };
25650
25971
 
25651
- const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
25652
- const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
25653
-
25654
25972
  /**
25655
25973
  * ```js
25656
25974
  * import { livePosts } from '@amityco/ts-sdk'
@@ -25904,7 +26222,9 @@ const liveComments = (params, callback, config) => {
25904
26222
  if (comments.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
25905
26223
  return;
25906
26224
  const query = createQuery(queryComments, Object.assign(Object.assign({}, queryParams), { page: (_e = (_d = collection === null || collection === void 0 ? void 0 : collection.params) === null || _d === void 0 ? void 0 : _d.page) !== null && _e !== void 0 ? _e : { limit } }));
25907
- runQuery(query, ({ data: result, error, loading, prevPage: page }) => {
26225
+ runQuery(query, ({ data: result, error, loading, prevPage, nextPage }) => {
26226
+ // depend on sortBy value we have two different pagination type
26227
+ const page = queryParams.sortBy ? nextPage : prevPage;
25908
26228
  const data = {
25909
26229
  loading,
25910
26230
  error,
@@ -26510,4 +26830,4 @@ const createUserToken = async (apiKey, apiRegion, params) => {
26510
26830
  return { accessToken: data.accessToken };
26511
26831
  };
26512
26832
 
26513
- export { API_REGIONS, SubscriptionLevels, VERSION$1 as VERSION, acceptFollower, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRoles, addReaction, approvePost, backupCache, closePoll, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createImage, createMessage, createPoll, createPost, createQuery, createReport, createStream, createUserToken, createVideo, declineFollower, declinePost, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePoll, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, follow, getActiveClient, getCategory, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getFollowInfo, getMessage, getMessages, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPoll, getPost, getPostTopic, getPosts, getRecommendedCommunities, getRole, getStream, getTopTrendingCommunities, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, liveComments, livePosts, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeFollowInfo, observeFollowers, observeFollowings, observeMessage, observeMessages, observePoll, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelMemberAdded, onChannelMemberRemoved, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onFollowInfoUpdated, onFollowRequestAccepted, onFollowRequestCanceled, onFollowRequestDeclined, onFollowerDeleted, onFollowerRequested, onMessageCreated, onMessageDeleted, onMessageUpdated, onPollDeleted, onPollUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserDeleted, onUserFlagCleared, onUserFlagged, onUserFollowed, onUserUnflagged, onUserUnfollowed, onUserUpdated, pullFromCache, pushToCache, queryCache, queryCategories, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryFollowers, queryFollowings, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryReactions, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRoles, removeReaction, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, unfollow, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser, upsertInCache, votePoll, wipeCache };
26833
+ export { API_REGIONS, SubscriptionLevels, VERSION$1 as VERSION, acceptFollower, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRoles, addReaction, approvePost, backupCache, banChannelMembers, closePoll, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createImage, createMessage, createPoll, createPost, createQuery, createReport, createStream, createUserToken, createVideo, declineFollower, declinePost, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePoll, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, follow, getActiveClient, getCategory, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getFollowInfo, getMessage, getMessages, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPoll, getPost, getPostTopic, getPosts, getRecommendedCommunities, getRole, getStream, getTopTrendingCommunities, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, liveComments, livePosts, liveReactions, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeFollowInfo, observeFollowers, observeFollowings, observeMessage, observeMessages, observePoll, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelMemberAdded, onChannelMemberRemoved, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onFollowInfoUpdated, onFollowRequestAccepted, onFollowRequestCanceled, onFollowRequestDeclined, onFollowerDeleted, onFollowerRequested, onMessageCreated, onMessageDeleted, onMessageUpdated, onPollDeleted, onPollUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionAdded, onReactionRemoved, onReactorAdded, onReactorRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserDeleted, onUserFlagCleared, onUserFlagged, onUserFollowed, onUserUnflagged, onUserUnfollowed, onUserUpdated, pullFromCache, pushToCache, queryCache, queryCategories, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryFollowers, queryFollowings, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryReactions, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRoles, removeReaction, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, unbanChannelMembers, unfollow, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser, upsertInCache, votePoll, wipeCache };