@amityco/ts-sdk 0.0.1-beta.39 → 0.0.1-beta.40

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 (285) hide show
  1. package/.eslintrc.json +2 -0
  2. package/dist/@types/core/events.d.ts +22 -22
  3. package/dist/@types/core/events.d.ts.map +1 -1
  4. package/dist/@types/core/model.d.ts +3 -2
  5. package/dist/@types/core/model.d.ts.map +1 -1
  6. package/dist/@types/core/payload.d.ts +87 -34
  7. package/dist/@types/core/payload.d.ts.map +1 -1
  8. package/dist/@types/domains/channel.d.ts +1 -1
  9. package/dist/@types/domains/client.d.ts +1 -1
  10. package/dist/@types/domains/client.d.ts.map +1 -1
  11. package/dist/@types/domains/comment.d.ts +5 -0
  12. package/dist/@types/domains/comment.d.ts.map +1 -1
  13. package/dist/@types/domains/community.d.ts +11 -0
  14. package/dist/@types/domains/community.d.ts.map +1 -1
  15. package/dist/@types/domains/content.d.ts +7 -1
  16. package/dist/@types/domains/content.d.ts.map +1 -1
  17. package/dist/@types/domains/group.d.ts +2 -2
  18. package/dist/@types/global.d.ts +8 -0
  19. package/dist/@types/global.d.ts.map +1 -1
  20. package/dist/cache/api/ingestInCache.d.ts +2 -1
  21. package/dist/cache/api/ingestInCache.d.ts.map +1 -1
  22. package/dist/channel/api/banChannelMembers.d.ts.map +1 -1
  23. package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
  24. package/dist/channel/api/unbanChannelMembers.d.ts.map +1 -1
  25. package/dist/channel/events/onChannelJoined.d.ts.map +1 -1
  26. package/dist/channel/events/onChannelLeft.d.ts.map +1 -1
  27. package/dist/channel/events/onChannelMemberAdded.d.ts.map +1 -1
  28. package/dist/channel/events/onChannelMemberBanned.d.ts.map +1 -1
  29. package/dist/channel/events/onChannelMemberRemoved.d.ts.map +1 -1
  30. package/dist/channel/events/onChannelMemberUnbanned.d.ts.map +1 -1
  31. package/dist/channel/utils/index.d.ts +2 -2
  32. package/dist/channel/utils/index.d.ts.map +1 -1
  33. package/dist/comment/api/createComment.d.ts +1 -1
  34. package/dist/comment/api/createComment.d.ts.map +1 -1
  35. package/dist/comment/api/deleteComment.d.ts.map +1 -1
  36. package/dist/comment/api/tests/updateComment.test.d.ts +2 -0
  37. package/dist/comment/api/tests/updateComment.test.d.ts.map +1 -0
  38. package/dist/community/api/addCommunityMembers.d.ts.map +1 -1
  39. package/dist/community/api/addCommunityMembersRoles.d.ts +1 -1
  40. package/dist/community/api/addCommunityMembersRoles.d.ts.map +1 -1
  41. package/dist/community/api/deleteCommunity.d.ts.map +1 -1
  42. package/dist/community/api/joinCommunity.d.ts.map +1 -1
  43. package/dist/community/api/leaveCommunity.d.ts.map +1 -1
  44. package/dist/community/api/queryCommunityMembers.d.ts +1 -7
  45. package/dist/community/api/queryCommunityMembers.d.ts.map +1 -1
  46. package/dist/community/api/removeCommunityMembers.d.ts.map +1 -1
  47. package/dist/community/api/removeCommunityMembersRoles.d.ts +1 -1
  48. package/dist/community/api/removeCommunityMembersRoles.d.ts.map +1 -1
  49. package/dist/community/events/index.d.ts +2 -0
  50. package/dist/community/events/index.d.ts.map +1 -1
  51. package/dist/community/events/onCommunityUserRoleAdded.d.ts +17 -0
  52. package/dist/community/events/onCommunityUserRoleAdded.d.ts.map +1 -0
  53. package/dist/community/events/onCommunityUserRoleRemoved.d.ts +17 -0
  54. package/dist/community/events/onCommunityUserRoleRemoved.d.ts.map +1 -0
  55. package/dist/community/events/test/onCommunityUserRoleAdded.test.d.ts +2 -0
  56. package/dist/community/events/test/onCommunityUserRoleAdded.test.d.ts.map +1 -0
  57. package/dist/community/events/test/onCommunityUserRoleRemoved.test.d.ts +2 -0
  58. package/dist/community/events/test/onCommunityUserRoleRemoved.test.d.ts.map +1 -0
  59. package/dist/community/events/utils.d.ts.map +1 -1
  60. package/dist/community/observers/index.d.ts +2 -0
  61. package/dist/community/observers/index.d.ts.map +1 -1
  62. package/dist/community/observers/liveCommunity.d.ts +21 -0
  63. package/dist/community/observers/liveCommunity.d.ts.map +1 -0
  64. package/dist/community/observers/liveCommunityMembers.d.ts +20 -0
  65. package/dist/community/observers/liveCommunityMembers.d.ts.map +1 -0
  66. package/dist/community/observers/tests/liveCommunity.test.d.ts +2 -0
  67. package/dist/community/observers/tests/liveCommunity.test.d.ts.map +1 -0
  68. package/dist/community/observers/tests/liveCommunityMembers.test.d.ts +2 -0
  69. package/dist/community/observers/tests/liveCommunityMembers.test.d.ts.map +1 -0
  70. package/dist/community/utils/payload.d.ts +3 -5
  71. package/dist/community/utils/payload.d.ts.map +1 -1
  72. package/dist/core/device.d.ts.map +1 -1
  73. package/dist/core/events.d.ts +3 -3
  74. package/dist/core/events.d.ts.map +1 -1
  75. package/dist/core/model/idResolvers.d.ts +2 -4
  76. package/dist/core/model/idResolvers.d.ts.map +1 -1
  77. package/dist/core/model/identifyModel.d.ts +2 -2
  78. package/dist/core/model/identifyModel.d.ts.map +1 -1
  79. package/dist/core/model/index.d.ts.map +1 -1
  80. package/dist/core/query/query.d.ts.map +1 -1
  81. package/dist/external/api/tests/createUserToken.test.d.ts +2 -0
  82. package/dist/external/api/tests/createUserToken.test.d.ts.map +1 -0
  83. package/dist/feed/api/queryGlobalFeed.d.ts.map +1 -1
  84. package/dist/group/utils/withUser.d.ts.map +1 -1
  85. package/dist/index.cjs.js +481 -200
  86. package/dist/index.esm.js +477 -200
  87. package/dist/index.umd.js +4 -4
  88. package/dist/message/api/createMessage.d.ts.map +1 -1
  89. package/dist/message/utils/index.d.ts +3 -3
  90. package/dist/message/utils/index.d.ts.map +1 -1
  91. package/dist/poll/api/tests/closePoll.test.d.ts +2 -0
  92. package/dist/poll/api/tests/closePoll.test.d.ts.map +1 -0
  93. package/dist/poll/api/tests/createPoll.test.d.ts +2 -0
  94. package/dist/poll/api/tests/createPoll.test.d.ts.map +1 -0
  95. package/dist/poll/api/tests/getPoll.test.d.ts +2 -0
  96. package/dist/poll/api/tests/getPoll.test.d.ts.map +1 -0
  97. package/dist/poll/api/tests/votePoll.test.d.ts +2 -0
  98. package/dist/poll/api/tests/votePoll.test.d.ts.map +1 -0
  99. package/dist/post/api/approvePost.d.ts.map +1 -1
  100. package/dist/post/api/createPost.d.ts.map +1 -1
  101. package/dist/post/api/declinePost.d.ts.map +1 -1
  102. package/dist/post/api/deletePost.d.ts.map +1 -1
  103. package/dist/post/api/getPost.d.ts.map +1 -1
  104. package/dist/post/api/getPosts.d.ts.map +1 -1
  105. package/dist/post/api/queryPosts.d.ts.map +1 -1
  106. package/dist/post/api/updatePost.d.ts.map +1 -1
  107. package/dist/post/events/utils.d.ts.map +1 -1
  108. package/dist/reaction/api/queryReactions.d.ts.map +1 -1
  109. package/dist/reaction/api/removeReaction.d.ts.map +1 -1
  110. package/dist/reaction/events/onReactorAdded.d.ts.map +1 -1
  111. package/dist/reaction/events/onReactorRemoved.d.ts.map +1 -1
  112. package/dist/reaction/utils/dispatchReactable.d.ts +1 -1
  113. package/dist/reaction/utils/dispatchReactable.d.ts.map +1 -1
  114. package/dist/report/api/createReport.d.ts.map +1 -1
  115. package/dist/report/api/deleteReport.d.ts.map +1 -1
  116. package/dist/subChannel/utils/index.d.ts +1 -1
  117. package/dist/subChannel/utils/index.d.ts.map +1 -1
  118. package/dist/utils/index.d.ts +2 -2
  119. package/dist/utils/index.d.ts.map +1 -1
  120. package/dist/utils/tests/dummy/channel.d.ts +31 -35
  121. package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
  122. package/dist/utils/tests/dummy/community.d.ts +35 -84
  123. package/dist/utils/tests/dummy/community.d.ts.map +1 -1
  124. package/dist/utils/tests/dummy/feed.d.ts +2 -18
  125. package/dist/utils/tests/dummy/feed.d.ts.map +1 -1
  126. package/dist/utils/tests/dummy/member.d.ts +1 -1
  127. package/dist/utils/tests/dummy/post.d.ts +30 -29
  128. package/dist/utils/tests/dummy/post.d.ts.map +1 -1
  129. package/dist/version.d.ts.map +1 -1
  130. package/package.json +1 -1
  131. package/src/@types/core/events.ts +22 -20
  132. package/src/@types/core/model.ts +3 -2
  133. package/src/@types/core/payload.ts +102 -38
  134. package/src/@types/domains/channel.ts +1 -1
  135. package/src/@types/domains/client.ts +1 -1
  136. package/src/@types/domains/comment.ts +7 -0
  137. package/src/@types/domains/community.ts +25 -0
  138. package/src/@types/domains/content.ts +9 -1
  139. package/src/@types/domains/group.ts +2 -2
  140. package/src/@types/global.ts +10 -0
  141. package/src/cache/api/ingestInCache.ts +3 -6
  142. package/src/cache/api/tests/ingestInCache.test.ts +12 -9
  143. package/src/channel/api/addChannelMembers.ts +5 -5
  144. package/src/channel/api/banChannelMembers.ts +1 -3
  145. package/src/channel/api/getChannel.ts +1 -1
  146. package/src/channel/api/queryChannelMembers.ts +1 -3
  147. package/src/channel/api/removeChannelMembers.ts +5 -5
  148. package/src/channel/api/tests/addChannelMembers.test.ts +4 -3
  149. package/src/channel/api/tests/createChannel.test.ts +5 -3
  150. package/src/channel/api/tests/getChannel.test.ts +2 -1
  151. package/src/channel/api/tests/joinChannel.test.ts +2 -2
  152. package/src/channel/api/tests/leaveChannel.test.ts +2 -2
  153. package/src/channel/api/tests/queryChannelMembers.test.ts +2 -5
  154. package/src/channel/api/tests/queryChannels.test.ts +4 -3
  155. package/src/channel/api/tests/removeChannelMembers.test.ts +16 -5
  156. package/src/channel/api/unbanChannelMembers.ts +1 -3
  157. package/src/channel/events/onChannelJoined.ts +1 -3
  158. package/src/channel/events/onChannelLeft.ts +1 -3
  159. package/src/channel/events/onChannelMemberAdded.ts +1 -3
  160. package/src/channel/events/onChannelMemberBanned.ts +1 -3
  161. package/src/channel/events/onChannelMemberRemoved.ts +1 -3
  162. package/src/channel/events/onChannelMemberUnbanned.ts +1 -3
  163. package/src/channel/observers/tests/liveChannelMembers.test.ts +5 -12
  164. package/src/channel/observers/tests/liveChannels.test.ts +3 -1
  165. package/src/channel/utils/index.ts +9 -6
  166. package/src/comment/api/createComment.ts +18 -2
  167. package/src/comment/api/deleteComment.ts +19 -2
  168. package/src/comment/api/tests/createComment.test.ts +169 -9
  169. package/src/comment/api/tests/updateComment.test.ts +189 -0
  170. package/src/comment/events/tests/onCommentCreated.test.ts +3 -3
  171. package/src/comment/events/tests/onCommentDeleted.test.ts +3 -3
  172. package/src/comment/observers/tests/liveComment.test.ts +18 -2
  173. package/src/community/api/addCommunityMembers.ts +6 -3
  174. package/src/community/api/addCommunityMembersRoles.ts +5 -2
  175. package/src/community/api/createCommunity.ts +5 -5
  176. package/src/community/api/deleteCommunity.ts +9 -1
  177. package/src/community/api/getCommunities.ts +2 -2
  178. package/src/community/api/getCommunity.ts +2 -2
  179. package/src/community/api/getRecommendedCommunities.ts +2 -2
  180. package/src/community/api/getTopTrendingCommunities.ts +2 -2
  181. package/src/community/api/joinCommunity.ts +6 -3
  182. package/src/community/api/leaveCommunity.ts +6 -3
  183. package/src/community/api/queryCommunities.ts +3 -3
  184. package/src/community/api/queryCommunityMembers.ts +3 -7
  185. package/src/community/api/removeCommunityMembers.ts +7 -3
  186. package/src/community/api/removeCommunityMembersRoles.ts +5 -2
  187. package/src/community/api/test/queryCommunityMembers.test.ts +2 -1
  188. package/src/community/api/test/removeCommunityMemberRole.test.ts +4 -1
  189. package/src/community/api/updateCommunity.ts +5 -5
  190. package/src/community/events/index.ts +2 -0
  191. package/src/community/events/onCommunityUserRoleAdded.ts +20 -0
  192. package/src/community/events/onCommunityUserRoleRemoved.ts +20 -0
  193. package/src/community/events/test/onCommunityDeleted.test.ts +8 -1
  194. package/src/community/events/test/onCommunityUserRoleAdded.test.ts +50 -0
  195. package/src/community/events/test/onCommunityUserRoleRemoved.test.ts +50 -0
  196. package/src/community/events/utils.ts +4 -8
  197. package/src/community/observers/index.ts +4 -0
  198. package/src/community/observers/liveCommunity.ts +45 -0
  199. package/src/community/observers/liveCommunityMembers.ts +187 -0
  200. package/src/community/observers/tests/liveCommunities.test.ts +38 -18
  201. package/src/community/observers/tests/liveCommunity.test.ts +147 -0
  202. package/src/community/observers/tests/liveCommunityMembers.test.ts +195 -0
  203. package/src/community/utils/payload.ts +28 -22
  204. package/src/core/device.ts +2 -4
  205. package/src/core/model/idResolvers.ts +4 -3
  206. package/src/core/model/identifyModel.ts +3 -3
  207. package/src/core/model/index.ts +1 -0
  208. package/src/core/query/query.ts +7 -0
  209. package/src/core/tests/query/query/runQuery.test.ts +8 -3
  210. package/src/core/tests/subscription.test.ts +80 -2
  211. package/src/external/api/tests/createUserToken.test.ts +29 -0
  212. package/src/feed/api/queryGlobalFeed.ts +8 -4
  213. package/src/group/utils/test/withUsers.test.ts +5 -5
  214. package/src/group/utils/withUser.ts +20 -14
  215. package/src/message/api/createMessage.ts +10 -9
  216. package/src/message/api/getMessage.ts +2 -2
  217. package/src/message/api/getMessages.ts +1 -1
  218. package/src/message/api/queryMessages.ts +2 -2
  219. package/src/message/api/tests/createMessage.test.ts +5 -1
  220. package/src/message/api/updateMessage.ts +1 -1
  221. package/src/message/events/onMessageCreated.ts +1 -1
  222. package/src/message/events/onMessageDeleted.ts +1 -1
  223. package/src/message/events/onMessageFetched.ts +1 -1
  224. package/src/message/events/onMessageFlagCleared.ts +1 -1
  225. package/src/message/events/onMessageFlagged.ts +1 -1
  226. package/src/message/events/onMessageReactionAdded.ts +1 -1
  227. package/src/message/events/onMessageReactionRemoved.ts +1 -1
  228. package/src/message/events/onMessageUnflagged.ts +1 -1
  229. package/src/message/events/onMessageUpdated.ts +1 -1
  230. package/src/message/tests/events.test.ts +10 -2
  231. package/src/message/tests/observers/liveMessage.test.ts +6 -1
  232. package/src/message/tests/observers/liveMessages.test.ts +16 -3
  233. package/src/message/utils/index.ts +5 -3
  234. package/src/poll/api/tests/closePoll.test.ts +50 -0
  235. package/src/poll/api/tests/createPoll.test.ts +70 -0
  236. package/src/poll/api/tests/getPoll.test.ts +31 -0
  237. package/src/poll/api/tests/votePoll.test.ts +41 -0
  238. package/src/poll/events/onPollDeleted.ts +1 -1
  239. package/src/poll/events/onPollUpdated.ts +1 -1
  240. package/src/post/api/approvePost.ts +10 -10
  241. package/src/post/api/createPost.ts +6 -3
  242. package/src/post/api/declinePost.ts +11 -11
  243. package/src/post/api/deletePost.ts +19 -2
  244. package/src/post/api/getPost.ts +5 -2
  245. package/src/post/api/getPosts.ts +4 -1
  246. package/src/post/api/queryPosts.ts +3 -1
  247. package/src/post/api/tests/queryPosts.test.ts +5 -4
  248. package/src/post/api/updatePost.ts +4 -1
  249. package/src/post/events/onPostReactionAdded.ts +1 -1
  250. package/src/post/events/onPostReactionRemoved.ts +1 -1
  251. package/src/post/events/utils.ts +12 -2
  252. package/src/post/observers/tests/livePost.test.ts +10 -3
  253. package/src/post/observers/tests/livePosts.test.ts +12 -4
  254. package/src/post/tests/api/getPost.test.ts +13 -3
  255. package/src/post/tests/api/queryPosts.test.ts +5 -4
  256. package/src/reaction/api/addReaction.ts +3 -3
  257. package/src/reaction/api/queryReactions.ts +2 -0
  258. package/src/reaction/api/removeReaction.ts +4 -3
  259. package/src/reaction/events/onReactionAdded.ts +3 -3
  260. package/src/reaction/events/onReactionRemoved.ts +3 -3
  261. package/src/reaction/events/onReactorAdded.ts +8 -2
  262. package/src/reaction/events/onReactorRemoved.ts +8 -2
  263. package/src/reaction/utils/dispatchReactable.ts +1 -1
  264. package/src/reaction/utils/fetchReference.ts +1 -1
  265. package/src/report/api/createReport.ts +14 -8
  266. package/src/report/api/deleteReport.ts +14 -8
  267. package/src/subChannel/api/createSubChannel.ts +1 -1
  268. package/src/subChannel/api/getSubChannel.ts +1 -1
  269. package/src/subChannel/api/getSubChannels.ts +1 -1
  270. package/src/subChannel/api/querySubChannels.ts +2 -2
  271. package/src/subChannel/api/updateSubChannel.ts +1 -1
  272. package/src/subChannel/events/onSubChannelCreated.ts +1 -1
  273. package/src/subChannel/events/onSubChannelDeleted.ts +1 -1
  274. package/src/subChannel/events/onSubChannelUpdated.ts +1 -1
  275. package/src/subChannel/utils/index.ts +2 -2
  276. package/src/user/observers/tests/liveUsers.test.ts +2 -0
  277. package/src/user/tests/api/getUser.test.ts +17 -3
  278. package/src/utils/index.ts +2 -2
  279. package/src/utils/liveObject.ts +1 -1
  280. package/src/utils/tests/dummy/channel.ts +18 -11
  281. package/src/utils/tests/dummy/community.ts +68 -6
  282. package/src/utils/tests/dummy/feed.ts +1 -1
  283. package/src/utils/tests/dummy/member.ts +1 -1
  284. package/src/utils/tests/dummy/post.ts +93 -9
  285. package/src/version.ts +9 -3
@@ -7,11 +7,11 @@ import {
7
7
  disconnectClient,
8
8
  pause,
9
9
  communityUser11,
10
+ emptyCommunityPayload,
10
11
  } from '~/utils/tests';
11
12
 
12
13
  import { liveCommunities } from '../liveCommunities';
13
-
14
- import { unpackCommunityPayload } from '../../utils';
14
+ import { prepareCommunityPayload } from '../../utils';
15
15
 
16
16
  const getSnapshot = (params?: Record<string, any>) => {
17
17
  return {
@@ -23,10 +23,9 @@ const getSnapshot = (params?: Record<string, any>) => {
23
23
  };
24
24
 
25
25
  const { paging, ...payload } = communityQueryResponse.data;
26
- const { paging: paging2, ...payload2 } = communityQueryResponsePage2.data;
27
26
 
28
- const community1 = unpackCommunityPayload(payload).communities[0];
29
- const community2 = unpackCommunityPayload(payload).communities[1];
27
+ const community1 = prepareCommunityPayload(payload).communities[0];
28
+ const community2 = prepareCommunityPayload(payload).communities[1];
30
29
 
31
30
  describe('liveCommunities', () => {
32
31
  beforeAll(connectClient);
@@ -49,7 +48,7 @@ describe('liveCommunities', () => {
49
48
  2,
50
49
  expect.objectContaining(
51
50
  getSnapshot({
52
- data: unpackCommunityPayload(payload).communities,
51
+ data: prepareCommunityPayload(payload).communities,
53
52
  loading: false,
54
53
  }),
55
54
  ),
@@ -70,7 +69,7 @@ describe('liveCommunities', () => {
70
69
  1,
71
70
  expect.objectContaining(
72
71
  getSnapshot({
73
- data: unpackCommunityPayload(payload).communities,
72
+ data: prepareCommunityPayload(payload).communities,
74
73
  }),
75
74
  ),
76
75
  );
@@ -78,7 +77,7 @@ describe('liveCommunities', () => {
78
77
  2,
79
78
  expect.objectContaining(
80
79
  getSnapshot({
81
- data: unpackCommunityPayload(payload).communities,
80
+ data: prepareCommunityPayload(payload).communities,
82
81
  loading: false,
83
82
  }),
84
83
  ),
@@ -146,7 +145,7 @@ describe('liveCommunities', () => {
146
145
  expect.objectContaining(
147
146
  getSnapshot({
148
147
  loading: false,
149
- data: unpackCommunityPayload(payload).communities,
148
+ data: prepareCommunityPayload(payload).communities,
150
149
  }),
151
150
  ),
152
151
  );
@@ -158,10 +157,14 @@ describe('liveCommunities', () => {
158
157
  communityId: 'new-community',
159
158
  isDeleted: false,
160
159
  };
161
- const newCommunity = unpackCommunityPayload({ communities: [newCommunityPayload] })
162
- .communities[0];
160
+
161
+ const newCommunity = prepareCommunityPayload({
162
+ ...emptyCommunityPayload,
163
+ communities: [newCommunityPayload],
164
+ }).communities[0];
163
165
 
164
166
  const communityPayload = {
167
+ ...emptyCommunityPayload,
165
168
  communities: [communityQueryResponse.data.communities[0]],
166
169
  communityUsers: [communityUser11],
167
170
  };
@@ -170,13 +173,19 @@ describe('liveCommunities', () => {
170
173
  [
171
174
  'it should add new community to collection onCreate',
172
175
  'community.created',
173
- { communities: [newCommunityPayload] },
176
+ {
177
+ ...emptyCommunityPayload,
178
+ communities: [newCommunityPayload],
179
+ },
174
180
  [newCommunity, community2],
175
181
  ],
176
182
  [
177
183
  'it should update community in collection onUpdate',
178
184
  'community.updated',
179
- { communities: [{ ...newCommunityPayload, communityId: community1.communityId }] },
185
+ {
186
+ ...emptyCommunityPayload,
187
+ communities: [{ ...newCommunityPayload, communityId: community1.communityId }],
188
+ },
180
189
  [{ ...newCommunity, communityId: community1.communityId }, community2],
181
190
  ],
182
191
  [
@@ -213,10 +222,13 @@ describe('liveCommunities', () => {
213
222
  communityId: 'joining-community',
214
223
  isDeleted: false,
215
224
  };
216
- const joinedCommunity = unpackCommunityPayload({ communities: [joinCommunityPayload] })
217
- .communities[0];
218
225
 
219
- const joiningUser: Amity.MembershipRaw<'community'> = {
226
+ const joinedCommunity = prepareCommunityPayload({
227
+ ...emptyCommunityPayload,
228
+ communities: [joinCommunityPayload],
229
+ }).communities[0];
230
+
231
+ const joiningUser: Amity.RawMembership<'community'> = {
220
232
  ...communityUser11,
221
233
  userId: 'test',
222
234
  communityId: 'joining-community',
@@ -234,14 +246,22 @@ describe('liveCommunities', () => {
234
246
  'it should add new community to collection onJoin',
235
247
  { membership: 'member' },
236
248
  'community.joined',
237
- { communities: [joinCommunityPayload], communityUsers: [joiningUser] },
249
+ {
250
+ ...emptyCommunityPayload,
251
+ communities: [joinCommunityPayload],
252
+ communityUsers: [joiningUser],
253
+ },
238
254
  [joinedCommunity, community1],
239
255
  ],
240
256
  [
241
257
  'it should not add new member to community collection onJoin if membership:not member',
242
258
  { membership: 'notMember' },
243
259
  'community.joined',
244
- { communities: [joinCommunityPayload], communityUsers: [joiningUser] },
260
+ {
261
+ ...emptyCommunityPayload,
262
+ communities: [joinCommunityPayload],
263
+ communityUsers: [joiningUser],
264
+ },
245
265
  [],
246
266
  ],
247
267
  [
@@ -0,0 +1,147 @@
1
+ import { disableCache, enableCache } from '~/cache/api';
2
+ import {
3
+ pause,
4
+ client,
5
+ connectClient,
6
+ disconnectClient,
7
+ community11,
8
+ user11,
9
+ communityUser11,
10
+ communityUser12,
11
+ } from '~/utils/tests';
12
+ import { getFutureDate } from '~/core/model';
13
+
14
+ import { liveCommunity } from '../liveCommunity';
15
+
16
+ const { communityId } = community11;
17
+ const response = {
18
+ data: {
19
+ communities: [community11],
20
+ communityUsers: [communityUser11],
21
+ files: [],
22
+ users: [user11],
23
+ categories: [],
24
+ feeds: [],
25
+ },
26
+ };
27
+
28
+ describe('liveCommunity events', () => {
29
+ beforeAll(connectClient);
30
+ afterAll(disconnectClient);
31
+
32
+ beforeEach(enableCache);
33
+ afterEach(disableCache);
34
+
35
+ const events: [string, keyof Amity.MqttCommunityEvents][] = [
36
+ ['it should get update on community.updated event', 'community.updated'],
37
+ ['it should get update on community.deleted event', 'community.deleted'],
38
+ ];
39
+
40
+ test.each(events)('%s', async (test, event) => {
41
+ const update =
42
+ event === 'community.updated'
43
+ ? {
44
+ ...community11,
45
+ displayName: 'updated-name',
46
+ updatedAt: getFutureDate(community11.updatedAt),
47
+ }
48
+ : {
49
+ ...community11,
50
+ isDeleted: true,
51
+ updatedAt: getFutureDate(community11.updatedAt),
52
+ };
53
+
54
+ const callback = jest.fn();
55
+ client.http.get = jest.fn().mockResolvedValue(response);
56
+
57
+ const unsub = liveCommunity(communityId, callback);
58
+ await pause();
59
+
60
+ client.emitter.emit(event, {
61
+ communities: [update],
62
+ communityUsers: [],
63
+ categories: [],
64
+ feeds: [],
65
+ users: [user11],
66
+ files: [],
67
+ });
68
+ await pause();
69
+
70
+ expect(callback).toHaveBeenCalledTimes(3);
71
+ expect(callback).toHaveBeenNthCalledWith(
72
+ 3,
73
+ expect.objectContaining({
74
+ data: update,
75
+ loading: false,
76
+ }),
77
+ );
78
+
79
+ unsub();
80
+ });
81
+
82
+ const communityUserEvents: [string, keyof Amity.MqttCommunityUserEvents][] = [
83
+ ['it should add user on community.joined event', 'community.joined'],
84
+ ['should get update on community.left event', 'community.left'],
85
+ ['should get update on community.userChanged event', 'community.userChanged'],
86
+ ['should get update on community.userBanned event', 'community.userBanned'],
87
+ ['should get update on community.userUnbanned event', 'community.userUnbanned'],
88
+ ];
89
+
90
+ test.each(communityUserEvents)('%s', async (test, event) => {
91
+ const callback = jest.fn();
92
+ client.http.get = jest.fn().mockResolvedValue(response);
93
+
94
+ const community = {
95
+ ...community11,
96
+ updatedAt: getFutureDate(community11.updatedAt),
97
+ };
98
+ let communityUsers: Amity.RawMembership<'community'>[];
99
+ let communities: Amity.RawCommunity[];
100
+
101
+ switch (event) {
102
+ case 'community.userChanged':
103
+ case 'community.left':
104
+ communityUsers = [communityUser11];
105
+ communities = [{ ...community, isJoined: true }];
106
+ break;
107
+
108
+ case 'community.userBanned':
109
+ communities = [{ ...community, isJoined: true }];
110
+ communityUsers = [{ ...communityUser11, communityMembership: 'banned' }];
111
+ break;
112
+
113
+ case 'community.userUnbanned':
114
+ communityUsers = [communityUser11];
115
+ communities = [{ ...community, isJoined: true }];
116
+ break;
117
+
118
+ // community.joined
119
+ default:
120
+ communities = [community];
121
+ communityUsers = [communityUser12];
122
+ }
123
+
124
+ const unsub = liveCommunity(communityId, callback);
125
+ await pause();
126
+
127
+ client.emitter.emit(event, {
128
+ communities,
129
+ communityUsers,
130
+ categories: [],
131
+ feeds: [],
132
+ users: [user11],
133
+ files: [],
134
+ });
135
+ await pause();
136
+
137
+ expect(callback).toHaveBeenCalledTimes(3);
138
+ expect(callback).toHaveBeenNthCalledWith(
139
+ 3,
140
+ expect.objectContaining({
141
+ data: communities[0],
142
+ }),
143
+ );
144
+
145
+ unsub();
146
+ });
147
+ });
@@ -0,0 +1,195 @@
1
+ import { disableCache, enableCache } from '~/cache/api';
2
+
3
+ import {
4
+ client,
5
+ connectClient,
6
+ disconnectClient,
7
+ pause,
8
+ user11,
9
+ user13,
10
+ community11,
11
+ communityUser11,
12
+ communityUser13,
13
+ withRoleCommunityUser,
14
+ bannedCommunityUser,
15
+ communityUserQueryResponse,
16
+ communityUserQueryResponsePage2,
17
+ convertedCommunityUser1,
18
+ convertedCommunityUser2,
19
+ convertedCommunityUser3,
20
+ } from '~/utils/tests';
21
+
22
+ import { liveCommunityMembers } from '../liveCommunityMembers';
23
+
24
+ const getSnapshot = (params?: Record<string, any>) => {
25
+ return {
26
+ data: [] as Amity.Membership<'community'>[],
27
+ loading: true,
28
+ error: undefined as any,
29
+ ...params,
30
+ };
31
+ };
32
+
33
+ describe('liveCommunityMembers', () => {
34
+ beforeAll(connectClient);
35
+ afterAll(disconnectClient);
36
+
37
+ beforeEach(enableCache);
38
+ afterEach(disableCache);
39
+
40
+ const { communityId } = community11;
41
+
42
+ test('it should return community members collection', async () => {
43
+ const callback = jest.fn();
44
+ client.http.get = jest.fn().mockResolvedValue(communityUserQueryResponse);
45
+
46
+ liveCommunityMembers({ communityId }, callback);
47
+ await pause();
48
+
49
+ expect(callback).toHaveBeenNthCalledWith(1, expect.objectContaining(getSnapshot()));
50
+ expect(callback).toHaveBeenNthCalledWith(
51
+ 2,
52
+ expect.objectContaining(
53
+ getSnapshot({ data: [convertedCommunityUser2, convertedCommunityUser1], loading: false }),
54
+ ),
55
+ );
56
+ });
57
+
58
+ const filters: [string, Amity.CommunityMemberLiveCollection, Amity.Membership<'community'>[]][] =
59
+ [
60
+ ['roles', { communityId, roles: ['test-role'] }, [withRoleCommunityUser]],
61
+ [
62
+ 'searched term',
63
+ { communityId, search: 'use' },
64
+ [withRoleCommunityUser, bannedCommunityUser],
65
+ ],
66
+ ['member', { communityId, membership: ['member'] }, [withRoleCommunityUser]],
67
+ ['banned members', { communityId, membership: ['banned'] }, [bannedCommunityUser]],
68
+ ];
69
+
70
+ test.each(filters)('it should filter channelUsers by %s', async (filter, params, expected) => {
71
+ const callback = jest.fn();
72
+ client.http.get = jest.fn().mockResolvedValue(communityUserQueryResponsePage2);
73
+
74
+ liveCommunityMembers(params, callback);
75
+ await pause();
76
+
77
+ expect(callback).toHaveBeenNthCalledWith(1, expect.objectContaining(getSnapshot()));
78
+ expect(callback).toHaveBeenNthCalledWith(
79
+ 2,
80
+ expect.objectContaining({ data: expected, loading: false }),
81
+ );
82
+ });
83
+
84
+ test('it should return method to fetch next page', async () => {
85
+ const callback = jest.fn();
86
+ client.http.get = jest
87
+ .fn()
88
+ .mockResolvedValue(communityUserQueryResponse)
89
+ .mockResolvedValueOnce(communityUserQueryResponsePage2);
90
+
91
+ liveCommunityMembers({ communityId, sortBy: 'firstCreated' }, callback);
92
+ await pause();
93
+
94
+ expect(callback).toHaveBeenCalled();
95
+ expect(callback.mock.lastCall).toHaveLength(1);
96
+
97
+ const { onNextPage, hasNextPage } = callback.mock.lastCall[0];
98
+
99
+ expect(hasNextPage).toBe(true);
100
+ expect(onNextPage).toBeTruthy();
101
+
102
+ onNextPage();
103
+ await pause();
104
+
105
+ const payload = [convertedCommunityUser1, convertedCommunityUser2];
106
+ const payload2 = [withRoleCommunityUser, bannedCommunityUser];
107
+
108
+ const snapshot = getSnapshot();
109
+ snapshot.loading = false;
110
+ snapshot.data = [...payload2, ...payload];
111
+
112
+ expect(callback).toHaveBeenNthCalledWith(4, expect.objectContaining(snapshot));
113
+ });
114
+
115
+ const events: [
116
+ string,
117
+ keyof Amity.Events,
118
+ Amity.RawMembership<'community'>,
119
+ Amity.User,
120
+ Amity.Membership<'community'>[],
121
+ ][] = [
122
+ [
123
+ 'it should add new member to collection onJoined',
124
+ 'community.joined',
125
+ communityUser13,
126
+ user13,
127
+ [convertedCommunityUser1, convertedCommunityUser3, convertedCommunityUser2],
128
+ ],
129
+ [
130
+ 'it should remove member from collection onLeft',
131
+ 'community.left',
132
+ { ...communityUser11, communityMembership: 'none' },
133
+ user11,
134
+ [{ ...convertedCommunityUser1, communityMembership: 'none' }, convertedCommunityUser2],
135
+ ],
136
+ [
137
+ 'it should add new member to collection onMemberCountChanged',
138
+ 'community.userChanged',
139
+ communityUser13,
140
+ user13,
141
+ [convertedCommunityUser1, convertedCommunityUser3, convertedCommunityUser2],
142
+ ],
143
+ [
144
+ 'it should update member in collection onMemberCountChanged',
145
+ 'community.userChanged',
146
+ { ...communityUser13, communityMembership: 'none' },
147
+ user13,
148
+ [
149
+ convertedCommunityUser1,
150
+ { ...convertedCommunityUser3, communityMembership: 'none' },
151
+ convertedCommunityUser2,
152
+ ],
153
+ ],
154
+ [
155
+ 'it should update member membership on ban',
156
+ 'community.userBanned',
157
+ { ...communityUser11, communityMembership: 'banned' },
158
+ user11,
159
+ [{ ...convertedCommunityUser1, communityMembership: 'banned' }, convertedCommunityUser2],
160
+ ],
161
+ [
162
+ 'it should update membership on Unban',
163
+ 'community.userUnbanned',
164
+ communityUser13,
165
+ user13,
166
+ [convertedCommunityUser1, convertedCommunityUser3, convertedCommunityUser2],
167
+ ],
168
+ ];
169
+
170
+ test.each(events)('%s', async (test, event, communityUserRaw, user, expected) => {
171
+ const callback = jest.fn();
172
+ client.http.get = jest.fn().mockResolvedValue(communityUserQueryResponse);
173
+
174
+ liveCommunityMembers({ communityId, sortBy: 'firstCreated' }, callback);
175
+ await pause();
176
+
177
+ client.emitter.emit(event, {
178
+ communities: [community11],
179
+ communityUsers: [communityUserRaw],
180
+ users: [user],
181
+ files: [],
182
+ });
183
+ await pause();
184
+
185
+ expect(callback).toHaveBeenNthCalledWith(
186
+ 3,
187
+ expect.objectContaining(
188
+ getSnapshot({
189
+ data: expected,
190
+ loading: false,
191
+ }),
192
+ ),
193
+ );
194
+ });
195
+ });
@@ -1,4 +1,5 @@
1
1
  import { CommunityPostSettingMaps, DefaultCommunityPostSetting } from '~/@types';
2
+ import { withUsers } from '~/group/utils';
2
3
 
3
4
  const getMatchPostSetting = (value: {
4
5
  needApprovalOnPostCreation: Amity.RawCommunity['needApprovalOnPostCreation'];
@@ -11,14 +12,11 @@ const getMatchPostSetting = (value: {
11
12
  value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost,
12
13
  ) ?? DefaultCommunityPostSetting;
13
14
 
14
- /*
15
- * Unpack community payload by mapping payload field to postSetting value.
16
- */
17
- export const unpackCommunityPayload = <T extends Amity.CommunityPayload>({
18
- communities,
19
- ...restPayload
20
- }: T) => ({
21
- communities: communities.map<Amity.Community>(
15
+ export const prepareCommunityPayload = (
16
+ rawPayload: Amity.CommunityPayload,
17
+ ): Amity.ProcessedCommunityPayload => {
18
+ // Unpack community payload by mapping payload field to postSetting value.
19
+ const communities = rawPayload.communities.map<Amity.Community>(
22
20
  ({ needApprovalOnPostCreation, onlyAdminCanPost, ...restCommunityPayload }) => ({
23
21
  postSetting: getMatchPostSetting({
24
22
  needApprovalOnPostCreation,
@@ -26,19 +24,27 @@ export const unpackCommunityPayload = <T extends Amity.CommunityPayload>({
26
24
  }),
27
25
  ...restCommunityPayload,
28
26
  }),
29
- ),
30
- ...restPayload,
31
- });
27
+ );
32
28
 
33
- /*
34
- * Repack community payload by mapping postSetting to the actual value.
35
- */
36
- export const packCommunityPayload = <
29
+ const communityUsers = withUsers(rawPayload.communityUsers);
30
+
31
+ return {
32
+ ...rawPayload,
33
+ communities,
34
+ communityUsers,
35
+ };
36
+ };
37
+
38
+ export const prepareCommunityRequest = <
37
39
  T extends { postSetting?: Amity.Community['postSetting']; [k: string]: any },
38
- >({
39
- postSetting = undefined,
40
- ...restParam
41
- }: T) => ({
42
- ...restParam,
43
- ...(postSetting ? CommunityPostSettingMaps[postSetting] : undefined),
44
- });
40
+ >(
41
+ params: T,
42
+ ) => {
43
+ const { postSetting = undefined, ...restParam } = params;
44
+
45
+ return {
46
+ ...restParam,
47
+ // Repack community payload by mapping postSetting to the actual value.
48
+ ...(postSetting ? CommunityPostSettingMaps[postSetting] : undefined),
49
+ };
50
+ };
@@ -1,9 +1,7 @@
1
1
  // TODO: find a way to uniquely identify the device
2
2
  // import { getStorage } from './storage'
3
3
  import { safeProcess } from '~/utils/env';
4
-
5
- /** @hidden */
6
- const VERSION = '11.0.0';
4
+ import { VERSION } from '~/version';
7
5
 
8
6
  /** @hidden */
9
7
  export const getDeviceId = () => {
@@ -30,9 +28,9 @@ export const getDeviceInfo = (): Amity.Device['deviceInfo'] => {
30
28
  const model = getDeviceModel();
31
29
 
32
30
  return {
33
- version: VERSION,
34
31
  // TODO: replace with: kind: process.versions ? 'node' : 'web', when backend has fixed this
35
32
  kind: 'web',
36
33
  model,
34
+ sdkVersion: VERSION,
37
35
  };
38
36
  };
@@ -4,8 +4,9 @@
4
4
  * to avoid using any and give some typing security at the
5
5
  * resolver's level.
6
6
  */
7
- type Resolvers<T extends Amity.Domain[] = Amity.Domain[]> = {
8
- [K in T[number]]: (model: Amity.Minimal[K]) => string;
7
+ type Resolver<T extends Amity.Domain> = (model: Amity.Minimal[T]) => string;
8
+ type Resolvers<T extends Amity.Domain = Amity.Domain> = {
9
+ [K in T]: Resolver<K>;
9
10
  };
10
11
 
11
12
  /** @hidden */
@@ -41,4 +42,4 @@ const idResolvers: Resolvers = {
41
42
  * @param name the domain name for the resolve
42
43
  * @returns an idResolver function for the given domain name
43
44
  */
44
- export const getResolver = <T extends Amity.Domain>(name: T): Resolvers[T] => idResolvers[name];
45
+ export const getResolver = <T extends Amity.Domain>(name: T): Resolver<T> => idResolvers[name];
@@ -5,8 +5,8 @@
5
5
  * adding new models.
6
6
  * @hidden
7
7
  */
8
- type Criterias<T extends Amity.Domain[] = Amity.Domain[]> = {
9
- [K in T[number]]: (keyof Amity.Model[K])[];
8
+ type Criterias<T extends Amity.Domain = Amity.Domain> = {
9
+ [K in T]: (keyof Amity.Models[K])[];
10
10
  };
11
11
 
12
12
  /**
@@ -49,7 +49,7 @@ const hasKeys = (object: Record<string, unknown>, needles: string[]) => {
49
49
  /**
50
50
  * Finds the name of the store for a given unknown model
51
51
  *
52
- * @param model one of the {@link Amity.Model} to identify
52
+ * @param model one of the {@link Amity.Models} to identify
53
53
  * @returns the name of the corresponding store
54
54
  */
55
55
  export const identifyModel = (model: Record<string, unknown>) => {
@@ -23,6 +23,7 @@ export const PAYLOAD2MODEL: Record<string, Amity.Domain> = {
23
23
  comments: 'comment',
24
24
  polls: 'poll',
25
25
  reactions: 'reaction',
26
+
26
27
  videoStreamings: 'stream',
27
28
 
28
29
  follows: 'follow',
@@ -165,6 +165,13 @@ export const runQuery = <Args extends any[], Returned extends any>(
165
165
  callback?: (args: Amity.Snapshot<Returned>) => void,
166
166
  options: Amity.QueryOptions = queryOptions('cache_then_server'),
167
167
  ) => {
168
+ console.warn(
169
+ 'Deprecation Notice: After 1 April 2023, CreateQuery/RunQuery will no longer be supported. You will be able to use the API without either methods. Check https://docs.amity.co/ for details',
170
+ );
171
+ console.warn(
172
+ 'Deprecation Notice: After 1 March 2023, individual module imoprts will no longer be supported. All public APIs will need to be imported from their respective repositories. Ex: CommunityRepository, UserRepository, etc. Check https://docs.amity.co/ for detailed info.',
173
+ );
174
+
168
175
  let local: Returned | undefined;
169
176
 
170
177
  const { lifeSpan } = queryOptions('cache_then_server', options.lifeSpan);
@@ -1,10 +1,10 @@
1
- import { ASCApiError, ASCError } from '~/core/errors';
1
+ import { ASCApiError } from '~/core/errors';
2
2
  import { disableCache, enableCache, pushToCache } from '~/cache/api';
3
3
  import { runQuery, createQuery } from '~/core/query';
4
4
  import { createPost, getPost } from '~/post/api';
5
5
  import { deleteMessage } from '~/message/api';
6
6
 
7
- import { posts, client, pause } from '~/utils/tests';
7
+ import { posts, client, pause, emptyPostPayload } from '~/utils/tests';
8
8
 
9
9
  const createPostArgs: Parameters<typeof createPost> = [
10
10
  {
@@ -54,7 +54,12 @@ describe('Core/Query/runQuery', () => {
54
54
 
55
55
  test('should call callback with server data for invalid cache', async () => {
56
56
  const callback = jest.fn();
57
- client.http.get = jest.fn().mockResolvedValue({ data: { posts: [post] } });
57
+ client.http.get = jest.fn().mockResolvedValue({
58
+ data: {
59
+ ...emptyPostPayload,
60
+ posts: [post],
61
+ },
62
+ });
58
63
 
59
64
  // at the time of writing this test, cache is valid for 2 minutes
60
65
  const expiredDate = Date.parse('04 Dec 1995 00:12:00 GMT');