@amityco/ts-sdk 7.11.1-b8fc6951.0 → 7.11.1-bd338235.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 (146) hide show
  1. package/dist/@types/core/events.d.ts +13 -32
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +3 -2
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +4 -15
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/core/transport.d.ts +0 -3
  8. package/dist/@types/core/transport.d.ts.map +1 -1
  9. package/dist/@types/domains/community.d.ts +1 -8
  10. package/dist/@types/domains/community.d.ts.map +1 -1
  11. package/dist/@types/domains/content.d.ts +4 -1
  12. package/dist/@types/domains/content.d.ts.map +1 -1
  13. package/dist/@types/domains/feed.d.ts +2 -1
  14. package/dist/@types/domains/feed.d.ts.map +1 -1
  15. package/dist/@types/domains/partials.d.ts +2 -2
  16. package/dist/@types/domains/partials.d.ts.map +1 -1
  17. package/dist/@types/domains/post.d.ts +2 -0
  18. package/dist/@types/domains/post.d.ts.map +1 -1
  19. package/dist/@types/domains/room.d.ts +74 -0
  20. package/dist/@types/domains/room.d.ts.map +1 -0
  21. package/dist/@types/index.d.ts +2 -1
  22. package/dist/@types/index.d.ts.map +1 -1
  23. package/dist/core/events.d.ts +3 -3
  24. package/dist/core/events.d.ts.map +1 -1
  25. package/dist/core/model/index.d.ts.map +1 -1
  26. package/dist/index.cjs.js +1295 -1020
  27. package/dist/index.d.ts +1 -1
  28. package/dist/index.d.ts.map +1 -1
  29. package/dist/index.esm.js +747 -472
  30. package/dist/index.umd.js +3 -3
  31. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -1
  32. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
  33. package/dist/roomRepository/api/createRoom.d.ts +24 -0
  34. package/dist/roomRepository/api/createRoom.d.ts.map +1 -0
  35. package/dist/roomRepository/api/deleteRoom.d.ts +16 -0
  36. package/dist/roomRepository/api/deleteRoom.d.ts.map +1 -0
  37. package/dist/roomRepository/api/getRecordedUrl.d.ts +19 -0
  38. package/dist/roomRepository/api/getRecordedUrl.d.ts.map +1 -0
  39. package/dist/roomRepository/api/getRoomToken.d.ts +16 -0
  40. package/dist/roomRepository/api/getRoomToken.d.ts.map +1 -0
  41. package/dist/roomRepository/api/index.d.ts +7 -0
  42. package/dist/roomRepository/api/index.d.ts.map +1 -0
  43. package/dist/roomRepository/api/stopRoom.d.ts +16 -0
  44. package/dist/roomRepository/api/stopRoom.d.ts.map +1 -0
  45. package/dist/roomRepository/api/updateRoom.d.ts +24 -0
  46. package/dist/roomRepository/api/updateRoom.d.ts.map +1 -0
  47. package/dist/roomRepository/events/index.d.ts +12 -0
  48. package/dist/roomRepository/events/index.d.ts.map +1 -0
  49. package/dist/roomRepository/events/onRoomCreated.d.ts +17 -0
  50. package/dist/roomRepository/events/onRoomCreated.d.ts.map +1 -0
  51. package/dist/roomRepository/events/onRoomDeleted.d.ts +17 -0
  52. package/dist/roomRepository/events/onRoomDeleted.d.ts.map +1 -0
  53. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts +17 -0
  54. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts.map +1 -0
  55. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts +17 -0
  56. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts.map +1 -0
  57. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts +17 -0
  58. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts.map +1 -0
  59. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts +17 -0
  60. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts.map +1 -0
  61. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts +17 -0
  62. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts.map +1 -0
  63. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts +17 -0
  64. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts.map +1 -0
  65. package/dist/roomRepository/events/onRoomStopped.d.ts +17 -0
  66. package/dist/roomRepository/events/onRoomStopped.d.ts.map +1 -0
  67. package/dist/roomRepository/events/onRoomUpdated.d.ts +17 -0
  68. package/dist/roomRepository/events/onRoomUpdated.d.ts.map +1 -0
  69. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts +17 -0
  70. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts.map +1 -0
  71. package/dist/roomRepository/index.d.ts.map +1 -0
  72. package/dist/roomRepository/internalApi/getRoomById.d.ts +5 -0
  73. package/dist/roomRepository/internalApi/getRoomById.d.ts.map +1 -0
  74. package/dist/roomRepository/internalApi/index.d.ts +2 -0
  75. package/dist/roomRepository/internalApi/index.d.ts.map +1 -0
  76. package/dist/roomRepository/observers/enums.d.ts +10 -0
  77. package/dist/roomRepository/observers/enums.d.ts.map +1 -0
  78. package/dist/roomRepository/observers/getRoom.d.ts +2 -0
  79. package/dist/roomRepository/observers/getRoom.d.ts.map +1 -0
  80. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts +14 -0
  81. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts.map +1 -0
  82. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts +5 -0
  83. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts.map +1 -0
  84. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts +15 -0
  85. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts.map +1 -0
  86. package/dist/roomRepository/observers/getRooms.d.ts +29 -0
  87. package/dist/roomRepository/observers/getRooms.d.ts.map +1 -0
  88. package/dist/roomRepository/observers/index.d.ts +3 -0
  89. package/dist/roomRepository/observers/index.d.ts.map +1 -0
  90. package/dist/roomRepository/observers/utils.d.ts +6 -0
  91. package/dist/roomRepository/observers/utils.d.ts.map +1 -0
  92. package/dist/utils/linkedObject/index.d.ts +0 -1
  93. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  94. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  95. package/dist/utils/linkedObject/roomLinkedObject.d.ts +4 -0
  96. package/dist/utils/linkedObject/roomLinkedObject.d.ts.map +1 -0
  97. package/dist/utils/postTypePredicate.d.ts +1 -0
  98. package/dist/utils/postTypePredicate.d.ts.map +1 -1
  99. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  100. package/package.json +1 -1
  101. package/dist/@types/domains/event.d.ts +0 -66
  102. package/dist/@types/domains/event.d.ts.map +0 -1
  103. package/dist/eventRepository/api/createEvent.d.ts +0 -16
  104. package/dist/eventRepository/api/createEvent.d.ts.map +0 -1
  105. package/dist/eventRepository/api/deleteEvent.d.ts +0 -15
  106. package/dist/eventRepository/api/deleteEvent.d.ts.map +0 -1
  107. package/dist/eventRepository/api/index.d.ts +0 -4
  108. package/dist/eventRepository/api/index.d.ts.map +0 -1
  109. package/dist/eventRepository/api/updateEvent.d.ts +0 -17
  110. package/dist/eventRepository/api/updateEvent.d.ts.map +0 -1
  111. package/dist/eventRepository/events/enums.d.ts +0 -6
  112. package/dist/eventRepository/events/enums.d.ts.map +0 -1
  113. package/dist/eventRepository/events/index.d.ts +0 -4
  114. package/dist/eventRepository/events/index.d.ts.map +0 -1
  115. package/dist/eventRepository/events/onEventCreated.d.ts +0 -17
  116. package/dist/eventRepository/events/onEventCreated.d.ts.map +0 -1
  117. package/dist/eventRepository/events/onEventDeleted.d.ts +0 -17
  118. package/dist/eventRepository/events/onEventDeleted.d.ts.map +0 -1
  119. package/dist/eventRepository/events/onEventUpdated.d.ts +0 -17
  120. package/dist/eventRepository/events/onEventUpdated.d.ts.map +0 -1
  121. package/dist/eventRepository/index.d.ts.map +0 -1
  122. package/dist/eventRepository/internalApi/getEvent.d.ts +0 -32
  123. package/dist/eventRepository/internalApi/getEvent.d.ts.map +0 -1
  124. package/dist/eventRepository/internalApi/index.d.ts +0 -2
  125. package/dist/eventRepository/internalApi/index.d.ts.map +0 -1
  126. package/dist/eventRepository/observers/getEvent.d.ts +0 -21
  127. package/dist/eventRepository/observers/getEvent.d.ts.map +0 -1
  128. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts +0 -13
  129. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +0 -1
  130. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts +0 -5
  131. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts.map +0 -1
  132. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts +0 -15
  133. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts.map +0 -1
  134. package/dist/eventRepository/observers/getEvents.d.ts +0 -12
  135. package/dist/eventRepository/observers/getEvents.d.ts.map +0 -1
  136. package/dist/eventRepository/observers/index.d.ts +0 -3
  137. package/dist/eventRepository/observers/index.d.ts.map +0 -1
  138. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +0 -2
  139. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +0 -1
  140. package/dist/eventRepository/utils/index.d.ts +0 -3
  141. package/dist/eventRepository/utils/index.d.ts.map +0 -1
  142. package/dist/eventRepository/utils/prepareEventPayload.d.ts +0 -2
  143. package/dist/eventRepository/utils/prepareEventPayload.d.ts.map +0 -1
  144. package/dist/utils/linkedObject/eventLinkObject.d.ts +0 -2
  145. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +0 -1
  146. /package/dist/{eventRepository → roomRepository}/index.d.ts +0 -0
package/dist/index.cjs.js CHANGED
@@ -127,6 +127,7 @@ const PostContentType = Object.freeze({
127
127
  POLL: 'poll',
128
128
  CLIP: 'clip',
129
129
  AUDIO: 'audio',
130
+ ROOM: 'room',
130
131
  });
131
132
  const PostStructureType = Object.freeze({
132
133
  TEXT: 'text',
@@ -178,6 +179,7 @@ exports.FeedDataTypeEnum = void 0;
178
179
  FeedDataTypeEnum["LiveStream"] = "liveStream";
179
180
  FeedDataTypeEnum["Clip"] = "clip";
180
181
  FeedDataTypeEnum["Poll"] = "poll";
182
+ FeedDataTypeEnum["Room"] = "room";
181
183
  })(exports.FeedDataTypeEnum || (exports.FeedDataTypeEnum = {}));
182
184
  exports.FeedSortByEnum = void 0;
183
185
  (function (FeedSortByEnum) {
@@ -192,24 +194,6 @@ exports.FeedSourceEnum = void 0;
192
194
  FeedSourceEnum["User"] = "user";
193
195
  })(exports.FeedSourceEnum || (exports.FeedSourceEnum = {}));
194
196
 
195
- exports.AmityEventType = void 0;
196
- (function (AmityEventType) {
197
- AmityEventType["Virtual"] = "virtual";
198
- AmityEventType["InPerson"] = "in_person";
199
- })(exports.AmityEventType || (exports.AmityEventType = {}));
200
- exports.AmityEventOriginType = void 0;
201
- (function (AmityEventOriginType) {
202
- AmityEventOriginType["Community"] = "community";
203
- AmityEventOriginType["User"] = "user";
204
- })(exports.AmityEventOriginType || (exports.AmityEventOriginType = {}));
205
- exports.AmityEventStatus = void 0;
206
- (function (AmityEventStatus) {
207
- AmityEventStatus["Scheduled"] = "scheduled";
208
- AmityEventStatus["Live"] = "live";
209
- AmityEventStatus["Ended"] = "ended";
210
- AmityEventStatus["Cancelled"] = "cancelled";
211
- })(exports.AmityEventStatus || (exports.AmityEventStatus = {}));
212
-
213
197
  function getVersion() {
214
198
  try {
215
199
  // the string ''v7.11.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
@@ -658,7 +642,7 @@ const idResolvers = {
658
642
  notificationTraySeen: ({ userId }) => userId,
659
643
  invitation: ({ _id }) => _id,
660
644
  joinRequest: ({ joinRequestId }) => joinRequestId,
661
- event: ({ eventId }) => eventId,
645
+ room: ({ roomId }) => roomId,
662
646
  };
663
647
  /**
664
648
  * Retrieve the id resolver matching a domain name
@@ -714,8 +698,7 @@ const PAYLOAD2MODEL = {
714
698
  notificationTrayItems: 'notificationTrayItem',
715
699
  invitations: 'invitation',
716
700
  joinRequests: 'joinRequest',
717
- events: 'event',
718
- discussionCommunities: 'community',
701
+ rooms: 'room',
719
702
  };
720
703
  /** hidden */
721
704
  const isOutdated = (prevData, nextData) => {
@@ -12228,6 +12211,12 @@ function isAmityAudioPost(post) {
12228
12211
  'fileId' in post.data &&
12229
12212
  post.dataType === 'audio');
12230
12213
  }
12214
+ function isAmityRoomPost(post) {
12215
+ return !!(post.data &&
12216
+ typeof post.data !== 'string' &&
12217
+ 'roomId' in post.data &&
12218
+ post.dataType === 'room');
12219
+ }
12231
12220
 
12232
12221
  const postLinkedObject = (post) => {
12233
12222
  return shallowClone(post, {
@@ -12322,6 +12311,12 @@ const postLinkedObject = (post) => {
12322
12311
  ? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
12323
12312
  : undefined;
12324
12313
  },
12314
+ getRoomInfo() {
12315
+ var _a, _b;
12316
+ if (!isAmityRoomPost(post))
12317
+ return;
12318
+ return (_b = pullFromCache(['room', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.roomId])) === null || _b === void 0 ? void 0 : _b.data;
12319
+ },
12325
12320
  });
12326
12321
  };
12327
12322
 
@@ -13679,35 +13674,6 @@ const communityLinkedObject = (community) => {
13679
13674
  } });
13680
13675
  };
13681
13676
 
13682
- const eventLinkedObject = (event) => {
13683
- return Object.assign(Object.assign({}, event), { get creator() {
13684
- const cacheData = pullFromCache(['user', 'get', event.userId]);
13685
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13686
- return;
13687
- return userLinkedObject(cacheData.data);
13688
- },
13689
- get discussionCommunity() {
13690
- if (!event.discussionCommunityId)
13691
- return;
13692
- const cacheData = pullFromCache([
13693
- 'community',
13694
- 'get',
13695
- event.discussionCommunityId,
13696
- ]);
13697
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13698
- return;
13699
- return communityLinkedObject(cacheData.data);
13700
- },
13701
- get liveStream() {
13702
- if (!event.livestreamId)
13703
- return;
13704
- const cacheData = pullFromCache(['stream', 'get', event.livestreamId]);
13705
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13706
- return;
13707
- return cacheData.data;
13708
- } });
13709
- };
13710
-
13711
13677
  const LinkedObject = {
13712
13678
  ad: adLinkedObject,
13713
13679
  comment: commentLinkedObject,
@@ -13726,7 +13692,6 @@ const LinkedObject = {
13726
13692
  invitation: invitationLinkedObject,
13727
13693
  joinRequest: joinRequestLinkedObject,
13728
13694
  channelMember: channelMemberLinkedObject,
13729
- event: eventLinkedObject,
13730
13695
  };
13731
13696
 
13732
13697
  /* begin_public_function
@@ -27712,328 +27677,1051 @@ var index$8 = /*#__PURE__*/Object.freeze({
27712
27677
  });
27713
27678
 
27714
27679
  /* begin_public_function
27715
- id: poll.create
27680
+ id: room.create
27716
27681
  */
27717
27682
  /**
27718
27683
  * ```js
27719
- * import { createPoll } from '@amityco/ts-sdk'
27720
- * const created = await createPoll({
27721
- * question: 'question',
27722
- * answers: [
27723
- * { dataType: 'text', data: 'answer1', fileId: 'fileId1' },
27724
- * { dataType: 'text', data: 'answer2', fileId: 'fileId2' },
27725
- * ],
27726
- * closedIn: 1649136484
27727
- * }))
27684
+ * import { createRoom } from '@amityco/ts-sdk'
27685
+ * const created = await createRoom({ title: 'my room', 'thumbnailFileId': fileId })
27728
27686
  * ```
27729
27687
  *
27730
- * Creates an {@link Amity.Poll}
27688
+ * Creates an {@link Amity.Room}
27731
27689
  *
27732
- * @param bundle The data necessary to create a new {@link Amity.Poll}
27733
- * @returns The newly created {@link Amity.Poll}
27690
+ * @param bundle The data necessary to create a new {@link Amity.Room}
27691
+ * @returns The newly created {@link Amity.Room}
27734
27692
  *
27735
- * @category Poll API
27693
+ * @category Room API
27736
27694
  * @async
27737
27695
  */
27738
- const createPoll = async (bundle) => {
27696
+ const createRoom = async (bundle) => {
27739
27697
  const client = getActiveClient();
27740
- client.log('post/createPoll', bundle);
27741
- const { data } = await client.http.post('/api/v3/polls', bundle);
27698
+ client.log('room/createRoom', bundle);
27699
+ const { data } = await client.http.post('/api/v1/rooms', bundle);
27700
+ fireEvent('local.room.created', data);
27742
27701
  const cachedAt = client.cache && Date.now();
27702
+ // TODO: check if should pick `users` filed which contains participants - if no need to ingest in the cache
27743
27703
  if (client.cache)
27744
27704
  ingestInCache(data, { cachedAt });
27745
- const { polls } = data;
27705
+ const { rooms } = data;
27746
27706
  return {
27747
- data: polls[0],
27707
+ data: rooms[0],
27748
27708
  cachedAt,
27749
27709
  };
27750
27710
  };
27751
27711
  /* end_public_function */
27752
27712
 
27753
27713
  /* begin_public_function
27754
- id: poll.close
27714
+ id: room.update
27755
27715
  */
27756
27716
  /**
27757
27717
  * ```js
27758
- * import { closePoll } from '@amityco/ts-sdk'
27759
- * const updated = await closePoll(pollId)
27718
+ * import { updateRoom } from '@amityco/ts-sdk'
27719
+ * const updated = await updateRoom('roomId', { title: 'updated title' })
27760
27720
  * ```
27761
27721
  *
27762
- * Updates an {@link Amity.Poll}
27722
+ * Updates an {@link Amity.InternalRoom}
27763
27723
  *
27764
- * @param pollId The ID of the {@link Amity.Poll} to close
27765
- * @returns the updated {@link Amity.Poll} object
27724
+ * @param roomId The ID of the room to update
27725
+ * @param bundle The data to update the room with
27726
+ * @returns The updated {@link Amity.InternalRoom}
27766
27727
  *
27767
- * @category Poll API
27728
+ * @category Room API
27768
27729
  * @async
27769
27730
  */
27770
- const closePoll = async (pollId) => {
27731
+ const updateRoom = async (roomId, bundle) => {
27771
27732
  const client = getActiveClient();
27772
- client.log('user/closePoll', pollId);
27773
- const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}`, { status: 'closed' });
27733
+ client.log('room/updateRoom', { roomId, bundle });
27734
+ const { data } = await client.http.put(`/api/v1/rooms/${roomId}`, bundle);
27735
+ fireEvent('local.room.updated', data);
27774
27736
  const cachedAt = client.cache && Date.now();
27775
27737
  if (client.cache)
27776
27738
  ingestInCache(data, { cachedAt });
27777
- fireEvent('poll.updated', data);
27778
- const { polls } = data;
27739
+ const { rooms } = data;
27779
27740
  return {
27780
- data: polls.find(poll => poll.pollId === pollId),
27741
+ data: rooms[0],
27781
27742
  cachedAt,
27782
27743
  };
27783
27744
  };
27784
27745
  /* end_public_function */
27785
27746
 
27786
27747
  /* begin_public_function
27787
- id: poll.get
27748
+ id: room.delete
27788
27749
  */
27789
27750
  /**
27790
27751
  * ```js
27791
- * import { getPoll } from '@amityco/ts-sdk'
27792
- * const poll = await getPoll('foobar')
27752
+ * import { deleteRoom } from '@amityco/ts-sdk'
27753
+ * const result = await deleteRoom('roomId')
27793
27754
  * ```
27794
27755
  *
27795
- * Fetches a {@link Amity.Poll} object
27756
+ * Deletes an {@link Amity.Room}
27796
27757
  *
27797
- * @param pollId the ID of the {@link Amity.Poll} to fetch
27798
- * @returns the associated {@link Amity.Poll} object
27758
+ * @param roomId The ID of the room to delete
27759
+ * @returns Promise that resolves when the room is deleted
27799
27760
  *
27800
- * @category Poll API
27761
+ * @category Room API
27801
27762
  * @async
27802
27763
  */
27803
- const getPoll$1 = async (pollId) => {
27764
+ const deleteRoom = async (roomId) => {
27804
27765
  const client = getActiveClient();
27805
- client.log('poll/getPoll', pollId);
27806
- const { data } = await client.http.get(`/api/v3/polls/${pollId}`);
27807
- const cachedAt = client.cache && Date.now();
27808
- if (client.cache)
27809
- ingestInCache(data, { cachedAt });
27810
- const { polls } = data;
27811
- return {
27812
- data: polls.find(poll => poll.pollId === pollId),
27813
- cachedAt,
27814
- };
27766
+ client.log('room/deleteRoom', { roomId });
27767
+ await client.http.delete(`/api/v1/rooms/${roomId}`);
27768
+ fireEvent('local.room.deleted', { rooms: [{ _id: roomId }] });
27815
27769
  };
27816
27770
  /* end_public_function */
27771
+
27772
+ /* begin_public_function
27773
+ id: room.stop
27774
+ */
27817
27775
  /**
27818
27776
  * ```js
27819
- * import { getPoll } from '@amityco/ts-sdk'
27820
- * const poll = getPoll.locally('foobar')
27777
+ * import { stopRoom } from '@amityco/ts-sdk'
27778
+ * const result = await stopRoom('roomId')
27821
27779
  * ```
27822
27780
  *
27823
- * Fetches a {@link Amity.Poll} object
27781
+ * Stops a room's broadcasting
27824
27782
  *
27825
- * @param pollId the ID of the {@link Amity.Poll} to fetch
27826
- * @returns the associated {@link Amity.Poll} object
27783
+ * @param roomId The ID of the room to stop
27784
+ * @returns The updated room data
27827
27785
  *
27828
- * @category Poll API
27786
+ * @category Room API
27787
+ * @async
27829
27788
  */
27830
- getPoll$1.locally = (pollId) => {
27789
+ const stopRoom = async (roomId) => {
27831
27790
  const client = getActiveClient();
27832
- client.log('poll/getPoll', pollId);
27833
- if (!client.cache)
27834
- return;
27835
- const cached = pullFromCache(['poll', 'get', pollId]);
27836
- if (!cached)
27837
- return;
27791
+ client.log('room/stopRoom', { roomId });
27792
+ const { data } = await client.http.post(`/api/v1/rooms/${roomId}/stop`);
27793
+ fireEvent('local.room.stopped', data);
27794
+ const cachedAt = client.cache && Date.now();
27795
+ if (client.cache)
27796
+ ingestInCache(data, { cachedAt });
27797
+ const { rooms } = data;
27838
27798
  return {
27839
- data: cached.data,
27840
- cachedAt: cached.cachedAt,
27799
+ data: rooms[0],
27800
+ cachedAt,
27841
27801
  };
27842
27802
  };
27803
+ /* end_public_function */
27843
27804
 
27844
27805
  /* begin_public_function
27845
- id: poll.delete
27806
+ id: room.getBroadcasterData
27846
27807
  */
27847
27808
  /**
27848
27809
  * ```js
27849
- * import { deletePoll } from '@amityco/ts-sdk'
27850
- * const success = await deletePoll(pollId)
27810
+ * import { getBroadcasterData } from '@amityco/ts-sdk'
27811
+ * const token = await getBroadcasterData('roomId')
27851
27812
  * ```
27852
27813
  *
27853
- * Deletes a {@link Amity.Poll}
27814
+ * Gets an access token for a room
27854
27815
  *
27855
- * @param pollId The {@link Amity.Poll} ID to delete
27856
- * @return A success boolean if the {@link Amity.Poll} was deleted
27816
+ * @param roomId The ID of the room to get token for
27817
+ * @returns The room access token
27857
27818
  *
27858
- * @category Poll API
27819
+ * @category Room API
27859
27820
  * @async
27860
27821
  */
27861
- const deletePoll = async (pollId) => {
27822
+ const getBroadcasterData = async (roomId) => {
27862
27823
  const client = getActiveClient();
27863
- client.log('poll/deletePoll', pollId);
27864
- const poll = await getPoll$1(pollId);
27865
- // API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
27866
- const { data } = await client.http.delete(`/api/v3/polls/${pollId}`);
27867
- const { success } = data; // unwrapPayload(data)
27868
- const deleted = Object.assign(Object.assign({}, poll.data), { isDeleted: true });
27869
- upsertInCache(['poll', 'get', pollId], deleted);
27870
- fireEvent('poll.deleted', { polls: [deleted], users: [] });
27871
- return success;
27824
+ client.log('room/getBroadcasterData', { roomId });
27825
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
27826
+ return data;
27872
27827
  };
27873
27828
  /* end_public_function */
27874
27829
 
27875
27830
  /* begin_public_function
27876
- id: poll.vote
27831
+ id: room.getRecordedUrl
27877
27832
  */
27878
27833
  /**
27879
27834
  * ```js
27880
- * import { votePoll } from '@amityco/ts-sdk'
27881
- * const voted = await votePoll(pollId)
27835
+ * import { getRecordedUrl } from '@amityco/ts-sdk'
27836
+ * const recordedUrl = await getRecordedUrl('roomId')
27882
27837
  * ```
27883
27838
  *
27884
- * Votes for an {@link Amity.Poll}
27839
+ * Gets the recorded URL for a room
27885
27840
  *
27886
- * @param pollId The ID of the {@link Amity.Poll} to vote
27887
- * @param answerIds The IDs of the {@link Amity.Poll} answers to vote {@link Amity.Poll}
27888
- * @returns the updated {@link Amity.Poll} object
27841
+ * @param roomId The ID of the room to get recorded URL for
27842
+ * @returns The recorded URL information
27889
27843
  *
27890
- * @category Poll API
27844
+ * @category Room API
27891
27845
  * @async
27892
27846
  */
27893
- const votePoll = async (pollId, answerIds) => {
27847
+ const getRecordedUrl = async (roomId) => {
27894
27848
  const client = getActiveClient();
27895
- client.log('user/votePoll', pollId);
27896
- const { data } = await client.http.post(`/api/v3/polls/${encodeURIComponent(pollId)}/votes`, { pollId, answerIds });
27897
- const cachedAt = client.cache && Date.now();
27898
- if (client.cache)
27899
- ingestInCache(data, { cachedAt });
27900
- const { polls } = data;
27901
- fireEvent('poll.updated', data);
27902
- return {
27903
- data: polls.find(poll => poll.pollId === pollId),
27904
- cachedAt,
27905
- };
27849
+ client.log('room/getRecordedUrl', { roomId });
27850
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/recorded`);
27851
+ return data;
27906
27852
  };
27907
27853
  /* end_public_function */
27908
27854
 
27909
- /* begin_public_function
27910
- id: poll.unvote
27911
- */
27912
27855
  /**
27913
27856
  * ```js
27914
- * import { PollRepository } from '@amityco/ts-sdk'
27915
- * await PollRepository.unvotePoll(pollId)
27857
+ * import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
27858
+ * const dispose = onRoomStartBroadcasting(room => {
27859
+ * // ...
27860
+ * })
27916
27861
  * ```
27917
27862
  *
27918
- * Votes for an {@link Amity.Poll}
27863
+ * Fired when a {@link Amity.Room} has started broadcasting
27919
27864
  *
27920
- * @param pollId The ID of the {@link Amity.Poll} to vote
27921
- * @returns void
27865
+ * @param callback The function to call when the event was fired
27866
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27922
27867
  *
27923
- * @category Poll API
27924
- * @async
27868
+ * @category Room Events
27925
27869
  */
27926
- const unvotePoll = async (pollId) => {
27870
+ const onRoomStartBroadcasting = (callback) => {
27927
27871
  const client = getActiveClient();
27928
- client.log('user/unvotePoll', pollId);
27929
- const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}/votes`, { pollId, answerIds: [] });
27930
- const cachedAt = client.cache && Date.now();
27931
- if (client.cache)
27932
- ingestInCache(data, { cachedAt });
27933
- fireEvent('poll.updated', data);
27872
+ const filter = (payload) => {
27873
+ ingestInCache(payload);
27874
+ callback(payload.rooms[0]);
27875
+ };
27876
+ return createEventSubscriber(client, 'room/onRoomStartBroadcasting', 'room.startBroadcasting', filter);
27934
27877
  };
27935
- /* end_public_function */
27936
27878
 
27937
27879
  /**
27938
27880
  * ```js
27939
- * import { onPollUpdated } from '@amityco/ts-sdk'
27940
- * const dispose = onPollUpdated(poll => {
27881
+ * import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
27882
+ * const dispose = onRoomWaitingReconnect(room => {
27941
27883
  * // ...
27942
27884
  * })
27943
27885
  * ```
27944
27886
  *
27945
- * Fired when an {@link Amity.Poll} has been updated
27887
+ * Fired when a {@link Amity.Room} is waiting for reconnection
27946
27888
  *
27947
27889
  * @param callback The function to call when the event was fired
27948
27890
  * @returns an {@link Amity.Unsubscriber} function to stop listening
27949
27891
  *
27950
- * @category Poll Events
27892
+ * @category Room Events
27951
27893
  */
27952
- const onPollUpdated = (callback) => {
27894
+ const onRoomWaitingReconnect = (callback) => {
27953
27895
  const client = getActiveClient();
27954
27896
  const filter = (payload) => {
27955
- if (client.cache)
27956
- ingestInCache(payload);
27957
- callback(payload.polls[0]);
27897
+ ingestInCache(payload);
27898
+ callback(payload.rooms[0]);
27958
27899
  };
27959
- return createEventSubscriber(client, 'poll/onPollUpdated', 'poll.updated', filter);
27900
+ return createEventSubscriber(client, 'room/onRoomWaitingReconnect', 'room.waitingReconnect', filter);
27960
27901
  };
27961
27902
 
27962
27903
  /**
27963
27904
  * ```js
27964
- * import { onPollDeleted } from '@amityco/ts-sdk'
27965
- * const dispose = onPollDeleted(poll => {
27905
+ * import { onRoomEndBroadcasting } from '@amityco/ts-sdk'
27906
+ * const dispose = onRoomEndBroadcasting(room => {
27966
27907
  * // ...
27967
27908
  * })
27968
27909
  * ```
27969
27910
  *
27970
- * Fired when an {@link Amity.Poll} has been deleted
27911
+ * Fired when a {@link Amity.Room} has ended broadcasting
27971
27912
  *
27972
27913
  * @param callback The function to call when the event was fired
27973
27914
  * @returns an {@link Amity.Unsubscriber} function to stop listening
27974
27915
  *
27975
- * @category Poll Events
27916
+ * @category Room Events
27976
27917
  */
27977
- const onPollDeleted = (callback) => {
27918
+ const onRoomEndBroadcasting = (callback) => {
27978
27919
  const client = getActiveClient();
27979
27920
  const filter = (payload) => {
27980
- if (client.cache)
27981
- ingestInCache(payload);
27982
- callback(payload.polls[0]);
27921
+ ingestInCache(payload);
27922
+ callback(payload.rooms[0]);
27983
27923
  };
27984
- return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
27924
+ return createEventSubscriber(client, 'room/onRoomEndBroadcasting', 'room.endBroadcasting', filter);
27985
27925
  };
27986
27926
 
27987
- /* begin_public_function
27988
- id: poll.get
27989
- */
27990
27927
  /**
27991
27928
  * ```js
27992
- * import { PollRepository } from '@amityco/ts-sdk';
27929
+ * import { onRoomRecordedAvailable } from '@amityco/ts-sdk'
27930
+ * const dispose = onRoomRecordedAvailable(room => {
27931
+ * // ...
27932
+ * })
27933
+ * ```
27993
27934
  *
27994
- * let poll;
27935
+ * Fired when a {@link Amity.Room} recorded content becomes available
27995
27936
  *
27996
- * const unsub = PollRepository.getPoll(commentId, response => {
27997
- * poll = response.data;
27998
- * });
27937
+ * @param callback The function to call when the event was fired
27938
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27939
+ *
27940
+ * @category Room Events
27941
+ */
27942
+ const onRoomRecordedAvailable = (callback) => {
27943
+ const client = getActiveClient();
27944
+ const filter = (payload) => {
27945
+ ingestInCache(payload);
27946
+ callback(payload.rooms[0]);
27947
+ };
27948
+ return createEventSubscriber(client, 'room/onRoomRecordedAvailable', 'room.recordedAvailable', filter);
27949
+ };
27950
+
27951
+ /**
27952
+ * ```js
27953
+ * import { onRoomParticipantInviting } from '@amityco/ts-sdk'
27954
+ * const dispose = onRoomParticipantInviting(room => {
27955
+ * // ...
27956
+ * })
27999
27957
  * ```
28000
27958
  *
28001
- * Observe all mutation on a given {@link Amity.Poll}
27959
+ * Fired when a participant is being invited to a {@link Amity.Room}
28002
27960
  *
28003
- * @param pollId the ID of the poll to observe
28004
- * @param callback the function to call when new data are available
28005
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
27961
+ * @param callback The function to call when the event was fired
27962
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28006
27963
  *
28007
- * @category Poll Live Object
27964
+ * @category Room Events
28008
27965
  */
28009
- const getPoll = (pollId, callback) => {
28010
- return liveObject(pollId, callback, 'pollId', getPoll$1, [onPollUpdated, onPollDeleted]);
27966
+ const onRoomParticipantInviting = (callback) => {
27967
+ const client = getActiveClient();
27968
+ const filter = (payload) => {
27969
+ ingestInCache(payload);
27970
+ callback(payload.rooms[0]);
27971
+ };
27972
+ return createEventSubscriber(client, 'room/onRoomParticipantInviting', 'room.participantInviting', filter);
28011
27973
  };
28012
- /* end_public_function */
28013
-
28014
- var index$7 = /*#__PURE__*/Object.freeze({
28015
- __proto__: null,
28016
- createPoll: createPoll,
28017
- closePoll: closePoll,
28018
- deletePoll: deletePoll,
28019
- votePoll: votePoll,
28020
- unvotePoll: unvotePoll,
28021
- onPollUpdated: onPollUpdated,
28022
- onPollDeleted: onPollDeleted,
28023
- getPoll: getPoll
28024
- });
28025
27974
 
28026
- const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
28027
- /*
28028
- * The crypto algorithm used for importing key and signing string
27975
+ /**
27976
+ * ```js
27977
+ * import { onRoomParticipantJoined } from '@amityco/ts-sdk'
27978
+ * const dispose = onRoomParticipantJoined(room => {
27979
+ * // ...
27980
+ * })
27981
+ * ```
27982
+ *
27983
+ * Fired when a participant has joined a {@link Amity.Room}
27984
+ *
27985
+ * @param callback The function to call when the event was fired
27986
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27987
+ *
27988
+ * @category Room Events
28029
27989
  */
28030
- const ALGORITHM = {
28031
- name: 'RSASSA-PKCS1-v1_5',
28032
- hash: { name: 'SHA-256' },
27990
+ const onRoomParticipantJoined = (callback) => {
27991
+ const client = getActiveClient();
27992
+ const filter = (payload) => {
27993
+ ingestInCache(payload);
27994
+ callback(payload.rooms[0]);
27995
+ };
27996
+ return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
28033
27997
  };
28034
- /*
28035
- * IMPORTANT!
28036
- * If you are recieving key from other platforms use an online tool to convert
27998
+
27999
+ /**
28000
+ * ```js
28001
+ * import { onRoomParticipantLeft } from '@amityco/ts-sdk'
28002
+ * const dispose = onRoomParticipantLeft(room => {
28003
+ * // ...
28004
+ * })
28005
+ * ```
28006
+ *
28007
+ * Fired when a participant has left a {@link Amity.Room}
28008
+ *
28009
+ * @param callback The function to call when the event was fired
28010
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28011
+ *
28012
+ * @category Room Events
28013
+ */
28014
+ const onRoomParticipantLeft = (callback) => {
28015
+ const client = getActiveClient();
28016
+ const filter = (payload) => {
28017
+ ingestInCache(payload);
28018
+ callback(payload.rooms[0]);
28019
+ };
28020
+ return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
28021
+ };
28022
+
28023
+ /**
28024
+ * ```js
28025
+ * import { onRoomCreated } from '@amityco/ts-sdk'
28026
+ * const dispose = onRoomCreated(room => {
28027
+ * // ...
28028
+ * })
28029
+ * ```
28030
+ *
28031
+ * Fired when a {@link Amity.Room} has been created locally
28032
+ *
28033
+ * @param callback The function to call when the event was fired
28034
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28035
+ *
28036
+ * @category Room Events
28037
+ */
28038
+ const onRoomCreated = (callback) => {
28039
+ const client = getActiveClient();
28040
+ const filter = (payload) => {
28041
+ ingestInCache(payload);
28042
+ callback(payload.rooms[0]);
28043
+ };
28044
+ return createEventSubscriber(client, 'room/onRoomCreated', 'local.room.created', filter);
28045
+ };
28046
+
28047
+ /**
28048
+ * ```js
28049
+ * import { onRoomUpdated } from '@amityco/ts-sdk'
28050
+ * const dispose = onRoomUpdated(room => {
28051
+ * // ...
28052
+ * })
28053
+ * ```
28054
+ *
28055
+ * Fired when a {@link Amity.Room} has been updated locally
28056
+ *
28057
+ * @param callback The function to call when the event was fired
28058
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28059
+ *
28060
+ * @category Room Events
28061
+ */
28062
+ const onRoomUpdated = (callback) => {
28063
+ const client = getActiveClient();
28064
+ const filter = (payload) => {
28065
+ ingestInCache(payload);
28066
+ callback(payload.rooms[0]);
28067
+ };
28068
+ return createEventSubscriber(client, 'room/onRoomUpdated', 'local.room.updated', filter);
28069
+ };
28070
+
28071
+ /**
28072
+ * ```js
28073
+ * import { onRoomDeleted } from '@amityco/ts-sdk'
28074
+ * const dispose = onRoomDeleted(room => {
28075
+ * // ...
28076
+ * })
28077
+ * ```
28078
+ *
28079
+ * Fired when a {@link Amity.Room} has been deleted locally
28080
+ *
28081
+ * @param callback The function to call when the event was fired
28082
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28083
+ *
28084
+ * @category Room Events
28085
+ */
28086
+ const onRoomDeleted = (callback) => {
28087
+ const client = getActiveClient();
28088
+ const filter = (payload) => {
28089
+ ingestInCache(payload);
28090
+ callback(payload.rooms[0]);
28091
+ };
28092
+ return createEventSubscriber(client, 'room/onRoomDeleted', 'local.room.deleted', filter);
28093
+ };
28094
+
28095
+ /**
28096
+ * ```js
28097
+ * import { onRoomStopped } from '@amityco/ts-sdk'
28098
+ * const dispose = onRoomStopped(room => {
28099
+ * // ...
28100
+ * })
28101
+ * ```
28102
+ *
28103
+ * Fired when a {@link Amity.Room} has been stopped locally
28104
+ *
28105
+ * @param callback The function to call when the event was fired
28106
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28107
+ *
28108
+ * @category Room Events
28109
+ */
28110
+ const onRoomStopped = (callback) => {
28111
+ const client = getActiveClient();
28112
+ const filter = (payload) => {
28113
+ ingestInCache(payload);
28114
+ callback(payload.rooms[0]);
28115
+ };
28116
+ return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
28117
+ };
28118
+
28119
+ const getRoomById = async (roomId) => {
28120
+ const client = getActiveClient();
28121
+ client.log('room/getRoomById', roomId);
28122
+ // Check if room is in tombstone
28123
+ isInTombstone('room', roomId);
28124
+ let data;
28125
+ try {
28126
+ const response = await client.http.get(`/api/v1/rooms/${roomId}`);
28127
+ data = response.data;
28128
+ }
28129
+ catch (error) {
28130
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
28131
+ pushToTombstone('room', roomId);
28132
+ }
28133
+ throw error;
28134
+ }
28135
+ const cachedAt = client.cache && Date.now();
28136
+ if (client.cache) {
28137
+ ingestInCache(data, { cachedAt });
28138
+ }
28139
+ return {
28140
+ data: data.rooms[0],
28141
+ cachedAt,
28142
+ };
28143
+ };
28144
+ getRoomById.locally = (roomId) => {
28145
+ const client = getActiveClient();
28146
+ client.log('room/getRoomById.locally', roomId);
28147
+ // Check if room is in tombstone
28148
+ isInTombstone('room', roomId);
28149
+ const cachedAt = client.cache && Date.now();
28150
+ const roomCache = pullFromCache(['room', 'get', roomId]);
28151
+ if (!roomCache)
28152
+ return;
28153
+ return {
28154
+ data: roomCache.data,
28155
+ cachedAt,
28156
+ };
28157
+ };
28158
+
28159
+ const getRoom = (roomId, callback) => {
28160
+ // TODO: add callbackDataSelector if there are linked object fields
28161
+ return liveObject(roomId, callback, '_id', getRoomById, [
28162
+ onRoomEndBroadcasting,
28163
+ onRoomStartBroadcasting,
28164
+ onRoomWaitingReconnect,
28165
+ onRoomRecordedAvailable,
28166
+ ]);
28167
+ };
28168
+
28169
+ class RoomPaginationController extends PaginationController {
28170
+ async getRequest(queryParams, token) {
28171
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
28172
+ const baseOptions = {
28173
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
28174
+ };
28175
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
28176
+ const { data: queryResponse } = await this.http.get(`/api/v1/rooms`, {
28177
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
28178
+ });
28179
+ return queryResponse;
28180
+ }
28181
+ }
28182
+
28183
+ var EnumRoomActions;
28184
+ (function (EnumRoomActions) {
28185
+ EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
28186
+ EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
28187
+ EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
28188
+ EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
28189
+ EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
28190
+ EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
28191
+ EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
28192
+ })(EnumRoomActions || (EnumRoomActions = {}));
28193
+
28194
+ class RoomQueryStreamController extends QueryStreamController {
28195
+ constructor(query, cacheKey, notifyChange, preparePayload) {
28196
+ super(query, cacheKey);
28197
+ this.notifyChange = notifyChange;
28198
+ this.preparePayload = preparePayload;
28199
+ }
28200
+ async saveToMainDB(response) {
28201
+ const processedPayload = await this.preparePayload(response);
28202
+ const client = getActiveClient();
28203
+ const cachedAt = client.cache && Date.now();
28204
+ if (client.cache) {
28205
+ ingestInCache(processedPayload, { cachedAt });
28206
+ }
28207
+ }
28208
+ appendToQueryStream(response, direction, refresh = false) {
28209
+ var _a, _b;
28210
+ if (refresh) {
28211
+ pushToCache(this.cacheKey, {
28212
+ data: response.rooms.map(getResolver('room')),
28213
+ });
28214
+ }
28215
+ else {
28216
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
28217
+ const rooms = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
28218
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...rooms, ...response.rooms.map(getResolver('room'))])] }));
28219
+ }
28220
+ }
28221
+ reactor(action) {
28222
+ return (room) => {
28223
+ var _a;
28224
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
28225
+ if (!collection)
28226
+ return;
28227
+ if (action === EnumRoomActions.OnRoomDeleted) {
28228
+ collection.data = collection.data.filter(roomId => roomId !== room._id);
28229
+ }
28230
+ if (action === EnumRoomActions.OnRoomCreated) {
28231
+ collection.data = [...new Set([room._id, ...collection.data])];
28232
+ }
28233
+ pushToCache(this.cacheKey, collection);
28234
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
28235
+ };
28236
+ }
28237
+ subscribeRTE(createSubscriber) {
28238
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
28239
+ }
28240
+ }
28241
+
28242
+ // TODO: confirm related events
28243
+ const getRoomSubscription = () => [
28244
+ {
28245
+ fn: onRoomStartBroadcasting,
28246
+ action: EnumRoomActions.OnRoomStartBroadcasting,
28247
+ },
28248
+ {
28249
+ fn: onRoomEndBroadcasting,
28250
+ action: EnumRoomActions.OnRoomEndBroadcasting,
28251
+ },
28252
+ {
28253
+ fn: onRoomRecordedAvailable,
28254
+ action: EnumRoomActions.OnRoomUpdated,
28255
+ },
28256
+ ];
28257
+
28258
+ class RoomLiveCollectionController extends LiveCollectionController {
28259
+ constructor(query, callback) {
28260
+ const queryStreamId = hash__default["default"](query);
28261
+ const cacheKey = ['rooms', 'collection', queryStreamId];
28262
+ const paginationController = new RoomPaginationController(query);
28263
+ super(paginationController, queryStreamId, cacheKey, callback);
28264
+ this.query = query;
28265
+ this.queryStreamController = new RoomQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
28266
+ this.callback = callback.bind(this);
28267
+ this.loadPage({ initial: true });
28268
+ }
28269
+ setup() {
28270
+ var _a;
28271
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
28272
+ if (!collection) {
28273
+ pushToCache(this.cacheKey, {
28274
+ data: [],
28275
+ params: {},
28276
+ });
28277
+ }
28278
+ }
28279
+ async persistModel(queryPayload) {
28280
+ await this.queryStreamController.saveToMainDB(queryPayload);
28281
+ }
28282
+ persistQueryStream({ response, direction, refresh, }) {
28283
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
28284
+ }
28285
+ startSubscription() {
28286
+ return this.queryStreamController.subscribeRTE(getRoomSubscription());
28287
+ }
28288
+ notifyChange({ origin, loading, error }) {
28289
+ var _a, _b;
28290
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
28291
+ if (!collection)
28292
+ return;
28293
+ const data = this.applyFilter((_b = collection.data
28294
+ .map(id => pullFromCache(['room', 'get', id]))
28295
+ .filter(isNonNullable)
28296
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(room => room); // Since Room is same as InternalRoom, no transformation needed
28297
+ if (!this.shouldNotify(data) && origin === 'event')
28298
+ return;
28299
+ this.callback({
28300
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
28301
+ data,
28302
+ hasNextPage: !!this.paginationController.getNextToken(),
28303
+ loading,
28304
+ error,
28305
+ });
28306
+ }
28307
+ applyFilter(data) {
28308
+ let rooms = data;
28309
+ if (!this.query.includeDeleted) {
28310
+ rooms = filterByPropEquality(rooms, 'isDeleted', false);
28311
+ }
28312
+ if (this.query.statuses && this.query.statuses.length > 0) {
28313
+ rooms = rooms.filter(room => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(room.status); });
28314
+ }
28315
+ if (this.query.type) {
28316
+ rooms = filterByPropEquality(rooms, 'type', this.query.type);
28317
+ }
28318
+ switch (this.query.sortBy) {
28319
+ case 'firstCreated':
28320
+ rooms = rooms.sort(sortByFirstCreated);
28321
+ break;
28322
+ case 'lastCreated':
28323
+ default:
28324
+ rooms = rooms.sort(sortByLastCreated);
28325
+ break;
28326
+ }
28327
+ return rooms;
28328
+ }
28329
+ }
28330
+
28331
+ /* begin_public_function
28332
+ id: room.get_rooms
28333
+ */
28334
+ /**
28335
+ * ```js
28336
+ * import { RoomRepository } from '@amityco/ts-sdk'
28337
+ *
28338
+ * let rooms = []
28339
+ * const unsub = RoomRepository.getRooms({
28340
+ * type: 'direct_streaming',
28341
+ * statuses: ['live', 'idle'],
28342
+ * sortBy: 'lastCreated',
28343
+ * limit: 20,
28344
+ * includeDeleted: false
28345
+ * }, response => merge(rooms, response.data))
28346
+ * ```
28347
+ *
28348
+ * Observe all mutations on a list of {@link Amity.Room} for a given query
28349
+ *
28350
+ * @param params.type the type of rooms to filter by ('direct_streaming' | 'co_hosts')
28351
+ * @param params.statuses array of room statuses to filter by (['idle', 'live', 'waiting_reconnect', 'ended', 'recorded'])
28352
+ * @param params.sortBy sort rooms by creation time ('firstCreated' | 'lastCreated')
28353
+ * @param params.limit maximum number of rooms to retrieve per page
28354
+ * @param params.includeDeleted whether to include deleted rooms in the results
28355
+ * @param callback the function to call when new data are available
28356
+ * @param config optional configuration for the live collection
28357
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the rooms
28358
+ *
28359
+ * @category Rooms Live Collection
28360
+ */
28361
+ const getRooms = (params, callback, config) => {
28362
+ const { log, cache } = getActiveClient();
28363
+ if (!cache) {
28364
+ console.log(ENABLE_CACHE_MESSAGE);
28365
+ }
28366
+ const timestamp = Date.now();
28367
+ log(`getRooms(tmpid: ${timestamp}) > listen`);
28368
+ const roomsLiveCollection = new RoomLiveCollectionController(params, callback);
28369
+ const disposers = roomsLiveCollection.startSubscription();
28370
+ const cacheKey = roomsLiveCollection.getCacheKey();
28371
+ disposers.push(() => dropFromCache(cacheKey));
28372
+ return () => {
28373
+ log(`getRooms(tmpid: ${timestamp}) > dispose`);
28374
+ disposers.forEach(fn => fn());
28375
+ };
28376
+ };
28377
+ /* end_public_function */
28378
+
28379
+ var index$7 = /*#__PURE__*/Object.freeze({
28380
+ __proto__: null,
28381
+ createRoom: createRoom,
28382
+ updateRoom: updateRoom,
28383
+ deleteRoom: deleteRoom,
28384
+ stopRoom: stopRoom,
28385
+ getBroadcasterData: getBroadcasterData,
28386
+ getRecordedUrl: getRecordedUrl,
28387
+ onRoomStartBroadcasting: onRoomStartBroadcasting,
28388
+ onRoomWaitingReconnect: onRoomWaitingReconnect,
28389
+ onRoomEndBroadcasting: onRoomEndBroadcasting,
28390
+ onRoomRecordedAvailable: onRoomRecordedAvailable,
28391
+ onRoomParticipantInviting: onRoomParticipantInviting,
28392
+ onRoomParticipantJoined: onRoomParticipantJoined,
28393
+ onRoomParticipantLeft: onRoomParticipantLeft,
28394
+ onRoomCreated: onRoomCreated,
28395
+ onRoomUpdated: onRoomUpdated,
28396
+ onRoomDeleted: onRoomDeleted,
28397
+ onRoomStopped: onRoomStopped,
28398
+ getRoom: getRoom,
28399
+ getRooms: getRooms
28400
+ });
28401
+
28402
+ /* begin_public_function
28403
+ id: poll.create
28404
+ */
28405
+ /**
28406
+ * ```js
28407
+ * import { createPoll } from '@amityco/ts-sdk'
28408
+ * const created = await createPoll({
28409
+ * question: 'question',
28410
+ * answers: [
28411
+ * { dataType: 'text', data: 'answer1', fileId: 'fileId1' },
28412
+ * { dataType: 'text', data: 'answer2', fileId: 'fileId2' },
28413
+ * ],
28414
+ * closedIn: 1649136484
28415
+ * }))
28416
+ * ```
28417
+ *
28418
+ * Creates an {@link Amity.Poll}
28419
+ *
28420
+ * @param bundle The data necessary to create a new {@link Amity.Poll}
28421
+ * @returns The newly created {@link Amity.Poll}
28422
+ *
28423
+ * @category Poll API
28424
+ * @async
28425
+ */
28426
+ const createPoll = async (bundle) => {
28427
+ const client = getActiveClient();
28428
+ client.log('post/createPoll', bundle);
28429
+ const { data } = await client.http.post('/api/v3/polls', bundle);
28430
+ const cachedAt = client.cache && Date.now();
28431
+ if (client.cache)
28432
+ ingestInCache(data, { cachedAt });
28433
+ const { polls } = data;
28434
+ return {
28435
+ data: polls[0],
28436
+ cachedAt,
28437
+ };
28438
+ };
28439
+ /* end_public_function */
28440
+
28441
+ /* begin_public_function
28442
+ id: poll.close
28443
+ */
28444
+ /**
28445
+ * ```js
28446
+ * import { closePoll } from '@amityco/ts-sdk'
28447
+ * const updated = await closePoll(pollId)
28448
+ * ```
28449
+ *
28450
+ * Updates an {@link Amity.Poll}
28451
+ *
28452
+ * @param pollId The ID of the {@link Amity.Poll} to close
28453
+ * @returns the updated {@link Amity.Poll} object
28454
+ *
28455
+ * @category Poll API
28456
+ * @async
28457
+ */
28458
+ const closePoll = async (pollId) => {
28459
+ const client = getActiveClient();
28460
+ client.log('user/closePoll', pollId);
28461
+ const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}`, { status: 'closed' });
28462
+ const cachedAt = client.cache && Date.now();
28463
+ if (client.cache)
28464
+ ingestInCache(data, { cachedAt });
28465
+ fireEvent('poll.updated', data);
28466
+ const { polls } = data;
28467
+ return {
28468
+ data: polls.find(poll => poll.pollId === pollId),
28469
+ cachedAt,
28470
+ };
28471
+ };
28472
+ /* end_public_function */
28473
+
28474
+ /* begin_public_function
28475
+ id: poll.get
28476
+ */
28477
+ /**
28478
+ * ```js
28479
+ * import { getPoll } from '@amityco/ts-sdk'
28480
+ * const poll = await getPoll('foobar')
28481
+ * ```
28482
+ *
28483
+ * Fetches a {@link Amity.Poll} object
28484
+ *
28485
+ * @param pollId the ID of the {@link Amity.Poll} to fetch
28486
+ * @returns the associated {@link Amity.Poll} object
28487
+ *
28488
+ * @category Poll API
28489
+ * @async
28490
+ */
28491
+ const getPoll$1 = async (pollId) => {
28492
+ const client = getActiveClient();
28493
+ client.log('poll/getPoll', pollId);
28494
+ const { data } = await client.http.get(`/api/v3/polls/${pollId}`);
28495
+ const cachedAt = client.cache && Date.now();
28496
+ if (client.cache)
28497
+ ingestInCache(data, { cachedAt });
28498
+ const { polls } = data;
28499
+ return {
28500
+ data: polls.find(poll => poll.pollId === pollId),
28501
+ cachedAt,
28502
+ };
28503
+ };
28504
+ /* end_public_function */
28505
+ /**
28506
+ * ```js
28507
+ * import { getPoll } from '@amityco/ts-sdk'
28508
+ * const poll = getPoll.locally('foobar')
28509
+ * ```
28510
+ *
28511
+ * Fetches a {@link Amity.Poll} object
28512
+ *
28513
+ * @param pollId the ID of the {@link Amity.Poll} to fetch
28514
+ * @returns the associated {@link Amity.Poll} object
28515
+ *
28516
+ * @category Poll API
28517
+ */
28518
+ getPoll$1.locally = (pollId) => {
28519
+ const client = getActiveClient();
28520
+ client.log('poll/getPoll', pollId);
28521
+ if (!client.cache)
28522
+ return;
28523
+ const cached = pullFromCache(['poll', 'get', pollId]);
28524
+ if (!cached)
28525
+ return;
28526
+ return {
28527
+ data: cached.data,
28528
+ cachedAt: cached.cachedAt,
28529
+ };
28530
+ };
28531
+
28532
+ /* begin_public_function
28533
+ id: poll.delete
28534
+ */
28535
+ /**
28536
+ * ```js
28537
+ * import { deletePoll } from '@amityco/ts-sdk'
28538
+ * const success = await deletePoll(pollId)
28539
+ * ```
28540
+ *
28541
+ * Deletes a {@link Amity.Poll}
28542
+ *
28543
+ * @param pollId The {@link Amity.Poll} ID to delete
28544
+ * @return A success boolean if the {@link Amity.Poll} was deleted
28545
+ *
28546
+ * @category Poll API
28547
+ * @async
28548
+ */
28549
+ const deletePoll = async (pollId) => {
28550
+ const client = getActiveClient();
28551
+ client.log('poll/deletePoll', pollId);
28552
+ const poll = await getPoll$1(pollId);
28553
+ // API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
28554
+ const { data } = await client.http.delete(`/api/v3/polls/${pollId}`);
28555
+ const { success } = data; // unwrapPayload(data)
28556
+ const deleted = Object.assign(Object.assign({}, poll.data), { isDeleted: true });
28557
+ upsertInCache(['poll', 'get', pollId], deleted);
28558
+ fireEvent('poll.deleted', { polls: [deleted], users: [] });
28559
+ return success;
28560
+ };
28561
+ /* end_public_function */
28562
+
28563
+ /* begin_public_function
28564
+ id: poll.vote
28565
+ */
28566
+ /**
28567
+ * ```js
28568
+ * import { votePoll } from '@amityco/ts-sdk'
28569
+ * const voted = await votePoll(pollId)
28570
+ * ```
28571
+ *
28572
+ * Votes for an {@link Amity.Poll}
28573
+ *
28574
+ * @param pollId The ID of the {@link Amity.Poll} to vote
28575
+ * @param answerIds The IDs of the {@link Amity.Poll} answers to vote {@link Amity.Poll}
28576
+ * @returns the updated {@link Amity.Poll} object
28577
+ *
28578
+ * @category Poll API
28579
+ * @async
28580
+ */
28581
+ const votePoll = async (pollId, answerIds) => {
28582
+ const client = getActiveClient();
28583
+ client.log('user/votePoll', pollId);
28584
+ const { data } = await client.http.post(`/api/v3/polls/${encodeURIComponent(pollId)}/votes`, { pollId, answerIds });
28585
+ const cachedAt = client.cache && Date.now();
28586
+ if (client.cache)
28587
+ ingestInCache(data, { cachedAt });
28588
+ const { polls } = data;
28589
+ fireEvent('poll.updated', data);
28590
+ return {
28591
+ data: polls.find(poll => poll.pollId === pollId),
28592
+ cachedAt,
28593
+ };
28594
+ };
28595
+ /* end_public_function */
28596
+
28597
+ /* begin_public_function
28598
+ id: poll.unvote
28599
+ */
28600
+ /**
28601
+ * ```js
28602
+ * import { PollRepository } from '@amityco/ts-sdk'
28603
+ * await PollRepository.unvotePoll(pollId)
28604
+ * ```
28605
+ *
28606
+ * Votes for an {@link Amity.Poll}
28607
+ *
28608
+ * @param pollId The ID of the {@link Amity.Poll} to vote
28609
+ * @returns void
28610
+ *
28611
+ * @category Poll API
28612
+ * @async
28613
+ */
28614
+ const unvotePoll = async (pollId) => {
28615
+ const client = getActiveClient();
28616
+ client.log('user/unvotePoll', pollId);
28617
+ const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}/votes`, { pollId, answerIds: [] });
28618
+ const cachedAt = client.cache && Date.now();
28619
+ if (client.cache)
28620
+ ingestInCache(data, { cachedAt });
28621
+ fireEvent('poll.updated', data);
28622
+ };
28623
+ /* end_public_function */
28624
+
28625
+ /**
28626
+ * ```js
28627
+ * import { onPollUpdated } from '@amityco/ts-sdk'
28628
+ * const dispose = onPollUpdated(poll => {
28629
+ * // ...
28630
+ * })
28631
+ * ```
28632
+ *
28633
+ * Fired when an {@link Amity.Poll} has been updated
28634
+ *
28635
+ * @param callback The function to call when the event was fired
28636
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28637
+ *
28638
+ * @category Poll Events
28639
+ */
28640
+ const onPollUpdated = (callback) => {
28641
+ const client = getActiveClient();
28642
+ const filter = (payload) => {
28643
+ if (client.cache)
28644
+ ingestInCache(payload);
28645
+ callback(payload.polls[0]);
28646
+ };
28647
+ return createEventSubscriber(client, 'poll/onPollUpdated', 'poll.updated', filter);
28648
+ };
28649
+
28650
+ /**
28651
+ * ```js
28652
+ * import { onPollDeleted } from '@amityco/ts-sdk'
28653
+ * const dispose = onPollDeleted(poll => {
28654
+ * // ...
28655
+ * })
28656
+ * ```
28657
+ *
28658
+ * Fired when an {@link Amity.Poll} has been deleted
28659
+ *
28660
+ * @param callback The function to call when the event was fired
28661
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28662
+ *
28663
+ * @category Poll Events
28664
+ */
28665
+ const onPollDeleted = (callback) => {
28666
+ const client = getActiveClient();
28667
+ const filter = (payload) => {
28668
+ if (client.cache)
28669
+ ingestInCache(payload);
28670
+ callback(payload.polls[0]);
28671
+ };
28672
+ return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
28673
+ };
28674
+
28675
+ /* begin_public_function
28676
+ id: poll.get
28677
+ */
28678
+ /**
28679
+ * ```js
28680
+ * import { PollRepository } from '@amityco/ts-sdk';
28681
+ *
28682
+ * let poll;
28683
+ *
28684
+ * const unsub = PollRepository.getPoll(commentId, response => {
28685
+ * poll = response.data;
28686
+ * });
28687
+ * ```
28688
+ *
28689
+ * Observe all mutation on a given {@link Amity.Poll}
28690
+ *
28691
+ * @param pollId the ID of the poll to observe
28692
+ * @param callback the function to call when new data are available
28693
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
28694
+ *
28695
+ * @category Poll Live Object
28696
+ */
28697
+ const getPoll = (pollId, callback) => {
28698
+ return liveObject(pollId, callback, 'pollId', getPoll$1, [onPollUpdated, onPollDeleted]);
28699
+ };
28700
+ /* end_public_function */
28701
+
28702
+ var index$6 = /*#__PURE__*/Object.freeze({
28703
+ __proto__: null,
28704
+ createPoll: createPoll,
28705
+ closePoll: closePoll,
28706
+ deletePoll: deletePoll,
28707
+ votePoll: votePoll,
28708
+ unvotePoll: unvotePoll,
28709
+ onPollUpdated: onPollUpdated,
28710
+ onPollDeleted: onPollDeleted,
28711
+ getPoll: getPoll
28712
+ });
28713
+
28714
+ const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
28715
+ /*
28716
+ * The crypto algorithm used for importing key and signing string
28717
+ */
28718
+ const ALGORITHM = {
28719
+ name: 'RSASSA-PKCS1-v1_5',
28720
+ hash: { name: 'SHA-256' },
28721
+ };
28722
+ /*
28723
+ * IMPORTANT!
28724
+ * If you are recieving key from other platforms use an online tool to convert
28037
28725
  * the PKCS1 to PKCS8. For instance the key from Android SDK is of the format
28038
28726
  * PKCS1.
28039
28727
  *
@@ -28394,7 +29082,7 @@ const getPlayer = async (parameters) => {
28394
29082
  return video;
28395
29083
  };
28396
29084
 
28397
- var index$6 = /*#__PURE__*/Object.freeze({
29085
+ var index$5 = /*#__PURE__*/Object.freeze({
28398
29086
  __proto__: null,
28399
29087
  getPlayer: getPlayer
28400
29088
  });
@@ -29567,7 +30255,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
29567
30255
  };
29568
30256
  };
29569
30257
 
29570
- var index$5 = /*#__PURE__*/Object.freeze({
30258
+ var index$4 = /*#__PURE__*/Object.freeze({
29571
30259
  __proto__: null,
29572
30260
  createImageStory: createImageStory,
29573
30261
  createVideoStory: createVideoStory,
@@ -29604,7 +30292,7 @@ const getNetworkAds = async () => {
29604
30292
  };
29605
30293
  };
29606
30294
 
29607
- var index$4 = /*#__PURE__*/Object.freeze({
30295
+ var index$3 = /*#__PURE__*/Object.freeze({
29608
30296
  __proto__: null,
29609
30297
  getNetworkAds: getNetworkAds
29610
30298
  });
@@ -29767,254 +30455,22 @@ const getNotificationTraySeen = (callback) => {
29767
30455
  };
29768
30456
  /* end_public_function */
29769
30457
 
29770
- /**
29771
- * TODO: handle cache receive cache option, and cache policy
29772
- * TODO: check if querybyIds is supported
29773
- */
29774
- class NotificationTrayItemsPaginationController extends PaginationController {
29775
- async getRequest(queryParams, token) {
29776
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
29777
- const options = token ? { token } : { limit };
29778
- const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
29779
- params: Object.assign(Object.assign({}, params), { options }),
29780
- });
29781
- return queryResponse;
29782
- }
29783
- }
29784
-
29785
- class NotificationTrayItemsQuerystreamController extends QueryStreamController {
29786
- constructor(query, cacheKey, notifyChange, preparePayload) {
29787
- super(query, cacheKey);
29788
- this.notifyChange = notifyChange;
29789
- this.preparePayload = preparePayload;
29790
- }
29791
- async saveToMainDB(response) {
29792
- const processedPayload = await this.preparePayload(response);
29793
- const client = getActiveClient();
29794
- const cachedAt = client.cache && Date.now();
29795
- if (client.cache) {
29796
- ingestInCache(processedPayload, { cachedAt });
29797
- }
29798
- }
29799
- appendToQueryStream(response, direction, refresh = false) {
29800
- var _a, _b;
29801
- if (refresh) {
29802
- pushToCache(this.cacheKey, {
29803
- data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
29804
- });
29805
- }
29806
- else {
29807
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
29808
- const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
29809
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
29810
- ...new Set([
29811
- ...notifications,
29812
- ...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
29813
- ]),
29814
- ] }));
29815
- }
29816
- }
29817
- }
29818
-
29819
- const prepareNotificationTrayItemsPayload = (rawPayload) => {
29820
- const users = rawPayload.users.map(convertRawUserToInternalUser);
29821
- return Object.assign(Object.assign({}, rawPayload), { users });
29822
- };
29823
-
29824
- class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
29825
- constructor(query, callback) {
29826
- const queryStreamId = hash__default["default"](query);
29827
- const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
29828
- const paginationController = new NotificationTrayItemsPaginationController(query);
29829
- super(paginationController, queryStreamId, cacheKey, callback);
29830
- this.query = query;
29831
- this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
29832
- this.callback = callback.bind(this);
29833
- this.loadPage({ initial: true });
29834
- }
29835
- setup() {
29836
- var _a;
29837
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
29838
- if (!collection) {
29839
- pushToCache(this.cacheKey, {
29840
- data: [],
29841
- params: {},
29842
- });
29843
- }
29844
- }
29845
- async persistModel(queryPayload) {
29846
- await this.queryStreamController.saveToMainDB(queryPayload);
29847
- }
29848
- persistQueryStream({ response, direction, refresh, }) {
29849
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
29850
- }
29851
- // eslint-disable-next-line class-methods-use-this
29852
- startSubscription() {
29853
- return [];
29854
- }
29855
- notifyChange({ origin, loading, error }) {
29856
- var _a, _b;
29857
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
29858
- if (!collection)
29859
- return;
29860
- const data = ((_b = collection.data
29861
- .map(id => pullFromCache(['notificationTrayItem', 'get', id]))
29862
- .filter(isNonNullable)
29863
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
29864
- if (!this.shouldNotify(data) && origin === 'event')
29865
- return;
29866
- this.callback({
29867
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
29868
- data,
29869
- hasNextPage: !!this.paginationController.getNextToken(),
29870
- loading,
29871
- error,
29872
- });
29873
- }
29874
- }
29875
-
29876
- /**
29877
- * Get notification tray items for a notification tray page
29878
- *
29879
- * @param params the limit query parameters
29880
- * @param callback the callback to be called when the notification tray items are updated
29881
- * @returns items in the notification tray
29882
- *
29883
- * @category Notification tray items Live Collection
29884
- *
29885
- */
29886
- const getNotificationTrayItems = (params, callback, config) => {
29887
- const { log, cache } = getActiveClient();
29888
- if (!cache) {
29889
- console.log(ENABLE_CACHE_MESSAGE);
29890
- }
29891
- const timestamp = Date.now();
29892
- log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
29893
- const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
29894
- const disposers = notiTrayItemsLiveCollection.startSubscription();
29895
- const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
29896
- disposers.push(() => dropFromCache(cacheKey));
29897
- return () => {
29898
- log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
29899
- disposers.forEach(fn => fn());
29900
- };
29901
- };
29902
-
29903
- /* begin_public_function
29904
- id: notificationTrayItem.markSeen
29905
- */
29906
- /**
29907
- * ```js
29908
- * import { notificationTray } from '@amityco/ts-sdk'
29909
- * const updated = await notificationTray.markItemsSeen()
29910
- * ```
29911
- *
29912
- * Updates an {@link Amity.NotificationItemSeen}
29913
- *
29914
- * @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
29915
- * @returns the updated {@link Amity.NotificationItemSeen} object
29916
- *
29917
- * @category NotificationItemSeen API
29918
- * @async
29919
- */
29920
- const markItemsSeen = async (trayItems) => {
29921
- const client = getActiveClient();
29922
- client.log('notificationTray/markItemsSeen', {});
29923
- const { data: payload } = await client.http.post(`api/v1/notification-tray/items/seen`, {
29924
- trayItems: trayItems.map(item => ({
29925
- id: item.id,
29926
- lastSeenAt: item.lastSeenAt,
29927
- })),
29928
- });
29929
- const updatedData = payload.trayItems
29930
- .map(patchItem => {
29931
- var _a;
29932
- const cacheData = (_a = pullFromCache([
29933
- 'notificationTrayItem',
29934
- 'get',
29935
- patchItem.id,
29936
- ])) === null || _a === void 0 ? void 0 : _a.data;
29937
- if (!cacheData)
29938
- return;
29939
- const data = Object.assign(Object.assign({}, cacheData), { lastSeenAt: patchItem.lastSeenAt });
29940
- if (client.cache) {
29941
- const cachedAt = Date.now();
29942
- pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
29943
- }
29944
- return data;
29945
- })
29946
- .filter(Boolean);
29947
- fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
29948
- };
29949
- /* end_public_function */
29950
-
29951
- /* begin_public_function
29952
- id: notificationTray.markSeen
29953
- */
29954
- /**
29955
- * ```js
29956
- * import { notificationTray } from '@amityco/ts-sdk'
29957
- * const updated = await notificationTray.markTraySeen({
29958
- * lastSeenAt: Amity.timestamp,
29959
- * })
29960
- * ```
29961
- *
29962
- * Updates an {@link Amity.NotificationTraySeen}
29963
- *
29964
- * @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
29965
- * @param lastSeenAt The patch data to apply
29966
- * @returns the updated {@link Amity.NotificationTraySeen} object
29967
- *
29968
- * @category Post API
29969
- * @async
29970
- */
29971
- const markTraySeen = async (lastSeenAt) => {
29972
- var _a;
29973
- const client = getActiveClient();
29974
- client.log('notificationTray/markTraySeen', {});
29975
- const { data: payload } = await client.http.post(`api/v1/notification-tray/tray/seen`, {
29976
- lastSeenAt,
29977
- });
29978
- const cacheData = (_a = pullFromCache([
29979
- 'notificationTraySeen',
29980
- 'get',
29981
- ])) === null || _a === void 0 ? void 0 : _a.data;
29982
- const data = {
29983
- userId: client.userId,
29984
- lastTraySeenAt: payload.lastSeenAt,
29985
- };
29986
- const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
29987
- const cachedAt = client.cache && Date.now();
29988
- if (client.cache)
29989
- pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
29990
- fireEvent('local.notificationTraySeen.updated', data);
29991
- return {
29992
- data: payload,
29993
- cachedAt,
29994
- };
29995
- };
29996
- /* end_public_function */
29997
-
29998
- var index$3 = /*#__PURE__*/Object.freeze({
29999
- __proto__: null,
30000
- getNotificationTraySeen: getNotificationTraySeen,
30001
- getNotificationTrayItems: getNotificationTrayItems,
30002
- markItemsSeen: markItemsSeen,
30003
- markTraySeen: markTraySeen,
30004
- onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
30005
- });
30006
-
30007
- class MyInvitationsPaginationController extends PaginationController {
30458
+ /**
30459
+ * TODO: handle cache receive cache option, and cache policy
30460
+ * TODO: check if querybyIds is supported
30461
+ */
30462
+ class NotificationTrayItemsPaginationController extends PaginationController {
30008
30463
  async getRequest(queryParams, token) {
30009
30464
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
30010
30465
  const options = token ? { token } : { limit };
30011
- const { data } = await this.http.get('/api/v1/invitations/me', { params: Object.assign(Object.assign({}, params), { options }) });
30012
- await getCommunities$1(data.invitations.map(invitation => invitation.communityId));
30013
- return data;
30466
+ const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
30467
+ params: Object.assign(Object.assign({}, params), { options }),
30468
+ });
30469
+ return queryResponse;
30014
30470
  }
30015
30471
  }
30016
30472
 
30017
- class MyInvitationsQueryStreamController extends QueryStreamController {
30473
+ class NotificationTrayItemsQuerystreamController extends QueryStreamController {
30018
30474
  constructor(query, cacheKey, notifyChange, preparePayload) {
30019
30475
  super(query, cacheKey);
30020
30476
  this.notifyChange = notifyChange;
@@ -30032,58 +30488,35 @@ class MyInvitationsQueryStreamController extends QueryStreamController {
30032
30488
  var _a, _b;
30033
30489
  if (refresh) {
30034
30490
  pushToCache(this.cacheKey, {
30035
- data: response.invitations.map(getResolver('invitation')),
30491
+ data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
30036
30492
  });
30037
30493
  }
30038
30494
  else {
30039
30495
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30040
- const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
30496
+ const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
30041
30497
  pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
30042
- ...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
30043
- ] }));
30044
- }
30045
- }
30046
- reactor(action) {
30047
- return (invitations) => {
30048
- var _a;
30049
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30050
- if (!collection)
30051
- return;
30052
- if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
30053
- const isExist = collection.data.find(id => id === invitations[0].invitationId);
30054
- if (!isExist)
30055
- return;
30056
- }
30057
- if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
30058
- const client = getActiveClient();
30059
- const myInvitations = invitations.filter(invitation => invitation.invitedUserId === client.userId);
30060
- collection.data = [
30061
30498
  ...new Set([
30062
- ...myInvitations.map(invitation => invitation.invitationId),
30063
- ...collection.data,
30499
+ ...notifications,
30500
+ ...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
30064
30501
  ]),
30065
- ];
30066
- }
30067
- if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
30068
- collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
30069
- }
30070
- pushToCache(this.cacheKey, collection);
30071
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
30072
- };
30073
- }
30074
- subscribeRTE(createSubscriber) {
30075
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
30502
+ ] }));
30503
+ }
30076
30504
  }
30077
30505
  }
30078
30506
 
30079
- class MyInvitationsLiveCollectionController extends LiveCollectionController {
30507
+ const prepareNotificationTrayItemsPayload = (rawPayload) => {
30508
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
30509
+ return Object.assign(Object.assign({}, rawPayload), { users });
30510
+ };
30511
+
30512
+ class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
30080
30513
  constructor(query, callback) {
30081
30514
  const queryStreamId = hash__default["default"](query);
30082
- const cacheKey = ['invitation', 'collection', queryStreamId];
30083
- const paginationController = new MyInvitationsPaginationController(query);
30515
+ const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
30516
+ const paginationController = new NotificationTrayItemsPaginationController(query);
30084
30517
  super(paginationController, queryStreamId, cacheKey, callback);
30085
30518
  this.query = query;
30086
- this.queryStreamController = new MyInvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareMyInvitationsPayload);
30519
+ this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
30087
30520
  this.callback = callback.bind(this);
30088
30521
  this.loadPage({ initial: true });
30089
30522
  }
@@ -30093,7 +30526,7 @@ class MyInvitationsLiveCollectionController extends LiveCollectionController {
30093
30526
  if (!collection) {
30094
30527
  pushToCache(this.cacheKey, {
30095
30528
  data: [],
30096
- params: this.query,
30529
+ params: {},
30097
30530
  });
30098
30531
  }
30099
30532
  }
@@ -30103,561 +30536,224 @@ class MyInvitationsLiveCollectionController extends LiveCollectionController {
30103
30536
  persistQueryStream({ response, direction, refresh, }) {
30104
30537
  this.queryStreamController.appendToQueryStream(response, direction, refresh);
30105
30538
  }
30539
+ // eslint-disable-next-line class-methods-use-this
30106
30540
  startSubscription() {
30107
- return this.queryStreamController.subscribeRTE([
30108
- {
30109
- fn: onLocalInvitationCreated,
30110
- action: InvitationActionsEnum.OnLocalInvitationCreated,
30111
- },
30112
- {
30113
- fn: onLocalInvitationUpdated,
30114
- action: InvitationActionsEnum.OnLocalInvitationUpdated,
30115
- },
30116
- {
30117
- fn: onLocalInvitationDeleted,
30118
- action: InvitationActionsEnum.OnLocalInvitationDeleted,
30119
- },
30120
- ]);
30541
+ return [];
30121
30542
  }
30122
30543
  notifyChange({ origin, loading, error }) {
30123
30544
  var _a, _b;
30124
30545
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30125
30546
  if (!collection)
30126
30547
  return;
30127
- const data = this.applyFilter((_b = collection.data
30128
- .map(id => pullFromCache(['invitation', 'get', id]))
30548
+ const data = ((_b = collection.data
30549
+ .map(id => pullFromCache(['notificationTrayItem', 'get', id]))
30129
30550
  .filter(isNonNullable)
30130
- .map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
30551
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
30131
30552
  if (!this.shouldNotify(data) && origin === 'event')
30132
30553
  return;
30133
30554
  this.callback({
30134
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
30135
- data,
30136
- hasNextPage: !!this.paginationController.getNextToken(),
30137
- loading,
30138
- error,
30139
- });
30140
- }
30141
- applyFilter(data) {
30142
- let invitations = data;
30143
- if (this.query.targetId) {
30144
- invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
30145
- }
30146
- if (this.query.statuses) {
30147
- invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
30148
- }
30149
- if (this.query.targetType) {
30150
- invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
30151
- }
30152
- if (this.query.type) {
30153
- invitations = invitations.filter(invitation => invitation.type === this.query.type);
30154
- }
30155
- const sortFn = (() => {
30156
- switch (this.query.sortBy) {
30157
- case 'firstCreated':
30158
- return sortByFirstCreated;
30159
- case 'lastCreated':
30160
- return sortByLastCreated;
30161
- default:
30162
- return sortByLastCreated;
30163
- }
30164
- })();
30165
- invitations = invitations.sort(sortFn);
30166
- return invitations;
30167
- }
30168
- }
30169
-
30170
- /**
30171
- * Get my community invitations
30172
- *
30173
- * @param params the query parameters
30174
- * @param callback the callback to be called when the invitations are fetched
30175
- * @returns invitations
30176
- *
30177
- * @category My Community Invitations Live Collection
30178
- *
30179
- */
30180
- const getMyCommunityInvitations = (params, callback, config) => {
30181
- const { log, cache } = getActiveClient();
30182
- if (!cache) {
30183
- console.log(ENABLE_CACHE_MESSAGE);
30184
- }
30185
- const timestamp = Date.now();
30186
- log(`getMyCommunityInvitations: (tmpid: ${timestamp}) > listen`);
30187
- const invitationsLiveCollection = new MyInvitationsLiveCollectionController(Object.assign(Object.assign({}, params), { targetType: 'community', statuses: ["pending" /* InvitationStatusEnum.Pending */] }), callback);
30188
- const disposers = invitationsLiveCollection.startSubscription();
30189
- const cacheKey = invitationsLiveCollection.getCacheKey();
30190
- disposers.push(() => {
30191
- dropFromCache(cacheKey);
30192
- });
30193
- return () => {
30194
- log(`getInvitations (tmpid: ${timestamp}) > dispose`);
30195
- disposers.forEach(fn => fn());
30196
- };
30197
- };
30198
-
30199
- var index$2 = /*#__PURE__*/Object.freeze({
30200
- __proto__: null,
30201
- onLocalInvitationCreated: onLocalInvitationCreated,
30202
- onLocalInvitationUpdated: onLocalInvitationUpdated,
30203
- onLocalInvitationDeleted: onLocalInvitationDeleted,
30204
- getMyCommunityInvitations: getMyCommunityInvitations
30205
- });
30206
-
30207
- // TODO: confirm id
30208
- /* begin_public_function
30209
- id: live_reaction.create
30210
- */
30211
- /**
30212
- * ```js
30213
- * import { LiveReactionRepository } from '@amityco/ts-sdk'
30214
- * await LiveReactionRepository.createReaction({
30215
- * referenceType: 'post',
30216
- * referenceId: 'postId',
30217
- * streamId: 'streamId',
30218
- * reactionName: 'like',
30219
- * })
30220
- * ```
30221
- *
30222
- *
30223
- * @param referenceId that is target post's ID linked with a livestream
30224
- * @param referenceType should be 'post'
30225
- * @param reactionName that is the reaction name
30226
- * @param streamId stream id
30227
- * @returns a success boolean if the reaction was added
30228
- *
30229
- * @category Live Reaction API
30230
- * @async
30231
- */
30232
- const createReaction = async ({ referenceId, referenceType, reactionName, streamId, }) => {
30233
- const client = getActiveClient();
30234
- client.log('live_reaction/createReaction', {
30235
- referenceId,
30236
- referenceType,
30237
- reactionName,
30238
- });
30239
- const reactionSynceEngine = ReactionSyncEngine.getInstance();
30240
- const reaction = {
30241
- reactionName,
30242
- referencePublicId: referenceId,
30243
- referenceType,
30244
- streamId,
30245
- occurredAt: new Date().toISOString(),
30246
- };
30247
- reactionSynceEngine.createLiveReaction(reaction);
30248
- fireEvent('local.liveReaction.created', [Object.assign(Object.assign({}, reaction), { userId: client.userId, referenceId })]);
30249
- return true;
30250
- };
30251
- /* end_public_function */
30252
-
30253
- /**
30254
- * ```js
30255
- * import { onLiveReactionCreated } from '@amityco/ts-sdk'
30256
- * const dispose = onLiveReactionCreated(reactions => {
30257
- * // ...
30258
- * })
30259
- * ```
30260
- *
30261
- * Fired when a batch of {@link Amity.LiveReaction} has been created
30262
- *
30263
- * @param callback The function to call when the event was fired
30264
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30265
- *
30266
- * @category Live Reaction Events
30267
- */
30268
- const onLiveReactionCreated = (callback) => {
30269
- const client = getActiveClient();
30270
- const filter = (rawPayload) => {
30271
- if (rawPayload.reactions.length > 0) {
30272
- // TODO: check with BE if user id is internal or pulbic id
30273
- const filteredPayload = rawPayload.reactions.filter(({ userId }) => userId !== client.userId);
30274
- callback(filteredPayload);
30275
- }
30276
- };
30277
- return createEventSubscriber(client, 'live_reaction/onLiveReactionCreated', 'liveReaction.created', filter);
30278
- };
30279
-
30280
- /**
30281
- * ```js
30282
- * import { onLiveReactionCreatedLocal } from '@amityco/ts-sdk'
30283
- * const dispose = onLiveReactionCreatedLocal(reactions => {
30284
- * // ...
30285
- * })
30286
- * ```
30287
- *
30288
- * Fired when a batch of {@link Amity.LiveReaction} has been created
30289
- *
30290
- * @param callback The function to call when the event was fired
30291
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30292
- *
30293
- * @category Live Reaction Events
30294
- */
30295
- const onLiveReactionCreatedLocal = (callback) => {
30296
- const client = getActiveClient();
30297
- return createEventSubscriber(client, 'live_reaction/onLiveReactionCreated', 'local.liveReaction.created', callback);
30298
- };
30555
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
30556
+ data,
30557
+ hasNextPage: !!this.paginationController.getNextToken(),
30558
+ loading,
30559
+ error,
30560
+ });
30561
+ }
30562
+ }
30299
30563
 
30300
30564
  /**
30565
+ * Get notification tray items for a notification tray page
30301
30566
  *
30302
- * ```js
30303
- * import { getReactions } from '@amityco/ts-sdk';
30304
- *
30305
- * const unsubscribe = getReactions(response => {
30306
- * reactions = response.data
30307
- * });
30308
- * ```
30309
- *
30310
- * Observe live reactions {@link_Amity.LiveReaction} that have been created in a post linked with a stream
30567
+ * @param params the limit query parameters
30568
+ * @param callback the callback to be called when the notification tray items are updated
30569
+ * @returns items in the notification tray
30311
30570
  *
30312
- * @param callback the function to call when new data are available
30313
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the events
30571
+ * @category Notification tray items Live Collection
30314
30572
  *
30315
- * @category Live Reaction Observable
30316
30573
  */
30317
- // TODO: confirm return type for this observable property
30318
- const getReactions = (postId, callback) => {
30319
- const { _id: userId } = getActiveUser();
30320
- if (!userId)
30321
- throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
30322
- const { log } = getActiveClient();
30574
+ const getNotificationTrayItems = (params, callback, config) => {
30575
+ const { log, cache } = getActiveClient();
30576
+ if (!cache) {
30577
+ console.log(ENABLE_CACHE_MESSAGE);
30578
+ }
30323
30579
  const timestamp = Date.now();
30324
- log(`getReactions(tmpid: ${timestamp}) > listen`);
30325
- const disposers = [];
30326
- const dispatcher = (data) => {
30327
- callback(data);
30328
- };
30329
- const realtimeRouter = (data) => {
30330
- const relevantReactions = data.filter(({ referenceId }) => referenceId === postId);
30331
- dispatcher(relevantReactions);
30332
- };
30333
- disposers.push(onLiveReactionCreated(realtimeRouter));
30334
- disposers.push(onLiveReactionCreatedLocal(realtimeRouter));
30580
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
30581
+ const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
30582
+ const disposers = notiTrayItemsLiveCollection.startSubscription();
30583
+ const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
30584
+ disposers.push(() => dropFromCache(cacheKey));
30335
30585
  return () => {
30586
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
30336
30587
  disposers.forEach(fn => fn());
30337
30588
  };
30338
30589
  };
30339
30590
 
30340
- var index$1 = /*#__PURE__*/Object.freeze({
30341
- __proto__: null,
30342
- createReaction: createReaction,
30343
- onLiveReactionCreated: onLiveReactionCreated,
30344
- getReactions: getReactions
30345
- });
30346
-
30347
- const prepareEventPayload = (rawPayload) => {
30348
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
30349
- };
30350
-
30351
- const createEventEventSubscriber = (event, callback) => {
30352
- const client = getActiveClient();
30353
- const filter = (payload) => {
30354
- const unpackedPayload = prepareEventPayload(payload);
30355
- if (!client.cache) {
30356
- callback(unpackedPayload.events[0]);
30357
- }
30358
- else {
30359
- ingestInCache(unpackedPayload);
30360
- const event = pullFromCache([
30361
- 'event',
30362
- 'get',
30363
- unpackedPayload.events[0].eventId,
30364
- ]);
30365
- callback(event.data);
30366
- }
30367
- };
30368
- return createEventSubscriber(client, event, event, filter);
30369
- };
30370
-
30371
30591
  /* begin_public_function
30372
- id: event.create
30592
+ id: notificationTrayItem.markSeen
30373
30593
  */
30374
30594
  /**
30375
30595
  * ```js
30376
- * import { EventRepository } from '@amityco/ts-sdk'
30377
- * const response = await EventRepository.createEvent(bundle)
30596
+ * import { notificationTray } from '@amityco/ts-sdk'
30597
+ * const updated = await notificationTray.markItemsSeen()
30378
30598
  * ```
30379
30599
  *
30380
- * Creates an {@link Amity.Event}
30600
+ * Updates an {@link Amity.NotificationItemSeen}
30381
30601
  *
30382
- * @param bundle The data necessary to create a new {@link Amity.Event}
30383
- * @returns The newly created {@link Amity.Event}
30602
+ * @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
30603
+ * @returns the updated {@link Amity.NotificationItemSeen} object
30384
30604
  *
30385
- * @category Event API
30605
+ * @category NotificationItemSeen API
30386
30606
  * @async
30387
30607
  */
30388
- const createEvent = async (bundle) => {
30608
+ const markItemsSeen = async (trayItems) => {
30389
30609
  const client = getActiveClient();
30390
- client.log('event/createEvent', bundle);
30391
- const { data: payload } = await client.http.post('/api/v1/events', bundle);
30392
- fireEvent('event.created', payload);
30393
- const preparedPayload = prepareEventPayload(payload);
30394
- const cachedAt = client.cache && Date.now();
30395
- if (client.cache)
30396
- ingestInCache(preparedPayload, { cachedAt });
30397
- return {
30398
- data: eventLinkedObject(preparedPayload.events[0]),
30399
- cachedAt,
30400
- };
30610
+ client.log('notificationTray/markItemsSeen', {});
30611
+ const { data: payload } = await client.http.post(`api/v1/notification-tray/items/seen`, {
30612
+ trayItems: trayItems.map(item => ({
30613
+ id: item.id,
30614
+ lastSeenAt: item.lastSeenAt,
30615
+ })),
30616
+ });
30617
+ const updatedData = payload.trayItems
30618
+ .map(patchItem => {
30619
+ var _a;
30620
+ const cacheData = (_a = pullFromCache([
30621
+ 'notificationTrayItem',
30622
+ 'get',
30623
+ patchItem.id,
30624
+ ])) === null || _a === void 0 ? void 0 : _a.data;
30625
+ if (!cacheData)
30626
+ return;
30627
+ const data = Object.assign(Object.assign({}, cacheData), { lastSeenAt: patchItem.lastSeenAt });
30628
+ if (client.cache) {
30629
+ const cachedAt = Date.now();
30630
+ pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
30631
+ }
30632
+ return data;
30633
+ })
30634
+ .filter(Boolean);
30635
+ fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
30401
30636
  };
30402
30637
  /* end_public_function */
30403
30638
 
30404
30639
  /* begin_public_function
30405
- id: event.update
30640
+ id: notificationTray.markSeen
30406
30641
  */
30407
30642
  /**
30408
30643
  * ```js
30409
- * import { EventRepository } from '@amityco/ts-sdk'
30410
- * const response = await EventRepository.updateEvent(eventId, bundle)
30644
+ * import { notificationTray } from '@amityco/ts-sdk'
30645
+ * const updated = await notificationTray.markTraySeen({
30646
+ * lastSeenAt: Amity.timestamp,
30647
+ * })
30411
30648
  * ```
30412
30649
  *
30413
- * Updates an {@link Amity.Event}
30650
+ * Updates an {@link Amity.NotificationTraySeen}
30414
30651
  *
30415
- * @param eventId The ID of the {@link Amity.Event} to edit
30416
- * @param bundle The data necessary to update an existing {@link Amity.Event}
30417
- * @returns the updated {@link Amity.Event}
30652
+ * @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
30653
+ * @param lastSeenAt The patch data to apply
30654
+ * @returns the updated {@link Amity.NotificationTraySeen} object
30418
30655
  *
30419
- * @category Event API
30656
+ * @category Post API
30420
30657
  * @async
30421
30658
  */
30422
- const updateEvent = async (eventId, bundle) => {
30659
+ const markTraySeen = async (lastSeenAt) => {
30660
+ var _a;
30423
30661
  const client = getActiveClient();
30424
- client.log('event/updateEvent', eventId, bundle);
30425
- const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
30426
- fireEvent('event.updated', payload);
30427
- const preparedPayload = prepareEventPayload(payload);
30428
- const cachedAt = client.cache && Date.now();
30429
- if (client.cache)
30430
- ingestInCache(preparedPayload, { cachedAt });
30431
- return {
30432
- data: eventLinkedObject(preparedPayload.events.find(event => event.eventId === eventId)),
30433
- cachedAt,
30662
+ client.log('notificationTray/markTraySeen', {});
30663
+ const { data: payload } = await client.http.post(`api/v1/notification-tray/tray/seen`, {
30664
+ lastSeenAt,
30665
+ });
30666
+ const cacheData = (_a = pullFromCache([
30667
+ 'notificationTraySeen',
30668
+ 'get',
30669
+ ])) === null || _a === void 0 ? void 0 : _a.data;
30670
+ const data = {
30671
+ userId: client.userId,
30672
+ lastTraySeenAt: payload.lastSeenAt,
30434
30673
  };
30435
- };
30436
- /* end_public_function */
30437
-
30438
- /* begin_public_function
30439
- id: event.get
30440
- */
30441
- /**
30442
- * ```js
30443
- * import { EventRepository } from '@amityco/ts-sdk'
30444
- * const event = await EventRepository.getEvent(eventId)
30445
- * ```
30446
- *
30447
- * Fetches a {@link Amity.Event} object
30448
- *
30449
- * @param eventId the ID of the {@link Amity.Event} to fetch
30450
- * @returns the associated {@link Amity.Event} object
30451
- *
30452
- * @category Event API
30453
- * @async
30454
- */
30455
- const getEvent$1 = async (eventId) => {
30456
- const client = getActiveClient();
30457
- client.log('event/getEvent', eventId);
30458
- const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
30459
- const data = prepareEventPayload(payload);
30674
+ const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
30460
30675
  const cachedAt = client.cache && Date.now();
30461
30676
  if (client.cache)
30462
- ingestInCache(data, { cachedAt });
30677
+ pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
30678
+ fireEvent('local.notificationTraySeen.updated', data);
30463
30679
  return {
30464
- data: data.events.find(event => event.eventId === eventId),
30680
+ data: payload,
30465
30681
  cachedAt,
30466
30682
  };
30467
30683
  };
30468
30684
  /* end_public_function */
30469
- /**
30470
- * ```js
30471
- * import { EventRepository } from '@amityco/ts-sdk'
30472
- * const event = EventRepository.getEvent.locally(eventId)
30473
- * ```
30474
- *
30475
- * Fetches a {@link Amity.Event} object in cache
30476
- *
30477
- * @param eventId the ID of the {@link Amity.Event} to fetch
30478
- * @returns the associated {@link Amity.Event} object
30479
- *
30480
- * @category Event API
30481
- */
30482
- getEvent$1.locally = (eventId) => {
30483
- const client = getActiveClient();
30484
- client.log('event/getEvent.locally', eventId);
30485
- if (!client.cache)
30486
- return;
30487
- const cache = pullFromCache(['event', 'get', eventId]);
30488
- if (!cache)
30489
- return;
30490
- return {
30491
- data: cache.data,
30492
- cachedAt: cache.cachedAt,
30493
- };
30494
- };
30495
-
30496
- /* begin_public_function
30497
- id: event.delete
30498
- */
30499
- /**
30500
- * ```js
30501
- * import { EventRepository } from '@amityco/ts-sdk'
30502
- * const { success } = await EventRepository.deleteEvent(eventId)
30503
- * ```
30504
- *
30505
- * Deletes a {@link Amity.Event}
30506
- *
30507
- * @param eventId The {@link Amity.Event} ID to delete
30508
- *
30509
- * @category Event API
30510
- * @async
30511
- */
30512
- const deleteEvent = async (eventId) => {
30513
- const client = getActiveClient();
30514
- client.log('event/deleteEvent', eventId);
30515
- const event = await getEvent$1(eventId);
30516
- await client.http.delete(`/api/v3/events/${eventId}`);
30517
- const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
30518
- upsertInCache(['event', 'get', eventId], deletedEvent);
30519
- fireEvent('event.deleted', {
30520
- users: [],
30521
- files: [],
30522
- communities: [],
30523
- videoStreamings: [],
30524
- events: [deletedEvent],
30525
- discussionCommunities: [],
30526
- });
30527
- };
30528
- /* end_public_function */
30529
-
30530
- /**
30531
- * ```js
30532
- * import { EventRepository } from '@amityco/ts-sdk'
30533
- * const dispose = EventRepository.onEventCreated(event => {
30534
- * // ...
30535
- * })
30536
- * ```
30537
- *
30538
- * Fired when a {@link Amity.Event} has been created
30539
- *
30540
- * @param callback The function to call when the event was fired
30541
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30542
- *
30543
- * @category Event Events
30544
- */
30545
- const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
30546
-
30547
- /**
30548
- * ```js
30549
- * import { EventRepository } from '@amityco/ts-sdk'
30550
- * const dispose = EventRepository.onEventUpdated(event => {
30551
- * // ...
30552
- * })
30553
- * ```
30554
- *
30555
- * Fired when a {@link Amity.Event} has been updated
30556
- *
30557
- * @param callback The function to call when the event was fired
30558
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30559
- *
30560
- * @category Event Events
30561
- */
30562
- const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
30563
-
30564
- /**
30565
- * ```js
30566
- * import { EventRepository } from '@amityco/ts-sdk'
30567
- * const dispose = EventRepository.onEventDeleted(event => {
30568
- * // ...
30569
- * })
30570
- * ```
30571
- *
30572
- * Fired when a {@link Amity.Event} has been deleted
30573
- *
30574
- * @param callback The function to call when the event was fired
30575
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30576
- *
30577
- * @category Event Events
30578
- */
30579
- const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
30580
-
30581
- /* begin_public_function
30582
- id: event.get
30583
- */
30584
- /**
30585
- * ```js
30586
- * import { EventRepository } from '@amityco/ts-sdk';
30587
- *
30588
- * let event;
30589
- *
30590
- * const unsubscribe = EventRepository.getEvent(eventId, response => {
30591
- * event = response.data;
30592
- * });
30593
- * ```
30594
- *
30595
- * Observe all mutation on a given {@link Amity.Event}
30596
- *
30597
- * @param eventId the ID of the event to observe
30598
- * @param callback the function to call when new snapshot of event are available
30599
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the event
30600
- *
30601
- * @category Event Live Object
30602
- */
30603
- const getEvent = (eventId, callback) => {
30604
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
30605
- callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
30606
- });
30607
- };
30608
- /* end_public_function */
30609
30685
 
30610
- var EventActionsEnum;
30611
- (function (EventActionsEnum) {
30612
- EventActionsEnum["OnEventCreated"] = "onEventCreated";
30613
- EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
30614
- EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
30615
- })(EventActionsEnum || (EventActionsEnum = {}));
30686
+ var index$2 = /*#__PURE__*/Object.freeze({
30687
+ __proto__: null,
30688
+ getNotificationTraySeen: getNotificationTraySeen,
30689
+ getNotificationTrayItems: getNotificationTrayItems,
30690
+ markItemsSeen: markItemsSeen,
30691
+ markTraySeen: markTraySeen,
30692
+ onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
30693
+ });
30616
30694
 
30617
- class EventPaginationController extends PaginationController {
30695
+ class MyInvitationsPaginationController extends PaginationController {
30618
30696
  async getRequest(queryParams, token) {
30619
30697
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
30620
30698
  const options = token ? { token } : { limit };
30621
- const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
30622
- return response;
30699
+ const { data } = await this.http.get('/api/v1/invitations/me', { params: Object.assign(Object.assign({}, params), { options }) });
30700
+ await getCommunities$1(data.invitations.map(invitation => invitation.communityId));
30701
+ return data;
30623
30702
  }
30624
30703
  }
30625
30704
 
30626
- class EventQueryStreamController extends QueryStreamController {
30705
+ class MyInvitationsQueryStreamController extends QueryStreamController {
30627
30706
  constructor(query, cacheKey, notifyChange, preparePayload) {
30628
30707
  super(query, cacheKey);
30629
30708
  this.notifyChange = notifyChange;
30630
30709
  this.preparePayload = preparePayload;
30631
30710
  }
30632
30711
  async saveToMainDB(response) {
30633
- const processedPayload = this.preparePayload(response);
30712
+ const processedPayload = await this.preparePayload(response);
30634
30713
  const client = getActiveClient();
30635
30714
  const cachedAt = client.cache && Date.now();
30636
- if (client.cache)
30715
+ if (client.cache) {
30637
30716
  ingestInCache(processedPayload, { cachedAt });
30717
+ }
30638
30718
  }
30639
30719
  appendToQueryStream(response, direction, refresh = false) {
30640
30720
  var _a, _b;
30641
30721
  if (refresh) {
30642
- pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
30722
+ pushToCache(this.cacheKey, {
30723
+ data: response.invitations.map(getResolver('invitation')),
30724
+ });
30643
30725
  }
30644
30726
  else {
30645
30727
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30646
- const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
30647
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
30728
+ const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
30729
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
30730
+ ...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
30731
+ ] }));
30648
30732
  }
30649
30733
  }
30650
30734
  reactor(action) {
30651
- return (event) => {
30735
+ return (invitations) => {
30652
30736
  var _a;
30653
30737
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30654
30738
  if (!collection)
30655
30739
  return;
30656
- if (action === EventActionsEnum.OnEventCreated) {
30657
- collection.data = [...new Set([event.eventId, ...collection.data])];
30740
+ if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
30741
+ const isExist = collection.data.find(id => id === invitations[0].invitationId);
30742
+ if (!isExist)
30743
+ return;
30744
+ }
30745
+ if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
30746
+ const client = getActiveClient();
30747
+ const myInvitations = invitations.filter(invitation => invitation.invitedUserId === client.userId);
30748
+ collection.data = [
30749
+ ...new Set([
30750
+ ...myInvitations.map(invitation => invitation.invitationId),
30751
+ ...collection.data,
30752
+ ]),
30753
+ ];
30658
30754
  }
30659
- if (action === EventActionsEnum.OnEventDeleted) {
30660
- collection.data = collection.data.filter(eventId => eventId !== event.eventId);
30755
+ if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
30756
+ collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
30661
30757
  }
30662
30758
  pushToCache(this.cacheKey, collection);
30663
30759
  this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
@@ -30668,22 +30764,26 @@ class EventQueryStreamController extends QueryStreamController {
30668
30764
  }
30669
30765
  }
30670
30766
 
30671
- class EventLiveCollectionController extends LiveCollectionController {
30767
+ class MyInvitationsLiveCollectionController extends LiveCollectionController {
30672
30768
  constructor(query, callback) {
30673
30769
  const queryStreamId = hash__default["default"](query);
30674
- const cacheKey = ['event', 'collection', queryStreamId];
30675
- const paginationController = new EventPaginationController(query);
30770
+ const cacheKey = ['invitation', 'collection', queryStreamId];
30771
+ const paginationController = new MyInvitationsPaginationController(query);
30676
30772
  super(paginationController, queryStreamId, cacheKey, callback);
30677
30773
  this.query = query;
30678
- this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
30774
+ this.queryStreamController = new MyInvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareMyInvitationsPayload);
30679
30775
  this.callback = callback.bind(this);
30680
30776
  this.loadPage({ initial: true });
30681
30777
  }
30682
30778
  setup() {
30683
30779
  var _a;
30684
30780
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30685
- if (!collection)
30686
- pushToCache(this.cacheKey, { data: [], params: {} });
30781
+ if (!collection) {
30782
+ pushToCache(this.cacheKey, {
30783
+ data: [],
30784
+ params: this.query,
30785
+ });
30786
+ }
30687
30787
  }
30688
30788
  async persistModel(queryPayload) {
30689
30789
  await this.queryStreamController.saveToMainDB(queryPayload);
@@ -30693,9 +30793,18 @@ class EventLiveCollectionController extends LiveCollectionController {
30693
30793
  }
30694
30794
  startSubscription() {
30695
30795
  return this.queryStreamController.subscribeRTE([
30696
- { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
30697
- { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
30698
- { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
30796
+ {
30797
+ fn: onLocalInvitationCreated,
30798
+ action: InvitationActionsEnum.OnLocalInvitationCreated,
30799
+ },
30800
+ {
30801
+ fn: onLocalInvitationUpdated,
30802
+ action: InvitationActionsEnum.OnLocalInvitationUpdated,
30803
+ },
30804
+ {
30805
+ fn: onLocalInvitationDeleted,
30806
+ action: InvitationActionsEnum.OnLocalInvitationDeleted,
30807
+ },
30699
30808
  ]);
30700
30809
  }
30701
30810
  notifyChange({ origin, loading, error }) {
@@ -30703,62 +30812,228 @@ class EventLiveCollectionController extends LiveCollectionController {
30703
30812
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30704
30813
  if (!collection)
30705
30814
  return;
30706
- const data = ((_b = collection.data
30707
- .map(eventId => pullFromCache(['event', 'get', eventId]))
30815
+ const data = this.applyFilter((_b = collection.data
30816
+ .map(id => pullFromCache(['invitation', 'get', id]))
30708
30817
  .filter(isNonNullable)
30709
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
30818
+ .map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
30710
30819
  if (!this.shouldNotify(data) && origin === 'event')
30711
30820
  return;
30712
30821
  this.callback({
30822
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
30713
30823
  data,
30714
- error,
30715
- loading,
30716
30824
  hasNextPage: !!this.paginationController.getNextToken(),
30717
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
30825
+ loading,
30826
+ error,
30718
30827
  });
30719
30828
  }
30829
+ applyFilter(data) {
30830
+ let invitations = data;
30831
+ if (this.query.targetId) {
30832
+ invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
30833
+ }
30834
+ if (this.query.statuses) {
30835
+ invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
30836
+ }
30837
+ if (this.query.targetType) {
30838
+ invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
30839
+ }
30840
+ if (this.query.type) {
30841
+ invitations = invitations.filter(invitation => invitation.type === this.query.type);
30842
+ }
30843
+ const sortFn = (() => {
30844
+ switch (this.query.sortBy) {
30845
+ case 'firstCreated':
30846
+ return sortByFirstCreated;
30847
+ case 'lastCreated':
30848
+ return sortByLastCreated;
30849
+ default:
30850
+ return sortByLastCreated;
30851
+ }
30852
+ })();
30853
+ invitations = invitations.sort(sortFn);
30854
+ return invitations;
30855
+ }
30720
30856
  }
30721
30857
 
30722
30858
  /**
30723
- * Get events
30859
+ * Get my community invitations
30724
30860
  *
30725
30861
  * @param params the query parameters
30726
- * @param callback the callback to be called when the events are updated
30727
- * @returns events
30862
+ * @param callback the callback to be called when the invitations are fetched
30863
+ * @returns invitations
30728
30864
  *
30729
- * @category Event Live Collection
30865
+ * @category My Community Invitations Live Collection
30730
30866
  *
30731
30867
  */
30732
- const getEvents = (params, callback, config) => {
30868
+ const getMyCommunityInvitations = (params, callback, config) => {
30733
30869
  const { log, cache } = getActiveClient();
30734
- if (!cache)
30870
+ if (!cache) {
30735
30871
  console.log(ENABLE_CACHE_MESSAGE);
30872
+ }
30736
30873
  const timestamp = Date.now();
30737
- log(`getEvents: (tmpid: ${timestamp}) > listen`);
30738
- const eventLiveCollection = new EventLiveCollectionController(params, callback);
30739
- const disposers = eventLiveCollection.startSubscription();
30740
- const cacheKey = eventLiveCollection.getCacheKey();
30741
- disposers.push(() => dropFromCache(cacheKey));
30874
+ log(`getMyCommunityInvitations: (tmpid: ${timestamp}) > listen`);
30875
+ const invitationsLiveCollection = new MyInvitationsLiveCollectionController(Object.assign(Object.assign({}, params), { targetType: 'community', statuses: ["pending" /* InvitationStatusEnum.Pending */] }), callback);
30876
+ const disposers = invitationsLiveCollection.startSubscription();
30877
+ const cacheKey = invitationsLiveCollection.getCacheKey();
30878
+ disposers.push(() => {
30879
+ dropFromCache(cacheKey);
30880
+ });
30881
+ return () => {
30882
+ log(`getInvitations (tmpid: ${timestamp}) > dispose`);
30883
+ disposers.forEach(fn => fn());
30884
+ };
30885
+ };
30886
+
30887
+ var index$1 = /*#__PURE__*/Object.freeze({
30888
+ __proto__: null,
30889
+ onLocalInvitationCreated: onLocalInvitationCreated,
30890
+ onLocalInvitationUpdated: onLocalInvitationUpdated,
30891
+ onLocalInvitationDeleted: onLocalInvitationDeleted,
30892
+ getMyCommunityInvitations: getMyCommunityInvitations
30893
+ });
30894
+
30895
+ // TODO: confirm id
30896
+ /* begin_public_function
30897
+ id: live_reaction.create
30898
+ */
30899
+ /**
30900
+ * ```js
30901
+ * import { LiveReactionRepository } from '@amityco/ts-sdk'
30902
+ * await LiveReactionRepository.createReaction({
30903
+ * referenceType: 'post',
30904
+ * referenceId: 'postId',
30905
+ * streamId: 'streamId',
30906
+ * reactionName: 'like',
30907
+ * })
30908
+ * ```
30909
+ *
30910
+ *
30911
+ * @param referenceId that is target post's ID linked with a livestream
30912
+ * @param referenceType should be 'post'
30913
+ * @param reactionName that is the reaction name
30914
+ * @param streamId stream id
30915
+ * @returns a success boolean if the reaction was added
30916
+ *
30917
+ * @category Live Reaction API
30918
+ * @async
30919
+ */
30920
+ const createReaction = async ({ referenceId, referenceType, reactionName, streamId, }) => {
30921
+ const client = getActiveClient();
30922
+ client.log('live_reaction/createReaction', {
30923
+ referenceId,
30924
+ referenceType,
30925
+ reactionName,
30926
+ });
30927
+ const reactionSynceEngine = ReactionSyncEngine.getInstance();
30928
+ const reaction = {
30929
+ reactionName,
30930
+ referencePublicId: referenceId,
30931
+ referenceType,
30932
+ streamId,
30933
+ occurredAt: new Date().toISOString(),
30934
+ };
30935
+ reactionSynceEngine.createLiveReaction(reaction);
30936
+ fireEvent('local.liveReaction.created', [Object.assign(Object.assign({}, reaction), { userId: client.userId, referenceId })]);
30937
+ return true;
30938
+ };
30939
+ /* end_public_function */
30940
+
30941
+ /**
30942
+ * ```js
30943
+ * import { onLiveReactionCreated } from '@amityco/ts-sdk'
30944
+ * const dispose = onLiveReactionCreated(reactions => {
30945
+ * // ...
30946
+ * })
30947
+ * ```
30948
+ *
30949
+ * Fired when a batch of {@link Amity.LiveReaction} has been created
30950
+ *
30951
+ * @param callback The function to call when the event was fired
30952
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30953
+ *
30954
+ * @category Live Reaction Events
30955
+ */
30956
+ const onLiveReactionCreated = (callback) => {
30957
+ const client = getActiveClient();
30958
+ const filter = (rawPayload) => {
30959
+ if (rawPayload.reactions.length > 0) {
30960
+ // TODO: check with BE if user id is internal or pulbic id
30961
+ const filteredPayload = rawPayload.reactions.filter(({ userId }) => userId !== client.userId);
30962
+ callback(filteredPayload);
30963
+ }
30964
+ };
30965
+ return createEventSubscriber(client, 'live_reaction/onLiveReactionCreated', 'liveReaction.created', filter);
30966
+ };
30967
+
30968
+ /**
30969
+ * ```js
30970
+ * import { onLiveReactionCreatedLocal } from '@amityco/ts-sdk'
30971
+ * const dispose = onLiveReactionCreatedLocal(reactions => {
30972
+ * // ...
30973
+ * })
30974
+ * ```
30975
+ *
30976
+ * Fired when a batch of {@link Amity.LiveReaction} has been created
30977
+ *
30978
+ * @param callback The function to call when the event was fired
30979
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30980
+ *
30981
+ * @category Live Reaction Events
30982
+ */
30983
+ const onLiveReactionCreatedLocal = (callback) => {
30984
+ const client = getActiveClient();
30985
+ return createEventSubscriber(client, 'live_reaction/onLiveReactionCreated', 'local.liveReaction.created', callback);
30986
+ };
30987
+
30988
+ /**
30989
+ *
30990
+ * ```js
30991
+ * import { getReactions } from '@amityco/ts-sdk';
30992
+ *
30993
+ * const unsubscribe = getReactions(response => {
30994
+ * reactions = response.data
30995
+ * });
30996
+ * ```
30997
+ *
30998
+ * Observe live reactions {@link_Amity.LiveReaction} that have been created in a post linked with a stream
30999
+ *
31000
+ * @param callback the function to call when new data are available
31001
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the events
31002
+ *
31003
+ * @category Live Reaction Observable
31004
+ */
31005
+ // TODO: confirm return type for this observable property
31006
+ const getReactions = (postId, callback) => {
31007
+ const { _id: userId } = getActiveUser();
31008
+ if (!userId)
31009
+ throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
31010
+ const { log } = getActiveClient();
31011
+ const timestamp = Date.now();
31012
+ log(`getReactions(tmpid: ${timestamp}) > listen`);
31013
+ const disposers = [];
31014
+ const dispatcher = (data) => {
31015
+ callback(data);
31016
+ };
31017
+ const realtimeRouter = (data) => {
31018
+ const relevantReactions = data.filter(({ referenceId }) => referenceId === postId);
31019
+ dispatcher(relevantReactions);
31020
+ };
31021
+ disposers.push(onLiveReactionCreated(realtimeRouter));
31022
+ disposers.push(onLiveReactionCreatedLocal(realtimeRouter));
30742
31023
  return () => {
30743
- log(`getEvents (tmpid: ${timestamp}) > dispose`);
30744
31024
  disposers.forEach(fn => fn());
30745
31025
  };
30746
31026
  };
30747
31027
 
30748
31028
  var index = /*#__PURE__*/Object.freeze({
30749
31029
  __proto__: null,
30750
- createEvent: createEvent,
30751
- updateEvent: updateEvent,
30752
- deleteEvent: deleteEvent,
30753
- onEventCreated: onEventCreated,
30754
- onEventUpdated: onEventUpdated,
30755
- onEventDeleted: onEventDeleted,
30756
- getEvent: getEvent,
30757
- getEvents: getEvents
31030
+ createReaction: createReaction,
31031
+ onLiveReactionCreated: onLiveReactionCreated,
31032
+ getReactions: getReactions
30758
31033
  });
30759
31034
 
30760
31035
  exports.API_REGIONS = API_REGIONS;
30761
- exports.AdRepository = index$4;
31036
+ exports.AdRepository = index$3;
30762
31037
  exports.CategoryRepository = index$c;
30763
31038
  exports.ChannelRepository = index$g;
30764
31039
  exports.Client = index$p;
@@ -30768,22 +31043,22 @@ exports.CommunityPostSettings = CommunityPostSettings;
30768
31043
  exports.CommunityRepository = index$d;
30769
31044
  exports.ContentFeedType = ContentFeedType;
30770
31045
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
30771
- exports.EventRepository = index;
30772
31046
  exports.FeedRepository = index$a;
30773
31047
  exports.FileRepository = index$m;
30774
31048
  exports.FileType = FileType;
30775
31049
  exports.GET_WATCHER_URLS = GET_WATCHER_URLS;
30776
- exports.InvitationRepository = index$2;
30777
- exports.LiveReactionRepository = index$1;
30778
- exports.LiveStreamPlayer = index$6;
31050
+ exports.InvitationRepository = index$1;
31051
+ exports.LiveReactionRepository = index;
31052
+ exports.LiveStreamPlayer = index$5;
30779
31053
  exports.MessageContentType = MessageContentType;
30780
31054
  exports.MessageRepository = index$k;
30781
- exports.PollRepository = index$7;
31055
+ exports.PollRepository = index$6;
30782
31056
  exports.PostContentType = PostContentType;
30783
31057
  exports.PostRepository = index$9;
30784
31058
  exports.PostStructureType = PostStructureType;
30785
31059
  exports.ReactionRepository = index$l;
30786
- exports.StoryRepository = index$5;
31060
+ exports.RoomRepository = index$7;
31061
+ exports.StoryRepository = index$4;
30787
31062
  exports.StreamRepository = index$8;
30788
31063
  exports.SubChannelRepository = index$j;
30789
31064
  exports.UserRepository = index$n;
@@ -30840,7 +31115,7 @@ exports.isPaged = isPaged;
30840
31115
  exports.isReportedByMe = isReportedByMe;
30841
31116
  exports.isSkip = isSkip;
30842
31117
  exports.mergeInCache = mergeInCache;
30843
- exports.notificationTray = index$3;
31118
+ exports.notificationTray = index$2;
30844
31119
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
30845
31120
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
30846
31121
  exports.onFeedMarkerUpdated = onFeedMarkerUpdated;