@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.cjs.js CHANGED
@@ -23155,6 +23155,7 @@ const queryReactions = async (query) => {
23155
23155
  });
23156
23156
  const { paging } = data, payload = __rest(data, ["paging"]);
23157
23157
  const { reactions } = payload;
23158
+ ingestInCache(Object.assign(Object.assign({}, payload), { reactions: reactions[0].reactors }));
23158
23159
  const nextPage = toPageRaw(paging.next);
23159
23160
  const prevPage = toPageRaw(paging.previous);
23160
23161
  return { data: reactions, prevPage, nextPage };
@@ -23557,6 +23558,56 @@ const onCommentReactionRemoved = (callback) => {
23557
23558
  return createEventSubscriber(client, 'comment.removeReaction', 'comment.removeReaction', filter);
23558
23559
  };
23559
23560
 
23561
+ /**
23562
+ * ```js
23563
+ * import { onReactionAdded } from '@amityco/ts-sdk'
23564
+ * const dispose = onReactionAdded('post', postId, post => {
23565
+ * // ...
23566
+ * })
23567
+ * ```
23568
+ *
23569
+ * Fired when an {@link Amity.Reaction} has been added
23570
+ *
23571
+ * @param {@link Amity.ReactableType} referenceType
23572
+ * @param {string} referenceId
23573
+ * @param callback The function to call when the event was fired
23574
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
23575
+ *
23576
+ * @category Message Events
23577
+ * */
23578
+ const onReactionAdded = (referenceType, referenceId, callback) => {
23579
+ const callbackWrapper = (model) => {
23580
+ if (getResolver(referenceType)(model) === referenceId) {
23581
+ callback(model);
23582
+ }
23583
+ };
23584
+ /*
23585
+ * Important: Want to point out that reference type will never be 'message'
23586
+ * for onReactionAdded
23587
+ */
23588
+ if (referenceType === 'message') {
23589
+ const client = getActiveClient();
23590
+ const filter = (payload) => {
23591
+ var _a;
23592
+ const cached = pullFromCache([
23593
+ 'message',
23594
+ 'get',
23595
+ payload.messages[0].messageId,
23596
+ ]);
23597
+ const isReactionEvent = ((_a = cached === null || cached === void 0 ? void 0 : cached.data) === null || _a === void 0 ? void 0 : _a.reactionsCount) !== payload.messages[0].reactionsCount;
23598
+ ingestInCache(payload);
23599
+ if (isReactionEvent) {
23600
+ callbackWrapper(payload.messages[0]);
23601
+ }
23602
+ };
23603
+ return createEventSubscriber(client, 'reaction/onReactionAdded', 'v3.message.didUpdate', filter);
23604
+ }
23605
+ if (referenceType === 'post') {
23606
+ return onPostReactionAdded(callbackWrapper);
23607
+ }
23608
+ return onCommentReactionAdded(callbackWrapper);
23609
+ };
23610
+
23560
23611
  /**
23561
23612
  * ```js
23562
23613
  * import { onReactionRemoved } from '@amityco/ts-sdk'
@@ -23603,6 +23654,214 @@ const onReactionRemoved = (referenceType, referenceId, callback) => {
23603
23654
  return onCommentReactionRemoved(callbackWrapper);
23604
23655
  };
23605
23656
 
23657
+ /**
23658
+ * ```js
23659
+ * import { onReactorAdded } from '@amityco/ts-sdk'
23660
+ * const dispose = onReactorAdded('post', postId, reactor => {
23661
+ * // ...
23662
+ * })
23663
+ * ```
23664
+ *
23665
+ * Fired when an {@link Amity.Reactor} has been added
23666
+ *
23667
+ * @param {@link Amity.ReactableType} referenceType
23668
+ * @param {string} referenceId
23669
+ * @param callback The function to call when the event was fired
23670
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
23671
+ *
23672
+ * @category Events
23673
+ * */
23674
+ const onReactorAdded = (referenceType, referenceId, callback) => {
23675
+ const client = getActiveClient();
23676
+ const callbackWrapper = (referenceType_, referenceId_, reaction) => {
23677
+ if (referenceType_ === referenceType && referenceId_ === referenceId) {
23678
+ callback(reaction);
23679
+ }
23680
+ };
23681
+ if (referenceType === 'message') {
23682
+ const filter = (payload) => {
23683
+ if (!payload.messages[0].latestReaction)
23684
+ return;
23685
+ const _a = payload.messages[0].latestReaction, { eventName, referenceId, referenceType, userDisplayName } = _a, reactor = __rest(_a, ["eventName", "referenceId", "referenceType", "userDisplayName"]);
23686
+ if (eventName !== 'add')
23687
+ return;
23688
+ ingestInCache(payload);
23689
+ ingestInCache({ reactions: [reactor] });
23690
+ callbackWrapper('message', payload.messages[0].messageId, reactor);
23691
+ };
23692
+ return createEventSubscriber(client, 'reaction/onReactorAdded', 'v3.message.didUpdate', filter);
23693
+ }
23694
+ if (referenceType === 'post') {
23695
+ const filter = (payload) => {
23696
+ const { reactor } = payload, rest = __rest(payload, ["reactor"]);
23697
+ ingestInCache(rest);
23698
+ ingestInCache({ reactions: [reactor] });
23699
+ callbackWrapper('post', payload.posts[0].postId, reactor);
23700
+ };
23701
+ return createEventSubscriber(client, 'post.addReaction', 'post.addReaction', filter);
23702
+ }
23703
+ const filter = (payload) => {
23704
+ const { reactor } = payload, rest = __rest(payload, ["reactor"]);
23705
+ ingestInCache(rest);
23706
+ ingestInCache({ reactions: [reactor] });
23707
+ callbackWrapper('comment', payload.comments[0].commentId, reactor);
23708
+ };
23709
+ return createEventSubscriber(client, 'comment.addReaction', 'comment.addReaction', filter);
23710
+ };
23711
+
23712
+ /**
23713
+ * ```js
23714
+ * import { onReactorRemoved } from '@amityco/ts-sdk'
23715
+ * const dispose = onReactorRemoved('post', postId, reactor => {
23716
+ * // ...
23717
+ * })
23718
+ * ```
23719
+ *
23720
+ * Fired when an {@link Amity.Reactor} has been removed
23721
+ *
23722
+ * @param {@link Amity.ReactableType} referenceType
23723
+ * @param {string} referenceId
23724
+ * @param callback The function to call when the event was fired
23725
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
23726
+ *
23727
+ * @category Events
23728
+ * */
23729
+ const onReactorRemoved = (referenceType, referenceId, callback) => {
23730
+ const client = getActiveClient();
23731
+ const callbackWrapper = (referenceType_, referenceId_, reaction) => {
23732
+ if (referenceType_ === referenceType && referenceId_ === referenceId) {
23733
+ callback(reaction);
23734
+ }
23735
+ };
23736
+ if (referenceType === 'message') {
23737
+ const filter = (payload) => {
23738
+ if (!payload.messages[0].latestReaction)
23739
+ return;
23740
+ const _a = payload.messages[0].latestReaction, { eventName, referenceId, referenceType } = _a, reactor = __rest(_a, ["eventName", "referenceId", "referenceType"]);
23741
+ if (eventName !== 'remove')
23742
+ return;
23743
+ ingestInCache(payload);
23744
+ ingestInCache({ reactions: [reactor] });
23745
+ callbackWrapper('message', payload.messages[0].messageId, reactor);
23746
+ };
23747
+ return createEventSubscriber(client, 'reaction/onReactorRemoved', 'v3.message.didUpdate', filter);
23748
+ }
23749
+ if (referenceType === 'post') {
23750
+ const filter = (payload) => {
23751
+ const { reactor } = payload, rest = __rest(payload, ["reactor"]);
23752
+ ingestInCache(rest);
23753
+ ingestInCache({ reactions: [reactor] });
23754
+ callbackWrapper('post', payload.posts[0].postId, reactor);
23755
+ };
23756
+ return createEventSubscriber(client, 'post.removeReaction', 'post.removeReaction', filter);
23757
+ }
23758
+ const filter = (payload) => {
23759
+ const { reactor } = payload, rest = __rest(payload, ["reactor"]);
23760
+ ingestInCache(rest);
23761
+ ingestInCache({ reactions: [reactor] });
23762
+ callbackWrapper('comment', payload.comments[0].commentId, reactor);
23763
+ };
23764
+ return createEventSubscriber(client, 'comment.removeReaction', 'comment.removeReaction', filter);
23765
+ };
23766
+
23767
+ const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
23768
+ const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
23769
+
23770
+ /**
23771
+ * ```js
23772
+ * import { liveReactions } from '@amityco/ts-sdk'
23773
+ *
23774
+ * let reactions = []
23775
+ * const unsub = liveReactions({
23776
+ * referenceId: Amity.Reaction['referenceId'],
23777
+ * referenceType: Amity.Reaction['referenceType'],
23778
+ * }, response => merge(reactions, response.data))
23779
+ * ```
23780
+ *
23781
+ * Observe all mutations on a list of {@link Amity.Reaction} for a given target object
23782
+ *
23783
+ * @param referenceType the type of the target
23784
+ * @param referenceId the ID of the target
23785
+ * @param callback the function to call when new data are available
23786
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
23787
+ *
23788
+ * @category Reactions Live Collection
23789
+ */
23790
+ const liveReactions = (params, callback, config) => {
23791
+ const { log, cache } = getActiveClient();
23792
+ if (!cache) {
23793
+ console.log('For using Live Collection feature you need to enable Cache!');
23794
+ }
23795
+ const timestamp = Date.now();
23796
+ log(`liveReactions(tmpid: ${timestamp}) > listen`);
23797
+ const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
23798
+ const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
23799
+ const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
23800
+ const disposers = [];
23801
+ const cacheKey = [
23802
+ 'reaction',
23803
+ 'collection',
23804
+ { referenceId: params.referenceId, referenceType: params.referenceType },
23805
+ ];
23806
+ const responder = (data) => {
23807
+ var _a, _b;
23808
+ const reactions = (_a = data.data
23809
+ .map(reactorId => pullFromCache(['reaction', 'get', reactorId]))
23810
+ .filter(Boolean)
23811
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
23812
+ callback({
23813
+ onNextPage: onFetch,
23814
+ data: reactions,
23815
+ hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
23816
+ loading: data.loading,
23817
+ error: data.error,
23818
+ });
23819
+ };
23820
+ const realtimeRouter = (reaction, action) => {
23821
+ var _a;
23822
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23823
+ if (!collection)
23824
+ return;
23825
+ if (action === 'onAdded') {
23826
+ collection.data = [...new Set([reaction.reactionId, ...collection.data])];
23827
+ }
23828
+ else if (action === 'onRemoved') {
23829
+ collection.data = collection.data.filter(p => p !== reaction.reactionId);
23830
+ }
23831
+ pushToCache(cacheKey, collection);
23832
+ responder(collection);
23833
+ };
23834
+ const onFetch = () => {
23835
+ var _a, _b, _c, _d, _e;
23836
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23837
+ const reactions = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
23838
+ if (reactions.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
23839
+ return;
23840
+ 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 } }));
23841
+ runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
23842
+ const data = {
23843
+ loading,
23844
+ error,
23845
+ params: { page },
23846
+ data: reactions,
23847
+ };
23848
+ if (result) {
23849
+ data.data = [
23850
+ ...new Set([...reactions, ...result[0].reactors.map(getResolver('reaction'))]),
23851
+ ];
23852
+ }
23853
+ pushToCache(cacheKey, data);
23854
+ responder(data);
23855
+ }, queryOptions(policy));
23856
+ };
23857
+ disposers.push(onReactorAdded(queryParams.referenceType, queryParams.referenceId, reaction => realtimeRouter(reaction, 'onAdded')), onReactorRemoved(queryParams.referenceType, queryParams.referenceId, reaction => realtimeRouter(reaction, 'onRemoved')));
23858
+ onFetch();
23859
+ return () => {
23860
+ log(`liveReactions(tmpid: ${timestamp}) > dispose`);
23861
+ disposers.forEach(fn => fn());
23862
+ };
23863
+ };
23864
+
23606
23865
  var REFERENCE_TYPES = {
23607
23866
  post: {
23608
23867
  domainName: 'posts',
@@ -24184,6 +24443,66 @@ const removeChannelMembersRole = async (channelId, roleId, userIds) => {
24184
24443
  return !!channelUsers.find(channelUser => channelUser.channelId === channelId && !channelUser.roles.includes(roleId));
24185
24444
  };
24186
24445
 
24446
+ /**
24447
+ * ```js
24448
+ * import { banChannelMembers } from '@amityco/ts-sdk'
24449
+ *
24450
+ * await banChannelMembers('channel-id-1', ['userId1', 'userId2'])
24451
+ * ```
24452
+ *
24453
+ * @param channelId of {@link Amity.Channel} from which the users should be banned
24454
+ * @param userIds of the {@link Amity.User}'s to be banned
24455
+ * @returns the updated {@link Amity.Membership}'s object
24456
+ *
24457
+ * @category Channel API
24458
+ * @async
24459
+ * */
24460
+ const banChannelMembers = async (channelId, userIds) => {
24461
+ const client = getActiveClient();
24462
+ client.log('channel/banChannelMembers', { userIds, channelId });
24463
+ const payload = await client.http.put(`/api/v3/channels/${channelId}/users/ban`, {
24464
+ userIds,
24465
+ });
24466
+ const cachedAt = client.cache && Date.now();
24467
+ if (client.cache)
24468
+ ingestInCache(payload.data, { cachedAt });
24469
+ const { channelUsers } = payload.data;
24470
+ return {
24471
+ data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
24472
+ cachedAt,
24473
+ };
24474
+ };
24475
+
24476
+ /**
24477
+ * ```js
24478
+ * import { unbanChannelMembers } from '@amityco/ts-sdk'
24479
+ *
24480
+ * await unbanChannelMembers('channel-id-1', ['userId1', 'userId2'])
24481
+ * ```
24482
+ *
24483
+ * @param channelId of {@link Amity.Channel} where the users should be unbanned
24484
+ * @param userIds of the {@link Amity.User}'s to be unbanned
24485
+ * @returns the updated {@link Amity.Membership}'s object
24486
+ *
24487
+ * @category Channel API
24488
+ * @async
24489
+ * */
24490
+ const unbanChannelMembers = async (channelId, userIds) => {
24491
+ const client = getActiveClient();
24492
+ client.log('channel/unbanChannelMembers', { userIds, channelId });
24493
+ const payload = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`, {
24494
+ userIds,
24495
+ });
24496
+ const cachedAt = client.cache && Date.now();
24497
+ if (client.cache)
24498
+ ingestInCache(payload.data, { cachedAt });
24499
+ const { channelUsers } = payload.data;
24500
+ return {
24501
+ data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
24502
+ cachedAt,
24503
+ };
24504
+ };
24505
+
24187
24506
  /**
24188
24507
  * ```js
24189
24508
  * import { onChannelUpdated } from '@amityco/ts-sdk'
@@ -25008,7 +25327,7 @@ const queryFollows = async (key, query) => {
25008
25327
  client.log(`follow/queryF${key.substring(1)}`, query);
25009
25328
  const { userId, page } = query, params = __rest(query, ["userId", "page"]);
25010
25329
  const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/${key}` : `/api/v4/users/${userId}/${key}`, {
25011
- params: Object.assign(Object.assign({}, params), { token: toToken(page, 'skiplimit') }),
25330
+ params: Object.assign(Object.assign({}, params), { token: toToken(page, 'afterbeforeraw') }),
25012
25331
  });
25013
25332
  const { paging } = data, payload = __rest(data, ["paging"]);
25014
25333
  const { follows } = payload;
@@ -25022,8 +25341,8 @@ const queryFollows = async (key, query) => {
25022
25341
  ];
25023
25342
  pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
25024
25343
  }
25025
- const nextPage = toPage(paging.next);
25026
- const prevPage = toPage(paging.previous);
25344
+ const nextPage = toPageRaw(paging.next);
25345
+ const prevPage = toPageRaw(paging.previous);
25027
25346
  return { data: follows, cachedAt, prevPage, nextPage };
25028
25347
  };
25029
25348
  queryFollows.locally = (key, query) => {
@@ -25042,8 +25361,8 @@ queryFollows.locally = (key, query) => {
25042
25361
  .map(key => pullFromCache(['follow', 'get', key]))
25043
25362
  .filter(Boolean)
25044
25363
  .map(({ data }) => data);
25045
- const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
25046
- const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
25364
+ const prevPage = toPageRaw(data === null || data === void 0 ? void 0 : data.paging.previous);
25365
+ const nextPage = toPageRaw(data === null || data === void 0 ? void 0 : data.paging.next);
25047
25366
  return follows.length === ((_b = data === null || data === void 0 ? void 0 : data.follows) === null || _b === void 0 ? void 0 : _b.length)
25048
25367
  ? { data: follows, cachedAt, prevPage, nextPage }
25049
25368
  : undefined;
@@ -25134,7 +25453,8 @@ const getFollowInfo = async (userId) => {
25134
25453
  client.log('follow/getFollowInfo', userId);
25135
25454
  const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/followInfo` : `/api/v4/users/${userId}/followInfo`);
25136
25455
  const cachedAt = client.cache && Date.now();
25137
- 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 });
25456
+ const followInfo = 'follows' in data
25457
+ ? 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];
25138
25458
  if (client.cache) {
25139
25459
  pushToCache(getCacheKey(userId), followInfo, { cachedAt });
25140
25460
  }
@@ -25194,7 +25514,7 @@ const follow = async (userId) => {
25194
25514
  if (client.cache) {
25195
25515
  ingestInCache(data, { cachedAt });
25196
25516
  }
25197
- fireEvent(data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested', data.follows[0]);
25517
+ fireEvent(data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested', data);
25198
25518
  return {
25199
25519
  data: data.follows[0],
25200
25520
  cachedAt,
@@ -25222,7 +25542,7 @@ const unfollow = async (userId) => {
25222
25542
  if (client.cache) {
25223
25543
  ingestInCache(data);
25224
25544
  }
25225
- fireEvent('follow.unfollowed', data.follows[0]);
25545
+ fireEvent('follow.unfollowed', data);
25226
25546
  return true;
25227
25547
  };
25228
25548
 
@@ -25247,7 +25567,7 @@ const acceptFollower = async (userId) => {
25247
25567
  if (client.cache) {
25248
25568
  ingestInCache(data);
25249
25569
  }
25250
- fireEvent('follow.accepted', data.follows[0]);
25570
+ fireEvent('follow.accepted', data);
25251
25571
  return true;
25252
25572
  };
25253
25573
 
@@ -25272,7 +25592,7 @@ const declineFollower = async (userId) => {
25272
25592
  if (client.cache) {
25273
25593
  ingestInCache(data);
25274
25594
  }
25275
- fireEvent('follow.requestDeclined', data.follows[0]);
25595
+ fireEvent('follow.requestDeclined', data);
25276
25596
  return true;
25277
25597
  };
25278
25598
 
@@ -25281,19 +25601,20 @@ const createFollowEventSubscriber = (event, callback) => {
25281
25601
  const filter = (payload) => {
25282
25602
  var _a, _b;
25283
25603
  if (!client.cache) {
25284
- callback(payload);
25604
+ callback(payload.follows[0]);
25285
25605
  }
25286
25606
  else {
25287
- ingestInCache({ follows: [payload] });
25607
+ ingestInCache(payload);
25288
25608
  const queries = [
25289
25609
  ...((_a = queryCache(['followers', 'query'])) !== null && _a !== void 0 ? _a : []),
25290
25610
  ...((_b = queryCache(['followings', 'query'])) !== null && _b !== void 0 ? _b : []),
25291
25611
  ];
25292
25612
  queries
25293
- // @ts-ignore
25294
- .filter(({ key }) => key[2].userId === payload.from || key[2].userId === payload.to)
25613
+ .filter(({ key }) =>
25614
+ // @ts-ignore
25615
+ key[2].userId === payload.follows[0].from || key[2].userId === payload.follows[0].to)
25295
25616
  .forEach(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
25296
- callback(payload);
25617
+ callback(payload.follows[0]);
25297
25618
  }
25298
25619
  };
25299
25620
  return createEventSubscriber(client, event, event, filter);
@@ -25662,9 +25983,6 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
25662
25983
  };
25663
25984
  };
25664
25985
 
25665
- const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
25666
- const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
25667
-
25668
25986
  /**
25669
25987
  * ```js
25670
25988
  * import { livePosts } from '@amityco/ts-sdk'
@@ -25918,7 +26236,9 @@ const liveComments = (params, callback, config) => {
25918
26236
  if (comments.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
25919
26237
  return;
25920
26238
  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 } }));
25921
- runQuery(query, ({ data: result, error, loading, prevPage: page }) => {
26239
+ runQuery(query, ({ data: result, error, loading, prevPage, nextPage }) => {
26240
+ // depend on sortBy value we have two different pagination type
26241
+ const page = queryParams.sortBy ? nextPage : prevPage;
25922
26242
  const data = {
25923
26243
  loading,
25924
26244
  error,
@@ -26534,6 +26854,7 @@ exports.addCommunityMembersRoles = addCommunityMembersRoles;
26534
26854
  exports.addReaction = addReaction;
26535
26855
  exports.approvePost = approvePost;
26536
26856
  exports.backupCache = backupCache;
26857
+ exports.banChannelMembers = banChannelMembers;
26537
26858
  exports.closePoll = closePoll;
26538
26859
  exports.connectClient = connectClient;
26539
26860
  exports.createChannel = createChannel;
@@ -26615,6 +26936,7 @@ exports.leaveChannel = leaveChannel;
26615
26936
  exports.leaveCommunity = leaveCommunity;
26616
26937
  exports.liveComments = liveComments;
26617
26938
  exports.livePosts = livePosts;
26939
+ exports.liveReactions = liveReactions;
26618
26940
  exports.mergeInCache = mergeInCache;
26619
26941
  exports.observeChannel = observeChannel;
26620
26942
  exports.observeComment = observeComment;
@@ -26675,7 +26997,10 @@ exports.onPostReactionAdded = onPostReactionAdded;
26675
26997
  exports.onPostReactionRemoved = onPostReactionRemoved;
26676
26998
  exports.onPostUnflagged = onPostUnflagged;
26677
26999
  exports.onPostUpdated = onPostUpdated;
27000
+ exports.onReactionAdded = onReactionAdded;
26678
27001
  exports.onReactionRemoved = onReactionRemoved;
27002
+ exports.onReactorAdded = onReactorAdded;
27003
+ exports.onReactorRemoved = onReactorRemoved;
26679
27004
  exports.onStreamRecorded = onStreamRecorded;
26680
27005
  exports.onStreamStarted = onStreamStarted;
26681
27006
  exports.onStreamStopped = onStreamStopped;
@@ -26722,6 +27047,7 @@ exports.subscribeTopic = subscribeTopic;
26722
27047
  exports.toPage = toPage;
26723
27048
  exports.toPageRaw = toPageRaw;
26724
27049
  exports.toToken = toToken;
27050
+ exports.unbanChannelMembers = unbanChannelMembers;
26725
27051
  exports.unfollow = unfollow;
26726
27052
  exports.updateChannel = updateChannel;
26727
27053
  exports.updateComment = updateComment;
package/dist/index.d.ts CHANGED
@@ -14,6 +14,7 @@ export * from './file/observers';
14
14
  export * from './role/api';
15
15
  export * from './reaction/api';
16
16
  export * from './reaction/events';
17
+ export * from './reaction/observers';
17
18
  export * from './report/api';
18
19
  export * from './channel/api';
19
20
  export * from './channel/events';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,CAAC;AAElB,cAAc,WAAW,CAAC;AAG1B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAE5B,cAAc,cAAc,CAAC;AAC7B,cAAc,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