@amityco/ts-sdk 7.33.2-b8d561be.0 → 7.33.2-cc1f86e4.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 (26) hide show
  1. package/dist/@types/domains/feed.d.ts +14 -0
  2. package/dist/@types/domains/feed.d.ts.map +1 -1
  3. package/dist/@types/domains/notification.d.ts +10 -2
  4. package/dist/@types/domains/notification.d.ts.map +1 -1
  5. package/dist/feedRepository/index.d.ts +1 -1
  6. package/dist/feedRepository/index.d.ts.map +1 -1
  7. package/dist/feedRepository/observers/getFollowingFeed/LiveCollectionController.d.ts +13 -0
  8. package/dist/feedRepository/observers/getFollowingFeed/LiveCollectionController.d.ts.map +1 -0
  9. package/dist/feedRepository/observers/getFollowingFeed/PaginationController.d.ts +10 -0
  10. package/dist/feedRepository/observers/getFollowingFeed/PaginationController.d.ts.map +1 -0
  11. package/dist/feedRepository/observers/getFollowingFeed/QueryStreamController.d.ts +22 -0
  12. package/dist/feedRepository/observers/getFollowingFeed/QueryStreamController.d.ts.map +1 -0
  13. package/dist/feedRepository/observers/getFollowingFeed.d.ts +35 -0
  14. package/dist/feedRepository/observers/getFollowingFeed.d.ts.map +1 -0
  15. package/dist/feedRepository/observers/index.d.ts +1 -0
  16. package/dist/feedRepository/observers/index.d.ts.map +1 -1
  17. package/dist/feedRepository/observers/tests/integration/getFollowingFeed.integration.test.d.ts +2 -0
  18. package/dist/feedRepository/observers/tests/integration/getFollowingFeed.integration.test.d.ts.map +1 -0
  19. package/dist/feedRepository/observers/tests/unit/FollowingFeedQueryStreamController.test.d.ts +2 -0
  20. package/dist/feedRepository/observers/tests/unit/FollowingFeedQueryStreamController.test.d.ts.map +1 -0
  21. package/dist/index.cjs.js +193 -0
  22. package/dist/index.esm.js +194 -1
  23. package/dist/index.umd.js +2 -2
  24. package/dist/utils/constants.d.ts +1 -0
  25. package/dist/utils/constants.d.ts.map +1 -1
  26. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -246,6 +246,14 @@ var FeedSortByEnum;
246
246
  FeedSortByEnum["LastUpdated"] = "lastUpdated";
247
247
  FeedSortByEnum["FirstUpdated"] = "firstUpdated";
248
248
  })(FeedSortByEnum || (FeedSortByEnum = {}));
249
+ /** Sort order of the following feed (`GET /api/v1/me/following-feeds`). */
250
+ var FollowingFeedSortByEnum;
251
+ (function (FollowingFeedSortByEnum) {
252
+ /** Server-ranked. The backend default when `sortBy` is not sent. */
253
+ FollowingFeedSortByEnum["CustomRanking"] = "customRanking";
254
+ /** Newest first. */
255
+ FollowingFeedSortByEnum["LastCreated"] = "lastCreated";
256
+ })(FollowingFeedSortByEnum || (FollowingFeedSortByEnum = {}));
249
257
  var FeedSourceEnum;
250
258
  (function (FeedSourceEnum) {
251
259
  FeedSourceEnum["Community"] = "community";
@@ -374,6 +382,7 @@ const YEAR = 365 * DAY;
374
382
  const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
375
383
  const API_ENDPOINTS = {
376
384
  forYouFeed: '/api/v1/feeds/for-you',
385
+ followingFeed: '/api/v1/me/following-feeds',
377
386
  commentReviewQueue: (communityId) => `/api/v3/communities/${encodeURIComponent(communityId)}/comments/review-queue`,
378
387
  };
379
388
  // The review-queue route defaults to 10, not the SDK-wide page size, and caps at 100
@@ -30724,6 +30733,189 @@ const getForYouFeed = (callback) => {
30724
30733
  };
30725
30734
  /* end_public_function */
30726
30735
 
30736
+ class FollowingFeedQueryStreamController extends QueryStreamController {
30737
+ constructor(query, cacheKey, notifyChange, preparePayload) {
30738
+ super(query, cacheKey);
30739
+ this.notifyChange = notifyChange;
30740
+ this.preparePayload = preparePayload;
30741
+ }
30742
+ async saveToMainDB(response) {
30743
+ const processedPayload = await this.preparePayload(response);
30744
+ const client = getActiveClient();
30745
+ const cachedAt = client.cache && Date.now();
30746
+ if (client.cache) {
30747
+ ingestInCache(processedPayload, { cachedAt });
30748
+ }
30749
+ }
30750
+ appendToQueryStream(response, direction, refresh = false) {
30751
+ var _a, _b;
30752
+ if (refresh) {
30753
+ pushToCache(this.cacheKey, {
30754
+ data: response.posts.map(getResolver('post')),
30755
+ });
30756
+ }
30757
+ else {
30758
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30759
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
30760
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
30761
+ }
30762
+ }
30763
+ /**
30764
+ * The SDK does not know the viewer's follow list or the network's `social.globalFeed`
30765
+ * switches, so it cannot tell whether a new post belongs in this feed. A created or
30766
+ * approved post, by anyone (the current user included), never changes the list: it
30767
+ * appears on the next first-page load. Deleted and declined posts are removed; any
30768
+ * other event re-emits so listed posts render their new state.
30769
+ */
30770
+ reactor(action) {
30771
+ return (post) => {
30772
+ var _a;
30773
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
30774
+ return;
30775
+ }
30776
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30777
+ if (!collection)
30778
+ return;
30779
+ // A child post event never adds or removes an entry; it re-emits only when its parent is listed
30780
+ if (post.parentPostId) {
30781
+ if (!collection.data.includes(post.parentPostId))
30782
+ return;
30783
+ }
30784
+ else if (action === EnumPostActions.OnPostDeleted ||
30785
+ action === EnumPostActions.OnPostDeclined) {
30786
+ collection.data = collection.data.filter(postId => postId !== post.postId);
30787
+ }
30788
+ pushToCache(this.cacheKey, collection);
30789
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
30790
+ };
30791
+ }
30792
+ subscribeRTE(createSubscriber) {
30793
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
30794
+ }
30795
+ }
30796
+
30797
+ /**
30798
+ * `GET /api/v1/me/following-feeds` reads `limit` and `token` as flat query params.
30799
+ * Unlike the global feed, they must not be nested in `options`: the endpoint forwards
30800
+ * only `{ limit, token }`, so a nested token would be dropped and every page would be page one.
30801
+ */
30802
+ class FollowingFeedPaginationController extends PaginationController {
30803
+ async getRequest(queryParams, token) {
30804
+ const { limit = COLLECTION_DEFAULT_PAGINATION_SIZE, sortBy } = queryParams;
30805
+ const params = token ? { token } : { limit };
30806
+ if (sortBy)
30807
+ params.sortBy = sortBy;
30808
+ const { data: queryResponse } = await this.http.get(API_ENDPOINTS.followingFeed, { params });
30809
+ return queryResponse;
30810
+ }
30811
+ }
30812
+
30813
+ class FollowingFeedLiveCollectionController extends LiveCollectionController {
30814
+ constructor(query, callback) {
30815
+ const queryStreamId = hash(query);
30816
+ const cacheKey = ['followingFeed', 'collection', queryStreamId];
30817
+ const paginationController = new FollowingFeedPaginationController(query);
30818
+ super(paginationController, queryStreamId, cacheKey, callback);
30819
+ this.query = query;
30820
+ this.queryStreamController = new FollowingFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
30821
+ this.callback = callback.bind(this);
30822
+ this.loadPage({ initial: true });
30823
+ }
30824
+ setup() {
30825
+ var _a;
30826
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30827
+ if (!collection) {
30828
+ pushToCache(this.cacheKey, {
30829
+ data: [],
30830
+ params: {},
30831
+ });
30832
+ }
30833
+ }
30834
+ async persistModel(queryPayload) {
30835
+ await this.queryStreamController.saveToMainDB(queryPayload);
30836
+ }
30837
+ persistQueryStream({ response, direction, refresh, }) {
30838
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
30839
+ }
30840
+ startSubscription() {
30841
+ return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
30842
+ }
30843
+ notifyChange({ origin, loading, error }) {
30844
+ var _a, _b;
30845
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30846
+ if (!collection)
30847
+ return;
30848
+ const data = ((_b = collection.data
30849
+ .map(id => pullFromCache(['post', 'get', id]))
30850
+ .filter(isNonNullable)
30851
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
30852
+ if (!this.shouldNotify(data) && origin === 'event')
30853
+ return;
30854
+ this.callback({
30855
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
30856
+ data,
30857
+ hasNextPage: !!this.paginationController.getNextToken(),
30858
+ loading,
30859
+ error,
30860
+ });
30861
+ }
30862
+ }
30863
+
30864
+ /* begin_public_function
30865
+ id: feed.query.following_feed
30866
+ api_style: live_collection
30867
+ */
30868
+ /**
30869
+ * ```js
30870
+ * import { FeedRepository, FollowingFeedSortByEnum } from '@amityco/ts-sdk'
30871
+ *
30872
+ * const unsub = FeedRepository.getFollowingFeed(
30873
+ * { sortBy: FollowingFeedSortByEnum.LastCreated, limit: 20 },
30874
+ * ({ data: posts, hasNextPage, onNextPage, loading, error }) => processResponse(posts),
30875
+ * )
30876
+ * ```
30877
+ *
30878
+ * Observe all mutations on a list of {@link Amity.Post} for the current user's following feed.
30879
+ * Which posts match is decided by the server, from the network's `social.globalFeed` setting:
30880
+ * - `lastCreated`: posts by the users the current user follows, plus the current user's own
30881
+ * posts, newest first.
30882
+ * - `customRanking` (the default): server-ranked posts by the current user, the users they
30883
+ * follow and the communities they joined.
30884
+ *
30885
+ * A new post, the current user's own included, is not added in real time: it appears
30886
+ * when the feed is next loaded from the first page (for example, a new subscription).
30887
+ * With `customRanking` the server may take up to 5 minutes to include it.
30888
+ * Deleted and declined posts are removed at once.
30889
+ *
30890
+ * When the network enforces module entitlement and the `feed` module is not entitled,
30891
+ * the request fails with `400325` (`ModuleNotEntitled`), reported through `error`.
30892
+ *
30893
+ * @param params.sortBy order of the feed. When omitted, the server default (`customRanking`) applies
30894
+ * @param params.limit page size of the first request (1 - 100)
30895
+ * @param callback the function to call when new data are available
30896
+ * @param config
30897
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the posts
30898
+ *
30899
+ * @category Posts Live Collection
30900
+ */
30901
+ const getFollowingFeed = (params, callback, config) => {
30902
+ const { log, cache } = getActiveClient();
30903
+ if (!cache) {
30904
+ console.log(ENABLE_CACHE_MESSAGE);
30905
+ }
30906
+ const timestamp = Date.now();
30907
+ log(`getFollowingFeed(tmpid: ${timestamp}) > listen`);
30908
+ const liveCollection = new FollowingFeedLiveCollectionController(params, callback);
30909
+ const disposers = liveCollection.startSubscription();
30910
+ const cacheKey = liveCollection.getCacheKey();
30911
+ disposers.push(() => dropFromCache(cacheKey));
30912
+ return () => {
30913
+ log(`getFollowingFeed(tmpid: ${timestamp}) > dispose`);
30914
+ disposers.forEach(fn => fn());
30915
+ };
30916
+ };
30917
+ /* end_public_function */
30918
+
30727
30919
  var index$e = /*#__PURE__*/Object.freeze({
30728
30920
  __proto__: null,
30729
30921
  queryGlobalFeed: queryGlobalFeed,
@@ -30732,6 +30924,7 @@ var index$e = /*#__PURE__*/Object.freeze({
30732
30924
  getUserFeed: getUserFeed,
30733
30925
  getCommunityFeed: getCommunityFeed,
30734
30926
  getForYouFeed: getForYouFeed,
30927
+ getFollowingFeed: getFollowingFeed,
30735
30928
  AmityForYouFeedDisabledError: AmityForYouFeedDisabledError
30736
30929
  });
30737
30930
 
@@ -38650,4 +38843,4 @@ const getContentFlagReasons = () => Object.values(ContentFlagReasonEnum);
38650
38843
  const getContentFlagReasonKey = (reason) => CONTENT_FLAG_REASON_KEYS[reason];
38651
38844
  /* end_public_function */
38652
38845
 
38653
- export { API_REGIONS, index$6 as AdRepository, AmityAttachmentProductTags, AmityAutoSubscription, AmityChannelNotificationModeEnum, AmityCommunityType, ContentFlagReasonEnum as AmityContentFlagReasonType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, AmityLiveViewerCountMode, AmityModuleNotEntitledError, AmitySharableContentType, AnalyticsSourceTypeEnum, index$g as CategoryRepository, index$k as ChannelRepository, index$t as Client, index$f as CommentRepository, CommunityNotificationEventNameEnum, CommunityPostSettingMaps, CommunityPostSettings, index$h as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, index as CuratedContentRepository, DefaultCommunityPostSetting, index$2 as EventRepository, FeedDataTypeEnum, index$e as FeedRepository, FeedSortByEnum, FeedSourceEnum, FeedTypeEnum, FileAccessTypeEnum, index$q as FileRepository, FileType, GET_WATCHER_URLS, index$4 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$3 as LiveReactionRepository, index$8 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$o as MessageRepository, NotificationRolesFilterTypeEnum, NotificationSettingsLevelEnum, index$9 as PollRepository, PostContentType, index$c as PostRepository, PostStructureType, index$1 as ProductRepository, index$p as ReactionRepository, index$a as RoomPresenceRepository, index$d as RoomRepository, SearchUsersByEnum, index$7 as StoryRepository, index$b as StreamRepository, index$n as SubChannelRepository, SubscriptionLevels, UserNotificationModuleNameEnum, UserProfileFieldEnum, UserReportTypeEnum, UserReportTypeFilterEnum, index$r as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, exceedsUntilAtBoundary, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, filterByUntilAt, filterCommentsByBlockUsers, filterPostsByBlockUsers, getBlockUsersId, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getContentFlagReasonKey, getContentFlagReasons, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkId, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$5 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, resolveModuleAvailability, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastMessage, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, validateUntilAt, wipeCache };
38846
+ export { API_REGIONS, index$6 as AdRepository, AmityAttachmentProductTags, AmityAutoSubscription, AmityChannelNotificationModeEnum, AmityCommunityType, ContentFlagReasonEnum as AmityContentFlagReasonType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, AmityLiveViewerCountMode, AmityModuleNotEntitledError, AmitySharableContentType, AnalyticsSourceTypeEnum, index$g as CategoryRepository, index$k as ChannelRepository, index$t as Client, index$f as CommentRepository, CommunityNotificationEventNameEnum, CommunityPostSettingMaps, CommunityPostSettings, index$h as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, index as CuratedContentRepository, DefaultCommunityPostSetting, index$2 as EventRepository, FeedDataTypeEnum, index$e as FeedRepository, FeedSortByEnum, FeedSourceEnum, FeedTypeEnum, FileAccessTypeEnum, index$q as FileRepository, FileType, FollowingFeedSortByEnum, GET_WATCHER_URLS, index$4 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$3 as LiveReactionRepository, index$8 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$o as MessageRepository, NotificationRolesFilterTypeEnum, NotificationSettingsLevelEnum, index$9 as PollRepository, PostContentType, index$c as PostRepository, PostStructureType, index$1 as ProductRepository, index$p as ReactionRepository, index$a as RoomPresenceRepository, index$d as RoomRepository, SearchUsersByEnum, index$7 as StoryRepository, index$b as StreamRepository, index$n as SubChannelRepository, SubscriptionLevels, UserNotificationModuleNameEnum, UserProfileFieldEnum, UserReportTypeEnum, UserReportTypeFilterEnum, index$r as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, exceedsUntilAtBoundary, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, filterByUntilAt, filterCommentsByBlockUsers, filterPostsByBlockUsers, getBlockUsersId, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getContentFlagReasonKey, getContentFlagReasons, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkId, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$5 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, resolveModuleAvailability, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastMessage, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, validateUntilAt, wipeCache };