@amityco/ts-sdk 7.11.1-38ad45e1.0 → 7.11.1-3b65d6ed.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 (136) hide show
  1. package/dist/@types/core/events.d.ts +13 -32
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +3 -2
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +4 -15
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/core/transport.d.ts +1 -4
  8. package/dist/@types/core/transport.d.ts.map +1 -1
  9. package/dist/@types/domains/content.d.ts +4 -1
  10. package/dist/@types/domains/content.d.ts.map +1 -1
  11. package/dist/@types/domains/feed.d.ts +2 -1
  12. package/dist/@types/domains/feed.d.ts.map +1 -1
  13. package/dist/@types/domains/post.d.ts +2 -0
  14. package/dist/@types/domains/post.d.ts.map +1 -1
  15. package/dist/@types/domains/room.d.ts +77 -0
  16. package/dist/@types/domains/room.d.ts.map +1 -0
  17. package/dist/@types/index.d.ts +2 -1
  18. package/dist/@types/index.d.ts.map +1 -1
  19. package/dist/channelRepository/api/createChannel.d.ts +1 -0
  20. package/dist/channelRepository/api/createChannel.d.ts.map +1 -1
  21. package/dist/core/events.d.ts +3 -3
  22. package/dist/core/events.d.ts.map +1 -1
  23. package/dist/core/model/idResolvers.d.ts.map +1 -1
  24. package/dist/core/model/index.d.ts.map +1 -1
  25. package/dist/index.cjs.js +994 -490
  26. package/dist/index.d.ts +1 -1
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.esm.js +833 -329
  29. package/dist/index.umd.js +3 -3
  30. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
  31. package/dist/roomRepository/api/createRoom.d.ts +24 -0
  32. package/dist/roomRepository/api/createRoom.d.ts.map +1 -0
  33. package/dist/roomRepository/api/deleteRoom.d.ts +16 -0
  34. package/dist/roomRepository/api/deleteRoom.d.ts.map +1 -0
  35. package/dist/roomRepository/api/getRecordedUrl.d.ts +19 -0
  36. package/dist/roomRepository/api/getRecordedUrl.d.ts.map +1 -0
  37. package/dist/roomRepository/api/getRoomToken.d.ts +16 -0
  38. package/dist/roomRepository/api/getRoomToken.d.ts.map +1 -0
  39. package/dist/roomRepository/api/index.d.ts +7 -0
  40. package/dist/roomRepository/api/index.d.ts.map +1 -0
  41. package/dist/roomRepository/api/stopRoom.d.ts +16 -0
  42. package/dist/roomRepository/api/stopRoom.d.ts.map +1 -0
  43. package/dist/roomRepository/api/updateRoom.d.ts +24 -0
  44. package/dist/roomRepository/api/updateRoom.d.ts.map +1 -0
  45. package/dist/roomRepository/events/index.d.ts +12 -0
  46. package/dist/roomRepository/events/index.d.ts.map +1 -0
  47. package/dist/roomRepository/events/onRoomCreated.d.ts +17 -0
  48. package/dist/roomRepository/events/onRoomCreated.d.ts.map +1 -0
  49. package/dist/roomRepository/events/onRoomDeleted.d.ts +17 -0
  50. package/dist/roomRepository/events/onRoomDeleted.d.ts.map +1 -0
  51. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts +17 -0
  52. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts.map +1 -0
  53. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts +17 -0
  54. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts.map +1 -0
  55. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts +17 -0
  56. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts.map +1 -0
  57. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts +17 -0
  58. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts.map +1 -0
  59. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts +17 -0
  60. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts.map +1 -0
  61. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts +17 -0
  62. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts.map +1 -0
  63. package/dist/roomRepository/events/onRoomStopped.d.ts +17 -0
  64. package/dist/roomRepository/events/onRoomStopped.d.ts.map +1 -0
  65. package/dist/roomRepository/events/onRoomUpdated.d.ts +17 -0
  66. package/dist/roomRepository/events/onRoomUpdated.d.ts.map +1 -0
  67. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts +17 -0
  68. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts.map +1 -0
  69. package/dist/roomRepository/index.d.ts.map +1 -0
  70. package/dist/roomRepository/internalApi/getLiveChat.d.ts +16 -0
  71. package/dist/roomRepository/internalApi/getLiveChat.d.ts.map +1 -0
  72. package/dist/roomRepository/internalApi/getRoomById.d.ts +5 -0
  73. package/dist/roomRepository/internalApi/getRoomById.d.ts.map +1 -0
  74. package/dist/roomRepository/internalApi/index.d.ts +3 -0
  75. package/dist/roomRepository/internalApi/index.d.ts.map +1 -0
  76. package/dist/roomRepository/observers/enums.d.ts +10 -0
  77. package/dist/roomRepository/observers/enums.d.ts.map +1 -0
  78. package/dist/roomRepository/observers/getRoom.d.ts +2 -0
  79. package/dist/roomRepository/observers/getRoom.d.ts.map +1 -0
  80. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts +14 -0
  81. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts.map +1 -0
  82. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts +5 -0
  83. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts.map +1 -0
  84. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts +15 -0
  85. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts.map +1 -0
  86. package/dist/roomRepository/observers/getRooms.d.ts +29 -0
  87. package/dist/roomRepository/observers/getRooms.d.ts.map +1 -0
  88. package/dist/roomRepository/observers/index.d.ts +3 -0
  89. package/dist/roomRepository/observers/index.d.ts.map +1 -0
  90. package/dist/roomRepository/observers/utils.d.ts +6 -0
  91. package/dist/roomRepository/observers/utils.d.ts.map +1 -0
  92. package/dist/utils/linkedObject/index.d.ts +0 -1
  93. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  94. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  95. package/dist/utils/linkedObject/roomLinkedObject.d.ts +2 -0
  96. package/dist/utils/linkedObject/roomLinkedObject.d.ts.map +1 -0
  97. package/dist/utils/postTypePredicate.d.ts +1 -0
  98. package/dist/utils/postTypePredicate.d.ts.map +1 -1
  99. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  100. package/package.json +1 -1
  101. package/dist/@types/domains/event.d.ts +0 -57
  102. package/dist/@types/domains/event.d.ts.map +0 -1
  103. package/dist/eventRepository/api/createEvent.d.ts +0 -16
  104. package/dist/eventRepository/api/createEvent.d.ts.map +0 -1
  105. package/dist/eventRepository/api/deleteEvent.d.ts +0 -16
  106. package/dist/eventRepository/api/deleteEvent.d.ts.map +0 -1
  107. package/dist/eventRepository/api/index.d.ts +0 -4
  108. package/dist/eventRepository/api/index.d.ts.map +0 -1
  109. package/dist/eventRepository/api/updateEvent.d.ts +0 -17
  110. package/dist/eventRepository/api/updateEvent.d.ts.map +0 -1
  111. package/dist/eventRepository/events/index.d.ts +0 -4
  112. package/dist/eventRepository/events/index.d.ts.map +0 -1
  113. package/dist/eventRepository/events/onEventCreated.d.ts +0 -17
  114. package/dist/eventRepository/events/onEventCreated.d.ts.map +0 -1
  115. package/dist/eventRepository/events/onEventDeleted.d.ts +0 -17
  116. package/dist/eventRepository/events/onEventDeleted.d.ts.map +0 -1
  117. package/dist/eventRepository/events/onEventUpdated.d.ts +0 -17
  118. package/dist/eventRepository/events/onEventUpdated.d.ts.map +0 -1
  119. package/dist/eventRepository/index.d.ts.map +0 -1
  120. package/dist/eventRepository/internalApi/getEvent.d.ts +0 -32
  121. package/dist/eventRepository/internalApi/getEvent.d.ts.map +0 -1
  122. package/dist/eventRepository/internalApi/index.d.ts +0 -2
  123. package/dist/eventRepository/internalApi/index.d.ts.map +0 -1
  124. package/dist/eventRepository/observers/getEvent.d.ts +0 -21
  125. package/dist/eventRepository/observers/getEvent.d.ts.map +0 -1
  126. package/dist/eventRepository/observers/index.d.ts +0 -2
  127. package/dist/eventRepository/observers/index.d.ts.map +0 -1
  128. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +0 -2
  129. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +0 -1
  130. package/dist/eventRepository/utils/index.d.ts +0 -3
  131. package/dist/eventRepository/utils/index.d.ts.map +0 -1
  132. package/dist/eventRepository/utils/prepareEventPayload.d.ts +0 -2
  133. package/dist/eventRepository/utils/prepareEventPayload.d.ts.map +0 -1
  134. package/dist/utils/linkedObject/eventLinkObject.d.ts +0 -2
  135. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +0 -1
  136. /package/dist/{eventRepository → roomRepository}/index.d.ts +0 -0
package/dist/index.cjs.js CHANGED
@@ -127,6 +127,7 @@ const PostContentType = Object.freeze({
127
127
  POLL: 'poll',
128
128
  CLIP: 'clip',
129
129
  AUDIO: 'audio',
130
+ ROOM: 'room',
130
131
  });
131
132
  const PostStructureType = Object.freeze({
132
133
  TEXT: 'text',
@@ -178,6 +179,7 @@ exports.FeedDataTypeEnum = void 0;
178
179
  FeedDataTypeEnum["LiveStream"] = "liveStream";
179
180
  FeedDataTypeEnum["Clip"] = "clip";
180
181
  FeedDataTypeEnum["Poll"] = "poll";
182
+ FeedDataTypeEnum["Room"] = "room";
181
183
  })(exports.FeedDataTypeEnum || (exports.FeedDataTypeEnum = {}));
182
184
  exports.FeedSortByEnum = void 0;
183
185
  (function (FeedSortByEnum) {
@@ -192,24 +194,6 @@ exports.FeedSourceEnum = void 0;
192
194
  FeedSourceEnum["User"] = "user";
193
195
  })(exports.FeedSourceEnum || (exports.FeedSourceEnum = {}));
194
196
 
195
- exports.AmityEventType = void 0;
196
- (function (AmityEventType) {
197
- AmityEventType["Virtual"] = "virtual";
198
- AmityEventType["InPerson"] = "in_person";
199
- })(exports.AmityEventType || (exports.AmityEventType = {}));
200
- exports.AmityEventOriginType = void 0;
201
- (function (AmityEventOriginType) {
202
- AmityEventOriginType["Community"] = "community";
203
- AmityEventOriginType["User"] = "user";
204
- })(exports.AmityEventOriginType || (exports.AmityEventOriginType = {}));
205
- exports.AmityEventStatus = void 0;
206
- (function (AmityEventStatus) {
207
- AmityEventStatus["Scheduled"] = "scheduled";
208
- AmityEventStatus["Live"] = "live";
209
- AmityEventStatus["Ended"] = "ended";
210
- AmityEventStatus["Cancelled"] = "cancelled";
211
- })(exports.AmityEventStatus || (exports.AmityEventStatus = {}));
212
-
213
197
  function getVersion() {
214
198
  try {
215
199
  // the string ''v7.11.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
@@ -658,6 +642,7 @@ const idResolvers = {
658
642
  notificationTraySeen: ({ userId }) => userId,
659
643
  invitation: ({ _id }) => _id,
660
644
  joinRequest: ({ joinRequestId }) => joinRequestId,
645
+ room: ({ roomId }) => roomId,
661
646
  };
662
647
  /**
663
648
  * Retrieve the id resolver matching a domain name
@@ -713,6 +698,7 @@ const PAYLOAD2MODEL = {
713
698
  notificationTrayItems: 'notificationTrayItem',
714
699
  invitations: 'invitation',
715
700
  joinRequests: 'joinRequest',
701
+ rooms: 'room',
716
702
  };
717
703
  /** hidden */
718
704
  const isOutdated = (prevData, nextData) => {
@@ -12050,7 +12036,7 @@ getChannel$1.locally = (channelId) => {
12050
12036
  * @category Stream API
12051
12037
  * @async
12052
12038
  */
12053
- const getLiveChat = async (stream) => {
12039
+ const getLiveChat$1 = async (stream) => {
12054
12040
  var _a;
12055
12041
  const client = getActiveClient();
12056
12042
  client.log('stream/getLiveChat', stream.streamId);
@@ -12117,7 +12103,7 @@ const streamLinkedObject = (stream) => {
12117
12103
  return streamLinkedObject(streamCache);
12118
12104
  })
12119
12105
  .filter(isNonNullable);
12120
- }, getLiveChat: () => getLiveChat(stream), isBanned: !stream.watcherUrl, watcherUrl: null, get [GET_WATCHER_URLS]() {
12106
+ }, getLiveChat: () => getLiveChat$1(stream), isBanned: !stream.watcherUrl, watcherUrl: null, get [GET_WATCHER_URLS]() {
12121
12107
  return stream.watcherUrl;
12122
12108
  } });
12123
12109
  };
@@ -12225,6 +12211,95 @@ function isAmityAudioPost(post) {
12225
12211
  'fileId' in post.data &&
12226
12212
  post.dataType === 'audio');
12227
12213
  }
12214
+ function isAmityRoomPost(post) {
12215
+ return !!(post.data &&
12216
+ typeof post.data !== 'string' &&
12217
+ 'roomId' in post.data &&
12218
+ post.dataType === 'room');
12219
+ }
12220
+
12221
+ /**
12222
+ * ```js
12223
+ * import { RoomRepository } from '@amityco/ts-sdk'
12224
+ * const stream = await getStream('foobar')
12225
+ * ```
12226
+ *
12227
+ * Fetches a {@link Amity.Channel} object linked with a current stream
12228
+ *
12229
+ * @param stream {@link Amity.Stream} that has linked live channel
12230
+ * @returns the associated {@link Amity.Channel<'live'>} object
12231
+ *
12232
+ * @category Stream API
12233
+ * @async
12234
+ */
12235
+ const getLiveChat = async (room) => {
12236
+ var _a;
12237
+ const client = getActiveClient();
12238
+ client.log('room/getLiveChat', room.roomId);
12239
+ if (room.liveChannelId) {
12240
+ const channel = (_a = pullFromCache([
12241
+ 'channel',
12242
+ 'get',
12243
+ room.liveChannelId,
12244
+ ])) === null || _a === void 0 ? void 0 : _a.data;
12245
+ if (channel)
12246
+ return channelLinkedObject(constructChannelObject(channel));
12247
+ const { data } = await getChannel$1(room.liveChannelId);
12248
+ return channelLinkedObject(constructChannelObject(data));
12249
+ }
12250
+ // No Channel ID
12251
+ // streamer: create a new live channel
12252
+ if (room.createdBy === client.userId) {
12253
+ const { data: channel } = await createChannel({
12254
+ type: 'live',
12255
+ postId: room.referenceId,
12256
+ roomId: room.roomId,
12257
+ });
12258
+ // Update channelId to stream object in cache
12259
+ mergeInCache(['room', 'get', room.roomId], {
12260
+ liveChannelId: channel.channelId,
12261
+ });
12262
+ return channel;
12263
+ }
12264
+ // watcher: return undefined
12265
+ return undefined;
12266
+ };
12267
+
12268
+ const roomLinkedObject = (room) => {
12269
+ return Object.assign(Object.assign({}, room), { get moderation() {
12270
+ var _a;
12271
+ return (_a = pullFromCache(['roomModeration', 'get', room.roomId])) === null || _a === void 0 ? void 0 : _a.data;
12272
+ },
12273
+ get post() {
12274
+ var _a;
12275
+ if (room.referenceType !== 'post')
12276
+ return;
12277
+ return (_a = pullFromCache(['post', 'get', room.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
12278
+ },
12279
+ get community() {
12280
+ var _a;
12281
+ if (room.targetType !== 'community')
12282
+ return;
12283
+ return (_a = pullFromCache(['community', 'get', room.targetId])) === null || _a === void 0 ? void 0 : _a.data;
12284
+ },
12285
+ get user() {
12286
+ var _a;
12287
+ return (_a = pullFromCache(['user', 'get', room.createdBy])) === null || _a === void 0 ? void 0 : _a.data;
12288
+ },
12289
+ get childRooms() {
12290
+ if (!room.childRoomIds || room.childRoomIds.length === 0)
12291
+ return [];
12292
+ return room.childRoomIds
12293
+ .map(id => {
12294
+ var _a;
12295
+ const roomCache = (_a = pullFromCache(['room', 'get', id])) === null || _a === void 0 ? void 0 : _a.data;
12296
+ if (!roomCache)
12297
+ return undefined;
12298
+ return roomLinkedObject(roomCache);
12299
+ })
12300
+ .filter(isNonNullable);
12301
+ }, getLiveChat: () => getLiveChat(room) });
12302
+ };
12228
12303
 
12229
12304
  const postLinkedObject = (post) => {
12230
12305
  return shallowClone(post, {
@@ -12319,6 +12394,13 @@ const postLinkedObject = (post) => {
12319
12394
  ? (_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
12320
12395
  : undefined;
12321
12396
  },
12397
+ getRoomInfo() {
12398
+ var _a, _b;
12399
+ if (!isAmityRoomPost(post))
12400
+ return;
12401
+ const room = (_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;
12402
+ return room ? roomLinkedObject(room) : undefined;
12403
+ },
12322
12404
  });
12323
12405
  };
12324
12406
 
@@ -13676,31 +13758,6 @@ const communityLinkedObject = (community) => {
13676
13758
  } });
13677
13759
  };
13678
13760
 
13679
- const eventLinkedObject = (event) => {
13680
- return Object.assign(Object.assign({}, event), { get creator() {
13681
- const cacheData = pullFromCache(['user', 'get', event.userId]);
13682
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13683
- return;
13684
- return userLinkedObject(cacheData.data);
13685
- },
13686
- get discussionCommunity() {
13687
- if (!event.communityId)
13688
- return;
13689
- const cacheData = pullFromCache(['community', 'get', event.communityId]);
13690
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13691
- return;
13692
- return communityLinkedObject(cacheData.data);
13693
- },
13694
- get liveStream() {
13695
- if (!event.livestreamId)
13696
- return;
13697
- const cacheData = pullFromCache(['stream', 'get', event.livestreamId]);
13698
- if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13699
- return;
13700
- return cacheData.data;
13701
- } });
13702
- };
13703
-
13704
13761
  const LinkedObject = {
13705
13762
  ad: adLinkedObject,
13706
13763
  comment: commentLinkedObject,
@@ -13719,7 +13776,6 @@ const LinkedObject = {
13719
13776
  invitation: invitationLinkedObject,
13720
13777
  joinRequest: joinRequestLinkedObject,
13721
13778
  channelMember: channelMemberLinkedObject,
13722
- event: eventLinkedObject,
13723
13779
  };
13724
13780
 
13725
13781
  /* begin_public_function
@@ -27705,306 +27761,1029 @@ var index$8 = /*#__PURE__*/Object.freeze({
27705
27761
  });
27706
27762
 
27707
27763
  /* begin_public_function
27708
- id: poll.create
27764
+ id: room.create
27709
27765
  */
27710
27766
  /**
27711
27767
  * ```js
27712
- * import { createPoll } from '@amityco/ts-sdk'
27713
- * const created = await createPoll({
27714
- * question: 'question',
27715
- * answers: [
27716
- * { dataType: 'text', data: 'answer1', fileId: 'fileId1' },
27717
- * { dataType: 'text', data: 'answer2', fileId: 'fileId2' },
27718
- * ],
27719
- * closedIn: 1649136484
27720
- * }))
27768
+ * import { createRoom } from '@amityco/ts-sdk'
27769
+ * const created = await createRoom({ title: 'my room', 'thumbnailFileId': fileId })
27721
27770
  * ```
27722
27771
  *
27723
- * Creates an {@link Amity.Poll}
27772
+ * Creates an {@link Amity.Room}
27724
27773
  *
27725
- * @param bundle The data necessary to create a new {@link Amity.Poll}
27726
- * @returns The newly created {@link Amity.Poll}
27774
+ * @param bundle The data necessary to create a new {@link Amity.Room}
27775
+ * @returns The newly created {@link Amity.Room}
27727
27776
  *
27728
- * @category Poll API
27777
+ * @category Room API
27729
27778
  * @async
27730
27779
  */
27731
- const createPoll = async (bundle) => {
27780
+ const createRoom = async (bundle) => {
27732
27781
  const client = getActiveClient();
27733
- client.log('post/createPoll', bundle);
27734
- const { data } = await client.http.post('/api/v3/polls', bundle);
27782
+ client.log('room/createRoom', bundle);
27783
+ const { data } = await client.http.post('/api/v1/rooms', bundle);
27784
+ fireEvent('local.room.created', data);
27735
27785
  const cachedAt = client.cache && Date.now();
27786
+ // TODO: check if should pick `users` filed which contains participants - if no need to ingest in the cache
27736
27787
  if (client.cache)
27737
27788
  ingestInCache(data, { cachedAt });
27738
- const { polls } = data;
27789
+ const { rooms } = data;
27739
27790
  return {
27740
- data: polls[0],
27791
+ data: roomLinkedObject(rooms[0]),
27741
27792
  cachedAt,
27742
27793
  };
27743
27794
  };
27744
27795
  /* end_public_function */
27745
27796
 
27746
27797
  /* begin_public_function
27747
- id: poll.close
27798
+ id: room.update
27748
27799
  */
27749
27800
  /**
27750
27801
  * ```js
27751
- * import { closePoll } from '@amityco/ts-sdk'
27752
- * const updated = await closePoll(pollId)
27802
+ * import { updateRoom } from '@amityco/ts-sdk'
27803
+ * const updated = await updateRoom('roomId', { title: 'updated title' })
27753
27804
  * ```
27754
27805
  *
27755
- * Updates an {@link Amity.Poll}
27806
+ * Updates an {@link Amity.InternalRoom}
27756
27807
  *
27757
- * @param pollId The ID of the {@link Amity.Poll} to close
27758
- * @returns the updated {@link Amity.Poll} object
27808
+ * @param roomId The ID of the room to update
27809
+ * @param bundle The data to update the room with
27810
+ * @returns The updated {@link Amity.InternalRoom}
27759
27811
  *
27760
- * @category Poll API
27812
+ * @category Room API
27761
27813
  * @async
27762
27814
  */
27763
- const closePoll = async (pollId) => {
27815
+ const updateRoom = async (roomId, bundle) => {
27764
27816
  const client = getActiveClient();
27765
- client.log('user/closePoll', pollId);
27766
- const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}`, { status: 'closed' });
27817
+ client.log('room/updateRoom', { roomId, bundle });
27818
+ const { data } = await client.http.put(`/api/v1/rooms/${roomId}`, bundle);
27819
+ fireEvent('local.room.updated', data);
27767
27820
  const cachedAt = client.cache && Date.now();
27768
27821
  if (client.cache)
27769
27822
  ingestInCache(data, { cachedAt });
27770
- fireEvent('poll.updated', data);
27771
- const { polls } = data;
27823
+ const { rooms } = data;
27772
27824
  return {
27773
- data: polls.find(poll => poll.pollId === pollId),
27825
+ data: rooms[0],
27774
27826
  cachedAt,
27775
27827
  };
27776
27828
  };
27777
27829
  /* end_public_function */
27778
27830
 
27779
27831
  /* begin_public_function
27780
- id: poll.get
27832
+ id: room.delete
27781
27833
  */
27782
27834
  /**
27783
27835
  * ```js
27784
- * import { getPoll } from '@amityco/ts-sdk'
27785
- * const poll = await getPoll('foobar')
27836
+ * import { deleteRoom } from '@amityco/ts-sdk'
27837
+ * const result = await deleteRoom('roomId')
27786
27838
  * ```
27787
27839
  *
27788
- * Fetches a {@link Amity.Poll} object
27840
+ * Deletes an {@link Amity.Room}
27789
27841
  *
27790
- * @param pollId the ID of the {@link Amity.Poll} to fetch
27791
- * @returns the associated {@link Amity.Poll} object
27842
+ * @param roomId The ID of the room to delete
27843
+ * @returns Promise that resolves when the room is deleted
27792
27844
  *
27793
- * @category Poll API
27845
+ * @category Room API
27794
27846
  * @async
27795
27847
  */
27796
- const getPoll$1 = async (pollId) => {
27848
+ const deleteRoom = async (roomId) => {
27797
27849
  const client = getActiveClient();
27798
- client.log('poll/getPoll', pollId);
27799
- const { data } = await client.http.get(`/api/v3/polls/${pollId}`);
27800
- const cachedAt = client.cache && Date.now();
27801
- if (client.cache)
27802
- ingestInCache(data, { cachedAt });
27803
- const { polls } = data;
27804
- return {
27805
- data: polls.find(poll => poll.pollId === pollId),
27806
- cachedAt,
27807
- };
27850
+ client.log('room/deleteRoom', { roomId });
27851
+ await client.http.delete(`/api/v1/rooms/${roomId}`);
27852
+ fireEvent('local.room.deleted', { rooms: [{ _id: roomId }] });
27808
27853
  };
27809
27854
  /* end_public_function */
27855
+
27856
+ /* begin_public_function
27857
+ id: room.stop
27858
+ */
27810
27859
  /**
27811
27860
  * ```js
27812
- * import { getPoll } from '@amityco/ts-sdk'
27813
- * const poll = getPoll.locally('foobar')
27861
+ * import { stopRoom } from '@amityco/ts-sdk'
27862
+ * const result = await stopRoom('roomId')
27814
27863
  * ```
27815
27864
  *
27816
- * Fetches a {@link Amity.Poll} object
27865
+ * Stops a room's broadcasting
27817
27866
  *
27818
- * @param pollId the ID of the {@link Amity.Poll} to fetch
27819
- * @returns the associated {@link Amity.Poll} object
27867
+ * @param roomId The ID of the room to stop
27868
+ * @returns The updated room data
27820
27869
  *
27821
- * @category Poll API
27870
+ * @category Room API
27871
+ * @async
27822
27872
  */
27823
- getPoll$1.locally = (pollId) => {
27873
+ const stopRoom = async (roomId) => {
27824
27874
  const client = getActiveClient();
27825
- client.log('poll/getPoll', pollId);
27826
- if (!client.cache)
27827
- return;
27828
- const cached = pullFromCache(['poll', 'get', pollId]);
27829
- if (!cached)
27830
- return;
27875
+ client.log('room/stopRoom', { roomId });
27876
+ const { data } = await client.http.post(`/api/v1/rooms/${roomId}/stop`);
27877
+ fireEvent('local.room.stopped', data);
27878
+ const cachedAt = client.cache && Date.now();
27879
+ if (client.cache)
27880
+ ingestInCache(data, { cachedAt });
27881
+ const { rooms } = data;
27831
27882
  return {
27832
- data: cached.data,
27833
- cachedAt: cached.cachedAt,
27883
+ data: rooms[0],
27884
+ cachedAt,
27834
27885
  };
27835
27886
  };
27887
+ /* end_public_function */
27836
27888
 
27837
27889
  /* begin_public_function
27838
- id: poll.delete
27890
+ id: room.getBroadcasterData
27839
27891
  */
27840
27892
  /**
27841
27893
  * ```js
27842
- * import { deletePoll } from '@amityco/ts-sdk'
27843
- * const success = await deletePoll(pollId)
27894
+ * import { getBroadcasterData } from '@amityco/ts-sdk'
27895
+ * const token = await getBroadcasterData('roomId')
27844
27896
  * ```
27845
27897
  *
27846
- * Deletes a {@link Amity.Poll}
27898
+ * Gets an access token for a room
27847
27899
  *
27848
- * @param pollId The {@link Amity.Poll} ID to delete
27849
- * @return A success boolean if the {@link Amity.Poll} was deleted
27900
+ * @param roomId The ID of the room to get token for
27901
+ * @returns The room access token
27850
27902
  *
27851
- * @category Poll API
27903
+ * @category Room API
27852
27904
  * @async
27853
27905
  */
27854
- const deletePoll = async (pollId) => {
27906
+ const getBroadcasterData = async (roomId) => {
27855
27907
  const client = getActiveClient();
27856
- client.log('poll/deletePoll', pollId);
27857
- const poll = await getPoll$1(pollId);
27858
- // API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
27859
- const { data } = await client.http.delete(`/api/v3/polls/${pollId}`);
27860
- const { success } = data; // unwrapPayload(data)
27861
- const deleted = Object.assign(Object.assign({}, poll.data), { isDeleted: true });
27862
- upsertInCache(['poll', 'get', pollId], deleted);
27863
- fireEvent('poll.deleted', { polls: [deleted], users: [] });
27864
- return success;
27908
+ client.log('room/getBroadcasterData', { roomId });
27909
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
27910
+ return data;
27865
27911
  };
27866
27912
  /* end_public_function */
27867
27913
 
27868
27914
  /* begin_public_function
27869
- id: poll.vote
27915
+ id: room.getRecordedUrl
27870
27916
  */
27871
27917
  /**
27872
27918
  * ```js
27873
- * import { votePoll } from '@amityco/ts-sdk'
27874
- * const voted = await votePoll(pollId)
27919
+ * import { getRecordedUrl } from '@amityco/ts-sdk'
27920
+ * const recordedUrl = await getRecordedUrl('roomId')
27875
27921
  * ```
27876
27922
  *
27877
- * Votes for an {@link Amity.Poll}
27923
+ * Gets the recorded URL for a room
27878
27924
  *
27879
- * @param pollId The ID of the {@link Amity.Poll} to vote
27880
- * @param answerIds The IDs of the {@link Amity.Poll} answers to vote {@link Amity.Poll}
27881
- * @returns the updated {@link Amity.Poll} object
27925
+ * @param roomId The ID of the room to get recorded URL for
27926
+ * @returns The recorded URL information
27882
27927
  *
27883
- * @category Poll API
27928
+ * @category Room API
27884
27929
  * @async
27885
27930
  */
27886
- const votePoll = async (pollId, answerIds) => {
27931
+ const getRecordedUrl = async (roomId) => {
27887
27932
  const client = getActiveClient();
27888
- client.log('user/votePoll', pollId);
27889
- const { data } = await client.http.post(`/api/v3/polls/${encodeURIComponent(pollId)}/votes`, { pollId, answerIds });
27890
- const cachedAt = client.cache && Date.now();
27891
- if (client.cache)
27892
- ingestInCache(data, { cachedAt });
27893
- const { polls } = data;
27894
- fireEvent('poll.updated', data);
27895
- return {
27896
- data: polls.find(poll => poll.pollId === pollId),
27897
- cachedAt,
27898
- };
27933
+ client.log('room/getRecordedUrl', { roomId });
27934
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/recorded`);
27935
+ return data;
27899
27936
  };
27900
27937
  /* end_public_function */
27901
27938
 
27902
- /* begin_public_function
27903
- id: poll.unvote
27904
- */
27905
27939
  /**
27906
27940
  * ```js
27907
- * import { PollRepository } from '@amityco/ts-sdk'
27908
- * await PollRepository.unvotePoll(pollId)
27941
+ * import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
27942
+ * const dispose = onRoomStartBroadcasting(room => {
27943
+ * // ...
27944
+ * })
27909
27945
  * ```
27910
27946
  *
27911
- * Votes for an {@link Amity.Poll}
27947
+ * Fired when a {@link Amity.Room} has started broadcasting
27912
27948
  *
27913
- * @param pollId The ID of the {@link Amity.Poll} to vote
27914
- * @returns void
27949
+ * @param callback The function to call when the event was fired
27950
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27915
27951
  *
27916
- * @category Poll API
27917
- * @async
27952
+ * @category Room Events
27918
27953
  */
27919
- const unvotePoll = async (pollId) => {
27954
+ const onRoomStartBroadcasting = (callback) => {
27920
27955
  const client = getActiveClient();
27921
- client.log('user/unvotePoll', pollId);
27922
- const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}/votes`, { pollId, answerIds: [] });
27923
- const cachedAt = client.cache && Date.now();
27924
- if (client.cache)
27925
- ingestInCache(data, { cachedAt });
27926
- fireEvent('poll.updated', data);
27956
+ const filter = (payload) => {
27957
+ ingestInCache(payload);
27958
+ callback(payload.rooms[0]);
27959
+ };
27960
+ return createEventSubscriber(client, 'room/onRoomStartBroadcasting', 'room.startBroadcasting', filter);
27927
27961
  };
27928
- /* end_public_function */
27929
27962
 
27930
27963
  /**
27931
27964
  * ```js
27932
- * import { onPollUpdated } from '@amityco/ts-sdk'
27933
- * const dispose = onPollUpdated(poll => {
27965
+ * import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
27966
+ * const dispose = onRoomWaitingReconnect(room => {
27934
27967
  * // ...
27935
27968
  * })
27936
27969
  * ```
27937
27970
  *
27938
- * Fired when an {@link Amity.Poll} has been updated
27971
+ * Fired when a {@link Amity.Room} is waiting for reconnection
27939
27972
  *
27940
27973
  * @param callback The function to call when the event was fired
27941
27974
  * @returns an {@link Amity.Unsubscriber} function to stop listening
27942
27975
  *
27943
- * @category Poll Events
27976
+ * @category Room Events
27944
27977
  */
27945
- const onPollUpdated = (callback) => {
27978
+ const onRoomWaitingReconnect = (callback) => {
27946
27979
  const client = getActiveClient();
27947
27980
  const filter = (payload) => {
27948
- if (client.cache)
27949
- ingestInCache(payload);
27950
- callback(payload.polls[0]);
27981
+ ingestInCache(payload);
27982
+ callback(payload.rooms[0]);
27951
27983
  };
27952
- return createEventSubscriber(client, 'poll/onPollUpdated', 'poll.updated', filter);
27984
+ return createEventSubscriber(client, 'room/onRoomWaitingReconnect', 'room.waitingReconnect', filter);
27953
27985
  };
27954
27986
 
27955
27987
  /**
27956
27988
  * ```js
27957
- * import { onPollDeleted } from '@amityco/ts-sdk'
27958
- * const dispose = onPollDeleted(poll => {
27989
+ * import { onRoomEndBroadcasting } from '@amityco/ts-sdk'
27990
+ * const dispose = onRoomEndBroadcasting(room => {
27959
27991
  * // ...
27960
27992
  * })
27961
27993
  * ```
27962
27994
  *
27963
- * Fired when an {@link Amity.Poll} has been deleted
27995
+ * Fired when a {@link Amity.Room} has ended broadcasting
27964
27996
  *
27965
27997
  * @param callback The function to call when the event was fired
27966
27998
  * @returns an {@link Amity.Unsubscriber} function to stop listening
27967
27999
  *
27968
- * @category Poll Events
28000
+ * @category Room Events
27969
28001
  */
27970
- const onPollDeleted = (callback) => {
28002
+ const onRoomEndBroadcasting = (callback) => {
27971
28003
  const client = getActiveClient();
27972
28004
  const filter = (payload) => {
27973
- if (client.cache)
27974
- ingestInCache(payload);
27975
- callback(payload.polls[0]);
28005
+ ingestInCache(payload);
28006
+ callback(payload.rooms[0]);
27976
28007
  };
27977
- return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
28008
+ return createEventSubscriber(client, 'room/onRoomEndBroadcasting', 'room.endBroadcasting', filter);
27978
28009
  };
27979
28010
 
27980
- /* begin_public_function
27981
- id: poll.get
27982
- */
27983
28011
  /**
27984
28012
  * ```js
27985
- * import { PollRepository } from '@amityco/ts-sdk';
27986
- *
27987
- * let poll;
27988
- *
27989
- * const unsub = PollRepository.getPoll(commentId, response => {
27990
- * poll = response.data;
27991
- * });
28013
+ * import { onRoomRecordedAvailable } from '@amityco/ts-sdk'
28014
+ * const dispose = onRoomRecordedAvailable(room => {
28015
+ * // ...
28016
+ * })
27992
28017
  * ```
27993
28018
  *
27994
- * Observe all mutation on a given {@link Amity.Poll}
28019
+ * Fired when a {@link Amity.Room} recorded content becomes available
27995
28020
  *
27996
- * @param pollId the ID of the poll to observe
27997
- * @param callback the function to call when new data are available
27998
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
28021
+ * @param callback The function to call when the event was fired
28022
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27999
28023
  *
28000
- * @category Poll Live Object
28024
+ * @category Room Events
28001
28025
  */
28002
- const getPoll = (pollId, callback) => {
28026
+ const onRoomRecordedAvailable = (callback) => {
28027
+ const client = getActiveClient();
28028
+ const filter = (payload) => {
28029
+ ingestInCache(payload);
28030
+ callback(payload.rooms[0]);
28031
+ };
28032
+ return createEventSubscriber(client, 'room/onRoomRecordedAvailable', 'room.recordedAvailable', filter);
28033
+ };
28034
+
28035
+ /**
28036
+ * ```js
28037
+ * import { onRoomParticipantInviting } from '@amityco/ts-sdk'
28038
+ * const dispose = onRoomParticipantInviting(room => {
28039
+ * // ...
28040
+ * })
28041
+ * ```
28042
+ *
28043
+ * Fired when a participant is being invited to a {@link Amity.Room}
28044
+ *
28045
+ * @param callback The function to call when the event was fired
28046
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28047
+ *
28048
+ * @category Room Events
28049
+ */
28050
+ const onRoomParticipantInviting = (callback) => {
28051
+ const client = getActiveClient();
28052
+ const filter = (payload) => {
28053
+ ingestInCache(payload);
28054
+ callback(payload.rooms[0]);
28055
+ };
28056
+ return createEventSubscriber(client, 'room/onRoomParticipantInviting', 'room.participantInviting', filter);
28057
+ };
28058
+
28059
+ /**
28060
+ * ```js
28061
+ * import { onRoomParticipantJoined } from '@amityco/ts-sdk'
28062
+ * const dispose = onRoomParticipantJoined(room => {
28063
+ * // ...
28064
+ * })
28065
+ * ```
28066
+ *
28067
+ * Fired when a participant has joined a {@link Amity.Room}
28068
+ *
28069
+ * @param callback The function to call when the event was fired
28070
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28071
+ *
28072
+ * @category Room Events
28073
+ */
28074
+ const onRoomParticipantJoined = (callback) => {
28075
+ const client = getActiveClient();
28076
+ const filter = (payload) => {
28077
+ ingestInCache(payload);
28078
+ callback(payload.rooms[0]);
28079
+ };
28080
+ return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
28081
+ };
28082
+
28083
+ /**
28084
+ * ```js
28085
+ * import { onRoomParticipantLeft } from '@amityco/ts-sdk'
28086
+ * const dispose = onRoomParticipantLeft(room => {
28087
+ * // ...
28088
+ * })
28089
+ * ```
28090
+ *
28091
+ * Fired when a participant has left a {@link Amity.Room}
28092
+ *
28093
+ * @param callback The function to call when the event was fired
28094
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28095
+ *
28096
+ * @category Room Events
28097
+ */
28098
+ const onRoomParticipantLeft = (callback) => {
28099
+ const client = getActiveClient();
28100
+ const filter = (payload) => {
28101
+ ingestInCache(payload);
28102
+ callback(payload.rooms[0]);
28103
+ };
28104
+ return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
28105
+ };
28106
+
28107
+ /**
28108
+ * ```js
28109
+ * import { onRoomCreated } from '@amityco/ts-sdk'
28110
+ * const dispose = onRoomCreated(room => {
28111
+ * // ...
28112
+ * })
28113
+ * ```
28114
+ *
28115
+ * Fired when a {@link Amity.Room} has been created locally
28116
+ *
28117
+ * @param callback The function to call when the event was fired
28118
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28119
+ *
28120
+ * @category Room Events
28121
+ */
28122
+ const onRoomCreated = (callback) => {
28123
+ const client = getActiveClient();
28124
+ const filter = (payload) => {
28125
+ ingestInCache(payload);
28126
+ callback(payload.rooms[0]);
28127
+ };
28128
+ return createEventSubscriber(client, 'room/onRoomCreated', 'local.room.created', filter);
28129
+ };
28130
+
28131
+ /**
28132
+ * ```js
28133
+ * import { onRoomUpdated } from '@amityco/ts-sdk'
28134
+ * const dispose = onRoomUpdated(room => {
28135
+ * // ...
28136
+ * })
28137
+ * ```
28138
+ *
28139
+ * Fired when a {@link Amity.Room} has been updated locally
28140
+ *
28141
+ * @param callback The function to call when the event was fired
28142
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28143
+ *
28144
+ * @category Room Events
28145
+ */
28146
+ const onRoomUpdated = (callback) => {
28147
+ const client = getActiveClient();
28148
+ const filter = (payload) => {
28149
+ ingestInCache(payload);
28150
+ callback(payload.rooms[0]);
28151
+ };
28152
+ return createEventSubscriber(client, 'room/onRoomUpdated', 'local.room.updated', filter);
28153
+ };
28154
+
28155
+ /**
28156
+ * ```js
28157
+ * import { onRoomDeleted } from '@amityco/ts-sdk'
28158
+ * const dispose = onRoomDeleted(room => {
28159
+ * // ...
28160
+ * })
28161
+ * ```
28162
+ *
28163
+ * Fired when a {@link Amity.Room} has been deleted locally
28164
+ *
28165
+ * @param callback The function to call when the event was fired
28166
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28167
+ *
28168
+ * @category Room Events
28169
+ */
28170
+ const onRoomDeleted = (callback) => {
28171
+ const client = getActiveClient();
28172
+ const filter = (payload) => {
28173
+ ingestInCache(payload);
28174
+ callback(payload.rooms[0]);
28175
+ };
28176
+ return createEventSubscriber(client, 'room/onRoomDeleted', 'local.room.deleted', filter);
28177
+ };
28178
+
28179
+ /**
28180
+ * ```js
28181
+ * import { onRoomStopped } from '@amityco/ts-sdk'
28182
+ * const dispose = onRoomStopped(room => {
28183
+ * // ...
28184
+ * })
28185
+ * ```
28186
+ *
28187
+ * Fired when a {@link Amity.Room} has been stopped locally
28188
+ *
28189
+ * @param callback The function to call when the event was fired
28190
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28191
+ *
28192
+ * @category Room Events
28193
+ */
28194
+ const onRoomStopped = (callback) => {
28195
+ const client = getActiveClient();
28196
+ const filter = (payload) => {
28197
+ ingestInCache(payload);
28198
+ callback(payload.rooms[0]);
28199
+ };
28200
+ return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
28201
+ };
28202
+
28203
+ const getRoomById = async (roomId) => {
28204
+ const client = getActiveClient();
28205
+ client.log('room/getRoomById', roomId);
28206
+ // Check if room is in tombstone
28207
+ isInTombstone('room', roomId);
28208
+ let data;
28209
+ try {
28210
+ const response = await client.http.get(`/api/v1/rooms/${roomId}`);
28211
+ data = response.data;
28212
+ }
28213
+ catch (error) {
28214
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
28215
+ pushToTombstone('room', roomId);
28216
+ }
28217
+ throw error;
28218
+ }
28219
+ const cachedAt = client.cache && Date.now();
28220
+ if (client.cache) {
28221
+ ingestInCache(data, { cachedAt });
28222
+ }
28223
+ return {
28224
+ data: data.rooms[0],
28225
+ cachedAt,
28226
+ };
28227
+ };
28228
+ getRoomById.locally = (roomId) => {
28229
+ const client = getActiveClient();
28230
+ client.log('room/getRoomById.locally', roomId);
28231
+ // Check if room is in tombstone
28232
+ isInTombstone('room', roomId);
28233
+ const cachedAt = client.cache && Date.now();
28234
+ const roomCache = pullFromCache(['room', 'get', roomId]);
28235
+ if (!roomCache)
28236
+ return;
28237
+ return {
28238
+ data: roomCache.data,
28239
+ cachedAt,
28240
+ };
28241
+ };
28242
+
28243
+ const getRoom = (roomId, callback) => {
28244
+ // TODO: add callbackDataSelector if there are linked object fields
28245
+ return liveObject(roomId, callback, '_id', getRoomById, [
28246
+ onRoomEndBroadcasting,
28247
+ onRoomStartBroadcasting,
28248
+ onRoomWaitingReconnect,
28249
+ onRoomRecordedAvailable,
28250
+ ]);
28251
+ };
28252
+
28253
+ class RoomPaginationController extends PaginationController {
28254
+ async getRequest(queryParams, token) {
28255
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
28256
+ const baseOptions = {
28257
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
28258
+ };
28259
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
28260
+ const { data: queryResponse } = await this.http.get(`/api/v1/rooms`, {
28261
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
28262
+ });
28263
+ return queryResponse;
28264
+ }
28265
+ }
28266
+
28267
+ var EnumRoomActions;
28268
+ (function (EnumRoomActions) {
28269
+ EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
28270
+ EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
28271
+ EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
28272
+ EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
28273
+ EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
28274
+ EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
28275
+ EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
28276
+ })(EnumRoomActions || (EnumRoomActions = {}));
28277
+
28278
+ class RoomQueryStreamController extends QueryStreamController {
28279
+ constructor(query, cacheKey, notifyChange, preparePayload) {
28280
+ super(query, cacheKey);
28281
+ this.notifyChange = notifyChange;
28282
+ this.preparePayload = preparePayload;
28283
+ }
28284
+ async saveToMainDB(response) {
28285
+ const processedPayload = await this.preparePayload(response);
28286
+ const client = getActiveClient();
28287
+ const cachedAt = client.cache && Date.now();
28288
+ if (client.cache) {
28289
+ ingestInCache(processedPayload, { cachedAt });
28290
+ }
28291
+ }
28292
+ appendToQueryStream(response, direction, refresh = false) {
28293
+ var _a, _b;
28294
+ if (refresh) {
28295
+ pushToCache(this.cacheKey, {
28296
+ data: response.rooms.map(getResolver('room')),
28297
+ });
28298
+ }
28299
+ else {
28300
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
28301
+ const rooms = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
28302
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...rooms, ...response.rooms.map(getResolver('room'))])] }));
28303
+ }
28304
+ }
28305
+ reactor(action) {
28306
+ return (room) => {
28307
+ var _a;
28308
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
28309
+ if (!collection)
28310
+ return;
28311
+ if (action === EnumRoomActions.OnRoomDeleted) {
28312
+ collection.data = collection.data.filter(roomId => roomId !== room._id);
28313
+ }
28314
+ if (action === EnumRoomActions.OnRoomCreated) {
28315
+ collection.data = [...new Set([room._id, ...collection.data])];
28316
+ }
28317
+ pushToCache(this.cacheKey, collection);
28318
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
28319
+ };
28320
+ }
28321
+ subscribeRTE(createSubscriber) {
28322
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
28323
+ }
28324
+ }
28325
+
28326
+ // TODO: confirm related events
28327
+ const getRoomSubscription = () => [
28328
+ {
28329
+ fn: onRoomStartBroadcasting,
28330
+ action: EnumRoomActions.OnRoomStartBroadcasting,
28331
+ },
28332
+ {
28333
+ fn: onRoomEndBroadcasting,
28334
+ action: EnumRoomActions.OnRoomEndBroadcasting,
28335
+ },
28336
+ {
28337
+ fn: onRoomRecordedAvailable,
28338
+ action: EnumRoomActions.OnRoomUpdated,
28339
+ },
28340
+ ];
28341
+
28342
+ class RoomLiveCollectionController extends LiveCollectionController {
28343
+ constructor(query, callback) {
28344
+ const queryStreamId = hash__default["default"](query);
28345
+ const cacheKey = ['rooms', 'collection', queryStreamId];
28346
+ const paginationController = new RoomPaginationController(query);
28347
+ super(paginationController, queryStreamId, cacheKey, callback);
28348
+ this.query = query;
28349
+ this.queryStreamController = new RoomQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
28350
+ this.callback = callback.bind(this);
28351
+ this.loadPage({ initial: true });
28352
+ }
28353
+ setup() {
28354
+ var _a;
28355
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
28356
+ if (!collection) {
28357
+ pushToCache(this.cacheKey, {
28358
+ data: [],
28359
+ params: {},
28360
+ });
28361
+ }
28362
+ }
28363
+ async persistModel(queryPayload) {
28364
+ await this.queryStreamController.saveToMainDB(queryPayload);
28365
+ }
28366
+ persistQueryStream({ response, direction, refresh, }) {
28367
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
28368
+ }
28369
+ startSubscription() {
28370
+ return this.queryStreamController.subscribeRTE(getRoomSubscription());
28371
+ }
28372
+ notifyChange({ origin, loading, error }) {
28373
+ var _a, _b;
28374
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
28375
+ if (!collection)
28376
+ return;
28377
+ const data = this.applyFilter((_b = collection.data
28378
+ .map(id => pullFromCache(['room', 'get', id]))
28379
+ .filter(isNonNullable)
28380
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(room => room); // Since Room is same as InternalRoom, no transformation needed
28381
+ if (!this.shouldNotify(data) && origin === 'event')
28382
+ return;
28383
+ this.callback({
28384
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
28385
+ data,
28386
+ hasNextPage: !!this.paginationController.getNextToken(),
28387
+ loading,
28388
+ error,
28389
+ });
28390
+ }
28391
+ applyFilter(data) {
28392
+ let rooms = data;
28393
+ if (!this.query.includeDeleted) {
28394
+ rooms = filterByPropEquality(rooms, 'isDeleted', false);
28395
+ }
28396
+ if (this.query.statuses && this.query.statuses.length > 0) {
28397
+ rooms = rooms.filter(room => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(room.status); });
28398
+ }
28399
+ if (this.query.type) {
28400
+ rooms = filterByPropEquality(rooms, 'type', this.query.type);
28401
+ }
28402
+ switch (this.query.sortBy) {
28403
+ case 'firstCreated':
28404
+ rooms = rooms.sort(sortByFirstCreated);
28405
+ break;
28406
+ case 'lastCreated':
28407
+ default:
28408
+ rooms = rooms.sort(sortByLastCreated);
28409
+ break;
28410
+ }
28411
+ return rooms;
28412
+ }
28413
+ }
28414
+
28415
+ /* begin_public_function
28416
+ id: room.get_rooms
28417
+ */
28418
+ /**
28419
+ * ```js
28420
+ * import { RoomRepository } from '@amityco/ts-sdk'
28421
+ *
28422
+ * let rooms = []
28423
+ * const unsub = RoomRepository.getRooms({
28424
+ * type: 'direct_streaming',
28425
+ * statuses: ['live', 'idle'],
28426
+ * sortBy: 'lastCreated',
28427
+ * limit: 20,
28428
+ * includeDeleted: false
28429
+ * }, response => merge(rooms, response.data))
28430
+ * ```
28431
+ *
28432
+ * Observe all mutations on a list of {@link Amity.Room} for a given query
28433
+ *
28434
+ * @param params.type the type of rooms to filter by ('direct_streaming' | 'co_hosts')
28435
+ * @param params.statuses array of room statuses to filter by (['idle', 'live', 'waiting_reconnect', 'ended', 'recorded'])
28436
+ * @param params.sortBy sort rooms by creation time ('firstCreated' | 'lastCreated')
28437
+ * @param params.limit maximum number of rooms to retrieve per page
28438
+ * @param params.includeDeleted whether to include deleted rooms in the results
28439
+ * @param callback the function to call when new data are available
28440
+ * @param config optional configuration for the live collection
28441
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the rooms
28442
+ *
28443
+ * @category Rooms Live Collection
28444
+ */
28445
+ const getRooms = (params, callback, config) => {
28446
+ const { log, cache } = getActiveClient();
28447
+ if (!cache) {
28448
+ console.log(ENABLE_CACHE_MESSAGE);
28449
+ }
28450
+ const timestamp = Date.now();
28451
+ log(`getRooms(tmpid: ${timestamp}) > listen`);
28452
+ const roomsLiveCollection = new RoomLiveCollectionController(params, callback);
28453
+ const disposers = roomsLiveCollection.startSubscription();
28454
+ const cacheKey = roomsLiveCollection.getCacheKey();
28455
+ disposers.push(() => dropFromCache(cacheKey));
28456
+ return () => {
28457
+ log(`getRooms(tmpid: ${timestamp}) > dispose`);
28458
+ disposers.forEach(fn => fn());
28459
+ };
28460
+ };
28461
+ /* end_public_function */
28462
+
28463
+ var index$7 = /*#__PURE__*/Object.freeze({
28464
+ __proto__: null,
28465
+ createRoom: createRoom,
28466
+ updateRoom: updateRoom,
28467
+ deleteRoom: deleteRoom,
28468
+ stopRoom: stopRoom,
28469
+ getBroadcasterData: getBroadcasterData,
28470
+ getRecordedUrl: getRecordedUrl,
28471
+ onRoomStartBroadcasting: onRoomStartBroadcasting,
28472
+ onRoomWaitingReconnect: onRoomWaitingReconnect,
28473
+ onRoomEndBroadcasting: onRoomEndBroadcasting,
28474
+ onRoomRecordedAvailable: onRoomRecordedAvailable,
28475
+ onRoomParticipantInviting: onRoomParticipantInviting,
28476
+ onRoomParticipantJoined: onRoomParticipantJoined,
28477
+ onRoomParticipantLeft: onRoomParticipantLeft,
28478
+ onRoomCreated: onRoomCreated,
28479
+ onRoomUpdated: onRoomUpdated,
28480
+ onRoomDeleted: onRoomDeleted,
28481
+ onRoomStopped: onRoomStopped,
28482
+ getRoom: getRoom,
28483
+ getRooms: getRooms
28484
+ });
28485
+
28486
+ /* begin_public_function
28487
+ id: poll.create
28488
+ */
28489
+ /**
28490
+ * ```js
28491
+ * import { createPoll } from '@amityco/ts-sdk'
28492
+ * const created = await createPoll({
28493
+ * question: 'question',
28494
+ * answers: [
28495
+ * { dataType: 'text', data: 'answer1', fileId: 'fileId1' },
28496
+ * { dataType: 'text', data: 'answer2', fileId: 'fileId2' },
28497
+ * ],
28498
+ * closedIn: 1649136484
28499
+ * }))
28500
+ * ```
28501
+ *
28502
+ * Creates an {@link Amity.Poll}
28503
+ *
28504
+ * @param bundle The data necessary to create a new {@link Amity.Poll}
28505
+ * @returns The newly created {@link Amity.Poll}
28506
+ *
28507
+ * @category Poll API
28508
+ * @async
28509
+ */
28510
+ const createPoll = async (bundle) => {
28511
+ const client = getActiveClient();
28512
+ client.log('post/createPoll', bundle);
28513
+ const { data } = await client.http.post('/api/v3/polls', bundle);
28514
+ const cachedAt = client.cache && Date.now();
28515
+ if (client.cache)
28516
+ ingestInCache(data, { cachedAt });
28517
+ const { polls } = data;
28518
+ return {
28519
+ data: polls[0],
28520
+ cachedAt,
28521
+ };
28522
+ };
28523
+ /* end_public_function */
28524
+
28525
+ /* begin_public_function
28526
+ id: poll.close
28527
+ */
28528
+ /**
28529
+ * ```js
28530
+ * import { closePoll } from '@amityco/ts-sdk'
28531
+ * const updated = await closePoll(pollId)
28532
+ * ```
28533
+ *
28534
+ * Updates an {@link Amity.Poll}
28535
+ *
28536
+ * @param pollId The ID of the {@link Amity.Poll} to close
28537
+ * @returns the updated {@link Amity.Poll} object
28538
+ *
28539
+ * @category Poll API
28540
+ * @async
28541
+ */
28542
+ const closePoll = async (pollId) => {
28543
+ const client = getActiveClient();
28544
+ client.log('user/closePoll', pollId);
28545
+ const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}`, { status: 'closed' });
28546
+ const cachedAt = client.cache && Date.now();
28547
+ if (client.cache)
28548
+ ingestInCache(data, { cachedAt });
28549
+ fireEvent('poll.updated', data);
28550
+ const { polls } = data;
28551
+ return {
28552
+ data: polls.find(poll => poll.pollId === pollId),
28553
+ cachedAt,
28554
+ };
28555
+ };
28556
+ /* end_public_function */
28557
+
28558
+ /* begin_public_function
28559
+ id: poll.get
28560
+ */
28561
+ /**
28562
+ * ```js
28563
+ * import { getPoll } from '@amityco/ts-sdk'
28564
+ * const poll = await getPoll('foobar')
28565
+ * ```
28566
+ *
28567
+ * Fetches a {@link Amity.Poll} object
28568
+ *
28569
+ * @param pollId the ID of the {@link Amity.Poll} to fetch
28570
+ * @returns the associated {@link Amity.Poll} object
28571
+ *
28572
+ * @category Poll API
28573
+ * @async
28574
+ */
28575
+ const getPoll$1 = async (pollId) => {
28576
+ const client = getActiveClient();
28577
+ client.log('poll/getPoll', pollId);
28578
+ const { data } = await client.http.get(`/api/v3/polls/${pollId}`);
28579
+ const cachedAt = client.cache && Date.now();
28580
+ if (client.cache)
28581
+ ingestInCache(data, { cachedAt });
28582
+ const { polls } = data;
28583
+ return {
28584
+ data: polls.find(poll => poll.pollId === pollId),
28585
+ cachedAt,
28586
+ };
28587
+ };
28588
+ /* end_public_function */
28589
+ /**
28590
+ * ```js
28591
+ * import { getPoll } from '@amityco/ts-sdk'
28592
+ * const poll = getPoll.locally('foobar')
28593
+ * ```
28594
+ *
28595
+ * Fetches a {@link Amity.Poll} object
28596
+ *
28597
+ * @param pollId the ID of the {@link Amity.Poll} to fetch
28598
+ * @returns the associated {@link Amity.Poll} object
28599
+ *
28600
+ * @category Poll API
28601
+ */
28602
+ getPoll$1.locally = (pollId) => {
28603
+ const client = getActiveClient();
28604
+ client.log('poll/getPoll', pollId);
28605
+ if (!client.cache)
28606
+ return;
28607
+ const cached = pullFromCache(['poll', 'get', pollId]);
28608
+ if (!cached)
28609
+ return;
28610
+ return {
28611
+ data: cached.data,
28612
+ cachedAt: cached.cachedAt,
28613
+ };
28614
+ };
28615
+
28616
+ /* begin_public_function
28617
+ id: poll.delete
28618
+ */
28619
+ /**
28620
+ * ```js
28621
+ * import { deletePoll } from '@amityco/ts-sdk'
28622
+ * const success = await deletePoll(pollId)
28623
+ * ```
28624
+ *
28625
+ * Deletes a {@link Amity.Poll}
28626
+ *
28627
+ * @param pollId The {@link Amity.Poll} ID to delete
28628
+ * @return A success boolean if the {@link Amity.Poll} was deleted
28629
+ *
28630
+ * @category Poll API
28631
+ * @async
28632
+ */
28633
+ const deletePoll = async (pollId) => {
28634
+ const client = getActiveClient();
28635
+ client.log('poll/deletePoll', pollId);
28636
+ const poll = await getPoll$1(pollId);
28637
+ // API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
28638
+ const { data } = await client.http.delete(`/api/v3/polls/${pollId}`);
28639
+ const { success } = data; // unwrapPayload(data)
28640
+ const deleted = Object.assign(Object.assign({}, poll.data), { isDeleted: true });
28641
+ upsertInCache(['poll', 'get', pollId], deleted);
28642
+ fireEvent('poll.deleted', { polls: [deleted], users: [] });
28643
+ return success;
28644
+ };
28645
+ /* end_public_function */
28646
+
28647
+ /* begin_public_function
28648
+ id: poll.vote
28649
+ */
28650
+ /**
28651
+ * ```js
28652
+ * import { votePoll } from '@amityco/ts-sdk'
28653
+ * const voted = await votePoll(pollId)
28654
+ * ```
28655
+ *
28656
+ * Votes for an {@link Amity.Poll}
28657
+ *
28658
+ * @param pollId The ID of the {@link Amity.Poll} to vote
28659
+ * @param answerIds The IDs of the {@link Amity.Poll} answers to vote {@link Amity.Poll}
28660
+ * @returns the updated {@link Amity.Poll} object
28661
+ *
28662
+ * @category Poll API
28663
+ * @async
28664
+ */
28665
+ const votePoll = async (pollId, answerIds) => {
28666
+ const client = getActiveClient();
28667
+ client.log('user/votePoll', pollId);
28668
+ const { data } = await client.http.post(`/api/v3/polls/${encodeURIComponent(pollId)}/votes`, { pollId, answerIds });
28669
+ const cachedAt = client.cache && Date.now();
28670
+ if (client.cache)
28671
+ ingestInCache(data, { cachedAt });
28672
+ const { polls } = data;
28673
+ fireEvent('poll.updated', data);
28674
+ return {
28675
+ data: polls.find(poll => poll.pollId === pollId),
28676
+ cachedAt,
28677
+ };
28678
+ };
28679
+ /* end_public_function */
28680
+
28681
+ /* begin_public_function
28682
+ id: poll.unvote
28683
+ */
28684
+ /**
28685
+ * ```js
28686
+ * import { PollRepository } from '@amityco/ts-sdk'
28687
+ * await PollRepository.unvotePoll(pollId)
28688
+ * ```
28689
+ *
28690
+ * Votes for an {@link Amity.Poll}
28691
+ *
28692
+ * @param pollId The ID of the {@link Amity.Poll} to vote
28693
+ * @returns void
28694
+ *
28695
+ * @category Poll API
28696
+ * @async
28697
+ */
28698
+ const unvotePoll = async (pollId) => {
28699
+ const client = getActiveClient();
28700
+ client.log('user/unvotePoll', pollId);
28701
+ const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}/votes`, { pollId, answerIds: [] });
28702
+ const cachedAt = client.cache && Date.now();
28703
+ if (client.cache)
28704
+ ingestInCache(data, { cachedAt });
28705
+ fireEvent('poll.updated', data);
28706
+ };
28707
+ /* end_public_function */
28708
+
28709
+ /**
28710
+ * ```js
28711
+ * import { onPollUpdated } from '@amityco/ts-sdk'
28712
+ * const dispose = onPollUpdated(poll => {
28713
+ * // ...
28714
+ * })
28715
+ * ```
28716
+ *
28717
+ * Fired when an {@link Amity.Poll} has been updated
28718
+ *
28719
+ * @param callback The function to call when the event was fired
28720
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28721
+ *
28722
+ * @category Poll Events
28723
+ */
28724
+ const onPollUpdated = (callback) => {
28725
+ const client = getActiveClient();
28726
+ const filter = (payload) => {
28727
+ if (client.cache)
28728
+ ingestInCache(payload);
28729
+ callback(payload.polls[0]);
28730
+ };
28731
+ return createEventSubscriber(client, 'poll/onPollUpdated', 'poll.updated', filter);
28732
+ };
28733
+
28734
+ /**
28735
+ * ```js
28736
+ * import { onPollDeleted } from '@amityco/ts-sdk'
28737
+ * const dispose = onPollDeleted(poll => {
28738
+ * // ...
28739
+ * })
28740
+ * ```
28741
+ *
28742
+ * Fired when an {@link Amity.Poll} has been deleted
28743
+ *
28744
+ * @param callback The function to call when the event was fired
28745
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28746
+ *
28747
+ * @category Poll Events
28748
+ */
28749
+ const onPollDeleted = (callback) => {
28750
+ const client = getActiveClient();
28751
+ const filter = (payload) => {
28752
+ if (client.cache)
28753
+ ingestInCache(payload);
28754
+ callback(payload.polls[0]);
28755
+ };
28756
+ return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
28757
+ };
28758
+
28759
+ /* begin_public_function
28760
+ id: poll.get
28761
+ */
28762
+ /**
28763
+ * ```js
28764
+ * import { PollRepository } from '@amityco/ts-sdk';
28765
+ *
28766
+ * let poll;
28767
+ *
28768
+ * const unsub = PollRepository.getPoll(commentId, response => {
28769
+ * poll = response.data;
28770
+ * });
28771
+ * ```
28772
+ *
28773
+ * Observe all mutation on a given {@link Amity.Poll}
28774
+ *
28775
+ * @param pollId the ID of the poll to observe
28776
+ * @param callback the function to call when new data are available
28777
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
28778
+ *
28779
+ * @category Poll Live Object
28780
+ */
28781
+ const getPoll = (pollId, callback) => {
28003
28782
  return liveObject(pollId, callback, 'pollId', getPoll$1, [onPollUpdated, onPollDeleted]);
28004
28783
  };
28005
28784
  /* end_public_function */
28006
28785
 
28007
- var index$7 = /*#__PURE__*/Object.freeze({
28786
+ var index$6 = /*#__PURE__*/Object.freeze({
28008
28787
  __proto__: null,
28009
28788
  createPoll: createPoll,
28010
28789
  closePoll: closePoll,
@@ -28387,7 +29166,7 @@ const getPlayer = async (parameters) => {
28387
29166
  return video;
28388
29167
  };
28389
29168
 
28390
- var index$6 = /*#__PURE__*/Object.freeze({
29169
+ var index$5 = /*#__PURE__*/Object.freeze({
28391
29170
  __proto__: null,
28392
29171
  getPlayer: getPlayer
28393
29172
  });
@@ -29560,7 +30339,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
29560
30339
  };
29561
30340
  };
29562
30341
 
29563
- var index$5 = /*#__PURE__*/Object.freeze({
30342
+ var index$4 = /*#__PURE__*/Object.freeze({
29564
30343
  __proto__: null,
29565
30344
  createImageStory: createImageStory,
29566
30345
  createVideoStory: createVideoStory,
@@ -29597,7 +30376,7 @@ const getNetworkAds = async () => {
29597
30376
  };
29598
30377
  };
29599
30378
 
29600
- var index$4 = /*#__PURE__*/Object.freeze({
30379
+ var index$3 = /*#__PURE__*/Object.freeze({
29601
30380
  __proto__: null,
29602
30381
  getNetworkAds: getNetworkAds
29603
30382
  });
@@ -29988,7 +30767,7 @@ const markTraySeen = async (lastSeenAt) => {
29988
30767
  };
29989
30768
  /* end_public_function */
29990
30769
 
29991
- var index$3 = /*#__PURE__*/Object.freeze({
30770
+ var index$2 = /*#__PURE__*/Object.freeze({
29992
30771
  __proto__: null,
29993
30772
  getNotificationTraySeen: getNotificationTraySeen,
29994
30773
  getNotificationTrayItems: getNotificationTrayItems,
@@ -30189,7 +30968,7 @@ const getMyCommunityInvitations = (params, callback, config) => {
30189
30968
  };
30190
30969
  };
30191
30970
 
30192
- var index$2 = /*#__PURE__*/Object.freeze({
30971
+ var index$1 = /*#__PURE__*/Object.freeze({
30193
30972
  __proto__: null,
30194
30973
  onLocalInvitationCreated: onLocalInvitationCreated,
30195
30974
  onLocalInvitationUpdated: onLocalInvitationUpdated,
@@ -30330,290 +31109,15 @@ const getReactions = (postId, callback) => {
30330
31109
  };
30331
31110
  };
30332
31111
 
30333
- var index$1 = /*#__PURE__*/Object.freeze({
31112
+ var index = /*#__PURE__*/Object.freeze({
30334
31113
  __proto__: null,
30335
31114
  createReaction: createReaction,
30336
31115
  onLiveReactionCreated: onLiveReactionCreated,
30337
31116
  getReactions: getReactions
30338
31117
  });
30339
31118
 
30340
- const prepareEventPayload = (rawPayload) => {
30341
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
30342
- };
30343
-
30344
- const createEventEventSubscriber = (event, callback) => {
30345
- const client = getActiveClient();
30346
- const filter = (payload) => {
30347
- const unpackedPayload = prepareEventPayload(payload);
30348
- if (!client.cache) {
30349
- callback(unpackedPayload.events[0]);
30350
- }
30351
- else {
30352
- ingestInCache(unpackedPayload);
30353
- const event = pullFromCache([
30354
- 'event',
30355
- 'get',
30356
- unpackedPayload.events[0].eventId,
30357
- ]);
30358
- callback(event.data);
30359
- }
30360
- };
30361
- return createEventSubscriber(client, event, event, filter);
30362
- };
30363
-
30364
- /* begin_public_function
30365
- id: event.create
30366
- */
30367
- /**
30368
- * ```js
30369
- * import { EventRepository } from '@amityco/ts-sdk'
30370
- * const response = await EventRepository.createEvent(bundle)
30371
- * ```
30372
- *
30373
- * Creates an {@link Amity.Event}
30374
- *
30375
- * @param bundle The data necessary to create a new {@link Amity.Event}
30376
- * @returns The newly created {@link Amity.Event}
30377
- *
30378
- * @category Event API
30379
- * @async
30380
- */
30381
- const createEvent = async (bundle) => {
30382
- const client = getActiveClient();
30383
- client.log('event/createEvent', bundle);
30384
- const { data: payload } = await client.http.post('/api/v1/events', bundle);
30385
- fireEvent('event.created', payload);
30386
- const preparedPayload = prepareEventPayload(payload);
30387
- const cachedAt = client.cache && Date.now();
30388
- if (client.cache)
30389
- ingestInCache(preparedPayload, { cachedAt });
30390
- return {
30391
- data: eventLinkedObject(preparedPayload.events[0]),
30392
- cachedAt,
30393
- };
30394
- };
30395
- /* end_public_function */
30396
-
30397
- /* begin_public_function
30398
- id: event.update
30399
- */
30400
- /**
30401
- * ```js
30402
- * import { EventRepository } from '@amityco/ts-sdk'
30403
- * const response = await EventRepository.updateEvent(eventId, bundle)
30404
- * ```
30405
- *
30406
- * Updates an {@link Amity.Event}
30407
- *
30408
- * @param eventId The ID of the {@link Amity.Event} to edit
30409
- * @param bundle The data necessary to update an existing {@link Amity.Event}
30410
- * @returns the updated {@link Amity.Event}
30411
- *
30412
- * @category Event API
30413
- * @async
30414
- */
30415
- const updateEvent = async (eventId, bundle) => {
30416
- const client = getActiveClient();
30417
- client.log('event/updateEvent', eventId, bundle);
30418
- const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
30419
- fireEvent('event.updated', payload);
30420
- const preparedPayload = prepareEventPayload(payload);
30421
- const cachedAt = client.cache && Date.now();
30422
- if (client.cache)
30423
- ingestInCache(preparedPayload, { cachedAt });
30424
- return {
30425
- data: eventLinkedObject(preparedPayload.events.find(event => event.eventId === eventId)),
30426
- cachedAt,
30427
- };
30428
- };
30429
- /* end_public_function */
30430
-
30431
- /* begin_public_function
30432
- id: event.get
30433
- */
30434
- /**
30435
- * ```js
30436
- * import { EventRepository } from '@amityco/ts-sdk'
30437
- * const event = await EventRepository.getEvent(eventId)
30438
- * ```
30439
- *
30440
- * Fetches a {@link Amity.Event} object
30441
- *
30442
- * @param eventId the ID of the {@link Amity.Event} to fetch
30443
- * @returns the associated {@link Amity.Event} object
30444
- *
30445
- * @category Event API
30446
- * @async
30447
- */
30448
- const getEvent$1 = async (eventId) => {
30449
- const client = getActiveClient();
30450
- client.log('event/getEvent', eventId);
30451
- const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
30452
- const data = prepareEventPayload(payload);
30453
- const cachedAt = client.cache && Date.now();
30454
- if (client.cache)
30455
- ingestInCache(data, { cachedAt });
30456
- return {
30457
- data: data.events.find(event => event.eventId === eventId),
30458
- cachedAt,
30459
- };
30460
- };
30461
- /* end_public_function */
30462
- /**
30463
- * ```js
30464
- * import { EventRepository } from '@amityco/ts-sdk'
30465
- * const event = EventRepository.getEvent.locally(eventId)
30466
- * ```
30467
- *
30468
- * Fetches a {@link Amity.Event} object in cache
30469
- *
30470
- * @param eventId the ID of the {@link Amity.Event} to fetch
30471
- * @returns the associated {@link Amity.Event} object
30472
- *
30473
- * @category Event API
30474
- */
30475
- getEvent$1.locally = (eventId) => {
30476
- const client = getActiveClient();
30477
- client.log('event/getEvent.locally', eventId);
30478
- if (!client.cache)
30479
- return;
30480
- const cache = pullFromCache(['event', 'get', eventId]);
30481
- if (!cache)
30482
- return;
30483
- return {
30484
- data: cache.data,
30485
- cachedAt: cache.cachedAt,
30486
- };
30487
- };
30488
-
30489
- /* begin_public_function
30490
- id: event.delete
30491
- */
30492
- /**
30493
- * ```js
30494
- * import { EventRepository } from '@amityco/ts-sdk'
30495
- * const { success } = await EventRepository.deleteEvent(eventId)
30496
- * ```
30497
- *
30498
- * Deletes a {@link Amity.Event}
30499
- *
30500
- * @param eventId The {@link Amity.Event} ID to delete
30501
- * @return A success boolean if the {@link Amity.Event} was deleted
30502
- *
30503
- * @category Event API
30504
- * @async
30505
- */
30506
- const deleteEvent = async (eventId) => {
30507
- const client = getActiveClient();
30508
- client.log('event/deleteEvent', eventId);
30509
- const event = await getEvent$1(eventId);
30510
- const { data } = await client.http.delete(`/api/v3/events/${eventId}`);
30511
- const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: data.success });
30512
- upsertInCache(['event', 'get', eventId], deletedEvent);
30513
- fireEvent('event.deleted', {
30514
- users: [],
30515
- files: [],
30516
- communities: [],
30517
- videoStreamings: [],
30518
- events: [deletedEvent],
30519
- discussionCommunities: [],
30520
- });
30521
- };
30522
- /* end_public_function */
30523
-
30524
- /**
30525
- * ```js
30526
- * import { EventRepository } from '@amityco/ts-sdk'
30527
- * const dispose = EventRepository.onEventCreated(event => {
30528
- * // ...
30529
- * })
30530
- * ```
30531
- *
30532
- * Fired when a {@link Amity.Event} has been created
30533
- *
30534
- * @param callback The function to call when the event was fired
30535
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30536
- *
30537
- * @category Event Events
30538
- */
30539
- const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
30540
-
30541
- /**
30542
- * ```js
30543
- * import { EventRepository } from '@amityco/ts-sdk'
30544
- * const dispose = EventRepository.onEventUpdated(event => {
30545
- * // ...
30546
- * })
30547
- * ```
30548
- *
30549
- * Fired when a {@link Amity.Event} has been updated
30550
- *
30551
- * @param callback The function to call when the event was fired
30552
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30553
- *
30554
- * @category Event Events
30555
- */
30556
- const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
30557
-
30558
- /**
30559
- * ```js
30560
- * import { EventRepository } from '@amityco/ts-sdk'
30561
- * const dispose = EventRepository.onEventDeleted(event => {
30562
- * // ...
30563
- * })
30564
- * ```
30565
- *
30566
- * Fired when a {@link Amity.Event} has been deleted
30567
- *
30568
- * @param callback The function to call when the event was fired
30569
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30570
- *
30571
- * @category Event Events
30572
- */
30573
- const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
30574
-
30575
- /* begin_public_function
30576
- id: event.get
30577
- */
30578
- /**
30579
- * ```js
30580
- * import { EventRepository } from '@amityco/ts-sdk';
30581
- *
30582
- * let event;
30583
- *
30584
- * const unsubscribe = EventRepository.getEvent(eventId, response => {
30585
- * event = response.data;
30586
- * });
30587
- * ```
30588
- *
30589
- * Observe all mutation on a given {@link Amity.Event}
30590
- *
30591
- * @param eventId the ID of the event to observe
30592
- * @param callback the function to call when new snapshot of event are available
30593
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the event
30594
- *
30595
- * @category Event Live Object
30596
- */
30597
- const getEvent = (eventId, callback) => {
30598
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
30599
- callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
30600
- });
30601
- };
30602
- /* end_public_function */
30603
-
30604
- var index = /*#__PURE__*/Object.freeze({
30605
- __proto__: null,
30606
- createEvent: createEvent,
30607
- updateEvent: updateEvent,
30608
- deleteEvent: deleteEvent,
30609
- onEventCreated: onEventCreated,
30610
- onEventUpdated: onEventUpdated,
30611
- onEventDeleted: onEventDeleted,
30612
- getEvent: getEvent
30613
- });
30614
-
30615
31119
  exports.API_REGIONS = API_REGIONS;
30616
- exports.AdRepository = index$4;
31120
+ exports.AdRepository = index$3;
30617
31121
  exports.CategoryRepository = index$c;
30618
31122
  exports.ChannelRepository = index$g;
30619
31123
  exports.Client = index$p;
@@ -30623,22 +31127,22 @@ exports.CommunityPostSettings = CommunityPostSettings;
30623
31127
  exports.CommunityRepository = index$d;
30624
31128
  exports.ContentFeedType = ContentFeedType;
30625
31129
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
30626
- exports.EventRepository = index;
30627
31130
  exports.FeedRepository = index$a;
30628
31131
  exports.FileRepository = index$m;
30629
31132
  exports.FileType = FileType;
30630
31133
  exports.GET_WATCHER_URLS = GET_WATCHER_URLS;
30631
- exports.InvitationRepository = index$2;
30632
- exports.LiveReactionRepository = index$1;
30633
- exports.LiveStreamPlayer = index$6;
31134
+ exports.InvitationRepository = index$1;
31135
+ exports.LiveReactionRepository = index;
31136
+ exports.LiveStreamPlayer = index$5;
30634
31137
  exports.MessageContentType = MessageContentType;
30635
31138
  exports.MessageRepository = index$k;
30636
- exports.PollRepository = index$7;
31139
+ exports.PollRepository = index$6;
30637
31140
  exports.PostContentType = PostContentType;
30638
31141
  exports.PostRepository = index$9;
30639
31142
  exports.PostStructureType = PostStructureType;
30640
31143
  exports.ReactionRepository = index$l;
30641
- exports.StoryRepository = index$5;
31144
+ exports.RoomRepository = index$7;
31145
+ exports.StoryRepository = index$4;
30642
31146
  exports.StreamRepository = index$8;
30643
31147
  exports.SubChannelRepository = index$j;
30644
31148
  exports.UserRepository = index$n;
@@ -30695,7 +31199,7 @@ exports.isPaged = isPaged;
30695
31199
  exports.isReportedByMe = isReportedByMe;
30696
31200
  exports.isSkip = isSkip;
30697
31201
  exports.mergeInCache = mergeInCache;
30698
- exports.notificationTray = index$3;
31202
+ exports.notificationTray = index$2;
30699
31203
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
30700
31204
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
30701
31205
  exports.onFeedMarkerUpdated = onFeedMarkerUpdated;