@amityco/ts-sdk 7.5.4-ec2fdd4.0 → 7.6.1-65b44ce1.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 (75) hide show
  1. package/dist/@types/domains/channel.d.ts +3 -0
  2. package/dist/@types/domains/channel.d.ts.map +1 -1
  3. package/dist/@types/domains/group.d.ts +2 -0
  4. package/dist/@types/domains/group.d.ts.map +1 -1
  5. package/dist/@types/domains/post.d.ts +3 -0
  6. package/dist/@types/domains/post.d.ts.map +1 -1
  7. package/dist/@types/domains/stream.d.ts +4 -0
  8. package/dist/@types/domains/stream.d.ts.map +1 -1
  9. package/dist/channelRepository/api/createChannel.d.ts +3 -1
  10. package/dist/channelRepository/api/createChannel.d.ts.map +1 -1
  11. package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
  12. package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts.map +1 -1
  13. package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts +2 -2
  14. package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts.map +1 -1
  15. package/dist/channelRepository/internalApi/getChannel.d.ts.map +1 -1
  16. package/dist/index.cjs.js +5921 -5734
  17. package/dist/index.esm.js +5758 -5571
  18. package/dist/index.umd.js +3 -3
  19. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +2 -0
  20. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
  21. package/dist/messageRepository/api/deleteMessage.d.ts.map +1 -1
  22. package/dist/messageRepository/observers/getMessages/MessageQueryStreamController.d.ts.map +1 -1
  23. package/dist/postRepository/api/createPost.d.ts.map +1 -1
  24. package/dist/postRepository/utils/payload.d.ts.map +1 -1
  25. package/dist/streamRepository/api/createStream.d.ts +1 -1
  26. package/dist/streamRepository/api/createStream.d.ts.map +1 -1
  27. package/dist/streamRepository/api/editStream.d.ts +18 -0
  28. package/dist/streamRepository/api/editStream.d.ts.map +1 -0
  29. package/dist/streamRepository/api/index.d.ts +1 -0
  30. package/dist/streamRepository/api/index.d.ts.map +1 -1
  31. package/dist/streamRepository/api/updateStream.d.ts +4 -1
  32. package/dist/streamRepository/api/updateStream.d.ts.map +1 -1
  33. package/dist/streamRepository/internalApi/getLiveChat.d.ts +16 -0
  34. package/dist/streamRepository/internalApi/getLiveChat.d.ts.map +1 -0
  35. package/dist/streamRepository/internalApi/getStream.d.ts +2 -2
  36. package/dist/streamRepository/internalApi/getStream.d.ts.map +1 -1
  37. package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
  38. package/dist/utils/linkedObject/channelMemberLinkedObject.d.ts +2 -0
  39. package/dist/utils/linkedObject/channelMemberLinkedObject.d.ts.map +1 -0
  40. package/dist/utils/linkedObject/index.d.ts +1 -0
  41. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  42. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  43. package/dist/utils/linkedObject/streamLinkedObject.d.ts.map +1 -1
  44. package/dist/utils/postTypePredicate.d.ts +5 -3
  45. package/dist/utils/postTypePredicate.d.ts.map +1 -1
  46. package/dist/utils/tests/dummy/community.d.ts +2 -0
  47. package/dist/utils/tests/dummy/community.d.ts.map +1 -1
  48. package/package.json +1 -1
  49. package/src/@types/domains/channel.ts +4 -0
  50. package/src/@types/domains/group.ts +2 -0
  51. package/src/@types/domains/post.ts +3 -0
  52. package/src/@types/domains/stream.ts +4 -0
  53. package/src/channelRepository/api/createChannel.ts +12 -9
  54. package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +3 -1
  55. package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.ts +2 -1
  56. package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.ts +2 -2
  57. package/src/channelRepository/internalApi/getChannel.ts +0 -1
  58. package/src/channelRepository/utils/constructChannelObject.ts +2 -2
  59. package/src/messageRepository/api/deleteMessage.ts +16 -0
  60. package/src/messageRepository/observers/getMessages/MessageQueryStreamController.ts +13 -0
  61. package/src/postRepository/api/createPost.ts +3 -2
  62. package/src/postRepository/utils/payload.ts +37 -1
  63. package/src/streamRepository/api/createStream.ts +4 -1
  64. package/src/streamRepository/api/editStream.ts +51 -0
  65. package/src/streamRepository/api/index.ts +1 -0
  66. package/src/streamRepository/api/updateStream.ts +8 -1
  67. package/src/streamRepository/internalApi/getLiveChat.ts +59 -0
  68. package/src/streamRepository/internalApi/getStream.ts +3 -3
  69. package/src/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.ts +1 -1
  70. package/src/utils/linkedObject/channelLinkedObject.ts +19 -0
  71. package/src/utils/linkedObject/channelMemberLinkedObject.ts +20 -0
  72. package/src/utils/linkedObject/index.ts +2 -0
  73. package/src/utils/linkedObject/postLinkedObject.ts +32 -2
  74. package/src/utils/linkedObject/streamLinkedObject.ts +2 -0
  75. package/src/utils/postTypePredicate.ts +26 -3
@@ -2,3 +2,4 @@ export * from './createStream';
2
2
  export * from './updateStream';
3
3
  export * from './deleteStream';
4
4
  export * from './disposeStream';
5
+ export * from './editStream';
@@ -7,6 +7,9 @@ import { LinkedObject } from '~/utils/linkedObject';
7
7
  id: stream.update
8
8
  */
9
9
  /**
10
+ * @deprecated this function is deprecated,
11
+ * please use {@link Amity.StreamRepository.editStream} instead.
12
+ *
10
13
  * ```js
11
14
  * import { updateStream } from '@amityco/ts-sdk'
12
15
  * const updated = await updateStream(streamId, { title: 'foobar' })
@@ -21,9 +24,13 @@ import { LinkedObject } from '~/utils/linkedObject';
21
24
  * @category Stream API
22
25
  * @async
23
26
  */
27
+
24
28
  export const updateStream = async (
25
29
  streamId: Amity.Stream['streamId'],
26
- patch: Patch<Amity.Stream, 'title' | 'thumbnailFileId' | 'description' | 'metadata'>,
30
+ patch: Patch<
31
+ Amity.Stream,
32
+ 'title' | 'thumbnailFileId' | 'description' | 'metadata' | 'channelEnabled'
33
+ >,
27
34
  ): Promise<Amity.Cached<Amity.Stream>> => {
28
35
  const client = getActiveClient();
29
36
  client.log('stream/updateStream', streamId, patch);
@@ -0,0 +1,59 @@
1
+ import { getActiveClient } from '~/client/api/activeClient';
2
+ import { mergeInCache, pullFromCache } from '~/cache/api';
3
+ import { createChannel } from '~/channelRepository/api/createChannel';
4
+ import { channelLinkedObject } from '~/utils/linkedObject/channelLinkedObject';
5
+ import { getChannel } from '~/channelRepository/internalApi/getChannel';
6
+ import { constructChannelObject } from '~/channelRepository/utils/constructChannelObject';
7
+
8
+ /**
9
+ * ```js
10
+ * import { getStream } from '@amityco/ts-sdk'
11
+ * const stream = await getStream('foobar')
12
+ * ```
13
+ *
14
+ * Fetches a {@link Amity.Channel} object linked with a current stream
15
+ *
16
+ * @param stream {@link Amity.Stream} that has linked live channel
17
+ * @returns the associated {@link Amity.Channel<'live'>} object
18
+ *
19
+ * @category Stream API
20
+ * @async
21
+ */
22
+
23
+ export const getLiveChat = async (
24
+ stream: Amity.InternalStream,
25
+ ): Promise<Amity.Channel<'live'> | undefined> => {
26
+ const client = getActiveClient();
27
+ client.log('stream/getLiveChat', stream.streamId);
28
+
29
+ if (stream.channelId) {
30
+ const channel = pullFromCache<Amity.StaticInternalChannel>([
31
+ 'channel',
32
+ 'get',
33
+ stream.channelId,
34
+ ])?.data;
35
+
36
+ if (channel) return channelLinkedObject(constructChannelObject(channel));
37
+
38
+ const { data } = await getChannel(stream.channelId);
39
+ return channelLinkedObject(constructChannelObject(data));
40
+ }
41
+ // No Channel ID
42
+ // streamer: create a new live channel
43
+ if (stream.userId === client.userId) {
44
+ const { data: channel } = await createChannel({
45
+ type: 'live',
46
+ postId: stream.postId,
47
+ videoStreamId: stream.streamId,
48
+ });
49
+
50
+ // Update channelId to stream object in cache
51
+ mergeInCache(['stream', 'get', stream.streamId], {
52
+ channelId: channel.channelId,
53
+ });
54
+
55
+ return channel;
56
+ }
57
+ // watcher: return undefined
58
+ return undefined;
59
+ };
@@ -22,7 +22,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
22
22
  */
23
23
  export const getStream = async (
24
24
  streamId: Amity.Stream['streamId'],
25
- ): Promise<Amity.Cached<Amity.Stream>> => {
25
+ ): Promise<Amity.Cached<Amity.InternalStream>> => {
26
26
  const client = getActiveClient();
27
27
  client.log('stream/getStream', streamId);
28
28
 
@@ -57,13 +57,13 @@ export const getStream = async (
57
57
  */
58
58
  getStream.locally = (
59
59
  streamId: Amity.Stream['streamId'],
60
- ): Amity.Cached<Amity.Stream> | undefined => {
60
+ ): Amity.Cached<Amity.InternalStream> | undefined => {
61
61
  const client = getActiveClient();
62
62
  client.log('stream/getStream', streamId);
63
63
 
64
64
  if (!client.cache) return;
65
65
 
66
- const cached = pullFromCache<Amity.Stream>(['stream', 'get', streamId]);
66
+ const cached = pullFromCache<Amity.InternalStream>(['stream', 'get', streamId]);
67
67
 
68
68
  if (!cached) return;
69
69
 
@@ -102,7 +102,7 @@ export class GetStreamsLiveCollectionController extends LiveCollectionController
102
102
  this.queryStreamController.appendToQueryStream(response, direction, refresh);
103
103
  }
104
104
 
105
- private applyFilter = (data: Amity.InternalStream[]): Amity.InternalStream[] => {
105
+ private applyFilter = (data: Amity.Stream[]): Amity.Stream[] => {
106
106
  let streams = filterByPropEquality(data, 'isDeleted', this.query.isDeleted);
107
107
 
108
108
  streams = streams.sort(
@@ -1,8 +1,27 @@
1
1
  import { markAsRead } from '~/channelRepository/internalApi/markAsRead';
2
2
  import { shallowClone } from '../shallowClone';
3
+ import { queryCache } from '~/cache/api';
4
+ import { channelMemberLinkedObject } from './channelMemberLinkedObject';
3
5
 
4
6
  export const channelLinkedObject = (channel: Amity.InternalChannel): Amity.Channel => {
7
+ let previewMembers: Amity.Membership<'channel'>[] = [];
8
+
9
+ if (channel.type === 'conversation') {
10
+ const channelUsers = queryCache<Amity.Membership<'channel'>>(['channelUsers', 'get']);
11
+ if (channelUsers && channelUsers?.length > 0) {
12
+ previewMembers = (
13
+ channelUsers?.filter(({ data }) => data.channelId === channel.channelId) ?? []
14
+ )
15
+ // sort in ascending order by userInternalId
16
+ .sort((a, b) => a.data.userInternalId.localeCompare(b.data.userInternalId))
17
+ // Select only first 4 members
18
+ .slice(0, 4)
19
+ .map(({ data }) => channelMemberLinkedObject(data));
20
+ }
21
+ }
22
+
5
23
  return shallowClone(channel, {
6
24
  markAsRead: () => markAsRead(channel.channelInternalId),
25
+ previewMembers,
7
26
  });
8
27
  };
@@ -0,0 +1,20 @@
1
+ import { pullFromCache } from '~/cache/api/pullFromCache';
2
+ import { userLinkedObject } from './userLinkedObject';
3
+
4
+ export const channelMemberLinkedObject = (
5
+ channelMember: Amity.Membership<'channel'>,
6
+ ): Amity.Membership<'channel'> => {
7
+ const getUser = (): Amity.User | undefined => {
8
+ const cacheKey = ['user', 'get', channelMember.userId];
9
+ const internalUser = pullFromCache<Amity.InternalUser>(cacheKey)?.data;
10
+
11
+ return internalUser ? userLinkedObject(internalUser) : undefined;
12
+ };
13
+
14
+ return {
15
+ ...channelMember,
16
+ get user() {
17
+ return getUser();
18
+ },
19
+ };
20
+ };
@@ -14,6 +14,7 @@ import { notificationTrayLinkedObject } from './notificationTrayLinkedObject';
14
14
  import { communityLinkedObject } from './communityLinkedObject';
15
15
  import { invitationLinkedObject } from './invitationLinkedObject';
16
16
  import { joinRequestLinkedObject } from './joinRequestLinkedObject';
17
+ import { channelMemberLinkedObject } from './channelMemberLinkedObject';
17
18
 
18
19
  export const LinkedObject = {
19
20
  ad: adLinkedObject,
@@ -32,4 +33,5 @@ export const LinkedObject = {
32
33
  community: communityLinkedObject,
33
34
  invitation: invitationLinkedObject,
34
35
  joinRequest: joinRequestLinkedObject,
36
+ channelMember: channelMemberLinkedObject,
35
37
  };
@@ -2,12 +2,23 @@ import { pullFromCache } from '~/cache/api';
2
2
  import { commentLinkedObject } from '~/utils/linkedObject/commentLinkedObject';
3
3
  import AnalyticsEngine from '../../analytic/service/analytic/AnalyticsEngine';
4
4
  import { userLinkedObject } from './userLinkedObject';
5
- import { isAmityFilePost, isAmityImagePost, isAmityVideoPost } from '../postTypePredicate';
5
+ import {
6
+ isAmityFilePost,
7
+ isAmityImagePost,
8
+ isAmityLivestreamPost,
9
+ isAmityPollPost,
10
+ isAmityVideoPost,
11
+ } from '../postTypePredicate';
12
+ import { streamLinkedObject } from './streamLinkedObject';
13
+ import { isNonNullable } from '..';
6
14
 
7
15
  export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
8
16
  return {
9
17
  ...post,
10
-
18
+ childrenPosts: post.children
19
+ .map(childPost => pullFromCache<Amity.InternalPost>(['post', 'get', childPost])?.data)
20
+ .filter(isNonNullable)
21
+ .map(postLinkedObject),
11
22
  analytics: {
12
23
  markAsViewed: () => {
13
24
  const analyticsEngineInstance = AnalyticsEngine.getInstance();
@@ -64,5 +75,24 @@ export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
64
75
  ? pullFromCache<Amity.File<'file'>>(['file', 'get', post?.data?.fileId])?.data
65
76
  : undefined;
66
77
  },
78
+
79
+ getLivestreamInfo(): Amity.Stream | undefined {
80
+ if (!isAmityLivestreamPost(post)) return;
81
+ const cache = pullFromCache<Amity.InternalStream>([
82
+ 'stream',
83
+ 'get',
84
+ post?.data?.streamId,
85
+ ])?.data;
86
+ if (!cache) return;
87
+
88
+ return streamLinkedObject(cache);
89
+ },
90
+
91
+ getPollInfo(): Amity.Poll | undefined {
92
+ if (!isAmityPollPost(post)) return;
93
+ const cache = pullFromCache<Amity.Poll>(['poll', 'get', post?.data?.pollId])?.data;
94
+ if (!cache) return;
95
+ return cache;
96
+ },
67
97
  };
68
98
  };
@@ -1,4 +1,5 @@
1
1
  import { pullFromCache } from '~/cache/api';
2
+ import { getLiveChat as _getLiveChat } from '~/streamRepository/internalApi/getLiveChat';
2
3
 
3
4
  export const streamLinkedObject = (stream: Amity.InternalStream): Amity.Stream => {
4
5
  return {
@@ -18,5 +19,6 @@ export const streamLinkedObject = (stream: Amity.InternalStream): Amity.Stream =
18
19
  get user() {
19
20
  return pullFromCache<Amity.User>(['user', 'get', stream.userId])?.data;
20
21
  },
22
+ getLiveChat: () => _getLiveChat(stream),
21
23
  };
22
24
  };
@@ -1,5 +1,6 @@
1
- export function isAmityImagePost(post: Amity.InternalPost): post is Amity.Post<'image'> {
1
+ export function isAmityImagePost(post?: Amity.InternalPost): post is Amity.Post<'image'> {
2
2
  return !!(
3
+ post &&
3
4
  post.data &&
4
5
  typeof post.data !== 'string' &&
5
6
  'fileId' in post.data &&
@@ -7,8 +8,9 @@ export function isAmityImagePost(post: Amity.InternalPost): post is Amity.Post<'
7
8
  );
8
9
  }
9
10
 
10
- export function isAmityFilePost(post: Amity.InternalPost): post is Amity.Post<'file'> {
11
+ export function isAmityFilePost(post?: Amity.InternalPost): post is Amity.Post<'file'> {
11
12
  return !!(
13
+ post &&
12
14
  post.data &&
13
15
  typeof post.data !== 'string' &&
14
16
  'fileId' in post.data &&
@@ -16,8 +18,9 @@ export function isAmityFilePost(post: Amity.InternalPost): post is Amity.Post<'f
16
18
  );
17
19
  }
18
20
 
19
- export function isAmityVideoPost(post: Amity.InternalPost): post is Amity.Post<'video'> {
21
+ export function isAmityVideoPost(post?: Amity.InternalPost): post is Amity.Post<'video'> {
20
22
  return !!(
23
+ post &&
21
24
  post.data &&
22
25
  typeof post.data !== 'string' &&
23
26
  'videoFileId' in post.data &&
@@ -25,3 +28,23 @@ export function isAmityVideoPost(post: Amity.InternalPost): post is Amity.Post<'
25
28
  post.dataType === 'video'
26
29
  );
27
30
  }
31
+
32
+ export function isAmityLivestreamPost(post?: Amity.InternalPost): post is Amity.Post<'liveStream'> {
33
+ return !!(
34
+ post &&
35
+ post.data &&
36
+ typeof post.data !== 'string' &&
37
+ 'streamId' in post.data &&
38
+ post.dataType === 'liveStream'
39
+ );
40
+ }
41
+
42
+ export function isAmityPollPost(post?: Amity.InternalPost): post is Amity.Post<'poll'> {
43
+ return !!(
44
+ post &&
45
+ post.data &&
46
+ typeof post.data !== 'string' &&
47
+ 'pollId' in post.data &&
48
+ post.dataType === 'poll'
49
+ );
50
+ }