@amityco/ts-sdk-react-native 7.5.3 → 7.6.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 (383) hide show
  1. package/dist/@types/core/events.d.ts +7 -0
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +5 -1
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +38 -5
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/channel.d.ts +1 -0
  8. package/dist/@types/domains/channel.d.ts.map +1 -1
  9. package/dist/@types/domains/client.d.ts +10 -0
  10. package/dist/@types/domains/client.d.ts.map +1 -1
  11. package/dist/@types/domains/community.d.ts +51 -1
  12. package/dist/@types/domains/community.d.ts.map +1 -1
  13. package/dist/@types/domains/content.d.ts +5 -2
  14. package/dist/@types/domains/content.d.ts.map +1 -1
  15. package/dist/@types/domains/group.d.ts +2 -0
  16. package/dist/@types/domains/group.d.ts.map +1 -1
  17. package/dist/@types/domains/invitation.d.ts +92 -0
  18. package/dist/@types/domains/invitation.d.ts.map +1 -0
  19. package/dist/@types/domains/joinRequest.d.ts +53 -0
  20. package/dist/@types/domains/joinRequest.d.ts.map +1 -0
  21. package/dist/@types/domains/notification.d.ts +4 -2
  22. package/dist/@types/domains/notification.d.ts.map +1 -1
  23. package/dist/@types/domains/pinnedPost.d.ts +1 -1
  24. package/dist/@types/domains/pinnedPost.d.ts.map +1 -1
  25. package/dist/@types/index.d.ts +5 -0
  26. package/dist/@types/index.d.ts.map +1 -1
  27. package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
  28. package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts.map +1 -1
  29. package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts +2 -2
  30. package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts.map +1 -1
  31. package/dist/client/api/index.d.ts +1 -0
  32. package/dist/client/api/index.d.ts.map +1 -1
  33. package/dist/client/api/resumeSession.d.ts +32 -0
  34. package/dist/client/api/resumeSession.d.ts.map +1 -0
  35. package/dist/client/api/tests/resumeSession.test.d.ts +2 -0
  36. package/dist/client/api/tests/resumeSession.test.d.ts.map +1 -0
  37. package/dist/communityRepository/api/createCommunity.d.ts +3 -3
  38. package/dist/communityRepository/api/createCommunity.d.ts.map +1 -1
  39. package/dist/communityRepository/api/deleteCommunity.d.ts.map +1 -1
  40. package/dist/communityRepository/api/getCommunities.d.ts +1 -1
  41. package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
  42. package/dist/communityRepository/api/getCommunity.d.ts +2 -2
  43. package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
  44. package/dist/communityRepository/api/getRecommendedCommunities.d.ts +3 -1
  45. package/dist/communityRepository/api/getRecommendedCommunities.d.ts.map +1 -1
  46. package/dist/communityRepository/api/getTrendingCommunities.d.ts +3 -1
  47. package/dist/communityRepository/api/getTrendingCommunities.d.ts.map +1 -1
  48. package/dist/communityRepository/api/joinCommunity.d.ts +3 -0
  49. package/dist/communityRepository/api/joinCommunity.d.ts.map +1 -1
  50. package/dist/communityRepository/api/queryCommunities.d.ts.map +1 -1
  51. package/dist/communityRepository/api/updateCommunity.d.ts +3 -3
  52. package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
  53. package/dist/communityRepository/communityMembership/events/index.d.ts +1 -0
  54. package/dist/communityRepository/communityMembership/events/index.d.ts.map +1 -1
  55. package/dist/communityRepository/communityMembership/events/onCommunityJoined.d.ts +1 -1
  56. package/dist/communityRepository/communityMembership/events/onCommunityJoined.d.ts.map +1 -1
  57. package/dist/communityRepository/communityMembership/events/onCommunityLeft.d.ts +1 -1
  58. package/dist/communityRepository/communityMembership/events/onCommunityLeft.d.ts.map +1 -1
  59. package/dist/communityRepository/communityMembership/events/onCommunityUserAdded.d.ts +1 -1
  60. package/dist/communityRepository/communityMembership/events/onCommunityUserAdded.d.ts.map +1 -1
  61. package/dist/communityRepository/communityMembership/events/onCommunityUserBanned.d.ts +1 -1
  62. package/dist/communityRepository/communityMembership/events/onCommunityUserBanned.d.ts.map +1 -1
  63. package/dist/communityRepository/communityMembership/events/onCommunityUserChanged.d.ts +1 -1
  64. package/dist/communityRepository/communityMembership/events/onCommunityUserChanged.d.ts.map +1 -1
  65. package/dist/communityRepository/communityMembership/events/onCommunityUserRemoved.d.ts +1 -1
  66. package/dist/communityRepository/communityMembership/events/onCommunityUserRemoved.d.ts.map +1 -1
  67. package/dist/communityRepository/communityMembership/events/onCommunityUserRoleAdded.d.ts +1 -1
  68. package/dist/communityRepository/communityMembership/events/onCommunityUserRoleAdded.d.ts.map +1 -1
  69. package/dist/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.d.ts +1 -1
  70. package/dist/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.d.ts.map +1 -1
  71. package/dist/communityRepository/communityMembership/events/onCommunityUserUnbanned.d.ts +1 -1
  72. package/dist/communityRepository/communityMembership/events/onCommunityUserUnbanned.d.ts.map +1 -1
  73. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts +2 -0
  74. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts.map +1 -0
  75. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts +1 -1
  76. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts.map +1 -1
  77. package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts +1 -1
  78. package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts.map +1 -1
  79. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts +1 -1
  80. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserAdded.d.ts.map +1 -1
  81. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts +1 -1
  82. package/dist/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.d.ts.map +1 -1
  83. package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts +1 -1
  84. package/dist/communityRepository/communityMembership/events/onUserDeleted.d.ts.map +1 -1
  85. package/dist/communityRepository/communityMembership/events/utils.d.ts +2 -2
  86. package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
  87. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts +2 -2
  88. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +1 -1
  89. package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts +2 -1
  90. package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts.map +1 -1
  91. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts +2 -2
  92. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts.map +1 -1
  93. package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts +1 -0
  94. package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts.map +1 -1
  95. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts +1 -1
  96. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.d.ts.map +1 -1
  97. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts +1 -1
  98. package/dist/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.d.ts.map +1 -1
  99. package/dist/communityRepository/events/onCommunityCreated.d.ts +1 -1
  100. package/dist/communityRepository/events/onCommunityCreated.d.ts.map +1 -1
  101. package/dist/communityRepository/events/onCommunityDeleted.d.ts +1 -1
  102. package/dist/communityRepository/events/onCommunityDeleted.d.ts.map +1 -1
  103. package/dist/communityRepository/events/onCommunityUpdated.d.ts +1 -1
  104. package/dist/communityRepository/events/onCommunityUpdated.d.ts.map +1 -1
  105. package/dist/communityRepository/events/utils.d.ts +1 -1
  106. package/dist/communityRepository/events/utils.d.ts.map +1 -1
  107. package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts +16 -0
  108. package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts.map +1 -0
  109. package/dist/communityRepository/internalAPI/joinCommunity.d.ts +16 -0
  110. package/dist/communityRepository/internalAPI/joinCommunity.d.ts.map +1 -0
  111. package/dist/communityRepository/joinRequest/events/index.d.ts +4 -0
  112. package/dist/communityRepository/joinRequest/events/index.d.ts.map +1 -0
  113. package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts +17 -0
  114. package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts.map +1 -0
  115. package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts +17 -0
  116. package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts.map +1 -0
  117. package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts +17 -0
  118. package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts.map +1 -0
  119. package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts +16 -0
  120. package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts.map +1 -0
  121. package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts +16 -0
  122. package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts.map +1 -0
  123. package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts +16 -0
  124. package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts.map +1 -0
  125. package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
  126. package/dist/communityRepository/observers/getCommunities/CommunitiesPaginationController.d.ts.map +1 -1
  127. package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts +2 -2
  128. package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts.map +1 -1
  129. package/dist/communityRepository/observers/getCommunity.d.ts.map +1 -1
  130. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts +14 -0
  131. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts.map +1 -0
  132. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts +9 -0
  133. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts.map +1 -0
  134. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts +15 -0
  135. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts.map +1 -0
  136. package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts +6 -0
  137. package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts.map +1 -0
  138. package/dist/communityRepository/observers/getJoinRequestList.d.ts +12 -0
  139. package/dist/communityRepository/observers/getJoinRequestList.d.ts.map +1 -0
  140. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts +14 -0
  141. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts.map +1 -0
  142. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts +9 -0
  143. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts.map +1 -0
  144. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts +15 -0
  145. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts.map +1 -0
  146. package/dist/communityRepository/observers/getJoinRequests/enum.d.ts +6 -0
  147. package/dist/communityRepository/observers/getJoinRequests/enum.d.ts.map +1 -0
  148. package/dist/communityRepository/observers/getJoinRequests.d.ts +12 -0
  149. package/dist/communityRepository/observers/getJoinRequests.d.ts.map +1 -0
  150. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.d.ts.map +1 -1
  151. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesPaginationController.d.ts.map +1 -1
  152. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts +2 -2
  153. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts.map +1 -1
  154. package/dist/communityRepository/observers/getRecommendedCommunities/enums.d.ts +2 -1
  155. package/dist/communityRepository/observers/getRecommendedCommunities/enums.d.ts.map +1 -1
  156. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.d.ts.map +1 -1
  157. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesPaginationController.d.ts.map +1 -1
  158. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts +2 -2
  159. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts.map +1 -1
  160. package/dist/communityRepository/observers/index.d.ts +1 -0
  161. package/dist/communityRepository/observers/index.d.ts.map +1 -1
  162. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.d.ts.map +1 -1
  163. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.d.ts.map +1 -1
  164. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts +2 -2
  165. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts.map +1 -1
  166. package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityLiveCollectionController.d.ts.map +1 -1
  167. package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityPaginationController.d.ts.map +1 -1
  168. package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.d.ts +2 -2
  169. package/dist/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.d.ts.map +1 -1
  170. package/dist/communityRepository/utils/communityWithMembership.d.ts +1 -1
  171. package/dist/communityRepository/utils/communityWithMembership.d.ts.map +1 -1
  172. package/dist/communityRepository/utils/payload.d.ts +2 -1
  173. package/dist/communityRepository/utils/payload.d.ts.map +1 -1
  174. package/dist/core/events.d.ts +3 -3
  175. package/dist/core/events.d.ts.map +1 -1
  176. package/dist/core/model/idResolvers.d.ts.map +1 -1
  177. package/dist/core/model/index.d.ts.map +1 -1
  178. package/dist/index.cjs.js +3209 -1543
  179. package/dist/index.d.ts +1 -0
  180. package/dist/index.d.ts.map +1 -1
  181. package/dist/index.esm.js +3374 -1710
  182. package/dist/index.umd.js +3 -3
  183. package/dist/invitationRepository/events/index.d.ts +4 -0
  184. package/dist/invitationRepository/events/index.d.ts.map +1 -0
  185. package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts +17 -0
  186. package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts.map +1 -0
  187. package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts +17 -0
  188. package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts.map +1 -0
  189. package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts +17 -0
  190. package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts.map +1 -0
  191. package/dist/invitationRepository/index.d.ts +3 -0
  192. package/dist/invitationRepository/index.d.ts.map +1 -0
  193. package/dist/invitationRepository/internalApi/acceptInvitation.d.ts +16 -0
  194. package/dist/invitationRepository/internalApi/acceptInvitation.d.ts.map +1 -0
  195. package/dist/invitationRepository/internalApi/createInvitations.d.ts +21 -0
  196. package/dist/invitationRepository/internalApi/createInvitations.d.ts.map +1 -0
  197. package/dist/invitationRepository/internalApi/getInvitation.d.ts +17 -0
  198. package/dist/invitationRepository/internalApi/getInvitation.d.ts.map +1 -0
  199. package/dist/invitationRepository/internalApi/index.d.ts +4 -0
  200. package/dist/invitationRepository/internalApi/index.d.ts.map +1 -0
  201. package/dist/invitationRepository/internalApi/rejectInvitation.d.ts +16 -0
  202. package/dist/invitationRepository/internalApi/rejectInvitation.d.ts.map +1 -0
  203. package/dist/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.d.ts +14 -0
  204. package/dist/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.d.ts.map +1 -0
  205. package/dist/invitationRepository/observers/getInvitations/InvitationsPaginationController.d.ts +5 -0
  206. package/dist/invitationRepository/observers/getInvitations/InvitationsPaginationController.d.ts.map +1 -0
  207. package/dist/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.d.ts +15 -0
  208. package/dist/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.d.ts.map +1 -0
  209. package/dist/invitationRepository/observers/getInvitations/enums.d.ts +6 -0
  210. package/dist/invitationRepository/observers/getInvitations/enums.d.ts.map +1 -0
  211. package/dist/invitationRepository/observers/getInvitations.d.ts +12 -0
  212. package/dist/invitationRepository/observers/getInvitations.d.ts.map +1 -0
  213. package/dist/invitationRepository/observers/getMyCommunityInvitations.d.ts +12 -0
  214. package/dist/invitationRepository/observers/getMyCommunityInvitations.d.ts.map +1 -0
  215. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts +14 -0
  216. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts.map +1 -0
  217. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts +5 -0
  218. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts.map +1 -0
  219. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts +15 -0
  220. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts.map +1 -0
  221. package/dist/invitationRepository/observers/index.d.ts +2 -0
  222. package/dist/invitationRepository/observers/index.d.ts.map +1 -0
  223. package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.d.ts +2 -0
  224. package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.d.ts.map +1 -0
  225. package/dist/invitationRepository/utils/index.d.ts +2 -0
  226. package/dist/invitationRepository/utils/index.d.ts.map +1 -0
  227. package/dist/invitationRepository/utils/prepareInvitationPayload.d.ts +2 -0
  228. package/dist/invitationRepository/utils/prepareInvitationPayload.d.ts.map +1 -0
  229. package/dist/invitationRepository/utils/prepareMyInvitationsPayload.d.ts +2 -0
  230. package/dist/invitationRepository/utils/prepareMyInvitationsPayload.d.ts.map +1 -0
  231. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
  232. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts.map +1 -1
  233. package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
  234. package/dist/subChannelRepository/utils/prepareSubChannelPayload.d.ts.map +1 -1
  235. package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
  236. package/dist/utils/linkedObject/channelMemberLinkedObject.d.ts +2 -0
  237. package/dist/utils/linkedObject/channelMemberLinkedObject.d.ts.map +1 -0
  238. package/dist/utils/linkedObject/communityLinkedObject.d.ts +2 -0
  239. package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -0
  240. package/dist/utils/linkedObject/index.d.ts +4 -0
  241. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  242. package/dist/utils/linkedObject/invitationLinkedObject.d.ts +2 -0
  243. package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -0
  244. package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts +2 -0
  245. package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts.map +1 -0
  246. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  247. package/dist/utils/tests/dummy/community.d.ts +2 -0
  248. package/dist/utils/tests/dummy/community.d.ts.map +1 -1
  249. package/dist/utils/tests/dummy/post.d.ts +3 -3
  250. package/package.json +2 -1
  251. package/src/@types/core/events.ts +10 -0
  252. package/src/@types/core/model.ts +8 -1
  253. package/src/@types/core/payload.ts +48 -5
  254. package/src/@types/domains/channel.ts +1 -0
  255. package/src/@types/domains/client.ts +12 -0
  256. package/src/@types/domains/community.ts +82 -3
  257. package/src/@types/domains/content.ts +15 -1
  258. package/src/@types/domains/group.ts +2 -0
  259. package/src/@types/domains/invitation.ts +119 -0
  260. package/src/@types/domains/joinRequest.ts +66 -0
  261. package/src/@types/domains/notification.ts +2 -0
  262. package/src/@types/domains/pinnedPost.ts +1 -1
  263. package/src/@types/index.ts +5 -0
  264. package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +3 -1
  265. package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.ts +2 -1
  266. package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.ts +2 -2
  267. package/src/client/api/index.ts +1 -0
  268. package/src/client/api/resumeSession.ts +282 -0
  269. package/src/client/api/tests/resumeSession.test.ts +173 -0
  270. package/src/communityRepository/api/createCommunity.ts +6 -3
  271. package/src/communityRepository/api/deleteCommunity.ts +2 -1
  272. package/src/communityRepository/api/getCommunities.ts +9 -2
  273. package/src/communityRepository/api/getCommunity.ts +12 -3
  274. package/src/communityRepository/api/getRecommendedCommunities.ts +11 -4
  275. package/src/communityRepository/api/getTrendingCommunities.ts +11 -4
  276. package/src/communityRepository/api/joinCommunity.ts +4 -1
  277. package/src/communityRepository/api/queryCommunities.ts +7 -1
  278. package/src/communityRepository/api/updateCommunity.ts +14 -4
  279. package/src/communityRepository/communityMembership/events/index.ts +1 -0
  280. package/src/communityRepository/communityMembership/events/onCommunityJoined.ts +1 -1
  281. package/src/communityRepository/communityMembership/events/onCommunityLeft.ts +1 -1
  282. package/src/communityRepository/communityMembership/events/onCommunityUserAdded.ts +1 -1
  283. package/src/communityRepository/communityMembership/events/onCommunityUserBanned.ts +1 -1
  284. package/src/communityRepository/communityMembership/events/onCommunityUserChanged.ts +1 -1
  285. package/src/communityRepository/communityMembership/events/onCommunityUserRemoved.ts +1 -1
  286. package/src/communityRepository/communityMembership/events/onCommunityUserRoleAdded.ts +1 -1
  287. package/src/communityRepository/communityMembership/events/onCommunityUserRoleRemoved.ts +1 -1
  288. package/src/communityRepository/communityMembership/events/onCommunityUserUnbanned.ts +1 -1
  289. package/src/communityRepository/communityMembership/events/onLocalCommunityJoin.ts +20 -0
  290. package/src/communityRepository/communityMembership/events/onLocalCommunityJoined.ts +1 -1
  291. package/src/communityRepository/communityMembership/events/onLocalCommunityLeft.ts +1 -1
  292. package/src/communityRepository/communityMembership/events/onLocalCommunityUserAdded.ts +1 -1
  293. package/src/communityRepository/communityMembership/events/onLocalCommunityUserRemoved.ts +1 -1
  294. package/src/communityRepository/communityMembership/events/onUserDeleted.ts +3 -1
  295. package/src/communityRepository/communityMembership/events/utils.ts +2 -2
  296. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +8 -2
  297. package/src/communityRepository/communityMembership/observers/getMembers/enums.ts +1 -0
  298. package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.ts +8 -2
  299. package/src/communityRepository/communityMembership/observers/searchMembers/enums.ts +1 -0
  300. package/src/communityRepository/communityModeration/events/onLocalCommunityRoleAdded.ts +1 -1
  301. package/src/communityRepository/communityModeration/events/onLocalCommunityRoleRemoved.ts +1 -1
  302. package/src/communityRepository/events/onCommunityCreated.ts +1 -1
  303. package/src/communityRepository/events/onCommunityDeleted.ts +1 -1
  304. package/src/communityRepository/events/onCommunityUpdated.ts +1 -1
  305. package/src/communityRepository/events/utils.ts +1 -1
  306. package/src/communityRepository/internalAPI/getMyJoinRequest.ts +43 -0
  307. package/src/communityRepository/internalAPI/joinCommunity.ts +66 -0
  308. package/src/communityRepository/joinRequest/events/index.ts +3 -0
  309. package/src/communityRepository/joinRequest/events/onJoinRequestCreated.ts +33 -0
  310. package/src/communityRepository/joinRequest/events/onJoinRequestDeleted.ts +33 -0
  311. package/src/communityRepository/joinRequest/events/onJoinRequestUpdated.ts +33 -0
  312. package/src/communityRepository/joinRequest/internalAPI/approveJoinRequest.ts +52 -0
  313. package/src/communityRepository/joinRequest/internalAPI/cancelJoinRequest.ts +49 -0
  314. package/src/communityRepository/joinRequest/internalAPI/rejectJoinRequest.ts +52 -0
  315. package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +6 -0
  316. package/src/communityRepository/observers/getCommunities/CommunitiesPaginationController.ts +1 -0
  317. package/src/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.ts +2 -2
  318. package/src/communityRepository/observers/getCommunity.ts +26 -11
  319. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.ts +135 -0
  320. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.ts +30 -0
  321. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.ts +116 -0
  322. package/src/communityRepository/observers/getJoinRequestList/enum.ts +5 -0
  323. package/src/communityRepository/observers/getJoinRequestList.ts +51 -0
  324. package/src/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.ts +126 -0
  325. package/src/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.ts +25 -0
  326. package/src/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.ts +108 -0
  327. package/src/communityRepository/observers/getJoinRequests/enum.ts +5 -0
  328. package/src/communityRepository/observers/getJoinRequests.ts +44 -0
  329. package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.ts +8 -1
  330. package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesPaginationController.ts +6 -1
  331. package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.ts +2 -2
  332. package/src/communityRepository/observers/getRecommendedCommunities/enums.ts +1 -0
  333. package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.ts +9 -1
  334. package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesPaginationController.ts +6 -1
  335. package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.ts +2 -2
  336. package/src/communityRepository/observers/index.ts +1 -0
  337. package/src/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.ts +6 -0
  338. package/src/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.ts +1 -0
  339. package/src/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.ts +2 -2
  340. package/src/communityRepository/observers/semanticSearch/SemanticSearchCommunityLiveCollectionController.ts +6 -0
  341. package/src/communityRepository/observers/semanticSearch/SemanticSearchCommunityPaginationController.ts +1 -0
  342. package/src/communityRepository/observers/semanticSearch/SemanticSearchCommunityQueryStreamController.ts +2 -2
  343. package/src/communityRepository/utils/communityWithMembership.ts +9 -5
  344. package/src/communityRepository/utils/payload.ts +28 -2
  345. package/src/core/liveCollection/PaginationController.ts +1 -1
  346. package/src/core/liveCollection/PaginationNoPageController.ts +1 -1
  347. package/src/core/model/idResolvers.ts +3 -0
  348. package/src/core/model/index.ts +3 -0
  349. package/src/index.ts +2 -0
  350. package/src/invitationRepository/events/index.ts +3 -0
  351. package/src/invitationRepository/events/onLocalInvitationCreated.ts +33 -0
  352. package/src/invitationRepository/events/onLocalInvitationDeleted.ts +33 -0
  353. package/src/invitationRepository/events/onLocalInvitationUpdated.ts +33 -0
  354. package/src/invitationRepository/index.ts +2 -0
  355. package/src/invitationRepository/internalApi/acceptInvitation.ts +45 -0
  356. package/src/invitationRepository/internalApi/createInvitations.ts +52 -0
  357. package/src/invitationRepository/internalApi/getInvitation.ts +47 -0
  358. package/src/invitationRepository/internalApi/index.ts +3 -0
  359. package/src/invitationRepository/internalApi/rejectInvitation.ts +45 -0
  360. package/src/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.ts +148 -0
  361. package/src/invitationRepository/observers/getInvitations/InvitationsPaginationController.ts +19 -0
  362. package/src/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.ts +97 -0
  363. package/src/invitationRepository/observers/getInvitations/enums.ts +5 -0
  364. package/src/invitationRepository/observers/getInvitations.ts +44 -0
  365. package/src/invitationRepository/observers/getMyCommunityInvitations.ts +48 -0
  366. package/src/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.ts +148 -0
  367. package/src/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.ts +22 -0
  368. package/src/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.ts +105 -0
  369. package/src/invitationRepository/observers/index.ts +1 -0
  370. package/src/invitationRepository/utils/convertRawInvitationToInternalInvitation.ts +8 -0
  371. package/src/invitationRepository/utils/index.ts +1 -0
  372. package/src/invitationRepository/utils/prepareInvitationPayload.ts +12 -0
  373. package/src/invitationRepository/utils/prepareMyInvitationsPayload.ts +12 -0
  374. package/src/messagePreview/utils/getChannelMessagePreviewWithUser.ts +3 -3
  375. package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.ts +7 -1
  376. package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +7 -1
  377. package/src/subChannelRepository/utils/prepareSubChannelPayload.ts +4 -0
  378. package/src/utils/linkedObject/channelLinkedObject.ts +19 -0
  379. package/src/utils/linkedObject/channelMemberLinkedObject.ts +20 -0
  380. package/src/utils/linkedObject/communityLinkedObject.ts +57 -0
  381. package/src/utils/linkedObject/index.ts +8 -0
  382. package/src/utils/linkedObject/invitationLinkedObject.ts +37 -0
  383. package/src/utils/linkedObject/joinRequestLinkedObject.ts +31 -0
@@ -0,0 +1,282 @@
1
+ import jwtDecode from 'jwt-decode';
2
+ /* eslint-disable no-param-reassign */
3
+ import { modifyMqttConnection } from '~/client/utils/modifyMqttConnection';
4
+ /* eslint-disable require-atomic-updates */
5
+ import { proxyWebsocketEvents } from '~/core/events';
6
+ import { onChannelDeleted } from '~/channelRepository/events/onChannelDeleted';
7
+ import { onChannelMemberBanned } from '~/channelRepository/events/onChannelMemberBanned';
8
+
9
+ import { markReadEngineOnLoginHandler } from '~/subChannelRepository/utils/markReadEngine';
10
+ import { onUserDeleted } from '~/userRepository/events/onUserDeleted';
11
+
12
+ import analyticsEngineOnLoginHandler from '~/analytic/utils/analyticsEngineOnLoginHandler';
13
+ import readReceiptSyncEngineOnLoginHandler from '~/client/utils/ReadReceiptSync/readReceiptSyncEngineOnLoginHandler';
14
+ import legacyReadReceiptSyncEngineOnLoginHandler from '~/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler';
15
+ import objectResolverEngineOnLoginHandler from '~/client/utils/ObjectResolver/objectResolverEngineOnLoginHandler';
16
+ import { logout } from './logout';
17
+
18
+ import { getActiveClient } from './activeClient';
19
+ import { terminateClient } from './terminateClient';
20
+ import { setActiveUser } from './activeUser';
21
+ import { setSessionState } from './setSessionState';
22
+
23
+ import { onClientBanned } from '../events';
24
+ import { onTokenExpired } from '../events/onTokenExpired';
25
+ import { onTokenTerminated } from '../events/onTokenTerminated';
26
+
27
+ import { removeChannelMarkerCache } from '../utils/removeChannelMarkerCache';
28
+ import { initializeMessagePreviewSetting } from '../utils/messagePreviewEngine';
29
+ import { ASCError } from '~/core/errors';
30
+ import SessionWatcher from '../utils/SessionWatcher';
31
+
32
+ /*
33
+ * declared earlier to accomodate case when logging in with a different user
34
+ * than the one already connected, in which case the existing subscriptions need
35
+ * to be cleared
36
+ */
37
+ let subscriptions: Amity.Unsubscriber[] = [];
38
+
39
+ async function runMqtt() {
40
+ await modifyMqttConnection();
41
+ }
42
+
43
+ interface Params {
44
+ userId: string;
45
+ token: {
46
+ issuedAt: string;
47
+ expiresAt: string;
48
+ accessToken: string;
49
+ };
50
+ }
51
+
52
+ const isSameUserId = (token: Params['token']['accessToken']) => {
53
+ const client = getActiveClient();
54
+
55
+ const decoded = jwtDecode<{
56
+ user: {
57
+ userId: string;
58
+ publicUserId: string;
59
+ deviceInfo: Amity.Device['deviceInfo'];
60
+ networkId: string;
61
+ displayName: string;
62
+ refreshToken: string;
63
+ };
64
+ }>(token);
65
+
66
+ return decoded?.user?.publicUserId === client.userId;
67
+ };
68
+
69
+ const validateAccessToken = async ({ token, userId }: Params) => {
70
+ const client = getActiveClient();
71
+ // begin establishing session
72
+ setSessionState(Amity.SessionStates.ESTABLISHING);
73
+
74
+ const {
75
+ data: { users },
76
+ } = await client.http.get(`/api/v3/users/${userId}`, {
77
+ headers: {
78
+ Authorization: `Bearer ${token.accessToken}`,
79
+ },
80
+ });
81
+
82
+ const user = users.find((u: Amity.User) => u.userId === userId);
83
+
84
+ client.http.defaults.headers.common.Authorization = `Bearer ${token.accessToken}`;
85
+
86
+ client.http.defaults.metadata = {
87
+ tokenExpiry: token.expiresAt,
88
+ isGlobalBanned: false,
89
+ isUserDeleted: false,
90
+ };
91
+
92
+ client.upload.defaults.headers.common.Authorization = `Bearer ${token.accessToken}`;
93
+
94
+ client.upload.defaults.metadata = {
95
+ tokenExpiry: token.expiresAt,
96
+ isGlobalBanned: false,
97
+ isUserDeleted: false,
98
+ };
99
+
100
+ // manually setup the token for ws transport
101
+ if (client.ws) client.ws.io.opts.query = { token: token.accessToken };
102
+
103
+ client.token = token;
104
+
105
+ setSessionState(Amity.SessionStates.ESTABLISHED);
106
+
107
+ return user;
108
+ };
109
+
110
+ /* begin_public_function
111
+ id: client.resumeSession
112
+ */
113
+ /**
114
+ * ```js
115
+ * import { resumeSession } from '@amityco/ts-sdk/client/api'
116
+ * const success = await resumeSession({
117
+ * userId: 'XYZ123456789',
118
+ * token: { accessToken: 'abc123', issuedAt: '2023-01-01T00:00:00Z', expiresAt: '2023-01-02T00:00:00Z' }
119
+ * })
120
+ * ```
121
+ *
122
+ * Connects an {@link Amity.Client} instance to ASC servers using an existing access token
123
+ *
124
+ * @param params the connect parameters
125
+ * @param params.userId the user ID for the current session
126
+ * @param params.token the existing access token with its metadata
127
+ * @param sessionHandler the session handler for token renewal
128
+ * @param config optional configuration
129
+ * @returns a success boolean if connected
130
+ *
131
+ * @category Client API
132
+ * @async
133
+ */
134
+ export const resumeSession = async (
135
+ params: Params,
136
+ sessionHandler: Amity.SessionHandler,
137
+ config?: Amity.ConnectClientConfig,
138
+ ): Promise<boolean> => {
139
+ const client = getActiveClient();
140
+ let unsubWatcher: Amity.Unsubscriber;
141
+
142
+ client.log('client/api/resumeSession', {
143
+ apiKey: client.apiKey,
144
+ sessionState: client.sessionState,
145
+ ...params,
146
+ });
147
+
148
+ // Handle existing connected user
149
+ if (client.userId) {
150
+ if (client.userId === params.userId && isSameUserId(params.token.accessToken)) {
151
+ // Clear connections and listeners but preserve cache
152
+ if (client.mqtt && client.mqtt.connected) {
153
+ client.mqtt.disconnect();
154
+ }
155
+ if (client.ws && client.ws.connected) {
156
+ client.ws.disconnect();
157
+ }
158
+
159
+ // Clear existing subscriptions
160
+ subscriptions.forEach(fn => fn());
161
+ subscriptions = [];
162
+ } else {
163
+ // Different user - do full logout
164
+ await logout();
165
+
166
+ // Remove subscription to ban and delete
167
+ subscriptions.forEach(fn => fn());
168
+ subscriptions = [];
169
+ }
170
+ }
171
+
172
+ try {
173
+ const user = await validateAccessToken(params);
174
+
175
+ if (user == null) {
176
+ throw new ASCError(
177
+ `${params.userId} has not been found`,
178
+ Amity.ClientError.UNKNOWN_ERROR,
179
+ Amity.ErrorLevel.ERROR,
180
+ );
181
+ }
182
+
183
+ if (user.isDeleted) {
184
+ terminateClient(Amity.TokenTerminationReason.USER_DELETED);
185
+ return false;
186
+ }
187
+
188
+ if (user.isGlobalBanned) {
189
+ terminateClient(Amity.TokenTerminationReason.GLOBAL_BAN);
190
+ return false;
191
+ }
192
+
193
+ // FIXME: events are duplicated if connectClient is called few times without disconnectClient
194
+ // wire websocket events to our event emitter
195
+ proxyWebsocketEvents(client.ws, client.emitter);
196
+
197
+ client.ws?.open();
198
+
199
+ client.userId = user.userId;
200
+
201
+ client.sessionHandler = sessionHandler;
202
+
203
+ /*
204
+ * Cannot push to subscriptions as watcher needs to continue working even if
205
+ * token expires
206
+ */
207
+ unsubWatcher = client.accessTokenExpiryWatcher(sessionHandler);
208
+
209
+ setActiveUser(user);
210
+ } catch (error) {
211
+ /*
212
+ * if getting token failed session state reverts to initial state when app
213
+ * is first launched
214
+ */
215
+ SessionWatcher.getInstance().setSessionState(Amity.SessionStates.NOT_LOGGED_IN);
216
+
217
+ // pass error down tree so the calling function handle it
218
+ throw error;
219
+ }
220
+
221
+ if (config?.disableRTE !== true) {
222
+ runMqtt();
223
+ }
224
+
225
+ await initializeMessagePreviewSetting();
226
+
227
+ if (subscriptions.length === 0) {
228
+ subscriptions.push(
229
+ // GLOBAL_BAN
230
+ onClientBanned((_: Amity.UserPayload) => {
231
+ terminateClient(Amity.TokenTerminationReason.GLOBAL_BAN);
232
+
233
+ subscriptions.forEach(fn => fn());
234
+
235
+ unsubWatcher();
236
+ }),
237
+
238
+ onTokenTerminated(_ => {
239
+ terminateClient();
240
+
241
+ subscriptions.forEach(fn => fn());
242
+
243
+ unsubWatcher();
244
+ }),
245
+
246
+ onUserDeleted((user: Amity.InternalUser) => {
247
+ if (user.userId === client.userId) {
248
+ terminateClient(Amity.TokenTerminationReason.USER_DELETED);
249
+
250
+ subscriptions.forEach(fn => fn());
251
+
252
+ unsubWatcher();
253
+ }
254
+ }),
255
+
256
+ onTokenExpired(state => {
257
+ SessionWatcher.getInstance().setSessionState(state);
258
+
259
+ logout();
260
+
261
+ subscriptions.forEach(fn => fn());
262
+ }),
263
+
264
+ // NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
265
+ // the channel because currently backend can't handle this, so every time a user is banned from
266
+ // a channel or the channel is deleted the channel's unread count will not be reset to zero
267
+ onChannelDeleted(removeChannelMarkerCache),
268
+ onChannelMemberBanned(removeChannelMarkerCache),
269
+
270
+ markReadEngineOnLoginHandler(),
271
+ analyticsEngineOnLoginHandler(),
272
+ objectResolverEngineOnLoginHandler(),
273
+ );
274
+
275
+ if (client.useLegacyUnreadCount) {
276
+ subscriptions.push(readReceiptSyncEngineOnLoginHandler());
277
+ } else subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
278
+ }
279
+
280
+ return true;
281
+ };
282
+ /* end_public_function */
@@ -0,0 +1,173 @@
1
+ import { ASCApiError } from '~/core/errors';
2
+ import { user11, disconnectClient } from '~/utils/tests';
3
+ import { resumeSession, createClient } from '..';
4
+ import { setActiveClient } from '../activeClient';
5
+
6
+ let client: Amity.Client;
7
+
8
+ const sessionHandler: Amity.SessionHandler = {
9
+ sessionWillRenewAccessToken(_) {
10
+ // do nothing
11
+ },
12
+ };
13
+
14
+ const mockToken = {
15
+ accessToken: 'mock-access-token',
16
+ issuedAt: '2023-01-01T00:00:00Z',
17
+ expiresAt: '2025-01-01T00:00:00Z',
18
+ };
19
+
20
+ const mockUserResponse = {
21
+ data: {
22
+ users: [user11],
23
+ },
24
+ };
25
+
26
+ const onConnect = () =>
27
+ setTimeout(() => {
28
+ const CONNECT_PACKET = { type: 0, nsp: client.ws?.nsp };
29
+
30
+ client.ws?.emit('connect');
31
+
32
+ // simulate a connection ack packet from server
33
+ client.ws?.io.emit('packet', CONNECT_PACKET);
34
+ }, 50);
35
+
36
+ describe('resumeSession', () => {
37
+ beforeEach(() => {
38
+ client = createClient('key', 'sg');
39
+ client.mqtt?.connect && (client.mqtt.connect = jest.fn());
40
+ client.mqtt?.subscribe && (client.mqtt.subscribe = jest.fn());
41
+ client.http.get = jest.fn().mockResolvedValueOnce(mockUserResponse);
42
+
43
+ setActiveClient(client);
44
+ });
45
+
46
+ afterEach(async () => {
47
+ if (client.sessionState === Amity.SessionStates.ESTABLISHED) await disconnectClient();
48
+ });
49
+
50
+ test('it should connect client with access token', async () => {
51
+ onConnect().unref();
52
+
53
+ const received = await resumeSession(
54
+ { userId: user11.userId, token: mockToken },
55
+ sessionHandler,
56
+ );
57
+
58
+ expect(received).toBe(true);
59
+ });
60
+
61
+ test('it should establish connection', async () => {
62
+ onConnect().unref();
63
+
64
+ await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
65
+ const { sessionState } = client;
66
+
67
+ expect(sessionState).toBe(Amity.SessionStates.ESTABLISHED);
68
+ });
69
+
70
+ test('it should have session state establishing while connecting client', () => {
71
+ resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
72
+
73
+ expect(client.sessionState).toBe(Amity.SessionStates.ESTABLISHING);
74
+ });
75
+
76
+ test('it should have session state notLoggedIn on failure', async () => {
77
+ client.http.get = jest
78
+ .fn()
79
+ .mockRejectedValue(
80
+ new ASCApiError('unauthorized', Amity.ServerError.UNAUTHORIZED, Amity.ErrorLevel.FATAL),
81
+ );
82
+
83
+ await expect(
84
+ resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler),
85
+ ).rejects.toThrow('unauthorized');
86
+ expect(client.sessionState).toBe(Amity.SessionStates.NOT_LOGGED_IN);
87
+ });
88
+
89
+ test('it should set authorization header with token', async () => {
90
+ onConnect().unref();
91
+
92
+ await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
93
+
94
+ expect(client.http.defaults.headers.common.Authorization).toBe(
95
+ `Bearer ${mockToken.accessToken}`,
96
+ );
97
+ expect(client.upload.defaults.headers.common.Authorization).toBe(
98
+ `Bearer ${mockToken.accessToken}`,
99
+ );
100
+ });
101
+
102
+ test('it should set token metadata', async () => {
103
+ onConnect().unref();
104
+
105
+ await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
106
+
107
+ expect(client.token).toEqual(mockToken);
108
+ expect(client.http.defaults.metadata).toEqual({
109
+ tokenExpiry: mockToken.expiresAt,
110
+ isGlobalBanned: false,
111
+ isUserDeleted: false,
112
+ });
113
+ });
114
+
115
+ test('it should call user endpoint to validate token', async () => {
116
+ onConnect().unref();
117
+
118
+ await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
119
+
120
+ expect(client.http.get).toHaveBeenCalledWith(`/api/v3/users/${user11.userId}`);
121
+ });
122
+
123
+ test('it should terminate session on ban', async () => {
124
+ onConnect().unref();
125
+
126
+ await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
127
+
128
+ // ban user
129
+ client.emitter.emit('user.didGlobalBan', {} as Amity.UserPayload);
130
+
131
+ expect(client.sessionState).toBe(Amity.SessionStates.TERMINATED);
132
+ });
133
+
134
+ test('it should reset client state when user is already connected with same userId', async () => {
135
+ onConnect().unref();
136
+
137
+ // First connection
138
+ await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
139
+ expect(client.sessionState).toBe(Amity.SessionStates.ESTABLISHED);
140
+ expect(client.userId).toBe(user11.userId);
141
+
142
+ // Mock the HTTP call for second connection
143
+ client.http.get = jest.fn().mockResolvedValueOnce(mockUserResponse);
144
+
145
+ // Second connection with same userId should treat as token expiry (preserve cache)
146
+ onConnect().unref();
147
+ await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
148
+
149
+ // Verify that the client is properly reset and reconnected
150
+ expect(client.sessionState).toBe(Amity.SessionStates.ESTABLISHED);
151
+ expect(client.userId).toBe(user11.userId);
152
+ });
153
+
154
+ test('it should preserve cache when resuming session with same userId', async () => {
155
+ onConnect().unref();
156
+
157
+ // First connection - set some cache data
158
+ await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
159
+ if (client.cache) {
160
+ client.cache.data = { test: 'data' };
161
+ }
162
+
163
+ // Mock the HTTP call for second connection
164
+ client.http.get = jest.fn().mockResolvedValueOnce(mockUserResponse);
165
+
166
+ // Second connection with same userId
167
+ onConnect().unref();
168
+ await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
169
+
170
+ // Cache should be preserved when same userId is used
171
+ expect(client.cache?.data).toEqual({ test: 'data' });
172
+ });
173
+ });
@@ -1,3 +1,4 @@
1
+ import { LinkedObject } from '~/utils/linkedObject';
1
2
  import { getActiveClient } from '~/client/api';
2
3
 
3
4
  import { ingestInCache } from '~/cache/api/ingestInCache';
@@ -10,8 +11,8 @@ import { prepareCommunityPayload, prepareCommunityRequest } from '../utils';
10
11
  */
11
12
  /**
12
13
  * ```js
13
- * import { createCommunity } from '@amityco/ts-sdk-react-native'
14
- * const created = await createCommunity({ communityId: 'foobar', displayName: 'foobar' })
14
+ * import { createCommunity } from '@amityco/ts-sdk'
15
+ * const created = await createCommunity({ communityId: 'foobar', displayName: 'foobar', isDiscoverable: true, requiresJoinApproval: false })
15
16
  * ```
16
17
  *
17
18
  * Creates an {@link Amity.Community}
@@ -33,6 +34,8 @@ export const createCommunity = async (
33
34
  | 'postSetting'
34
35
  | 'tags'
35
36
  | 'metadata'
37
+ | 'isDiscoverable'
38
+ | 'requiresJoinApproval'
36
39
  > &
37
40
  Amity.CommunityStorySettings & {
38
41
  userIds?: string[];
@@ -60,7 +63,7 @@ export const createCommunity = async (
60
63
 
61
64
  const { communities } = data;
62
65
  return {
63
- data: communities[0],
66
+ data: LinkedObject.community(communities[0]),
64
67
  cachedAt,
65
68
  };
66
69
  };
@@ -2,6 +2,7 @@ import { getActiveClient } from '~/client/api';
2
2
 
3
3
  import { fireEvent } from '~/core/events';
4
4
  import { getCommunity } from './getCommunity';
5
+ import { LinkedObject } from '~/utils/linkedObject';
5
6
 
6
7
  /* begin_public_function
7
8
  id: community.delete
@@ -40,6 +41,6 @@ export const deleteCommunity = async (
40
41
  users: [],
41
42
  });
42
43
 
43
- return deleted.data;
44
+ return LinkedObject.community(deleted.data);
44
45
  };
45
46
  /* end_public_function */
@@ -5,6 +5,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
5
5
 
6
6
  import { saveCommunityUsers } from '~/communityRepository/utils/saveCommunityUsers';
7
7
  import { prepareCommunityPayload } from '../utils';
8
+ import { LinkedObject } from '~/utils/linkedObject';
8
9
 
9
10
  /**
10
11
  * ```js
@@ -22,15 +23,21 @@ import { prepareCommunityPayload } from '../utils';
22
23
  */
23
24
  export const getCommunities = async (
24
25
  communityIds: Amity.Community['communityId'][],
26
+ includeDiscoverablePrivateCommunity?: boolean,
25
27
  ): Promise<Amity.Cached<Amity.Community[]>> => {
26
28
  const client = getActiveClient();
27
29
  client.log('community/getCommunities', communityIds);
28
30
 
31
+ const encodedCommunityIds = communityIds.map(communityId => encodeURIComponent(communityId));
32
+
29
33
  // API-FIX: endpoint should not be /list, parameters should be querystring.
30
34
  const { data: payload } = await client.http.get<Amity.CommunityPayload>(
31
35
  `/api/v3/communities/list`,
32
36
  {
33
- params: { communityIds },
37
+ params: {
38
+ communityIds: encodedCommunityIds,
39
+ includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity ?? true,
40
+ },
34
41
  },
35
42
  );
36
43
 
@@ -43,7 +50,7 @@ export const getCommunities = async (
43
50
  }
44
51
 
45
52
  return {
46
- data: data.communities,
53
+ data: data.communities.map(community => LinkedObject.community(community)),
47
54
  cachedAt,
48
55
  };
49
56
  };
@@ -5,6 +5,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
5
5
 
6
6
  import { saveCommunityUsers } from '~/communityRepository/utils/saveCommunityUsers';
7
7
  import { prepareCommunityPayload } from '../utils';
8
+ import { LinkedObject } from '~/utils/linkedObject';
8
9
 
9
10
  /**
10
11
  * ```js
@@ -22,13 +23,21 @@ import { prepareCommunityPayload } from '../utils';
22
23
  */
23
24
  export const getCommunity = async (
24
25
  communityId: Amity.Community['communityId'],
25
- ): Promise<Amity.Cached<Amity.Community>> => {
26
+ type?: Amity.JoinRequestType,
27
+ includeDiscoverablePrivateCommunity?: boolean,
28
+ ): Promise<Amity.Cached<Amity.InternalCommunity>> => {
26
29
  const client = getActiveClient();
27
30
  client.log('community/getCommunity', communityId);
28
31
 
29
32
  // API-FIX: endpoint should not be /list, parameters should be querystring.
30
33
  const { data: payload } = await client.http.get<Amity.CommunityPayload>(
31
34
  `/api/v3/communities/${communityId}`,
35
+ {
36
+ params: {
37
+ type: 'communityJoinRequest',
38
+ includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity ?? true,
39
+ },
40
+ },
32
41
  );
33
42
 
34
43
  const data = prepareCommunityPayload(payload);
@@ -62,13 +71,13 @@ export const getCommunity = async (
62
71
  */
63
72
  getCommunity.locally = (
64
73
  communityId: Amity.Community['communityId'],
65
- ): Amity.Cached<Amity.Community> | undefined => {
74
+ ): Amity.Cached<Amity.InternalCommunity> | undefined => {
66
75
  const client = getActiveClient();
67
76
  client.log('community/getCommunity.locally', communityId);
68
77
 
69
78
  if (!client.cache) return;
70
79
 
71
- const cached = pullFromCache<Amity.Community>(['community', 'get', communityId]);
80
+ const cached = pullFromCache<Amity.InternalCommunity>(['community', 'get', communityId]);
72
81
 
73
82
  if (!cached) return;
74
83
 
@@ -4,6 +4,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
4
4
 
5
5
  import { prepareCommunityPayload } from '../utils';
6
6
  import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
7
+ import { LinkedObject } from '~/utils/linkedObject';
7
8
 
8
9
  /* begin_public_function
9
10
  id: community.query.recommended_communities
@@ -24,18 +25,24 @@ import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
24
25
  * @private
25
26
  */
26
27
  export const getRecommendedCommunities = async (
27
- query?: Amity.PageLimit,
28
+ query?: Amity.PageLimit & { includeDiscoverablePrivateCommunity?: boolean },
28
29
  ): Promise<Amity.Cached<Amity.Community[]>> => {
29
30
  const client = getActiveClient();
30
31
  client.log('community/getRecommendedCommunities', query);
31
32
 
32
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = query ?? {};
33
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDiscoverablePrivateCommunity } =
34
+ query ?? {};
33
35
 
34
36
  // API-FIX: backend doesnt answer Amity.Response
35
37
  // const { data: payload } = await client.http.get<Amity.Response<CommunityPayload>>(
36
38
  const { data: payload } = await client.http.get<Amity.CommunityPayload>(
37
39
  `/api/v3/communities/recommended`,
38
- { params: { options: { limit } } },
40
+ {
41
+ params: {
42
+ includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity ?? true,
43
+ options: { limit },
44
+ },
45
+ },
39
46
  );
40
47
 
41
48
  const data = prepareCommunityPayload(payload);
@@ -47,5 +54,5 @@ export const getRecommendedCommunities = async (
47
54
  ingestInCache(data, { cachedAt });
48
55
  }
49
56
 
50
- return { data: communities, cachedAt };
57
+ return { data: communities.map(community => LinkedObject.community(community)), cachedAt };
51
58
  };
@@ -4,6 +4,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
4
4
 
5
5
  import { prepareCommunityPayload } from '../utils';
6
6
  import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
7
+ import { LinkedObject } from '~/utils/linkedObject';
7
8
 
8
9
  /**
9
10
  * ```js
@@ -21,18 +22,24 @@ import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
21
22
  * @private
22
23
  */
23
24
  export const getTrendingCommunities = async (
24
- query?: Amity.PageLimit,
25
+ query?: Amity.PageLimit & { includeDiscoverablePrivateCommunity?: boolean },
25
26
  ): Promise<Amity.Cached<Amity.Community[]>> => {
26
27
  const client = getActiveClient();
27
28
  client.log('community/getTrendingCommunities', query);
28
29
 
29
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = query ?? {};
30
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDiscoverablePrivateCommunity } =
31
+ query ?? {};
30
32
 
31
33
  // API-FIX: backend doesnt answer Amity.Response
32
34
  // const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
33
35
  const { data: payload } = await client.http.get<Amity.CommunityPayload>(
34
36
  `/api/v3/communities/top-trending`,
35
- { params: { options: { limit } } },
37
+ {
38
+ params: {
39
+ includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity ?? true,
40
+ options: { limit },
41
+ },
42
+ },
36
43
  );
37
44
 
38
45
  const data = prepareCommunityPayload(payload);
@@ -44,5 +51,5 @@ export const getTrendingCommunities = async (
44
51
  ingestInCache(data, { cachedAt });
45
52
  }
46
53
 
47
- return { data: communities, cachedAt };
54
+ return { data: communities.map(community => LinkedObject.community(community)), cachedAt };
48
55
  };
@@ -1,9 +1,12 @@
1
- import { getActiveClient } from '~/client/api';
1
+ import { getActiveClient } from '~/client/api/activeClient';
2
2
 
3
3
  import { ingestInCache } from '~/cache/api/ingestInCache';
4
4
  import { prepareCommunityPayload } from '~/communityRepository/utils';
5
5
  import { fireEvent } from '~/core/events';
6
6
 
7
+ /**
8
+ * @deprecated This function will to be deprecated and use the new community.join().
9
+ */
7
10
  /* begin_public_function
8
11
  id: community.join
9
12
  */