@amityco/ts-sdk 7.11.1-b750131c.0 → 7.11.1-b94657c5.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 (195) hide show
  1. package/dist/@types/core/events.d.ts +36 -13
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +6 -3
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +30 -4
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/core/permissions.d.ts +5 -1
  8. package/dist/@types/core/permissions.d.ts.map +1 -1
  9. package/dist/@types/core/transport.d.ts +3 -0
  10. package/dist/@types/core/transport.d.ts.map +1 -1
  11. package/dist/@types/domains/community.d.ts +11 -1
  12. package/dist/@types/domains/community.d.ts.map +1 -1
  13. package/dist/@types/domains/content.d.ts +1 -4
  14. package/dist/@types/domains/content.d.ts.map +1 -1
  15. package/dist/@types/domains/event.d.ts +109 -0
  16. package/dist/@types/domains/event.d.ts.map +1 -0
  17. package/dist/@types/domains/feed.d.ts +1 -2
  18. package/dist/@types/domains/feed.d.ts.map +1 -1
  19. package/dist/@types/domains/notification.d.ts +4 -1
  20. package/dist/@types/domains/notification.d.ts.map +1 -1
  21. package/dist/@types/domains/partials.d.ts +2 -2
  22. package/dist/@types/domains/partials.d.ts.map +1 -1
  23. package/dist/@types/domains/post.d.ts +0 -2
  24. package/dist/@types/domains/post.d.ts.map +1 -1
  25. package/dist/@types/index.d.ts +1 -2
  26. package/dist/@types/index.d.ts.map +1 -1
  27. package/dist/channelRepository/api/createChannel.d.ts +0 -1
  28. package/dist/channelRepository/api/createChannel.d.ts.map +1 -1
  29. package/dist/core/events.d.ts +3 -3
  30. package/dist/core/events.d.ts.map +1 -1
  31. package/dist/core/model/idResolvers.d.ts.map +1 -1
  32. package/dist/core/model/index.d.ts.map +1 -1
  33. package/dist/eventRepository/api/createEvent.d.ts +16 -0
  34. package/dist/eventRepository/api/createEvent.d.ts.map +1 -0
  35. package/dist/eventRepository/api/deleteEvent.d.ts +15 -0
  36. package/dist/eventRepository/api/deleteEvent.d.ts.map +1 -0
  37. package/dist/eventRepository/api/index.d.ts +4 -0
  38. package/dist/eventRepository/api/index.d.ts.map +1 -0
  39. package/dist/eventRepository/api/updateEvent.d.ts +17 -0
  40. package/dist/eventRepository/api/updateEvent.d.ts.map +1 -0
  41. package/dist/eventRepository/events/enums.d.ts +8 -0
  42. package/dist/eventRepository/events/enums.d.ts.map +1 -0
  43. package/dist/eventRepository/events/index.d.ts +11 -0
  44. package/dist/eventRepository/events/index.d.ts.map +1 -0
  45. package/dist/eventRepository/events/onEventCreated.d.ts +17 -0
  46. package/dist/eventRepository/events/onEventCreated.d.ts.map +1 -0
  47. package/dist/eventRepository/events/onEventDeleted.d.ts +17 -0
  48. package/dist/eventRepository/events/onEventDeleted.d.ts.map +1 -0
  49. package/dist/eventRepository/events/onEventUpdated.d.ts +17 -0
  50. package/dist/eventRepository/events/onEventUpdated.d.ts.map +1 -0
  51. package/dist/eventRepository/events/onLocalEventCreated.d.ts +17 -0
  52. package/dist/eventRepository/events/onLocalEventCreated.d.ts.map +1 -0
  53. package/dist/eventRepository/events/onLocalEventDeleted.d.ts +17 -0
  54. package/dist/eventRepository/events/onLocalEventDeleted.d.ts.map +1 -0
  55. package/dist/eventRepository/events/onLocalEventUpdated.d.ts +17 -0
  56. package/dist/eventRepository/events/onLocalEventUpdated.d.ts.map +1 -0
  57. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts +17 -0
  58. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts.map +1 -0
  59. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts +17 -0
  60. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts.map +1 -0
  61. package/dist/eventRepository/events/onRSVPCreated.d.ts +17 -0
  62. package/dist/eventRepository/events/onRSVPCreated.d.ts.map +1 -0
  63. package/dist/eventRepository/events/onRSVPUpdated.d.ts +17 -0
  64. package/dist/eventRepository/events/onRSVPUpdated.d.ts.map +1 -0
  65. package/dist/eventRepository/index.d.ts.map +1 -0
  66. package/dist/eventRepository/internalApi/createRSVP.d.ts +16 -0
  67. package/dist/eventRepository/internalApi/createRSVP.d.ts.map +1 -0
  68. package/dist/eventRepository/internalApi/getEvent.d.ts +32 -0
  69. package/dist/eventRepository/internalApi/getEvent.d.ts.map +1 -0
  70. package/dist/eventRepository/internalApi/getMyRSVP.d.ts +32 -0
  71. package/dist/eventRepository/internalApi/getMyRSVP.d.ts.map +1 -0
  72. package/dist/eventRepository/internalApi/index.d.ts +5 -0
  73. package/dist/eventRepository/internalApi/index.d.ts.map +1 -0
  74. package/dist/eventRepository/internalApi/updateRSVP.d.ts +17 -0
  75. package/dist/eventRepository/internalApi/updateRSVP.d.ts.map +1 -0
  76. package/dist/eventRepository/observers/getEvent.d.ts +21 -0
  77. package/dist/eventRepository/observers/getEvent.d.ts.map +1 -0
  78. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts +13 -0
  79. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +1 -0
  80. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts +5 -0
  81. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts.map +1 -0
  82. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts +15 -0
  83. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts.map +1 -0
  84. package/dist/eventRepository/observers/getEvents.d.ts +12 -0
  85. package/dist/eventRepository/observers/getEvents.d.ts.map +1 -0
  86. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts +13 -0
  87. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -0
  88. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts +5 -0
  89. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts.map +1 -0
  90. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts +15 -0
  91. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +1 -0
  92. package/dist/eventRepository/observers/getMyEvents.d.ts +12 -0
  93. package/dist/eventRepository/observers/getMyEvents.d.ts.map +1 -0
  94. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts +13 -0
  95. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts.map +1 -0
  96. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts +5 -0
  97. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts.map +1 -0
  98. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts +15 -0
  99. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts.map +1 -0
  100. package/dist/eventRepository/observers/getRSVPs.d.ts +12 -0
  101. package/dist/eventRepository/observers/getRSVPs.d.ts.map +1 -0
  102. package/dist/eventRepository/observers/index.d.ts +5 -0
  103. package/dist/eventRepository/observers/index.d.ts.map +1 -0
  104. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +2 -0
  105. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -0
  106. package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts +2 -0
  107. package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts.map +1 -0
  108. package/dist/eventRepository/utils/index.d.ts +5 -0
  109. package/dist/eventRepository/utils/index.d.ts.map +1 -0
  110. package/dist/eventRepository/utils/prepareEventPayload.d.ts +2 -0
  111. package/dist/eventRepository/utils/prepareEventPayload.d.ts.map +1 -0
  112. package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts +2 -0
  113. package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts.map +1 -0
  114. package/dist/index.cjs.js +13043 -12718
  115. package/dist/index.d.ts +1 -1
  116. package/dist/index.d.ts.map +1 -1
  117. package/dist/index.esm.js +1072 -747
  118. package/dist/index.umd.js +3 -3
  119. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -1
  120. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
  121. package/dist/utils/linkedObject/eventLinkObject.d.ts +2 -0
  122. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -0
  123. package/dist/utils/linkedObject/index.d.ts +1 -0
  124. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  125. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  126. package/dist/utils/postTypePredicate.d.ts +0 -1
  127. package/dist/utils/postTypePredicate.d.ts.map +1 -1
  128. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  129. package/package.json +1 -1
  130. package/dist/@types/domains/room.d.ts +0 -77
  131. package/dist/@types/domains/room.d.ts.map +0 -1
  132. package/dist/roomRepository/api/createRoom.d.ts +0 -24
  133. package/dist/roomRepository/api/createRoom.d.ts.map +0 -1
  134. package/dist/roomRepository/api/deleteRoom.d.ts +0 -16
  135. package/dist/roomRepository/api/deleteRoom.d.ts.map +0 -1
  136. package/dist/roomRepository/api/getRecordedUrl.d.ts +0 -19
  137. package/dist/roomRepository/api/getRecordedUrl.d.ts.map +0 -1
  138. package/dist/roomRepository/api/getRoomToken.d.ts +0 -16
  139. package/dist/roomRepository/api/getRoomToken.d.ts.map +0 -1
  140. package/dist/roomRepository/api/index.d.ts +0 -7
  141. package/dist/roomRepository/api/index.d.ts.map +0 -1
  142. package/dist/roomRepository/api/stopRoom.d.ts +0 -16
  143. package/dist/roomRepository/api/stopRoom.d.ts.map +0 -1
  144. package/dist/roomRepository/api/updateRoom.d.ts +0 -24
  145. package/dist/roomRepository/api/updateRoom.d.ts.map +0 -1
  146. package/dist/roomRepository/events/index.d.ts +0 -12
  147. package/dist/roomRepository/events/index.d.ts.map +0 -1
  148. package/dist/roomRepository/events/onRoomCreated.d.ts +0 -17
  149. package/dist/roomRepository/events/onRoomCreated.d.ts.map +0 -1
  150. package/dist/roomRepository/events/onRoomDeleted.d.ts +0 -17
  151. package/dist/roomRepository/events/onRoomDeleted.d.ts.map +0 -1
  152. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts +0 -17
  153. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts.map +0 -1
  154. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts +0 -17
  155. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts.map +0 -1
  156. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts +0 -17
  157. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts.map +0 -1
  158. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts +0 -17
  159. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts.map +0 -1
  160. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts +0 -17
  161. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts.map +0 -1
  162. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts +0 -17
  163. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts.map +0 -1
  164. package/dist/roomRepository/events/onRoomStopped.d.ts +0 -17
  165. package/dist/roomRepository/events/onRoomStopped.d.ts.map +0 -1
  166. package/dist/roomRepository/events/onRoomUpdated.d.ts +0 -17
  167. package/dist/roomRepository/events/onRoomUpdated.d.ts.map +0 -1
  168. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts +0 -17
  169. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts.map +0 -1
  170. package/dist/roomRepository/index.d.ts.map +0 -1
  171. package/dist/roomRepository/internalApi/getLiveChat.d.ts +0 -16
  172. package/dist/roomRepository/internalApi/getLiveChat.d.ts.map +0 -1
  173. package/dist/roomRepository/internalApi/getRoomById.d.ts +0 -5
  174. package/dist/roomRepository/internalApi/getRoomById.d.ts.map +0 -1
  175. package/dist/roomRepository/internalApi/index.d.ts +0 -3
  176. package/dist/roomRepository/internalApi/index.d.ts.map +0 -1
  177. package/dist/roomRepository/observers/enums.d.ts +0 -10
  178. package/dist/roomRepository/observers/enums.d.ts.map +0 -1
  179. package/dist/roomRepository/observers/getRoom.d.ts +0 -2
  180. package/dist/roomRepository/observers/getRoom.d.ts.map +0 -1
  181. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts +0 -14
  182. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts.map +0 -1
  183. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts +0 -5
  184. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts.map +0 -1
  185. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts +0 -15
  186. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts.map +0 -1
  187. package/dist/roomRepository/observers/getRooms.d.ts +0 -29
  188. package/dist/roomRepository/observers/getRooms.d.ts.map +0 -1
  189. package/dist/roomRepository/observers/index.d.ts +0 -3
  190. package/dist/roomRepository/observers/index.d.ts.map +0 -1
  191. package/dist/roomRepository/observers/utils.d.ts +0 -6
  192. package/dist/roomRepository/observers/utils.d.ts.map +0 -1
  193. package/dist/utils/linkedObject/roomLinkedObject.d.ts +0 -2
  194. package/dist/utils/linkedObject/roomLinkedObject.d.ts.map +0 -1
  195. /package/dist/{roomRepository → eventRepository}/index.d.ts +0 -0
package/dist/index.esm.js CHANGED
@@ -112,7 +112,6 @@ const PostContentType = Object.freeze({
112
112
  POLL: 'poll',
113
113
  CLIP: 'clip',
114
114
  AUDIO: 'audio',
115
- ROOM: 'room',
116
115
  });
117
116
  const PostStructureType = Object.freeze({
118
117
  TEXT: 'text',
@@ -164,7 +163,6 @@ var FeedDataTypeEnum;
164
163
  FeedDataTypeEnum["LiveStream"] = "liveStream";
165
164
  FeedDataTypeEnum["Clip"] = "clip";
166
165
  FeedDataTypeEnum["Poll"] = "poll";
167
- FeedDataTypeEnum["Room"] = "room";
168
166
  })(FeedDataTypeEnum || (FeedDataTypeEnum = {}));
169
167
  var FeedSortByEnum;
170
168
  (function (FeedSortByEnum) {
@@ -179,6 +177,29 @@ var FeedSourceEnum;
179
177
  FeedSourceEnum["User"] = "user";
180
178
  })(FeedSourceEnum || (FeedSourceEnum = {}));
181
179
 
180
+ var AmityEventType;
181
+ (function (AmityEventType) {
182
+ AmityEventType["Virtual"] = "virtual";
183
+ AmityEventType["InPerson"] = "in_person";
184
+ })(AmityEventType || (AmityEventType = {}));
185
+ var AmityEventOriginType;
186
+ (function (AmityEventOriginType) {
187
+ AmityEventOriginType["Community"] = "community";
188
+ AmityEventOriginType["User"] = "user";
189
+ })(AmityEventOriginType || (AmityEventOriginType = {}));
190
+ var AmityEventStatus;
191
+ (function (AmityEventStatus) {
192
+ AmityEventStatus["Scheduled"] = "scheduled";
193
+ AmityEventStatus["Live"] = "live";
194
+ AmityEventStatus["Ended"] = "ended";
195
+ AmityEventStatus["Cancelled"] = "cancelled";
196
+ })(AmityEventStatus || (AmityEventStatus = {}));
197
+ var AmityEventResponseStatus;
198
+ (function (AmityEventResponseStatus) {
199
+ AmityEventResponseStatus["Going"] = "going";
200
+ AmityEventResponseStatus["NotGoing"] = "not_going";
201
+ })(AmityEventResponseStatus || (AmityEventResponseStatus = {}));
202
+
182
203
  function getVersion() {
183
204
  try {
184
205
  // the string ''v7.11.0-esm'' should be replaced by actual value by @rollup/plugin-replace
@@ -627,7 +648,9 @@ const idResolvers = {
627
648
  notificationTraySeen: ({ userId }) => userId,
628
649
  invitation: ({ _id }) => _id,
629
650
  joinRequest: ({ joinRequestId }) => joinRequestId,
630
- room: ({ roomId }) => roomId,
651
+ event: ({ eventId }) => eventId,
652
+ eventResponse: ({ eventId }) => eventId,
653
+ discussionCommunity: ({ communityId }) => communityId,
631
654
  };
632
655
  /**
633
656
  * Retrieve the id resolver matching a domain name
@@ -683,7 +706,9 @@ const PAYLOAD2MODEL = {
683
706
  notificationTrayItems: 'notificationTrayItem',
684
707
  invitations: 'invitation',
685
708
  joinRequests: 'joinRequest',
686
- rooms: 'room',
709
+ events: 'event',
710
+ eventResponses: 'eventResponse',
711
+ discussionCommunities: 'discussionCommunity',
687
712
  };
688
713
  /** hidden */
689
714
  const isOutdated = (prevData, nextData) => {
@@ -28303,12 +28328,6 @@ function isAmityAudioPost(post) {
28303
28328
  'fileId' in post.data &&
28304
28329
  post.dataType === 'audio');
28305
28330
  }
28306
- function isAmityRoomPost(post) {
28307
- return !!(post.data &&
28308
- typeof post.data !== 'string' &&
28309
- 'roomId' in post.data &&
28310
- post.dataType === 'room');
28311
- }
28312
28331
 
28313
28332
  const postLinkedObject = (post) => {
28314
28333
  return shallowClone(post, {
@@ -28403,12 +28422,6 @@ const postLinkedObject = (post) => {
28403
28422
  ? (_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
28404
28423
  : undefined;
28405
28424
  },
28406
- getRoomInfo() {
28407
- var _a, _b;
28408
- if (!isAmityRoomPost(post))
28409
- return;
28410
- 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;
28411
- },
28412
28425
  });
28413
28426
  };
28414
28427
 
@@ -29766,6 +29779,560 @@ const communityLinkedObject = (community) => {
29766
29779
  } });
29767
29780
  };
29768
29781
 
29782
+ const prepareEventResponsePayload = (rawPayload) => {
29783
+ return {
29784
+ respondedAt: rawPayload.eventResponses[0].respondedAt,
29785
+ status: rawPayload.eventResponses[0].status,
29786
+ eventId: rawPayload.eventResponses[0].eventId,
29787
+ event: rawPayload.events,
29788
+ userId: rawPayload.eventResponses[0].userId,
29789
+ user: rawPayload.users.map(convertRawUserToInternalUser),
29790
+ };
29791
+ };
29792
+
29793
+ /* begin_public_function
29794
+ id: event.rsvp.create
29795
+ */
29796
+ /**
29797
+ * ```js
29798
+ * import { event } from '@amityco/ts-sdk'
29799
+ * const response = await event.createRSVP(eventId, status)
29800
+ * ```
29801
+ *
29802
+ * Creates an {@link Amity.InternalEvent}
29803
+ *
29804
+ * @param bundle The data necessary to create a new {@link Amity.InternalEvent}
29805
+ * @returns The newly created {@link Amity.InternalEvent}
29806
+ *
29807
+ * @category Event API
29808
+ * @async
29809
+ */
29810
+ const createRSVP = async (eventId, status) => {
29811
+ const client = getActiveClient();
29812
+ client.log('event/createRSVP', eventId, status);
29813
+ const { data: payload } = await client.http.post(`/api/v1/events/${eventId}/rsvp`, { status });
29814
+ fireEvent('local.rsvp.created', payload);
29815
+ const data = prepareEventResponsePayload(payload);
29816
+ const cachedAt = client.cache && Date.now();
29817
+ if (client.cache)
29818
+ ingestInCache({ eventResponses: [data] }, { cachedAt });
29819
+ return {
29820
+ data,
29821
+ cachedAt,
29822
+ };
29823
+ };
29824
+ /* end_public_function */
29825
+
29826
+ /* begin_public_function
29827
+ id: event.update
29828
+ */
29829
+ /**
29830
+ * ```js
29831
+ * import { event } from '@amityco/ts-sdk'
29832
+ * const response = await event.updateRSVP(eventId, status)
29833
+ * ```
29834
+ *
29835
+ * Updates an {@link Amity.EventResponse}
29836
+ *
29837
+ * @param eventId The ID of the {@link Amity.EventResponse} to edit
29838
+ * @param bundle The data necessary to update an existing {@link Amity.EventResponse}
29839
+ * @returns the updated {@link Amity.EventResponse}
29840
+ *
29841
+ * @category Event API
29842
+ * @async
29843
+ */
29844
+ const updateRSVP = async (eventId, status) => {
29845
+ const client = getActiveClient();
29846
+ client.log('event/updateRSVP', eventId, status);
29847
+ const { data: payload } = await client.http.put(`/api/v1/events/${eventId}/rsvp`, { status });
29848
+ fireEvent('local.rsvp.updated', payload);
29849
+ const data = prepareEventResponsePayload(payload);
29850
+ const cachedAt = client.cache && Date.now();
29851
+ if (client.cache)
29852
+ ingestInCache({ eventResponses: [data] }, { cachedAt });
29853
+ return {
29854
+ data,
29855
+ cachedAt,
29856
+ };
29857
+ };
29858
+ /* end_public_function */
29859
+
29860
+ const prepareEventPayload = (rawPayload) => {
29861
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
29862
+ };
29863
+
29864
+ const createEventEventSubscriber = (event, callback) => {
29865
+ const client = getActiveClient();
29866
+ const filter = (payload) => {
29867
+ const unpackedPayload = prepareEventPayload(payload);
29868
+ if (!client.cache) {
29869
+ callback(unpackedPayload.events[0]);
29870
+ }
29871
+ else {
29872
+ ingestInCache(unpackedPayload);
29873
+ const event = pullFromCache([
29874
+ 'event',
29875
+ 'get',
29876
+ unpackedPayload.events[0].eventId,
29877
+ ]);
29878
+ callback(event.data);
29879
+ }
29880
+ };
29881
+ return createEventSubscriber(client, event, event, filter);
29882
+ };
29883
+
29884
+ const createEventResponseSubscriber = (event, callback) => {
29885
+ const client = getActiveClient();
29886
+ const filter = (payload) => {
29887
+ const unpackedPayload = prepareEventResponsePayload(payload);
29888
+ if (!client.cache) {
29889
+ callback(unpackedPayload);
29890
+ }
29891
+ else {
29892
+ ingestInCache(unpackedPayload.event[0]);
29893
+ const eventResponse = pullFromCache([
29894
+ 'eventResponse',
29895
+ 'get',
29896
+ payload.eventResponses[0].eventId,
29897
+ ]);
29898
+ callback(eventResponse.data);
29899
+ }
29900
+ };
29901
+ return createEventSubscriber(client, event, event, filter);
29902
+ };
29903
+
29904
+ /* begin_public_function
29905
+ id: event.rsvp.me
29906
+ */
29907
+ /**
29908
+ * ```js
29909
+ * import { event } from '@amityco/ts-sdk'
29910
+ * const myRSVP = await event.getMyRSVP()
29911
+ * ```
29912
+ *
29913
+ * Joins a {@link Amity.EventResponse} object
29914
+ *
29915
+ * @param eventId the {@link Amity.EventResponse} to get RSVP for
29916
+ * @returns A success boolean if the {@link Amity.EventResponse} RSVP was retrieved
29917
+ *
29918
+ * @category Event API
29919
+ * @async
29920
+ */
29921
+ const getMyRSVP = async (eventId) => {
29922
+ const client = getActiveClient();
29923
+ client.log('event/getMyRSVP', eventId);
29924
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}/me/rsvp`);
29925
+ const data = prepareEventResponsePayload(payload);
29926
+ const cachedAt = client.cache && Date.now();
29927
+ if (client.cache)
29928
+ ingestInCache({ eventResponses: [data] }, { cachedAt });
29929
+ return {
29930
+ data,
29931
+ cachedAt,
29932
+ };
29933
+ };
29934
+ /* end_public_function */
29935
+ /**
29936
+ * ```js
29937
+ * import { event } from '@amityco/ts-sdk'
29938
+ * const event = event.getMyRSVP.locally(eventId)
29939
+ * ```
29940
+ *
29941
+ * Fetches a {@link Amity.EventResponse} object in cache
29942
+ *
29943
+ * @param eventId the ID of the {@link Amity.EventResponse} to fetch
29944
+ * @returns the associated {@link Amity.EventResponse} object
29945
+ *
29946
+ * @category Event API
29947
+ */
29948
+ getMyRSVP.locally = (eventId) => {
29949
+ const client = getActiveClient();
29950
+ client.log('event/getMyRSVP.locally', eventId);
29951
+ if (!client.cache)
29952
+ return;
29953
+ const cache = pullFromCache(['event', 'getMyRSVP', eventId]);
29954
+ if (!cache)
29955
+ return;
29956
+ return {
29957
+ data: cache.data,
29958
+ cachedAt: cache.cachedAt,
29959
+ };
29960
+ };
29961
+
29962
+ var EventActionsEnum;
29963
+ (function (EventActionsEnum) {
29964
+ EventActionsEnum["OnEventCreated"] = "onEventCreated";
29965
+ EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
29966
+ EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
29967
+ EventActionsEnum["OnRSVPCreated"] = "onRSVPCreated";
29968
+ EventActionsEnum["OnRSVPUpdated"] = "onRSVPUpdated";
29969
+ })(EventActionsEnum || (EventActionsEnum = {}));
29970
+
29971
+ class RSVPPaginationController extends PaginationController {
29972
+ async getRequest(queryParams, token) {
29973
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, eventId } = queryParams, params = __rest(queryParams, ["limit", "eventId"]);
29974
+ const options = token ? { token } : { limit };
29975
+ const { data: response } = await this.http.get(`/api/v1/events/${eventId}/rsvp`, { params: Object.assign(Object.assign({}, params), { options }) });
29976
+ return response;
29977
+ }
29978
+ }
29979
+
29980
+ class RSVPQueryStreamController extends QueryStreamController {
29981
+ constructor(query, cacheKey, notifyChange, preparePayload) {
29982
+ super(query, cacheKey);
29983
+ this.notifyChange = notifyChange;
29984
+ this.preparePayload = preparePayload;
29985
+ }
29986
+ async saveToMainDB(response) {
29987
+ const processedPayload = this.preparePayload(response);
29988
+ const client = getActiveClient();
29989
+ const cachedAt = client.cache && Date.now();
29990
+ if (client.cache)
29991
+ ingestInCache({ eventResponses: [processedPayload] }, { cachedAt });
29992
+ }
29993
+ appendToQueryStream(response, direction, refresh = false) {
29994
+ var _a, _b;
29995
+ if (refresh) {
29996
+ pushToCache(this.cacheKey, {
29997
+ data: response.eventResponses.map(getResolver('eventResponse')),
29998
+ });
29999
+ }
30000
+ else {
30001
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30002
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
30003
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
30004
+ ...new Set([...events, ...response.eventResponses.map(getResolver('eventResponse'))]),
30005
+ ] }));
30006
+ }
30007
+ }
30008
+ reactor(action) {
30009
+ return (event) => {
30010
+ var _a;
30011
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30012
+ if (!collection)
30013
+ return;
30014
+ if (action === EventActionsEnum.OnRSVPCreated) {
30015
+ const client = getActiveClient();
30016
+ if (client.userId !== event.userId)
30017
+ return;
30018
+ collection.data = [...new Set([event.eventId, ...collection.data])];
30019
+ }
30020
+ if (action === EventActionsEnum.OnEventDeleted) {
30021
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
30022
+ }
30023
+ pushToCache(this.cacheKey, collection);
30024
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
30025
+ };
30026
+ }
30027
+ subscribeRTE(createSubscriber) {
30028
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
30029
+ }
30030
+ }
30031
+
30032
+ /**
30033
+ * ```js
30034
+ * import { EventRepository } from '@amityco/ts-sdk'
30035
+ * const dispose = EventRepository.onEventCreated(event => {
30036
+ * // ...
30037
+ * })
30038
+ * ```
30039
+ *
30040
+ * Fired when a {@link Amity.Event} has been created
30041
+ *
30042
+ * @param callback The function to call when the event was fired
30043
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30044
+ *
30045
+ * @category Event Events
30046
+ */
30047
+ const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
30048
+
30049
+ /**
30050
+ * ```js
30051
+ * import { EventRepository } from '@amityco/ts-sdk'
30052
+ * const dispose = EventRepository.onEventUpdated(event => {
30053
+ * // ...
30054
+ * })
30055
+ * ```
30056
+ *
30057
+ * Fired when a {@link Amity.Event} has been updated
30058
+ *
30059
+ * @param callback The function to call when the event was fired
30060
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30061
+ *
30062
+ * @category Event Events
30063
+ */
30064
+ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
30065
+
30066
+ /**
30067
+ * ```js
30068
+ * import { EventRepository } from '@amityco/ts-sdk'
30069
+ * const dispose = EventRepository.onEventDeleted(event => {
30070
+ * // ...
30071
+ * })
30072
+ * ```
30073
+ *
30074
+ * Fired when a {@link Amity.Event} has been deleted
30075
+ *
30076
+ * @param callback The function to call when the event was fired
30077
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30078
+ *
30079
+ * @category Event Events
30080
+ */
30081
+ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
30082
+
30083
+ /**
30084
+ * ```js
30085
+ * import { EventRepository } from '@amityco/ts-sdk'
30086
+ * const dispose = EventRepository.onLocalEventCreated(event => {
30087
+ * // ...
30088
+ * })
30089
+ * ```
30090
+ *
30091
+ * Fired when a {@link Amity.Event} has been created
30092
+ *
30093
+ * @param callback The function to call when the event was fired
30094
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30095
+ *
30096
+ * @category Event Events
30097
+ */
30098
+ const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
30099
+
30100
+ /**
30101
+ * ```js
30102
+ * import { EventRepository } from '@amityco/ts-sdk'
30103
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
30104
+ * // ...
30105
+ * })
30106
+ * ```
30107
+ *
30108
+ * Fired when a {@link Amity.Event} has been updated
30109
+ *
30110
+ * @param callback The function to call when the event was fired
30111
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30112
+ *
30113
+ * @category Event Events
30114
+ */
30115
+ const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
30116
+
30117
+ /**
30118
+ * ```js
30119
+ * import { EventRepository } from '@amityco/ts-sdk'
30120
+ * const dispose = EventRepository.onLocalEventDeleted(event => {
30121
+ * // ...
30122
+ * })
30123
+ * ```
30124
+ *
30125
+ * Fired when a {@link Amity.Event} has been deleted
30126
+ *
30127
+ * @param callback The function to call when the event was fired
30128
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30129
+ *
30130
+ * @category Event Events
30131
+ */
30132
+ const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
30133
+
30134
+ /**
30135
+ * ```js
30136
+ * import { EventRepository } from '@amityco/ts-sdk'
30137
+ * const dispose = EventRepository.onRSVPCreated(event => {
30138
+ * // ...
30139
+ * })
30140
+ * ```
30141
+ *
30142
+ * Fired when a {@link Amity.Event} has been created
30143
+ *
30144
+ * @param callback The function to call when the event was fired
30145
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30146
+ *
30147
+ * @category Event Events
30148
+ */
30149
+ const onRSVPCreated = (callback) => createEventResponseSubscriber('event.rsvp.created', callback);
30150
+
30151
+ /**
30152
+ * ```js
30153
+ * import { EventRepository } from '@amityco/ts-sdk'
30154
+ * const dispose = EventRepository.onRSVPUpdated(event => {
30155
+ * // ...
30156
+ * })
30157
+ * ```
30158
+ *
30159
+ * Fired when a {@link Amity.InternalEventResponse} has been updated
30160
+ *
30161
+ * @param callback The function to call when the event was fired
30162
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30163
+ *
30164
+ * @category Event Events
30165
+ */
30166
+ const onRSVPUpdated = (callback) => createEventResponseSubscriber('event.rsvp.updated', callback);
30167
+
30168
+ /**
30169
+ * ```js
30170
+ * import { EventRepository } from '@amityco/ts-sdk'
30171
+ * const dispose = EventRepository.onLocalRSVPCreated(event => {
30172
+ * // ...
30173
+ * })
30174
+ * ```
30175
+ *
30176
+ * Fired when a {@link Amity.Event} has been created
30177
+ *
30178
+ * @param callback The function to call when the event was fired
30179
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30180
+ *
30181
+ * @category Event Events
30182
+ */
30183
+ const onLocalRSVPCreated = (callback) => createEventResponseSubscriber('local.rsvp.created', callback);
30184
+
30185
+ /**
30186
+ * ```js
30187
+ * import { EventRepository } from '@amityco/ts-sdk'
30188
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
30189
+ * // ...
30190
+ * })
30191
+ * ```
30192
+ *
30193
+ * Fired when a {@link Amity.Event} has been updated
30194
+ *
30195
+ * @param callback The function to call when the event was fired
30196
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30197
+ *
30198
+ * @category Event Events
30199
+ */
30200
+ const onLocalRSVPUpdated = (callback) => createEventResponseSubscriber('local.rsvp.updated', callback);
30201
+
30202
+ class RSVPLiveCollectionController extends LiveCollectionController {
30203
+ constructor(query, callback) {
30204
+ const queryStreamId = hash(query);
30205
+ const cacheKey = ['eventResponse', 'collection', queryStreamId];
30206
+ const paginationController = new RSVPPaginationController(query);
30207
+ super(paginationController, queryStreamId, cacheKey, callback);
30208
+ this.query = query;
30209
+ this.queryStreamController = new RSVPQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventResponsePayload);
30210
+ this.callback = callback.bind(this);
30211
+ this.loadPage({ initial: true });
30212
+ }
30213
+ setup() {
30214
+ var _a;
30215
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30216
+ if (!collection)
30217
+ pushToCache(this.cacheKey, { data: [], params: this.query });
30218
+ }
30219
+ async persistModel(queryPayload) {
30220
+ await this.queryStreamController.saveToMainDB(queryPayload);
30221
+ }
30222
+ persistQueryStream({ response, direction, refresh, }) {
30223
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
30224
+ }
30225
+ startSubscription() {
30226
+ return this.queryStreamController.subscribeRTE([
30227
+ { fn: onRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
30228
+ { fn: onRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
30229
+ { fn: onLocalRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
30230
+ { fn: onLocalRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
30231
+ ]);
30232
+ }
30233
+ notifyChange({ origin, loading, error }) {
30234
+ var _a, _b;
30235
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30236
+ if (!collection)
30237
+ return;
30238
+ const data = (_b = collection.data
30239
+ .map(eventId => pullFromCache(['eventResponse', 'get', eventId]))
30240
+ .filter(isNonNullable)
30241
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
30242
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
30243
+ return;
30244
+ this.callback({
30245
+ data,
30246
+ error,
30247
+ loading,
30248
+ hasNextPage: !!this.paginationController.getNextToken(),
30249
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
30250
+ });
30251
+ }
30252
+ }
30253
+
30254
+ /**
30255
+ * Get events
30256
+ *
30257
+ * @param params the query parameters
30258
+ * @param callback the callback to be called when the events are updated
30259
+ * @returns events
30260
+ *
30261
+ * @category RSVP Live Collection
30262
+ *
30263
+ */
30264
+ const getRSVPs = (params, callback, config) => {
30265
+ const { log, cache } = getActiveClient();
30266
+ if (!cache)
30267
+ console.log(ENABLE_CACHE_MESSAGE);
30268
+ const timestamp = Date.now();
30269
+ log(`getRSVPs: (tmpid: ${timestamp}) > listen`);
30270
+ const rsvpLiveCollection = new RSVPLiveCollectionController(params, callback);
30271
+ const disposers = rsvpLiveCollection.startSubscription();
30272
+ const cacheKey = rsvpLiveCollection.getCacheKey();
30273
+ disposers.push(() => dropFromCache(cacheKey));
30274
+ return () => {
30275
+ log(`getRSVPs (tmpid: ${timestamp}) > dispose`);
30276
+ disposers.forEach(fn => fn());
30277
+ };
30278
+ };
30279
+
30280
+ const eventLinkedObject = (event) => {
30281
+ return Object.assign(Object.assign({}, event), { get creator() {
30282
+ const cacheData = pullFromCache(['user', 'get', event.userId]);
30283
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
30284
+ return;
30285
+ return userLinkedObject(cacheData.data);
30286
+ },
30287
+ get discussionCommunity() {
30288
+ if (!event.discussionCommunityId)
30289
+ return;
30290
+ const cacheData = pullFromCache([
30291
+ 'discussionCommunity',
30292
+ 'get',
30293
+ event.discussionCommunityId,
30294
+ ]);
30295
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
30296
+ return;
30297
+ return communityLinkedObject(cacheData.data);
30298
+ },
30299
+ get targetCommunity() {
30300
+ if (!event.originId)
30301
+ return;
30302
+ const cacheData = pullFromCache(['community', 'get', event.originId]);
30303
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
30304
+ return;
30305
+ return communityLinkedObject(cacheData.data);
30306
+ },
30307
+ get coverImage() {
30308
+ if (!event.coverImageFileId)
30309
+ return;
30310
+ const cacheData = pullFromCache(['file', 'get', event.coverImageFileId]);
30311
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
30312
+ return;
30313
+ return cacheData.data;
30314
+ },
30315
+ get liveStream() {
30316
+ if (!event.livestreamId)
30317
+ return;
30318
+ const cacheData = pullFromCache(['stream', 'get', event.livestreamId]);
30319
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
30320
+ return;
30321
+ return cacheData.data;
30322
+ }, createRSVP: async (status) => {
30323
+ const { data } = await createRSVP(event.eventId, status);
30324
+ return data;
30325
+ }, updateRSVP: async (status) => {
30326
+ const { data } = await updateRSVP(event.eventId, status);
30327
+ return data;
30328
+ }, getMyRSVP: async () => {
30329
+ const { data } = await getMyRSVP(event.eventId);
30330
+ return data;
30331
+ }, getRSVPs: (params, callback) => {
30332
+ return getRSVPs(Object.assign({ eventId: event.eventId }, params), callback);
30333
+ } });
30334
+ };
30335
+
29769
30336
  const LinkedObject = {
29770
30337
  ad: adLinkedObject,
29771
30338
  comment: commentLinkedObject,
@@ -29784,6 +30351,7 @@ const LinkedObject = {
29784
30351
  invitation: invitationLinkedObject,
29785
30352
  joinRequest: joinRequestLinkedObject,
29786
30353
  channelMember: channelMemberLinkedObject,
30354
+ event: eventLinkedObject,
29787
30355
  };
29788
30356
 
29789
30357
  /* begin_public_function
@@ -43768,729 +44336,6 @@ var index$8 = /*#__PURE__*/Object.freeze({
43768
44336
  getStreams: getStreams
43769
44337
  });
43770
44338
 
43771
- /* begin_public_function
43772
- id: room.create
43773
- */
43774
- /**
43775
- * ```js
43776
- * import { createRoom } from '@amityco/ts-sdk'
43777
- * const created = await createRoom({ title: 'my room', 'thumbnailFileId': fileId })
43778
- * ```
43779
- *
43780
- * Creates an {@link Amity.Room}
43781
- *
43782
- * @param bundle The data necessary to create a new {@link Amity.Room}
43783
- * @returns The newly created {@link Amity.Room}
43784
- *
43785
- * @category Room API
43786
- * @async
43787
- */
43788
- const createRoom = async (bundle) => {
43789
- const client = getActiveClient();
43790
- client.log('room/createRoom', bundle);
43791
- const { data } = await client.http.post('/api/v1/rooms', bundle);
43792
- fireEvent('local.room.created', data);
43793
- const cachedAt = client.cache && Date.now();
43794
- // TODO: check if should pick `users` filed which contains participants - if no need to ingest in the cache
43795
- if (client.cache)
43796
- ingestInCache(data, { cachedAt });
43797
- const { rooms } = data;
43798
- return {
43799
- data: rooms[0],
43800
- cachedAt,
43801
- };
43802
- };
43803
- /* end_public_function */
43804
-
43805
- /* begin_public_function
43806
- id: room.update
43807
- */
43808
- /**
43809
- * ```js
43810
- * import { updateRoom } from '@amityco/ts-sdk'
43811
- * const updated = await updateRoom('roomId', { title: 'updated title' })
43812
- * ```
43813
- *
43814
- * Updates an {@link Amity.InternalRoom}
43815
- *
43816
- * @param roomId The ID of the room to update
43817
- * @param bundle The data to update the room with
43818
- * @returns The updated {@link Amity.InternalRoom}
43819
- *
43820
- * @category Room API
43821
- * @async
43822
- */
43823
- const updateRoom = async (roomId, bundle) => {
43824
- const client = getActiveClient();
43825
- client.log('room/updateRoom', { roomId, bundle });
43826
- const { data } = await client.http.put(`/api/v1/rooms/${roomId}`, bundle);
43827
- fireEvent('local.room.updated', data);
43828
- const cachedAt = client.cache && Date.now();
43829
- if (client.cache)
43830
- ingestInCache(data, { cachedAt });
43831
- const { rooms } = data;
43832
- return {
43833
- data: rooms[0],
43834
- cachedAt,
43835
- };
43836
- };
43837
- /* end_public_function */
43838
-
43839
- /* begin_public_function
43840
- id: room.delete
43841
- */
43842
- /**
43843
- * ```js
43844
- * import { deleteRoom } from '@amityco/ts-sdk'
43845
- * const result = await deleteRoom('roomId')
43846
- * ```
43847
- *
43848
- * Deletes an {@link Amity.Room}
43849
- *
43850
- * @param roomId The ID of the room to delete
43851
- * @returns Promise that resolves when the room is deleted
43852
- *
43853
- * @category Room API
43854
- * @async
43855
- */
43856
- const deleteRoom = async (roomId) => {
43857
- const client = getActiveClient();
43858
- client.log('room/deleteRoom', { roomId });
43859
- await client.http.delete(`/api/v1/rooms/${roomId}`);
43860
- fireEvent('local.room.deleted', { rooms: [{ _id: roomId }] });
43861
- };
43862
- /* end_public_function */
43863
-
43864
- /* begin_public_function
43865
- id: room.stop
43866
- */
43867
- /**
43868
- * ```js
43869
- * import { stopRoom } from '@amityco/ts-sdk'
43870
- * const result = await stopRoom('roomId')
43871
- * ```
43872
- *
43873
- * Stops a room's broadcasting
43874
- *
43875
- * @param roomId The ID of the room to stop
43876
- * @returns The updated room data
43877
- *
43878
- * @category Room API
43879
- * @async
43880
- */
43881
- const stopRoom = async (roomId) => {
43882
- const client = getActiveClient();
43883
- client.log('room/stopRoom', { roomId });
43884
- const { data } = await client.http.post(`/api/v1/rooms/${roomId}/stop`);
43885
- fireEvent('local.room.stopped', data);
43886
- const cachedAt = client.cache && Date.now();
43887
- if (client.cache)
43888
- ingestInCache(data, { cachedAt });
43889
- const { rooms } = data;
43890
- return {
43891
- data: rooms[0],
43892
- cachedAt,
43893
- };
43894
- };
43895
- /* end_public_function */
43896
-
43897
- /* begin_public_function
43898
- id: room.getBroadcasterData
43899
- */
43900
- /**
43901
- * ```js
43902
- * import { getBroadcasterData } from '@amityco/ts-sdk'
43903
- * const token = await getBroadcasterData('roomId')
43904
- * ```
43905
- *
43906
- * Gets an access token for a room
43907
- *
43908
- * @param roomId The ID of the room to get token for
43909
- * @returns The room access token
43910
- *
43911
- * @category Room API
43912
- * @async
43913
- */
43914
- const getBroadcasterData = async (roomId) => {
43915
- const client = getActiveClient();
43916
- client.log('room/getBroadcasterData', { roomId });
43917
- const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
43918
- return data;
43919
- };
43920
- /* end_public_function */
43921
-
43922
- /* begin_public_function
43923
- id: room.getRecordedUrl
43924
- */
43925
- /**
43926
- * ```js
43927
- * import { getRecordedUrl } from '@amityco/ts-sdk'
43928
- * const recordedUrl = await getRecordedUrl('roomId')
43929
- * ```
43930
- *
43931
- * Gets the recorded URL for a room
43932
- *
43933
- * @param roomId The ID of the room to get recorded URL for
43934
- * @returns The recorded URL information
43935
- *
43936
- * @category Room API
43937
- * @async
43938
- */
43939
- const getRecordedUrl = async (roomId) => {
43940
- const client = getActiveClient();
43941
- client.log('room/getRecordedUrl', { roomId });
43942
- const { data } = await client.http.get(`/api/v1/rooms/${roomId}/recorded`);
43943
- return data;
43944
- };
43945
- /* end_public_function */
43946
-
43947
- /**
43948
- * ```js
43949
- * import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
43950
- * const dispose = onRoomStartBroadcasting(room => {
43951
- * // ...
43952
- * })
43953
- * ```
43954
- *
43955
- * Fired when a {@link Amity.Room} has started broadcasting
43956
- *
43957
- * @param callback The function to call when the event was fired
43958
- * @returns an {@link Amity.Unsubscriber} function to stop listening
43959
- *
43960
- * @category Room Events
43961
- */
43962
- const onRoomStartBroadcasting = (callback) => {
43963
- const client = getActiveClient();
43964
- const filter = (payload) => {
43965
- ingestInCache(payload);
43966
- callback(payload.rooms[0]);
43967
- };
43968
- return createEventSubscriber(client, 'room/onRoomStartBroadcasting', 'room.startBroadcasting', filter);
43969
- };
43970
-
43971
- /**
43972
- * ```js
43973
- * import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
43974
- * const dispose = onRoomWaitingReconnect(room => {
43975
- * // ...
43976
- * })
43977
- * ```
43978
- *
43979
- * Fired when a {@link Amity.Room} is waiting for reconnection
43980
- *
43981
- * @param callback The function to call when the event was fired
43982
- * @returns an {@link Amity.Unsubscriber} function to stop listening
43983
- *
43984
- * @category Room Events
43985
- */
43986
- const onRoomWaitingReconnect = (callback) => {
43987
- const client = getActiveClient();
43988
- const filter = (payload) => {
43989
- ingestInCache(payload);
43990
- callback(payload.rooms[0]);
43991
- };
43992
- return createEventSubscriber(client, 'room/onRoomWaitingReconnect', 'room.waitingReconnect', filter);
43993
- };
43994
-
43995
- /**
43996
- * ```js
43997
- * import { onRoomEndBroadcasting } from '@amityco/ts-sdk'
43998
- * const dispose = onRoomEndBroadcasting(room => {
43999
- * // ...
44000
- * })
44001
- * ```
44002
- *
44003
- * Fired when a {@link Amity.Room} has ended broadcasting
44004
- *
44005
- * @param callback The function to call when the event was fired
44006
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44007
- *
44008
- * @category Room Events
44009
- */
44010
- const onRoomEndBroadcasting = (callback) => {
44011
- const client = getActiveClient();
44012
- const filter = (payload) => {
44013
- ingestInCache(payload);
44014
- callback(payload.rooms[0]);
44015
- };
44016
- return createEventSubscriber(client, 'room/onRoomEndBroadcasting', 'room.endBroadcasting', filter);
44017
- };
44018
-
44019
- /**
44020
- * ```js
44021
- * import { onRoomRecordedAvailable } from '@amityco/ts-sdk'
44022
- * const dispose = onRoomRecordedAvailable(room => {
44023
- * // ...
44024
- * })
44025
- * ```
44026
- *
44027
- * Fired when a {@link Amity.Room} recorded content becomes available
44028
- *
44029
- * @param callback The function to call when the event was fired
44030
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44031
- *
44032
- * @category Room Events
44033
- */
44034
- const onRoomRecordedAvailable = (callback) => {
44035
- const client = getActiveClient();
44036
- const filter = (payload) => {
44037
- ingestInCache(payload);
44038
- callback(payload.rooms[0]);
44039
- };
44040
- return createEventSubscriber(client, 'room/onRoomRecordedAvailable', 'room.recordedAvailable', filter);
44041
- };
44042
-
44043
- /**
44044
- * ```js
44045
- * import { onRoomParticipantInviting } from '@amityco/ts-sdk'
44046
- * const dispose = onRoomParticipantInviting(room => {
44047
- * // ...
44048
- * })
44049
- * ```
44050
- *
44051
- * Fired when a participant is being invited to a {@link Amity.Room}
44052
- *
44053
- * @param callback The function to call when the event was fired
44054
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44055
- *
44056
- * @category Room Events
44057
- */
44058
- const onRoomParticipantInviting = (callback) => {
44059
- const client = getActiveClient();
44060
- const filter = (payload) => {
44061
- ingestInCache(payload);
44062
- callback(payload.rooms[0]);
44063
- };
44064
- return createEventSubscriber(client, 'room/onRoomParticipantInviting', 'room.participantInviting', filter);
44065
- };
44066
-
44067
- /**
44068
- * ```js
44069
- * import { onRoomParticipantJoined } from '@amityco/ts-sdk'
44070
- * const dispose = onRoomParticipantJoined(room => {
44071
- * // ...
44072
- * })
44073
- * ```
44074
- *
44075
- * Fired when a participant has joined a {@link Amity.Room}
44076
- *
44077
- * @param callback The function to call when the event was fired
44078
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44079
- *
44080
- * @category Room Events
44081
- */
44082
- const onRoomParticipantJoined = (callback) => {
44083
- const client = getActiveClient();
44084
- const filter = (payload) => {
44085
- ingestInCache(payload);
44086
- callback(payload.rooms[0]);
44087
- };
44088
- return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
44089
- };
44090
-
44091
- /**
44092
- * ```js
44093
- * import { onRoomParticipantLeft } from '@amityco/ts-sdk'
44094
- * const dispose = onRoomParticipantLeft(room => {
44095
- * // ...
44096
- * })
44097
- * ```
44098
- *
44099
- * Fired when a participant has left a {@link Amity.Room}
44100
- *
44101
- * @param callback The function to call when the event was fired
44102
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44103
- *
44104
- * @category Room Events
44105
- */
44106
- const onRoomParticipantLeft = (callback) => {
44107
- const client = getActiveClient();
44108
- const filter = (payload) => {
44109
- ingestInCache(payload);
44110
- callback(payload.rooms[0]);
44111
- };
44112
- return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
44113
- };
44114
-
44115
- /**
44116
- * ```js
44117
- * import { onRoomCreated } from '@amityco/ts-sdk'
44118
- * const dispose = onRoomCreated(room => {
44119
- * // ...
44120
- * })
44121
- * ```
44122
- *
44123
- * Fired when a {@link Amity.Room} has been created locally
44124
- *
44125
- * @param callback The function to call when the event was fired
44126
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44127
- *
44128
- * @category Room Events
44129
- */
44130
- const onRoomCreated = (callback) => {
44131
- const client = getActiveClient();
44132
- const filter = (payload) => {
44133
- ingestInCache(payload);
44134
- callback(payload.rooms[0]);
44135
- };
44136
- return createEventSubscriber(client, 'room/onRoomCreated', 'local.room.created', filter);
44137
- };
44138
-
44139
- /**
44140
- * ```js
44141
- * import { onRoomUpdated } from '@amityco/ts-sdk'
44142
- * const dispose = onRoomUpdated(room => {
44143
- * // ...
44144
- * })
44145
- * ```
44146
- *
44147
- * Fired when a {@link Amity.Room} has been updated locally
44148
- *
44149
- * @param callback The function to call when the event was fired
44150
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44151
- *
44152
- * @category Room Events
44153
- */
44154
- const onRoomUpdated = (callback) => {
44155
- const client = getActiveClient();
44156
- const filter = (payload) => {
44157
- ingestInCache(payload);
44158
- callback(payload.rooms[0]);
44159
- };
44160
- return createEventSubscriber(client, 'room/onRoomUpdated', 'local.room.updated', filter);
44161
- };
44162
-
44163
- /**
44164
- * ```js
44165
- * import { onRoomDeleted } from '@amityco/ts-sdk'
44166
- * const dispose = onRoomDeleted(room => {
44167
- * // ...
44168
- * })
44169
- * ```
44170
- *
44171
- * Fired when a {@link Amity.Room} has been deleted locally
44172
- *
44173
- * @param callback The function to call when the event was fired
44174
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44175
- *
44176
- * @category Room Events
44177
- */
44178
- const onRoomDeleted = (callback) => {
44179
- const client = getActiveClient();
44180
- const filter = (payload) => {
44181
- ingestInCache(payload);
44182
- callback(payload.rooms[0]);
44183
- };
44184
- return createEventSubscriber(client, 'room/onRoomDeleted', 'local.room.deleted', filter);
44185
- };
44186
-
44187
- /**
44188
- * ```js
44189
- * import { onRoomStopped } from '@amityco/ts-sdk'
44190
- * const dispose = onRoomStopped(room => {
44191
- * // ...
44192
- * })
44193
- * ```
44194
- *
44195
- * Fired when a {@link Amity.Room} has been stopped locally
44196
- *
44197
- * @param callback The function to call when the event was fired
44198
- * @returns an {@link Amity.Unsubscriber} function to stop listening
44199
- *
44200
- * @category Room Events
44201
- */
44202
- const onRoomStopped = (callback) => {
44203
- const client = getActiveClient();
44204
- const filter = (payload) => {
44205
- ingestInCache(payload);
44206
- callback(payload.rooms[0]);
44207
- };
44208
- return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
44209
- };
44210
-
44211
- const getRoomById = async (roomId) => {
44212
- const client = getActiveClient();
44213
- client.log('room/getRoomById', roomId);
44214
- // Check if room is in tombstone
44215
- isInTombstone('room', roomId);
44216
- let data;
44217
- try {
44218
- const response = await client.http.get(`/api/v1/rooms/${roomId}`);
44219
- data = response.data;
44220
- }
44221
- catch (error) {
44222
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
44223
- pushToTombstone('room', roomId);
44224
- }
44225
- throw error;
44226
- }
44227
- const cachedAt = client.cache && Date.now();
44228
- if (client.cache) {
44229
- ingestInCache(data, { cachedAt });
44230
- }
44231
- return {
44232
- data: data.rooms[0],
44233
- cachedAt,
44234
- };
44235
- };
44236
- getRoomById.locally = (roomId) => {
44237
- const client = getActiveClient();
44238
- client.log('room/getRoomById.locally', roomId);
44239
- // Check if room is in tombstone
44240
- isInTombstone('room', roomId);
44241
- const cachedAt = client.cache && Date.now();
44242
- const roomCache = pullFromCache(['room', 'get', roomId]);
44243
- if (!roomCache)
44244
- return;
44245
- return {
44246
- data: roomCache.data,
44247
- cachedAt,
44248
- };
44249
- };
44250
-
44251
- const getRoom = (roomId, callback) => {
44252
- // TODO: add callbackDataSelector if there are linked object fields
44253
- return liveObject(roomId, callback, '_id', getRoomById, [
44254
- onRoomEndBroadcasting,
44255
- onRoomStartBroadcasting,
44256
- onRoomWaitingReconnect,
44257
- onRoomRecordedAvailable,
44258
- ]);
44259
- };
44260
-
44261
- class RoomPaginationController extends PaginationController {
44262
- async getRequest(queryParams, token) {
44263
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
44264
- const baseOptions = {
44265
- type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
44266
- };
44267
- const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
44268
- const { data: queryResponse } = await this.http.get(`/api/v1/rooms`, {
44269
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
44270
- });
44271
- return queryResponse;
44272
- }
44273
- }
44274
-
44275
- var EnumRoomActions;
44276
- (function (EnumRoomActions) {
44277
- EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
44278
- EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
44279
- EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
44280
- EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
44281
- EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
44282
- EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
44283
- EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
44284
- })(EnumRoomActions || (EnumRoomActions = {}));
44285
-
44286
- class RoomQueryStreamController extends QueryStreamController {
44287
- constructor(query, cacheKey, notifyChange, preparePayload) {
44288
- super(query, cacheKey);
44289
- this.notifyChange = notifyChange;
44290
- this.preparePayload = preparePayload;
44291
- }
44292
- async saveToMainDB(response) {
44293
- const processedPayload = await this.preparePayload(response);
44294
- const client = getActiveClient();
44295
- const cachedAt = client.cache && Date.now();
44296
- if (client.cache) {
44297
- ingestInCache(processedPayload, { cachedAt });
44298
- }
44299
- }
44300
- appendToQueryStream(response, direction, refresh = false) {
44301
- var _a, _b;
44302
- if (refresh) {
44303
- pushToCache(this.cacheKey, {
44304
- data: response.rooms.map(getResolver('room')),
44305
- });
44306
- }
44307
- else {
44308
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44309
- const rooms = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
44310
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...rooms, ...response.rooms.map(getResolver('room'))])] }));
44311
- }
44312
- }
44313
- reactor(action) {
44314
- return (room) => {
44315
- var _a;
44316
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44317
- if (!collection)
44318
- return;
44319
- if (action === EnumRoomActions.OnRoomDeleted) {
44320
- collection.data = collection.data.filter(roomId => roomId !== room._id);
44321
- }
44322
- if (action === EnumRoomActions.OnRoomCreated) {
44323
- collection.data = [...new Set([room._id, ...collection.data])];
44324
- }
44325
- pushToCache(this.cacheKey, collection);
44326
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
44327
- };
44328
- }
44329
- subscribeRTE(createSubscriber) {
44330
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
44331
- }
44332
- }
44333
-
44334
- // TODO: confirm related events
44335
- const getRoomSubscription = () => [
44336
- {
44337
- fn: onRoomStartBroadcasting,
44338
- action: EnumRoomActions.OnRoomStartBroadcasting,
44339
- },
44340
- {
44341
- fn: onRoomEndBroadcasting,
44342
- action: EnumRoomActions.OnRoomEndBroadcasting,
44343
- },
44344
- {
44345
- fn: onRoomRecordedAvailable,
44346
- action: EnumRoomActions.OnRoomUpdated,
44347
- },
44348
- ];
44349
-
44350
- class RoomLiveCollectionController extends LiveCollectionController {
44351
- constructor(query, callback) {
44352
- const queryStreamId = hash(query);
44353
- const cacheKey = ['rooms', 'collection', queryStreamId];
44354
- const paginationController = new RoomPaginationController(query);
44355
- super(paginationController, queryStreamId, cacheKey, callback);
44356
- this.query = query;
44357
- this.queryStreamController = new RoomQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
44358
- this.callback = callback.bind(this);
44359
- this.loadPage({ initial: true });
44360
- }
44361
- setup() {
44362
- var _a;
44363
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44364
- if (!collection) {
44365
- pushToCache(this.cacheKey, {
44366
- data: [],
44367
- params: {},
44368
- });
44369
- }
44370
- }
44371
- async persistModel(queryPayload) {
44372
- await this.queryStreamController.saveToMainDB(queryPayload);
44373
- }
44374
- persistQueryStream({ response, direction, refresh, }) {
44375
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
44376
- }
44377
- startSubscription() {
44378
- return this.queryStreamController.subscribeRTE(getRoomSubscription());
44379
- }
44380
- notifyChange({ origin, loading, error }) {
44381
- var _a, _b;
44382
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
44383
- if (!collection)
44384
- return;
44385
- const data = this.applyFilter((_b = collection.data
44386
- .map(id => pullFromCache(['room', 'get', id]))
44387
- .filter(isNonNullable)
44388
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(room => room); // Since Room is same as InternalRoom, no transformation needed
44389
- if (!this.shouldNotify(data) && origin === 'event')
44390
- return;
44391
- this.callback({
44392
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
44393
- data,
44394
- hasNextPage: !!this.paginationController.getNextToken(),
44395
- loading,
44396
- error,
44397
- });
44398
- }
44399
- applyFilter(data) {
44400
- let rooms = data;
44401
- if (!this.query.includeDeleted) {
44402
- rooms = filterByPropEquality(rooms, 'isDeleted', false);
44403
- }
44404
- if (this.query.statuses && this.query.statuses.length > 0) {
44405
- rooms = rooms.filter(room => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(room.status); });
44406
- }
44407
- if (this.query.type) {
44408
- rooms = filterByPropEquality(rooms, 'type', this.query.type);
44409
- }
44410
- switch (this.query.sortBy) {
44411
- case 'firstCreated':
44412
- rooms = rooms.sort(sortByFirstCreated);
44413
- break;
44414
- case 'lastCreated':
44415
- default:
44416
- rooms = rooms.sort(sortByLastCreated);
44417
- break;
44418
- }
44419
- return rooms;
44420
- }
44421
- }
44422
-
44423
- /* begin_public_function
44424
- id: room.get_rooms
44425
- */
44426
- /**
44427
- * ```js
44428
- * import { RoomRepository } from '@amityco/ts-sdk'
44429
- *
44430
- * let rooms = []
44431
- * const unsub = RoomRepository.getRooms({
44432
- * type: 'direct_streaming',
44433
- * statuses: ['live', 'idle'],
44434
- * sortBy: 'lastCreated',
44435
- * limit: 20,
44436
- * includeDeleted: false
44437
- * }, response => merge(rooms, response.data))
44438
- * ```
44439
- *
44440
- * Observe all mutations on a list of {@link Amity.Room} for a given query
44441
- *
44442
- * @param params.type the type of rooms to filter by ('direct_streaming' | 'co_hosts')
44443
- * @param params.statuses array of room statuses to filter by (['idle', 'live', 'waiting_reconnect', 'ended', 'recorded'])
44444
- * @param params.sortBy sort rooms by creation time ('firstCreated' | 'lastCreated')
44445
- * @param params.limit maximum number of rooms to retrieve per page
44446
- * @param params.includeDeleted whether to include deleted rooms in the results
44447
- * @param callback the function to call when new data are available
44448
- * @param config optional configuration for the live collection
44449
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the rooms
44450
- *
44451
- * @category Rooms Live Collection
44452
- */
44453
- const getRooms = (params, callback, config) => {
44454
- const { log, cache } = getActiveClient();
44455
- if (!cache) {
44456
- console.log(ENABLE_CACHE_MESSAGE);
44457
- }
44458
- const timestamp = Date.now();
44459
- log(`getRooms(tmpid: ${timestamp}) > listen`);
44460
- const roomsLiveCollection = new RoomLiveCollectionController(params, callback);
44461
- const disposers = roomsLiveCollection.startSubscription();
44462
- const cacheKey = roomsLiveCollection.getCacheKey();
44463
- disposers.push(() => dropFromCache(cacheKey));
44464
- return () => {
44465
- log(`getRooms(tmpid: ${timestamp}) > dispose`);
44466
- disposers.forEach(fn => fn());
44467
- };
44468
- };
44469
- /* end_public_function */
44470
-
44471
- var index$7 = /*#__PURE__*/Object.freeze({
44472
- __proto__: null,
44473
- createRoom: createRoom,
44474
- updateRoom: updateRoom,
44475
- deleteRoom: deleteRoom,
44476
- stopRoom: stopRoom,
44477
- getBroadcasterData: getBroadcasterData,
44478
- getRecordedUrl: getRecordedUrl,
44479
- onRoomStartBroadcasting: onRoomStartBroadcasting,
44480
- onRoomWaitingReconnect: onRoomWaitingReconnect,
44481
- onRoomEndBroadcasting: onRoomEndBroadcasting,
44482
- onRoomRecordedAvailable: onRoomRecordedAvailable,
44483
- onRoomParticipantInviting: onRoomParticipantInviting,
44484
- onRoomParticipantJoined: onRoomParticipantJoined,
44485
- onRoomParticipantLeft: onRoomParticipantLeft,
44486
- onRoomCreated: onRoomCreated,
44487
- onRoomUpdated: onRoomUpdated,
44488
- onRoomDeleted: onRoomDeleted,
44489
- onRoomStopped: onRoomStopped,
44490
- getRoom: getRoom,
44491
- getRooms: getRooms
44492
- });
44493
-
44494
44339
  /* begin_public_function
44495
44340
  id: poll.create
44496
44341
  */
@@ -44791,7 +44636,7 @@ const getPoll = (pollId, callback) => {
44791
44636
  };
44792
44637
  /* end_public_function */
44793
44638
 
44794
- var index$6 = /*#__PURE__*/Object.freeze({
44639
+ var index$7 = /*#__PURE__*/Object.freeze({
44795
44640
  __proto__: null,
44796
44641
  createPoll: createPoll,
44797
44642
  closePoll: closePoll,
@@ -45174,7 +45019,7 @@ const getPlayer = async (parameters) => {
45174
45019
  return video;
45175
45020
  };
45176
45021
 
45177
- var index$5 = /*#__PURE__*/Object.freeze({
45022
+ var index$6 = /*#__PURE__*/Object.freeze({
45178
45023
  __proto__: null,
45179
45024
  getPlayer: getPlayer
45180
45025
  });
@@ -46347,7 +46192,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
46347
46192
  };
46348
46193
  };
46349
46194
 
46350
- var index$4 = /*#__PURE__*/Object.freeze({
46195
+ var index$5 = /*#__PURE__*/Object.freeze({
46351
46196
  __proto__: null,
46352
46197
  createImageStory: createImageStory,
46353
46198
  createVideoStory: createVideoStory,
@@ -46384,7 +46229,7 @@ const getNetworkAds = async () => {
46384
46229
  };
46385
46230
  };
46386
46231
 
46387
- var index$3 = /*#__PURE__*/Object.freeze({
46232
+ var index$4 = /*#__PURE__*/Object.freeze({
46388
46233
  __proto__: null,
46389
46234
  getNetworkAds: getNetworkAds
46390
46235
  });
@@ -46775,7 +46620,7 @@ const markTraySeen = async (lastSeenAt) => {
46775
46620
  };
46776
46621
  /* end_public_function */
46777
46622
 
46778
- var index$2 = /*#__PURE__*/Object.freeze({
46623
+ var index$3 = /*#__PURE__*/Object.freeze({
46779
46624
  __proto__: null,
46780
46625
  getNotificationTraySeen: getNotificationTraySeen,
46781
46626
  getNotificationTrayItems: getNotificationTrayItems,
@@ -46976,7 +46821,7 @@ const getMyCommunityInvitations = (params, callback, config) => {
46976
46821
  };
46977
46822
  };
46978
46823
 
46979
- var index$1 = /*#__PURE__*/Object.freeze({
46824
+ var index$2 = /*#__PURE__*/Object.freeze({
46980
46825
  __proto__: null,
46981
46826
  onLocalInvitationCreated: onLocalInvitationCreated,
46982
46827
  onLocalInvitationUpdated: onLocalInvitationUpdated,
@@ -47117,11 +46962,491 @@ const getReactions = (postId, callback) => {
47117
46962
  };
47118
46963
  };
47119
46964
 
47120
- var index = /*#__PURE__*/Object.freeze({
46965
+ var index$1 = /*#__PURE__*/Object.freeze({
47121
46966
  __proto__: null,
47122
46967
  createReaction: createReaction,
47123
46968
  onLiveReactionCreated: onLiveReactionCreated,
47124
46969
  getReactions: getReactions
47125
46970
  });
47126
46971
 
47127
- export { API_REGIONS, index$3 as AdRepository, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$1 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index as LiveReactionRepository, index$5 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$6 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$7 as RoomRepository, index$4 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$2 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
46972
+ /* begin_public_function
46973
+ id: event.create
46974
+ */
46975
+ /**
46976
+ * ```js
46977
+ * import { EventRepository } from '@amityco/ts-sdk'
46978
+ * const response = await EventRepository.createEvent(bundle)
46979
+ * ```
46980
+ *
46981
+ * Creates an {@link Amity.Event}
46982
+ *
46983
+ * @param bundle The data necessary to create a new {@link Amity.Event}
46984
+ * @returns The newly created {@link Amity.Event}
46985
+ *
46986
+ * @category Event API
46987
+ * @async
46988
+ */
46989
+ const createEvent = async (bundle) => {
46990
+ const client = getActiveClient();
46991
+ client.log('event/createEvent', bundle);
46992
+ const { data: payload } = await client.http.post('/api/v1/events', bundle);
46993
+ fireEvent('local.event.created', payload);
46994
+ const preparedPayload = prepareEventPayload(payload);
46995
+ const cachedAt = client.cache && Date.now();
46996
+ if (client.cache)
46997
+ ingestInCache(preparedPayload, { cachedAt });
46998
+ return {
46999
+ data: eventLinkedObject(preparedPayload.events[0]),
47000
+ cachedAt,
47001
+ };
47002
+ };
47003
+ /* end_public_function */
47004
+
47005
+ /* begin_public_function
47006
+ id: event.update
47007
+ */
47008
+ /**
47009
+ * ```js
47010
+ * import { EventRepository } from '@amityco/ts-sdk'
47011
+ * const response = await EventRepository.updateEvent(eventId, bundle)
47012
+ * ```
47013
+ *
47014
+ * Updates an {@link Amity.Event}
47015
+ *
47016
+ * @param eventId The ID of the {@link Amity.Event} to edit
47017
+ * @param bundle The data necessary to update an existing {@link Amity.Event}
47018
+ * @returns the updated {@link Amity.Event}
47019
+ *
47020
+ * @category Event API
47021
+ * @async
47022
+ */
47023
+ const updateEvent = async (eventId, bundle) => {
47024
+ const client = getActiveClient();
47025
+ client.log('event/updateEvent', eventId, bundle);
47026
+ const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
47027
+ fireEvent('local.event.updated', payload);
47028
+ const preparedPayload = prepareEventPayload(payload);
47029
+ const cachedAt = client.cache && Date.now();
47030
+ if (client.cache)
47031
+ ingestInCache(preparedPayload, { cachedAt });
47032
+ return {
47033
+ data: eventLinkedObject(preparedPayload.events.find(event => event.eventId === eventId)),
47034
+ cachedAt,
47035
+ };
47036
+ };
47037
+ /* end_public_function */
47038
+
47039
+ /* begin_public_function
47040
+ id: event.get
47041
+ */
47042
+ /**
47043
+ * ```js
47044
+ * import { EventRepository } from '@amityco/ts-sdk'
47045
+ * const event = await EventRepository.getEvent(eventId)
47046
+ * ```
47047
+ *
47048
+ * Fetches a {@link Amity.Event} object
47049
+ *
47050
+ * @param eventId the ID of the {@link Amity.Event} to fetch
47051
+ * @returns the associated {@link Amity.Event} object
47052
+ *
47053
+ * @category Event API
47054
+ * @async
47055
+ */
47056
+ const getEvent$1 = async (eventId) => {
47057
+ const client = getActiveClient();
47058
+ client.log('event/getEvent', eventId);
47059
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
47060
+ const data = prepareEventPayload(payload);
47061
+ const cachedAt = client.cache && Date.now();
47062
+ if (client.cache)
47063
+ ingestInCache(data, { cachedAt });
47064
+ return {
47065
+ data: data.events.find(event => event.eventId === eventId),
47066
+ cachedAt,
47067
+ };
47068
+ };
47069
+ /* end_public_function */
47070
+ /**
47071
+ * ```js
47072
+ * import { EventRepository } from '@amityco/ts-sdk'
47073
+ * const event = EventRepository.getEvent.locally(eventId)
47074
+ * ```
47075
+ *
47076
+ * Fetches a {@link Amity.Event} object in cache
47077
+ *
47078
+ * @param eventId the ID of the {@link Amity.Event} to fetch
47079
+ * @returns the associated {@link Amity.Event} object
47080
+ *
47081
+ * @category Event API
47082
+ */
47083
+ getEvent$1.locally = (eventId) => {
47084
+ const client = getActiveClient();
47085
+ client.log('event/getEvent.locally', eventId);
47086
+ if (!client.cache)
47087
+ return;
47088
+ const cache = pullFromCache(['event', 'get', eventId]);
47089
+ if (!cache)
47090
+ return;
47091
+ return {
47092
+ data: cache.data,
47093
+ cachedAt: cache.cachedAt,
47094
+ };
47095
+ };
47096
+
47097
+ /* begin_public_function
47098
+ id: event.delete
47099
+ */
47100
+ /**
47101
+ * ```js
47102
+ * import { EventRepository } from '@amityco/ts-sdk'
47103
+ * const { success } = await EventRepository.deleteEvent(eventId)
47104
+ * ```
47105
+ *
47106
+ * Deletes a {@link Amity.Event}
47107
+ *
47108
+ * @param eventId The {@link Amity.Event} ID to delete
47109
+ *
47110
+ * @category Event API
47111
+ * @async
47112
+ */
47113
+ const deleteEvent = async (eventId) => {
47114
+ const client = getActiveClient();
47115
+ client.log('event/deleteEvent', eventId);
47116
+ const event = await getEvent$1(eventId);
47117
+ await client.http.delete(`/api/v1/events/${eventId}`);
47118
+ const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
47119
+ upsertInCache(['event', 'get', eventId], deletedEvent);
47120
+ fireEvent('local.event.deleted', {
47121
+ users: [],
47122
+ files: [],
47123
+ communities: [],
47124
+ videoStreamings: [],
47125
+ events: [deletedEvent],
47126
+ discussionCommunities: [],
47127
+ });
47128
+ };
47129
+ /* end_public_function */
47130
+
47131
+ /* begin_public_function
47132
+ id: event.get
47133
+ */
47134
+ /**
47135
+ * ```js
47136
+ * import { EventRepository } from '@amityco/ts-sdk';
47137
+ *
47138
+ * let event;
47139
+ *
47140
+ * const unsubscribe = EventRepository.getEvent(eventId, response => {
47141
+ * event = response.data;
47142
+ * });
47143
+ * ```
47144
+ *
47145
+ * Observe all mutation on a given {@link Amity.Event}
47146
+ *
47147
+ * @param eventId the ID of the event to observe
47148
+ * @param callback the function to call when new snapshot of event are available
47149
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the event
47150
+ *
47151
+ * @category Event Live Object
47152
+ */
47153
+ const getEvent = (eventId, callback) => {
47154
+ return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
47155
+ callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
47156
+ });
47157
+ };
47158
+ /* end_public_function */
47159
+
47160
+ class EventPaginationController extends PaginationController {
47161
+ async getRequest(queryParams, token) {
47162
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
47163
+ const options = token ? { token } : { limit };
47164
+ const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
47165
+ return response;
47166
+ }
47167
+ }
47168
+
47169
+ class EventQueryStreamController extends QueryStreamController {
47170
+ constructor(query, cacheKey, notifyChange, preparePayload) {
47171
+ super(query, cacheKey);
47172
+ this.notifyChange = notifyChange;
47173
+ this.preparePayload = preparePayload;
47174
+ }
47175
+ async saveToMainDB(response) {
47176
+ const processedPayload = this.preparePayload(response);
47177
+ const client = getActiveClient();
47178
+ const cachedAt = client.cache && Date.now();
47179
+ if (client.cache)
47180
+ ingestInCache(processedPayload, { cachedAt });
47181
+ }
47182
+ appendToQueryStream(response, direction, refresh = false) {
47183
+ var _a, _b;
47184
+ if (refresh) {
47185
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
47186
+ }
47187
+ else {
47188
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47189
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
47190
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
47191
+ }
47192
+ }
47193
+ reactor(action) {
47194
+ return (event) => {
47195
+ var _a;
47196
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47197
+ if (!collection)
47198
+ return;
47199
+ if (action === EventActionsEnum.OnEventCreated) {
47200
+ collection.data = [...new Set([event.eventId, ...collection.data])];
47201
+ }
47202
+ if (action === EventActionsEnum.OnEventDeleted) {
47203
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
47204
+ }
47205
+ pushToCache(this.cacheKey, collection);
47206
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
47207
+ };
47208
+ }
47209
+ subscribeRTE(createSubscriber) {
47210
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
47211
+ }
47212
+ }
47213
+
47214
+ class EventLiveCollectionController extends LiveCollectionController {
47215
+ constructor(query, callback) {
47216
+ const queryStreamId = hash(query);
47217
+ const cacheKey = ['event', 'collection', queryStreamId];
47218
+ const paginationController = new EventPaginationController(query);
47219
+ super(paginationController, queryStreamId, cacheKey, callback);
47220
+ this.query = query;
47221
+ this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
47222
+ this.callback = callback.bind(this);
47223
+ this.loadPage({ initial: true });
47224
+ }
47225
+ setup() {
47226
+ var _a;
47227
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47228
+ if (!collection)
47229
+ pushToCache(this.cacheKey, { data: [], params: {} });
47230
+ }
47231
+ async persistModel(queryPayload) {
47232
+ await this.queryStreamController.saveToMainDB(queryPayload);
47233
+ }
47234
+ persistQueryStream({ response, direction, refresh, }) {
47235
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
47236
+ }
47237
+ startSubscription() {
47238
+ return this.queryStreamController.subscribeRTE([
47239
+ { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
47240
+ { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
47241
+ { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
47242
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
47243
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
47244
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
47245
+ ]);
47246
+ }
47247
+ notifyChange({ origin, loading, error }) {
47248
+ var _a, _b;
47249
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47250
+ if (!collection)
47251
+ return;
47252
+ const data = ((_b = collection.data
47253
+ .map(eventId => pullFromCache(['event', 'get', eventId]))
47254
+ .filter(isNonNullable)
47255
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
47256
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
47257
+ return;
47258
+ this.callback({
47259
+ data,
47260
+ error,
47261
+ loading,
47262
+ hasNextPage: !!this.paginationController.getNextToken(),
47263
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
47264
+ });
47265
+ }
47266
+ }
47267
+
47268
+ /**
47269
+ * Get events
47270
+ *
47271
+ * @param params the query parameters
47272
+ * @param callback the callback to be called when the events are updated
47273
+ * @returns events
47274
+ *
47275
+ * @category Event Live Collection
47276
+ *
47277
+ */
47278
+ const getEvents = (params, callback, config) => {
47279
+ const { log, cache } = getActiveClient();
47280
+ if (!cache)
47281
+ console.log(ENABLE_CACHE_MESSAGE);
47282
+ const timestamp = Date.now();
47283
+ log(`getEvents: (tmpid: ${timestamp}) > listen`);
47284
+ const eventLiveCollection = new EventLiveCollectionController(params, callback);
47285
+ const disposers = eventLiveCollection.startSubscription();
47286
+ const cacheKey = eventLiveCollection.getCacheKey();
47287
+ disposers.push(() => dropFromCache(cacheKey));
47288
+ return () => {
47289
+ log(`getEvents (tmpid: ${timestamp}) > dispose`);
47290
+ disposers.forEach(fn => fn());
47291
+ };
47292
+ };
47293
+
47294
+ class MyEventPaginationController extends PaginationController {
47295
+ async getRequest(queryParams, token) {
47296
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
47297
+ const options = token ? { token } : { limit };
47298
+ const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
47299
+ return response;
47300
+ }
47301
+ }
47302
+
47303
+ class MyEventQueryStreamController extends QueryStreamController {
47304
+ constructor(query, cacheKey, notifyChange, preparePayload) {
47305
+ super(query, cacheKey);
47306
+ this.notifyChange = notifyChange;
47307
+ this.preparePayload = preparePayload;
47308
+ }
47309
+ async saveToMainDB(response) {
47310
+ const processedPayload = this.preparePayload(response);
47311
+ const client = getActiveClient();
47312
+ const cachedAt = client.cache && Date.now();
47313
+ if (client.cache)
47314
+ ingestInCache(processedPayload, { cachedAt });
47315
+ }
47316
+ appendToQueryStream(response, direction, refresh = false) {
47317
+ var _a, _b;
47318
+ if (refresh) {
47319
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
47320
+ }
47321
+ else {
47322
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47323
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
47324
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
47325
+ }
47326
+ }
47327
+ reactor(action) {
47328
+ return (event) => {
47329
+ var _a;
47330
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47331
+ if (!collection)
47332
+ return;
47333
+ if (action === EventActionsEnum.OnEventCreated) {
47334
+ const client = getActiveClient();
47335
+ if (client.userId !== event.userId)
47336
+ return;
47337
+ collection.data = [...new Set([event.eventId, ...collection.data])];
47338
+ }
47339
+ if (action === EventActionsEnum.OnEventDeleted) {
47340
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
47341
+ }
47342
+ pushToCache(this.cacheKey, collection);
47343
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
47344
+ };
47345
+ }
47346
+ subscribeRTE(createSubscriber) {
47347
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
47348
+ }
47349
+ }
47350
+
47351
+ class MyEventLiveCollectionController extends LiveCollectionController {
47352
+ constructor(query, callback) {
47353
+ const queryStreamId = hash(query);
47354
+ const cacheKey = ['event', 'collection', queryStreamId];
47355
+ const paginationController = new MyEventPaginationController(query);
47356
+ super(paginationController, queryStreamId, cacheKey, callback);
47357
+ this.query = query;
47358
+ this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
47359
+ this.callback = callback.bind(this);
47360
+ this.loadPage({ initial: true });
47361
+ }
47362
+ setup() {
47363
+ var _a;
47364
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47365
+ if (!collection)
47366
+ pushToCache(this.cacheKey, { data: [], params: {} });
47367
+ }
47368
+ async persistModel(queryPayload) {
47369
+ await this.queryStreamController.saveToMainDB(queryPayload);
47370
+ }
47371
+ persistQueryStream({ response, direction, refresh, }) {
47372
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
47373
+ }
47374
+ startSubscription() {
47375
+ return this.queryStreamController.subscribeRTE([
47376
+ { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
47377
+ { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
47378
+ { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
47379
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
47380
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
47381
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
47382
+ ]);
47383
+ }
47384
+ notifyChange({ origin, loading, error }) {
47385
+ var _a, _b;
47386
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47387
+ if (!collection)
47388
+ return;
47389
+ const data = ((_b = collection.data
47390
+ .map(eventId => pullFromCache(['event', 'get', eventId]))
47391
+ .filter(isNonNullable)
47392
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
47393
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
47394
+ return;
47395
+ this.callback({
47396
+ data,
47397
+ error,
47398
+ loading,
47399
+ hasNextPage: !!this.paginationController.getNextToken(),
47400
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
47401
+ });
47402
+ }
47403
+ }
47404
+
47405
+ /**
47406
+ * Get my events
47407
+ *
47408
+ * @param params the query parameters
47409
+ * @param callback the callback to be called when the events are updated
47410
+ * @returns events
47411
+ *
47412
+ * @category Event Live Collection
47413
+ *
47414
+ */
47415
+ const getMyEvents = (params, callback, config) => {
47416
+ const { log, cache } = getActiveClient();
47417
+ if (!cache)
47418
+ console.log(ENABLE_CACHE_MESSAGE);
47419
+ const timestamp = Date.now();
47420
+ log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
47421
+ const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
47422
+ const disposers = myEventLiveCollection.startSubscription();
47423
+ const cacheKey = myEventLiveCollection.getCacheKey();
47424
+ disposers.push(() => dropFromCache(cacheKey));
47425
+ return () => {
47426
+ log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
47427
+ disposers.forEach(fn => fn());
47428
+ };
47429
+ };
47430
+
47431
+ var index = /*#__PURE__*/Object.freeze({
47432
+ __proto__: null,
47433
+ createEvent: createEvent,
47434
+ updateEvent: updateEvent,
47435
+ deleteEvent: deleteEvent,
47436
+ onEventCreated: onEventCreated,
47437
+ onEventUpdated: onEventUpdated,
47438
+ onEventDeleted: onEventDeleted,
47439
+ onLocalEventCreated: onLocalEventCreated,
47440
+ onLocalEventUpdated: onLocalEventUpdated,
47441
+ onLocalEventDeleted: onLocalEventDeleted,
47442
+ onRSVPCreated: onRSVPCreated,
47443
+ onRSVPUpdated: onRSVPUpdated,
47444
+ onLocalRSVPCreated: onLocalRSVPCreated,
47445
+ onLocalRSVPUpdated: onLocalRSVPUpdated,
47446
+ getEvent: getEvent,
47447
+ getEvents: getEvents,
47448
+ getMyEvents: getMyEvents,
47449
+ getRSVPs: getRSVPs
47450
+ });
47451
+
47452
+ export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, AmityEventResponseStatus, AmityEventStatus, AmityEventType, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$7 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$5 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$3 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };