@amityco/ts-sdk 7.11.1-88f39a40.0 → 7.11.1-8ef0bbb7.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 (128) hide show
  1. package/dist/@types/core/events.d.ts +13 -32
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +3 -2
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +4 -15
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/core/transport.d.ts +0 -3
  8. package/dist/@types/core/transport.d.ts.map +1 -1
  9. package/dist/@types/domains/content.d.ts +4 -1
  10. package/dist/@types/domains/content.d.ts.map +1 -1
  11. package/dist/@types/domains/post.d.ts +2 -0
  12. package/dist/@types/domains/post.d.ts.map +1 -1
  13. package/dist/@types/domains/room.d.ts +71 -0
  14. package/dist/@types/domains/room.d.ts.map +1 -0
  15. package/dist/@types/index.d.ts +2 -1
  16. package/dist/@types/index.d.ts.map +1 -1
  17. package/dist/core/events.d.ts +3 -3
  18. package/dist/core/events.d.ts.map +1 -1
  19. package/dist/core/model/idResolvers.d.ts.map +1 -1
  20. package/dist/core/model/index.d.ts.map +1 -1
  21. package/dist/index.cjs.js +935 -515
  22. package/dist/index.d.ts +1 -1
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.esm.js +746 -326
  25. package/dist/index.umd.js +3 -3
  26. package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
  27. package/dist/roomRepository/api/createRoom.d.ts +24 -0
  28. package/dist/roomRepository/api/createRoom.d.ts.map +1 -0
  29. package/dist/roomRepository/api/deleteRoom.d.ts +16 -0
  30. package/dist/roomRepository/api/deleteRoom.d.ts.map +1 -0
  31. package/dist/roomRepository/api/getRecordedUrl.d.ts +19 -0
  32. package/dist/roomRepository/api/getRecordedUrl.d.ts.map +1 -0
  33. package/dist/roomRepository/api/getRoomToken.d.ts +16 -0
  34. package/dist/roomRepository/api/getRoomToken.d.ts.map +1 -0
  35. package/dist/roomRepository/api/index.d.ts +7 -0
  36. package/dist/roomRepository/api/index.d.ts.map +1 -0
  37. package/dist/roomRepository/api/stopRoom.d.ts +16 -0
  38. package/dist/roomRepository/api/stopRoom.d.ts.map +1 -0
  39. package/dist/roomRepository/api/updateRoom.d.ts +24 -0
  40. package/dist/roomRepository/api/updateRoom.d.ts.map +1 -0
  41. package/dist/roomRepository/events/index.d.ts +12 -0
  42. package/dist/roomRepository/events/index.d.ts.map +1 -0
  43. package/dist/roomRepository/events/onRoomCreated.d.ts +17 -0
  44. package/dist/roomRepository/events/onRoomCreated.d.ts.map +1 -0
  45. package/dist/roomRepository/events/onRoomDeleted.d.ts +17 -0
  46. package/dist/roomRepository/events/onRoomDeleted.d.ts.map +1 -0
  47. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts +17 -0
  48. package/dist/roomRepository/events/onRoomEndBroadcasting.d.ts.map +1 -0
  49. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts +17 -0
  50. package/dist/roomRepository/events/onRoomParticipantInviting.d.ts.map +1 -0
  51. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts +17 -0
  52. package/dist/roomRepository/events/onRoomParticipantJoined.d.ts.map +1 -0
  53. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts +17 -0
  54. package/dist/roomRepository/events/onRoomParticipantLeft.d.ts.map +1 -0
  55. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts +17 -0
  56. package/dist/roomRepository/events/onRoomRecordedAvailable.d.ts.map +1 -0
  57. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts +17 -0
  58. package/dist/roomRepository/events/onRoomStartBroadcasting.d.ts.map +1 -0
  59. package/dist/roomRepository/events/onRoomStopped.d.ts +17 -0
  60. package/dist/roomRepository/events/onRoomStopped.d.ts.map +1 -0
  61. package/dist/roomRepository/events/onRoomUpdated.d.ts +17 -0
  62. package/dist/roomRepository/events/onRoomUpdated.d.ts.map +1 -0
  63. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts +17 -0
  64. package/dist/roomRepository/events/onRoomWaitingReconnect.d.ts.map +1 -0
  65. package/dist/roomRepository/index.d.ts.map +1 -0
  66. package/dist/roomRepository/internalApi/getRoomById.d.ts +5 -0
  67. package/dist/roomRepository/internalApi/getRoomById.d.ts.map +1 -0
  68. package/dist/roomRepository/internalApi/index.d.ts +2 -0
  69. package/dist/roomRepository/internalApi/index.d.ts.map +1 -0
  70. package/dist/roomRepository/observers/enums.d.ts +10 -0
  71. package/dist/roomRepository/observers/enums.d.ts.map +1 -0
  72. package/dist/roomRepository/observers/getRoom.d.ts +2 -0
  73. package/dist/roomRepository/observers/getRoom.d.ts.map +1 -0
  74. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts +14 -0
  75. package/dist/roomRepository/observers/getRooms/RoomLiveCollectionController.d.ts.map +1 -0
  76. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts +5 -0
  77. package/dist/roomRepository/observers/getRooms/RoomPaginationController.d.ts.map +1 -0
  78. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts +15 -0
  79. package/dist/roomRepository/observers/getRooms/RoomQueryStreamController.d.ts.map +1 -0
  80. package/dist/roomRepository/observers/getRooms.d.ts +29 -0
  81. package/dist/roomRepository/observers/getRooms.d.ts.map +1 -0
  82. package/dist/roomRepository/observers/index.d.ts +3 -0
  83. package/dist/roomRepository/observers/index.d.ts.map +1 -0
  84. package/dist/roomRepository/observers/utils.d.ts +6 -0
  85. package/dist/roomRepository/observers/utils.d.ts.map +1 -0
  86. package/dist/utils/linkedObject/index.d.ts +0 -1
  87. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  88. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  89. package/dist/utils/postTypePredicate.d.ts +1 -0
  90. package/dist/utils/postTypePredicate.d.ts.map +1 -1
  91. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  92. package/package.json +1 -1
  93. package/dist/@types/domains/event.d.ts +0 -57
  94. package/dist/@types/domains/event.d.ts.map +0 -1
  95. package/dist/eventRepository/api/createEvent.d.ts +0 -16
  96. package/dist/eventRepository/api/createEvent.d.ts.map +0 -1
  97. package/dist/eventRepository/api/deleteEvent.d.ts +0 -15
  98. package/dist/eventRepository/api/deleteEvent.d.ts.map +0 -1
  99. package/dist/eventRepository/api/index.d.ts +0 -4
  100. package/dist/eventRepository/api/index.d.ts.map +0 -1
  101. package/dist/eventRepository/api/updateEvent.d.ts +0 -17
  102. package/dist/eventRepository/api/updateEvent.d.ts.map +0 -1
  103. package/dist/eventRepository/events/index.d.ts +0 -4
  104. package/dist/eventRepository/events/index.d.ts.map +0 -1
  105. package/dist/eventRepository/events/onEventCreated.d.ts +0 -17
  106. package/dist/eventRepository/events/onEventCreated.d.ts.map +0 -1
  107. package/dist/eventRepository/events/onEventDeleted.d.ts +0 -17
  108. package/dist/eventRepository/events/onEventDeleted.d.ts.map +0 -1
  109. package/dist/eventRepository/events/onEventUpdated.d.ts +0 -17
  110. package/dist/eventRepository/events/onEventUpdated.d.ts.map +0 -1
  111. package/dist/eventRepository/index.d.ts.map +0 -1
  112. package/dist/eventRepository/internalApi/getEvent.d.ts +0 -32
  113. package/dist/eventRepository/internalApi/getEvent.d.ts.map +0 -1
  114. package/dist/eventRepository/internalApi/index.d.ts +0 -2
  115. package/dist/eventRepository/internalApi/index.d.ts.map +0 -1
  116. package/dist/eventRepository/observers/getEvent.d.ts +0 -21
  117. package/dist/eventRepository/observers/getEvent.d.ts.map +0 -1
  118. package/dist/eventRepository/observers/index.d.ts +0 -2
  119. package/dist/eventRepository/observers/index.d.ts.map +0 -1
  120. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +0 -2
  121. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +0 -1
  122. package/dist/eventRepository/utils/index.d.ts +0 -3
  123. package/dist/eventRepository/utils/index.d.ts.map +0 -1
  124. package/dist/eventRepository/utils/prepareEventPayload.d.ts +0 -2
  125. package/dist/eventRepository/utils/prepareEventPayload.d.ts.map +0 -1
  126. package/dist/utils/linkedObject/eventLinkObject.d.ts +0 -2
  127. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +0 -1
  128. /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',
@@ -192,24 +193,6 @@ exports.FeedSourceEnum = void 0;
192
193
  FeedSourceEnum["User"] = "user";
193
194
  })(exports.FeedSourceEnum || (exports.FeedSourceEnum = {}));
194
195
 
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
196
  function getVersion() {
214
197
  try {
215
198
  // the string ''v7.11.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
@@ -658,6 +641,7 @@ const idResolvers = {
658
641
  notificationTraySeen: ({ userId }) => userId,
659
642
  invitation: ({ _id }) => _id,
660
643
  joinRequest: ({ joinRequestId }) => joinRequestId,
644
+ room: ({ roomId }) => roomId,
661
645
  };
662
646
  /**
663
647
  * Retrieve the id resolver matching a domain name
@@ -713,6 +697,7 @@ const PAYLOAD2MODEL = {
713
697
  notificationTrayItems: 'notificationTrayItem',
714
698
  invitations: 'invitation',
715
699
  joinRequests: 'joinRequest',
700
+ rooms: 'room',
716
701
  };
717
702
  /** hidden */
718
703
  const isOutdated = (prevData, nextData) => {
@@ -12225,6 +12210,12 @@ function isAmityAudioPost(post) {
12225
12210
  'fileId' in post.data &&
12226
12211
  post.dataType === 'audio');
12227
12212
  }
12213
+ function isAmityRoomPost(post) {
12214
+ return !!(post.data &&
12215
+ typeof post.data !== 'string' &&
12216
+ 'roomId' in post.data &&
12217
+ post.dataType === 'room');
12218
+ }
12228
12219
 
12229
12220
  const postLinkedObject = (post) => {
12230
12221
  return shallowClone(post, {
@@ -12319,6 +12310,12 @@ const postLinkedObject = (post) => {
12319
12310
  ? (_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
12311
  : undefined;
12321
12312
  },
12313
+ getRoomInfo() {
12314
+ var _a, _b;
12315
+ if (!isAmityRoomPost(post))
12316
+ return;
12317
+ 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;
12318
+ },
12322
12319
  });
12323
12320
  };
12324
12321
 
@@ -13676,31 +13673,6 @@ const communityLinkedObject = (community) => {
13676
13673
  } });
13677
13674
  };
13678
13675
 
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
13676
  const LinkedObject = {
13705
13677
  ad: adLinkedObject,
13706
13678
  comment: commentLinkedObject,
@@ -13719,7 +13691,6 @@ const LinkedObject = {
13719
13691
  invitation: invitationLinkedObject,
13720
13692
  joinRequest: joinRequestLinkedObject,
13721
13693
  channelMember: channelMemberLinkedObject,
13722
- event: eventLinkedObject,
13723
13694
  };
13724
13695
 
13725
13696
  /* begin_public_function
@@ -27705,336 +27676,1059 @@ var index$8 = /*#__PURE__*/Object.freeze({
27705
27676
  });
27706
27677
 
27707
27678
  /* begin_public_function
27708
- id: poll.create
27679
+ id: room.create
27709
27680
  */
27710
27681
  /**
27711
27682
  * ```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
- * }))
27683
+ * import { createRoom } from '@amityco/ts-sdk'
27684
+ * const created = await createRoom({ title: 'my room', 'thumbnailFileId': fileId })
27721
27685
  * ```
27722
27686
  *
27723
- * Creates an {@link Amity.Poll}
27687
+ * Creates an {@link Amity.Room}
27724
27688
  *
27725
- * @param bundle The data necessary to create a new {@link Amity.Poll}
27726
- * @returns The newly created {@link Amity.Poll}
27689
+ * @param bundle The data necessary to create a new {@link Amity.Room}
27690
+ * @returns The newly created {@link Amity.Room}
27727
27691
  *
27728
- * @category Poll API
27692
+ * @category Room API
27729
27693
  * @async
27730
27694
  */
27731
- const createPoll = async (bundle) => {
27695
+ const createRoom = async (bundle) => {
27732
27696
  const client = getActiveClient();
27733
- client.log('post/createPoll', bundle);
27734
- const { data } = await client.http.post('/api/v3/polls', bundle);
27697
+ client.log('room/createRoom', bundle);
27698
+ const { data } = await client.http.post('/api/v1/rooms', bundle);
27699
+ fireEvent('local.room.created', data);
27735
27700
  const cachedAt = client.cache && Date.now();
27701
+ // TODO: check if should pick `users` filed which contains participants - if no need to ingest in the cache
27736
27702
  if (client.cache)
27737
27703
  ingestInCache(data, { cachedAt });
27738
- const { polls } = data;
27704
+ const { rooms } = data;
27739
27705
  return {
27740
- data: polls[0],
27706
+ data: rooms[0],
27741
27707
  cachedAt,
27742
27708
  };
27743
27709
  };
27744
27710
  /* end_public_function */
27745
27711
 
27746
27712
  /* begin_public_function
27747
- id: poll.close
27713
+ id: room.update
27748
27714
  */
27749
27715
  /**
27750
27716
  * ```js
27751
- * import { closePoll } from '@amityco/ts-sdk'
27752
- * const updated = await closePoll(pollId)
27717
+ * import { updateRoom } from '@amityco/ts-sdk'
27718
+ * const updated = await updateRoom('roomId', { title: 'updated title' })
27753
27719
  * ```
27754
27720
  *
27755
- * Updates an {@link Amity.Poll}
27721
+ * Updates an {@link Amity.InternalRoom}
27756
27722
  *
27757
- * @param pollId The ID of the {@link Amity.Poll} to close
27758
- * @returns the updated {@link Amity.Poll} object
27723
+ * @param roomId The ID of the room to update
27724
+ * @param bundle The data to update the room with
27725
+ * @returns The updated {@link Amity.InternalRoom}
27759
27726
  *
27760
- * @category Poll API
27727
+ * @category Room API
27761
27728
  * @async
27762
27729
  */
27763
- const closePoll = async (pollId) => {
27730
+ const updateRoom = async (roomId, bundle) => {
27764
27731
  const client = getActiveClient();
27765
- client.log('user/closePoll', pollId);
27766
- const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}`, { status: 'closed' });
27732
+ client.log('room/updateRoom', { roomId, bundle });
27733
+ const { data } = await client.http.put(`/api/v1/rooms/${roomId}`, bundle);
27734
+ fireEvent('local.room.updated', data);
27767
27735
  const cachedAt = client.cache && Date.now();
27768
27736
  if (client.cache)
27769
27737
  ingestInCache(data, { cachedAt });
27770
- fireEvent('poll.updated', data);
27771
- const { polls } = data;
27738
+ const { rooms } = data;
27772
27739
  return {
27773
- data: polls.find(poll => poll.pollId === pollId),
27740
+ data: rooms[0],
27774
27741
  cachedAt,
27775
27742
  };
27776
27743
  };
27777
27744
  /* end_public_function */
27778
27745
 
27779
27746
  /* begin_public_function
27780
- id: poll.get
27747
+ id: room.delete
27781
27748
  */
27782
27749
  /**
27783
27750
  * ```js
27784
- * import { getPoll } from '@amityco/ts-sdk'
27785
- * const poll = await getPoll('foobar')
27751
+ * import { deleteRoom } from '@amityco/ts-sdk'
27752
+ * const result = await deleteRoom('roomId')
27786
27753
  * ```
27787
27754
  *
27788
- * Fetches a {@link Amity.Poll} object
27755
+ * Deletes an {@link Amity.Room}
27789
27756
  *
27790
- * @param pollId the ID of the {@link Amity.Poll} to fetch
27791
- * @returns the associated {@link Amity.Poll} object
27757
+ * @param roomId The ID of the room to delete
27758
+ * @returns Promise that resolves when the room is deleted
27792
27759
  *
27793
- * @category Poll API
27760
+ * @category Room API
27794
27761
  * @async
27795
27762
  */
27796
- const getPoll$1 = async (pollId) => {
27763
+ const deleteRoom = async (roomId) => {
27797
27764
  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
- };
27765
+ client.log('room/deleteRoom', { roomId });
27766
+ await client.http.delete(`/api/v1/rooms/${roomId}`);
27767
+ fireEvent('local.room.deleted', { rooms: [{ _id: roomId }] });
27808
27768
  };
27809
27769
  /* end_public_function */
27770
+
27771
+ /* begin_public_function
27772
+ id: room.stop
27773
+ */
27810
27774
  /**
27811
27775
  * ```js
27812
- * import { getPoll } from '@amityco/ts-sdk'
27813
- * const poll = getPoll.locally('foobar')
27776
+ * import { stopRoom } from '@amityco/ts-sdk'
27777
+ * const result = await stopRoom('roomId')
27814
27778
  * ```
27815
27779
  *
27816
- * Fetches a {@link Amity.Poll} object
27780
+ * Stops a room's broadcasting
27817
27781
  *
27818
- * @param pollId the ID of the {@link Amity.Poll} to fetch
27819
- * @returns the associated {@link Amity.Poll} object
27782
+ * @param roomId The ID of the room to stop
27783
+ * @returns The updated room data
27820
27784
  *
27821
- * @category Poll API
27785
+ * @category Room API
27786
+ * @async
27822
27787
  */
27823
- getPoll$1.locally = (pollId) => {
27788
+ const stopRoom = async (roomId) => {
27824
27789
  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;
27790
+ client.log('room/stopRoom', { roomId });
27791
+ const { data } = await client.http.post(`/api/v1/rooms/${roomId}/stop`);
27792
+ fireEvent('local.room.stopped', data);
27793
+ const cachedAt = client.cache && Date.now();
27794
+ if (client.cache)
27795
+ ingestInCache(data, { cachedAt });
27796
+ const { rooms } = data;
27831
27797
  return {
27832
- data: cached.data,
27833
- cachedAt: cached.cachedAt,
27798
+ data: rooms[0],
27799
+ cachedAt,
27834
27800
  };
27835
27801
  };
27802
+ /* end_public_function */
27836
27803
 
27837
27804
  /* begin_public_function
27838
- id: poll.delete
27805
+ id: room.getToken
27839
27806
  */
27840
27807
  /**
27841
27808
  * ```js
27842
- * import { deletePoll } from '@amityco/ts-sdk'
27843
- * const success = await deletePoll(pollId)
27809
+ * import { getRoomToken } from '@amityco/ts-sdk'
27810
+ * const token = await getRoomToken('roomId')
27844
27811
  * ```
27845
27812
  *
27846
- * Deletes a {@link Amity.Poll}
27813
+ * Gets an access token for a room
27847
27814
  *
27848
- * @param pollId The {@link Amity.Poll} ID to delete
27849
- * @return A success boolean if the {@link Amity.Poll} was deleted
27815
+ * @param roomId The ID of the room to get token for
27816
+ * @returns The room access token
27850
27817
  *
27851
- * @category Poll API
27818
+ * @category Room API
27852
27819
  * @async
27853
27820
  */
27854
- const deletePoll = async (pollId) => {
27821
+ const getRoomToken = async (roomId) => {
27855
27822
  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;
27823
+ client.log('room/getRoomToken', { roomId });
27824
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/token`);
27825
+ return data;
27865
27826
  };
27866
27827
  /* end_public_function */
27867
27828
 
27868
27829
  /* begin_public_function
27869
- id: poll.vote
27830
+ id: room.getRecordedUrl
27870
27831
  */
27871
27832
  /**
27872
27833
  * ```js
27873
- * import { votePoll } from '@amityco/ts-sdk'
27874
- * const voted = await votePoll(pollId)
27834
+ * import { getRecordedUrl } from '@amityco/ts-sdk'
27835
+ * const recordedUrl = await getRecordedUrl('roomId')
27875
27836
  * ```
27876
27837
  *
27877
- * Votes for an {@link Amity.Poll}
27838
+ * Gets the recorded URL for a room
27878
27839
  *
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
27840
+ * @param roomId The ID of the room to get recorded URL for
27841
+ * @returns The recorded URL information
27882
27842
  *
27883
- * @category Poll API
27843
+ * @category Room API
27884
27844
  * @async
27885
27845
  */
27886
- const votePoll = async (pollId, answerIds) => {
27846
+ const getRecordedUrl = async (roomId) => {
27887
27847
  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
- };
27848
+ client.log('room/getRecordedUrl', { roomId });
27849
+ const { data } = await client.http.get(`/api/v1/rooms/${roomId}/recorded`);
27850
+ return data;
27899
27851
  };
27900
27852
  /* end_public_function */
27901
27853
 
27902
- /* begin_public_function
27903
- id: poll.unvote
27904
- */
27905
27854
  /**
27906
27855
  * ```js
27907
- * import { PollRepository } from '@amityco/ts-sdk'
27908
- * await PollRepository.unvotePoll(pollId)
27856
+ * import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
27857
+ * const dispose = onRoomStartBroadcasting(room => {
27858
+ * // ...
27859
+ * })
27909
27860
  * ```
27910
27861
  *
27911
- * Votes for an {@link Amity.Poll}
27862
+ * Fired when a {@link Amity.Room} has started broadcasting
27912
27863
  *
27913
- * @param pollId The ID of the {@link Amity.Poll} to vote
27914
- * @returns void
27864
+ * @param callback The function to call when the event was fired
27865
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27915
27866
  *
27916
- * @category Poll API
27917
- * @async
27867
+ * @category Room Events
27918
27868
  */
27919
- const unvotePoll = async (pollId) => {
27869
+ const onRoomStartBroadcasting = (callback) => {
27920
27870
  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);
27871
+ const filter = (payload) => {
27872
+ ingestInCache(payload);
27873
+ callback(payload.rooms[0]);
27874
+ };
27875
+ return createEventSubscriber(client, 'room/onRoomStartBroadcasting', 'room.startBroadcasting', filter);
27927
27876
  };
27928
- /* end_public_function */
27929
27877
 
27930
27878
  /**
27931
27879
  * ```js
27932
- * import { onPollUpdated } from '@amityco/ts-sdk'
27933
- * const dispose = onPollUpdated(poll => {
27880
+ * import { onRoomWaitingReconnect } from '@amityco/ts-sdk'
27881
+ * const dispose = onRoomWaitingReconnect(room => {
27934
27882
  * // ...
27935
27883
  * })
27936
27884
  * ```
27937
27885
  *
27938
- * Fired when an {@link Amity.Poll} has been updated
27886
+ * Fired when a {@link Amity.Room} is waiting for reconnection
27939
27887
  *
27940
27888
  * @param callback The function to call when the event was fired
27941
27889
  * @returns an {@link Amity.Unsubscriber} function to stop listening
27942
27890
  *
27943
- * @category Poll Events
27891
+ * @category Room Events
27944
27892
  */
27945
- const onPollUpdated = (callback) => {
27893
+ const onRoomWaitingReconnect = (callback) => {
27946
27894
  const client = getActiveClient();
27947
27895
  const filter = (payload) => {
27948
- if (client.cache)
27949
- ingestInCache(payload);
27950
- callback(payload.polls[0]);
27896
+ ingestInCache(payload);
27897
+ callback(payload.rooms[0]);
27951
27898
  };
27952
- return createEventSubscriber(client, 'poll/onPollUpdated', 'poll.updated', filter);
27899
+ return createEventSubscriber(client, 'room/onRoomWaitingReconnect', 'room.waitingReconnect', filter);
27953
27900
  };
27954
27901
 
27955
27902
  /**
27956
27903
  * ```js
27957
- * import { onPollDeleted } from '@amityco/ts-sdk'
27958
- * const dispose = onPollDeleted(poll => {
27904
+ * import { onRoomEndBroadcasting } from '@amityco/ts-sdk'
27905
+ * const dispose = onRoomEndBroadcasting(room => {
27959
27906
  * // ...
27960
27907
  * })
27961
27908
  * ```
27962
27909
  *
27963
- * Fired when an {@link Amity.Poll} has been deleted
27910
+ * Fired when a {@link Amity.Room} has ended broadcasting
27964
27911
  *
27965
27912
  * @param callback The function to call when the event was fired
27966
27913
  * @returns an {@link Amity.Unsubscriber} function to stop listening
27967
27914
  *
27968
- * @category Poll Events
27915
+ * @category Room Events
27969
27916
  */
27970
- const onPollDeleted = (callback) => {
27917
+ const onRoomEndBroadcasting = (callback) => {
27971
27918
  const client = getActiveClient();
27972
27919
  const filter = (payload) => {
27973
- if (client.cache)
27974
- ingestInCache(payload);
27975
- callback(payload.polls[0]);
27920
+ ingestInCache(payload);
27921
+ callback(payload.rooms[0]);
27976
27922
  };
27977
- return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
27923
+ return createEventSubscriber(client, 'room/onRoomEndBroadcasting', 'room.endBroadcasting', filter);
27978
27924
  };
27979
27925
 
27980
- /* begin_public_function
27981
- id: poll.get
27982
- */
27983
27926
  /**
27984
27927
  * ```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
- * });
27928
+ * import { onRoomRecordedAvailable } from '@amityco/ts-sdk'
27929
+ * const dispose = onRoomRecordedAvailable(room => {
27930
+ * // ...
27931
+ * })
27992
27932
  * ```
27993
27933
  *
27994
- * Observe all mutation on a given {@link Amity.Poll}
27934
+ * Fired when a {@link Amity.Room} recorded content becomes available
27995
27935
  *
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
27936
+ * @param callback The function to call when the event was fired
27937
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27999
27938
  *
28000
- * @category Poll Live Object
27939
+ * @category Room Events
28001
27940
  */
28002
- const getPoll = (pollId, callback) => {
28003
- return liveObject(pollId, callback, 'pollId', getPoll$1, [onPollUpdated, onPollDeleted]);
27941
+ const onRoomRecordedAvailable = (callback) => {
27942
+ const client = getActiveClient();
27943
+ const filter = (payload) => {
27944
+ ingestInCache(payload);
27945
+ callback(payload.rooms[0]);
27946
+ };
27947
+ return createEventSubscriber(client, 'room/onRoomRecordedAvailable', 'room.recordedAvailable', filter);
28004
27948
  };
28005
- /* end_public_function */
28006
-
28007
- var index$7 = /*#__PURE__*/Object.freeze({
28008
- __proto__: null,
28009
- createPoll: createPoll,
28010
- closePoll: closePoll,
28011
- deletePoll: deletePoll,
28012
- votePoll: votePoll,
28013
- unvotePoll: unvotePoll,
28014
- onPollUpdated: onPollUpdated,
28015
- onPollDeleted: onPollDeleted,
28016
- getPoll: getPoll
28017
- });
28018
27949
 
28019
- const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
28020
- /*
28021
- * The crypto algorithm used for importing key and signing string
27950
+ /**
27951
+ * ```js
27952
+ * import { onRoomParticipantInviting } from '@amityco/ts-sdk'
27953
+ * const dispose = onRoomParticipantInviting(room => {
27954
+ * // ...
27955
+ * })
27956
+ * ```
27957
+ *
27958
+ * Fired when a participant is being invited to a {@link Amity.Room}
27959
+ *
27960
+ * @param callback The function to call when the event was fired
27961
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27962
+ *
27963
+ * @category Room Events
28022
27964
  */
28023
- const ALGORITHM = {
28024
- name: 'RSASSA-PKCS1-v1_5',
28025
- hash: { name: 'SHA-256' },
27965
+ const onRoomParticipantInviting = (callback) => {
27966
+ const client = getActiveClient();
27967
+ const filter = (payload) => {
27968
+ ingestInCache(payload);
27969
+ callback(payload.rooms[0]);
27970
+ };
27971
+ return createEventSubscriber(client, 'room/onRoomParticipantInviting', 'room.participantInviting', filter);
28026
27972
  };
28027
- /*
28028
- * IMPORTANT!
28029
- * If you are recieving key from other platforms use an online tool to convert
28030
- * the PKCS1 to PKCS8. For instance the key from Android SDK is of the format
28031
- * PKCS1.
27973
+
27974
+ /**
27975
+ * ```js
27976
+ * import { onRoomParticipantJoined } from '@amityco/ts-sdk'
27977
+ * const dispose = onRoomParticipantJoined(room => {
27978
+ * // ...
27979
+ * })
27980
+ * ```
28032
27981
  *
28033
- * If recieving from the platform, verify if it's already in the expected
28034
- * format. Otherwise the crypto.subtle.importKey will throw a DOMException
27982
+ * Fired when a participant has joined a {@link Amity.Room}
27983
+ *
27984
+ * @param callback The function to call when the event was fired
27985
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
27986
+ *
27987
+ * @category Room Events
28035
27988
  */
28036
- const PRIVATE_KEY_SIGNATURE = 'pkcs8';
28037
- /*
27989
+ const onRoomParticipantJoined = (callback) => {
27990
+ const client = getActiveClient();
27991
+ const filter = (payload) => {
27992
+ ingestInCache(payload);
27993
+ callback(payload.rooms[0]);
27994
+ };
27995
+ return createEventSubscriber(client, 'room/onRoomParticipantJoined', 'room.participantJoined', filter);
27996
+ };
27997
+
27998
+ /**
27999
+ * ```js
28000
+ * import { onRoomParticipantLeft } from '@amityco/ts-sdk'
28001
+ * const dispose = onRoomParticipantLeft(room => {
28002
+ * // ...
28003
+ * })
28004
+ * ```
28005
+ *
28006
+ * Fired when a participant has left a {@link Amity.Room}
28007
+ *
28008
+ * @param callback The function to call when the event was fired
28009
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28010
+ *
28011
+ * @category Room Events
28012
+ */
28013
+ const onRoomParticipantLeft = (callback) => {
28014
+ const client = getActiveClient();
28015
+ const filter = (payload) => {
28016
+ ingestInCache(payload);
28017
+ callback(payload.rooms[0]);
28018
+ };
28019
+ return createEventSubscriber(client, 'room/onRoomParticipantLeft', 'room.participantLeft', filter);
28020
+ };
28021
+
28022
+ /**
28023
+ * ```js
28024
+ * import { onRoomCreated } from '@amityco/ts-sdk'
28025
+ * const dispose = onRoomCreated(room => {
28026
+ * // ...
28027
+ * })
28028
+ * ```
28029
+ *
28030
+ * Fired when a {@link Amity.Room} has been created locally
28031
+ *
28032
+ * @param callback The function to call when the event was fired
28033
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28034
+ *
28035
+ * @category Room Events
28036
+ */
28037
+ const onRoomCreated = (callback) => {
28038
+ const client = getActiveClient();
28039
+ const filter = (payload) => {
28040
+ ingestInCache(payload);
28041
+ callback(payload.rooms[0]);
28042
+ };
28043
+ return createEventSubscriber(client, 'room/onRoomCreated', 'local.room.created', filter);
28044
+ };
28045
+
28046
+ /**
28047
+ * ```js
28048
+ * import { onRoomUpdated } from '@amityco/ts-sdk'
28049
+ * const dispose = onRoomUpdated(room => {
28050
+ * // ...
28051
+ * })
28052
+ * ```
28053
+ *
28054
+ * Fired when a {@link Amity.Room} has been updated locally
28055
+ *
28056
+ * @param callback The function to call when the event was fired
28057
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28058
+ *
28059
+ * @category Room Events
28060
+ */
28061
+ const onRoomUpdated = (callback) => {
28062
+ const client = getActiveClient();
28063
+ const filter = (payload) => {
28064
+ ingestInCache(payload);
28065
+ callback(payload.rooms[0]);
28066
+ };
28067
+ return createEventSubscriber(client, 'room/onRoomUpdated', 'local.room.updated', filter);
28068
+ };
28069
+
28070
+ /**
28071
+ * ```js
28072
+ * import { onRoomDeleted } from '@amityco/ts-sdk'
28073
+ * const dispose = onRoomDeleted(room => {
28074
+ * // ...
28075
+ * })
28076
+ * ```
28077
+ *
28078
+ * Fired when a {@link Amity.Room} has been deleted locally
28079
+ *
28080
+ * @param callback The function to call when the event was fired
28081
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28082
+ *
28083
+ * @category Room Events
28084
+ */
28085
+ const onRoomDeleted = (callback) => {
28086
+ const client = getActiveClient();
28087
+ const filter = (payload) => {
28088
+ ingestInCache(payload);
28089
+ callback(payload.rooms[0]);
28090
+ };
28091
+ return createEventSubscriber(client, 'room/onRoomDeleted', 'local.room.deleted', filter);
28092
+ };
28093
+
28094
+ /**
28095
+ * ```js
28096
+ * import { onRoomStopped } from '@amityco/ts-sdk'
28097
+ * const dispose = onRoomStopped(room => {
28098
+ * // ...
28099
+ * })
28100
+ * ```
28101
+ *
28102
+ * Fired when a {@link Amity.Room} has been stopped locally
28103
+ *
28104
+ * @param callback The function to call when the event was fired
28105
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28106
+ *
28107
+ * @category Room Events
28108
+ */
28109
+ const onRoomStopped = (callback) => {
28110
+ const client = getActiveClient();
28111
+ const filter = (payload) => {
28112
+ ingestInCache(payload);
28113
+ callback(payload.rooms[0]);
28114
+ };
28115
+ return createEventSubscriber(client, 'room/onRoomStopped', 'local.room.stopped', filter);
28116
+ };
28117
+
28118
+ const getRoomById = async (roomId) => {
28119
+ const client = getActiveClient();
28120
+ client.log('room/getRoomById', roomId);
28121
+ // Check if room is in tombstone
28122
+ isInTombstone('room', roomId);
28123
+ let data;
28124
+ try {
28125
+ const response = await client.http.get(`/api/v1/rooms/${roomId}`);
28126
+ data = response.data;
28127
+ }
28128
+ catch (error) {
28129
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
28130
+ pushToTombstone('room', roomId);
28131
+ }
28132
+ throw error;
28133
+ }
28134
+ const cachedAt = client.cache && Date.now();
28135
+ if (client.cache) {
28136
+ ingestInCache(data, { cachedAt });
28137
+ }
28138
+ return {
28139
+ data: data.rooms[0],
28140
+ cachedAt,
28141
+ };
28142
+ };
28143
+ getRoomById.locally = (roomId) => {
28144
+ const client = getActiveClient();
28145
+ client.log('room/getRoomById.locally', roomId);
28146
+ // Check if room is in tombstone
28147
+ isInTombstone('room', roomId);
28148
+ const cachedAt = client.cache && Date.now();
28149
+ const roomCache = pullFromCache(['room', 'get', roomId]);
28150
+ if (!roomCache)
28151
+ return;
28152
+ return {
28153
+ data: roomCache.data,
28154
+ cachedAt,
28155
+ };
28156
+ };
28157
+
28158
+ const getRoom = (roomId, callback) => {
28159
+ // TODO: add callbackDataSelector if there are linked object fields
28160
+ return liveObject(roomId, callback, '_id', getRoomById, [
28161
+ onRoomEndBroadcasting,
28162
+ onRoomStartBroadcasting,
28163
+ onRoomWaitingReconnect,
28164
+ onRoomRecordedAvailable,
28165
+ ]);
28166
+ };
28167
+
28168
+ class RoomPaginationController extends PaginationController {
28169
+ async getRequest(queryParams, token) {
28170
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
28171
+ const baseOptions = {
28172
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
28173
+ };
28174
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
28175
+ const { data: queryResponse } = await this.http.get(`/api/v1/rooms`, {
28176
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
28177
+ });
28178
+ return queryResponse;
28179
+ }
28180
+ }
28181
+
28182
+ var EnumRoomActions;
28183
+ (function (EnumRoomActions) {
28184
+ EnumRoomActions["OnRoomCreated"] = "OnRoomCreated";
28185
+ EnumRoomActions["OnRoomUpdated"] = "OnRoomUpdated";
28186
+ EnumRoomActions["OnRoomDeleted"] = "OnRoomDeleted";
28187
+ EnumRoomActions["OnRoomStartBroadcasting"] = "OnRoomStartBroadcasting";
28188
+ EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
28189
+ EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
28190
+ EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
28191
+ })(EnumRoomActions || (EnumRoomActions = {}));
28192
+
28193
+ class RoomQueryStreamController extends QueryStreamController {
28194
+ constructor(query, cacheKey, notifyChange, preparePayload) {
28195
+ super(query, cacheKey);
28196
+ this.notifyChange = notifyChange;
28197
+ this.preparePayload = preparePayload;
28198
+ }
28199
+ async saveToMainDB(response) {
28200
+ const processedPayload = await this.preparePayload(response);
28201
+ const client = getActiveClient();
28202
+ const cachedAt = client.cache && Date.now();
28203
+ if (client.cache) {
28204
+ ingestInCache(processedPayload, { cachedAt });
28205
+ }
28206
+ }
28207
+ appendToQueryStream(response, direction, refresh = false) {
28208
+ var _a, _b;
28209
+ if (refresh) {
28210
+ pushToCache(this.cacheKey, {
28211
+ data: response.rooms.map(getResolver('room')),
28212
+ });
28213
+ }
28214
+ else {
28215
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
28216
+ const rooms = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
28217
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...rooms, ...response.rooms.map(getResolver('room'))])] }));
28218
+ }
28219
+ }
28220
+ reactor(action) {
28221
+ return (room) => {
28222
+ var _a;
28223
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
28224
+ if (!collection)
28225
+ return;
28226
+ if (action === EnumRoomActions.OnRoomDeleted) {
28227
+ collection.data = collection.data.filter(roomId => roomId !== room._id);
28228
+ }
28229
+ if (action === EnumRoomActions.OnRoomCreated) {
28230
+ collection.data = [...new Set([room._id, ...collection.data])];
28231
+ }
28232
+ pushToCache(this.cacheKey, collection);
28233
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
28234
+ };
28235
+ }
28236
+ subscribeRTE(createSubscriber) {
28237
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
28238
+ }
28239
+ }
28240
+
28241
+ // TODO: confirm related events
28242
+ const getRoomSubscription = () => [
28243
+ {
28244
+ fn: onRoomStartBroadcasting,
28245
+ action: EnumRoomActions.OnRoomStartBroadcasting,
28246
+ },
28247
+ {
28248
+ fn: onRoomEndBroadcasting,
28249
+ action: EnumRoomActions.OnRoomEndBroadcasting,
28250
+ },
28251
+ {
28252
+ fn: onRoomRecordedAvailable,
28253
+ action: EnumRoomActions.OnRoomUpdated,
28254
+ },
28255
+ ];
28256
+
28257
+ class RoomLiveCollectionController extends LiveCollectionController {
28258
+ constructor(query, callback) {
28259
+ const queryStreamId = hash__default["default"](query);
28260
+ const cacheKey = ['rooms', 'collection', queryStreamId];
28261
+ const paginationController = new RoomPaginationController(query);
28262
+ super(paginationController, queryStreamId, cacheKey, callback);
28263
+ this.query = query;
28264
+ this.queryStreamController = new RoomQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
28265
+ this.callback = callback.bind(this);
28266
+ this.loadPage({ initial: true });
28267
+ }
28268
+ setup() {
28269
+ var _a;
28270
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
28271
+ if (!collection) {
28272
+ pushToCache(this.cacheKey, {
28273
+ data: [],
28274
+ params: {},
28275
+ });
28276
+ }
28277
+ }
28278
+ async persistModel(queryPayload) {
28279
+ await this.queryStreamController.saveToMainDB(queryPayload);
28280
+ }
28281
+ persistQueryStream({ response, direction, refresh, }) {
28282
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
28283
+ }
28284
+ startSubscription() {
28285
+ return this.queryStreamController.subscribeRTE(getRoomSubscription());
28286
+ }
28287
+ notifyChange({ origin, loading, error }) {
28288
+ var _a, _b;
28289
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
28290
+ if (!collection)
28291
+ return;
28292
+ const data = this.applyFilter((_b = collection.data
28293
+ .map(id => pullFromCache(['room', 'get', id]))
28294
+ .filter(isNonNullable)
28295
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(room => room); // Since Room is same as InternalRoom, no transformation needed
28296
+ if (!this.shouldNotify(data) && origin === 'event')
28297
+ return;
28298
+ this.callback({
28299
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
28300
+ data,
28301
+ hasNextPage: !!this.paginationController.getNextToken(),
28302
+ loading,
28303
+ error,
28304
+ });
28305
+ }
28306
+ applyFilter(data) {
28307
+ let rooms = data;
28308
+ if (!this.query.includeDeleted) {
28309
+ rooms = filterByPropEquality(rooms, 'isDeleted', false);
28310
+ }
28311
+ if (this.query.statuses && this.query.statuses.length > 0) {
28312
+ rooms = rooms.filter(room => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(room.status); });
28313
+ }
28314
+ if (this.query.type) {
28315
+ rooms = filterByPropEquality(rooms, 'type', this.query.type);
28316
+ }
28317
+ switch (this.query.sortBy) {
28318
+ case 'firstCreated':
28319
+ rooms = rooms.sort(sortByFirstCreated);
28320
+ break;
28321
+ case 'lastCreated':
28322
+ default:
28323
+ rooms = rooms.sort(sortByLastCreated);
28324
+ break;
28325
+ }
28326
+ return rooms;
28327
+ }
28328
+ }
28329
+
28330
+ /* begin_public_function
28331
+ id: room.get_rooms
28332
+ */
28333
+ /**
28334
+ * ```js
28335
+ * import { RoomRepository } from '@amityco/ts-sdk'
28336
+ *
28337
+ * let rooms = []
28338
+ * const unsub = RoomRepository.getRooms({
28339
+ * type: 'direct_streaming',
28340
+ * statuses: ['live', 'idle'],
28341
+ * sortBy: 'lastCreated',
28342
+ * limit: 20,
28343
+ * includeDeleted: false
28344
+ * }, response => merge(rooms, response.data))
28345
+ * ```
28346
+ *
28347
+ * Observe all mutations on a list of {@link Amity.Room} for a given query
28348
+ *
28349
+ * @param params.type the type of rooms to filter by ('direct_streaming' | 'co_hosts')
28350
+ * @param params.statuses array of room statuses to filter by (['idle', 'live', 'waiting_reconnect', 'ended', 'recorded'])
28351
+ * @param params.sortBy sort rooms by creation time ('firstCreated' | 'lastCreated')
28352
+ * @param params.limit maximum number of rooms to retrieve per page
28353
+ * @param params.includeDeleted whether to include deleted rooms in the results
28354
+ * @param callback the function to call when new data are available
28355
+ * @param config optional configuration for the live collection
28356
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the rooms
28357
+ *
28358
+ * @category Rooms Live Collection
28359
+ */
28360
+ const getRooms = (params, callback, config) => {
28361
+ const { log, cache } = getActiveClient();
28362
+ if (!cache) {
28363
+ console.log(ENABLE_CACHE_MESSAGE);
28364
+ }
28365
+ const timestamp = Date.now();
28366
+ log(`getRooms(tmpid: ${timestamp}) > listen`);
28367
+ const roomsLiveCollection = new RoomLiveCollectionController(params, callback);
28368
+ const disposers = roomsLiveCollection.startSubscription();
28369
+ const cacheKey = roomsLiveCollection.getCacheKey();
28370
+ disposers.push(() => dropFromCache(cacheKey));
28371
+ return () => {
28372
+ log(`getRooms(tmpid: ${timestamp}) > dispose`);
28373
+ disposers.forEach(fn => fn());
28374
+ };
28375
+ };
28376
+ /* end_public_function */
28377
+
28378
+ var index$7 = /*#__PURE__*/Object.freeze({
28379
+ __proto__: null,
28380
+ createRoom: createRoom,
28381
+ updateRoom: updateRoom,
28382
+ deleteRoom: deleteRoom,
28383
+ stopRoom: stopRoom,
28384
+ getRoomToken: getRoomToken,
28385
+ getRecordedUrl: getRecordedUrl,
28386
+ onRoomStartBroadcasting: onRoomStartBroadcasting,
28387
+ onRoomWaitingReconnect: onRoomWaitingReconnect,
28388
+ onRoomEndBroadcasting: onRoomEndBroadcasting,
28389
+ onRoomRecordedAvailable: onRoomRecordedAvailable,
28390
+ onRoomParticipantInviting: onRoomParticipantInviting,
28391
+ onRoomParticipantJoined: onRoomParticipantJoined,
28392
+ onRoomParticipantLeft: onRoomParticipantLeft,
28393
+ onRoomCreated: onRoomCreated,
28394
+ onRoomUpdated: onRoomUpdated,
28395
+ onRoomDeleted: onRoomDeleted,
28396
+ onRoomStopped: onRoomStopped,
28397
+ getRoom: getRoom,
28398
+ getRooms: getRooms
28399
+ });
28400
+
28401
+ /* begin_public_function
28402
+ id: poll.create
28403
+ */
28404
+ /**
28405
+ * ```js
28406
+ * import { createPoll } from '@amityco/ts-sdk'
28407
+ * const created = await createPoll({
28408
+ * question: 'question',
28409
+ * answers: [
28410
+ * { dataType: 'text', data: 'answer1', fileId: 'fileId1' },
28411
+ * { dataType: 'text', data: 'answer2', fileId: 'fileId2' },
28412
+ * ],
28413
+ * closedIn: 1649136484
28414
+ * }))
28415
+ * ```
28416
+ *
28417
+ * Creates an {@link Amity.Poll}
28418
+ *
28419
+ * @param bundle The data necessary to create a new {@link Amity.Poll}
28420
+ * @returns The newly created {@link Amity.Poll}
28421
+ *
28422
+ * @category Poll API
28423
+ * @async
28424
+ */
28425
+ const createPoll = async (bundle) => {
28426
+ const client = getActiveClient();
28427
+ client.log('post/createPoll', bundle);
28428
+ const { data } = await client.http.post('/api/v3/polls', bundle);
28429
+ const cachedAt = client.cache && Date.now();
28430
+ if (client.cache)
28431
+ ingestInCache(data, { cachedAt });
28432
+ const { polls } = data;
28433
+ return {
28434
+ data: polls[0],
28435
+ cachedAt,
28436
+ };
28437
+ };
28438
+ /* end_public_function */
28439
+
28440
+ /* begin_public_function
28441
+ id: poll.close
28442
+ */
28443
+ /**
28444
+ * ```js
28445
+ * import { closePoll } from '@amityco/ts-sdk'
28446
+ * const updated = await closePoll(pollId)
28447
+ * ```
28448
+ *
28449
+ * Updates an {@link Amity.Poll}
28450
+ *
28451
+ * @param pollId The ID of the {@link Amity.Poll} to close
28452
+ * @returns the updated {@link Amity.Poll} object
28453
+ *
28454
+ * @category Poll API
28455
+ * @async
28456
+ */
28457
+ const closePoll = async (pollId) => {
28458
+ const client = getActiveClient();
28459
+ client.log('user/closePoll', pollId);
28460
+ const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}`, { status: 'closed' });
28461
+ const cachedAt = client.cache && Date.now();
28462
+ if (client.cache)
28463
+ ingestInCache(data, { cachedAt });
28464
+ fireEvent('poll.updated', data);
28465
+ const { polls } = data;
28466
+ return {
28467
+ data: polls.find(poll => poll.pollId === pollId),
28468
+ cachedAt,
28469
+ };
28470
+ };
28471
+ /* end_public_function */
28472
+
28473
+ /* begin_public_function
28474
+ id: poll.get
28475
+ */
28476
+ /**
28477
+ * ```js
28478
+ * import { getPoll } from '@amityco/ts-sdk'
28479
+ * const poll = await getPoll('foobar')
28480
+ * ```
28481
+ *
28482
+ * Fetches a {@link Amity.Poll} object
28483
+ *
28484
+ * @param pollId the ID of the {@link Amity.Poll} to fetch
28485
+ * @returns the associated {@link Amity.Poll} object
28486
+ *
28487
+ * @category Poll API
28488
+ * @async
28489
+ */
28490
+ const getPoll$1 = async (pollId) => {
28491
+ const client = getActiveClient();
28492
+ client.log('poll/getPoll', pollId);
28493
+ const { data } = await client.http.get(`/api/v3/polls/${pollId}`);
28494
+ const cachedAt = client.cache && Date.now();
28495
+ if (client.cache)
28496
+ ingestInCache(data, { cachedAt });
28497
+ const { polls } = data;
28498
+ return {
28499
+ data: polls.find(poll => poll.pollId === pollId),
28500
+ cachedAt,
28501
+ };
28502
+ };
28503
+ /* end_public_function */
28504
+ /**
28505
+ * ```js
28506
+ * import { getPoll } from '@amityco/ts-sdk'
28507
+ * const poll = getPoll.locally('foobar')
28508
+ * ```
28509
+ *
28510
+ * Fetches a {@link Amity.Poll} object
28511
+ *
28512
+ * @param pollId the ID of the {@link Amity.Poll} to fetch
28513
+ * @returns the associated {@link Amity.Poll} object
28514
+ *
28515
+ * @category Poll API
28516
+ */
28517
+ getPoll$1.locally = (pollId) => {
28518
+ const client = getActiveClient();
28519
+ client.log('poll/getPoll', pollId);
28520
+ if (!client.cache)
28521
+ return;
28522
+ const cached = pullFromCache(['poll', 'get', pollId]);
28523
+ if (!cached)
28524
+ return;
28525
+ return {
28526
+ data: cached.data,
28527
+ cachedAt: cached.cachedAt,
28528
+ };
28529
+ };
28530
+
28531
+ /* begin_public_function
28532
+ id: poll.delete
28533
+ */
28534
+ /**
28535
+ * ```js
28536
+ * import { deletePoll } from '@amityco/ts-sdk'
28537
+ * const success = await deletePoll(pollId)
28538
+ * ```
28539
+ *
28540
+ * Deletes a {@link Amity.Poll}
28541
+ *
28542
+ * @param pollId The {@link Amity.Poll} ID to delete
28543
+ * @return A success boolean if the {@link Amity.Poll} was deleted
28544
+ *
28545
+ * @category Poll API
28546
+ * @async
28547
+ */
28548
+ const deletePoll = async (pollId) => {
28549
+ const client = getActiveClient();
28550
+ client.log('poll/deletePoll', pollId);
28551
+ const poll = await getPoll$1(pollId);
28552
+ // API-FIX: it returns { success: boolean } but seems it should be Amity.Response<{ success: boolean }
28553
+ const { data } = await client.http.delete(`/api/v3/polls/${pollId}`);
28554
+ const { success } = data; // unwrapPayload(data)
28555
+ const deleted = Object.assign(Object.assign({}, poll.data), { isDeleted: true });
28556
+ upsertInCache(['poll', 'get', pollId], deleted);
28557
+ fireEvent('poll.deleted', { polls: [deleted], users: [] });
28558
+ return success;
28559
+ };
28560
+ /* end_public_function */
28561
+
28562
+ /* begin_public_function
28563
+ id: poll.vote
28564
+ */
28565
+ /**
28566
+ * ```js
28567
+ * import { votePoll } from '@amityco/ts-sdk'
28568
+ * const voted = await votePoll(pollId)
28569
+ * ```
28570
+ *
28571
+ * Votes for an {@link Amity.Poll}
28572
+ *
28573
+ * @param pollId The ID of the {@link Amity.Poll} to vote
28574
+ * @param answerIds The IDs of the {@link Amity.Poll} answers to vote {@link Amity.Poll}
28575
+ * @returns the updated {@link Amity.Poll} object
28576
+ *
28577
+ * @category Poll API
28578
+ * @async
28579
+ */
28580
+ const votePoll = async (pollId, answerIds) => {
28581
+ const client = getActiveClient();
28582
+ client.log('user/votePoll', pollId);
28583
+ const { data } = await client.http.post(`/api/v3/polls/${encodeURIComponent(pollId)}/votes`, { pollId, answerIds });
28584
+ const cachedAt = client.cache && Date.now();
28585
+ if (client.cache)
28586
+ ingestInCache(data, { cachedAt });
28587
+ const { polls } = data;
28588
+ fireEvent('poll.updated', data);
28589
+ return {
28590
+ data: polls.find(poll => poll.pollId === pollId),
28591
+ cachedAt,
28592
+ };
28593
+ };
28594
+ /* end_public_function */
28595
+
28596
+ /* begin_public_function
28597
+ id: poll.unvote
28598
+ */
28599
+ /**
28600
+ * ```js
28601
+ * import { PollRepository } from '@amityco/ts-sdk'
28602
+ * await PollRepository.unvotePoll(pollId)
28603
+ * ```
28604
+ *
28605
+ * Votes for an {@link Amity.Poll}
28606
+ *
28607
+ * @param pollId The ID of the {@link Amity.Poll} to vote
28608
+ * @returns void
28609
+ *
28610
+ * @category Poll API
28611
+ * @async
28612
+ */
28613
+ const unvotePoll = async (pollId) => {
28614
+ const client = getActiveClient();
28615
+ client.log('user/unvotePoll', pollId);
28616
+ const { data } = await client.http.put(`/api/v3/polls/${encodeURIComponent(pollId)}/votes`, { pollId, answerIds: [] });
28617
+ const cachedAt = client.cache && Date.now();
28618
+ if (client.cache)
28619
+ ingestInCache(data, { cachedAt });
28620
+ fireEvent('poll.updated', data);
28621
+ };
28622
+ /* end_public_function */
28623
+
28624
+ /**
28625
+ * ```js
28626
+ * import { onPollUpdated } from '@amityco/ts-sdk'
28627
+ * const dispose = onPollUpdated(poll => {
28628
+ * // ...
28629
+ * })
28630
+ * ```
28631
+ *
28632
+ * Fired when an {@link Amity.Poll} has been updated
28633
+ *
28634
+ * @param callback The function to call when the event was fired
28635
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28636
+ *
28637
+ * @category Poll Events
28638
+ */
28639
+ const onPollUpdated = (callback) => {
28640
+ const client = getActiveClient();
28641
+ const filter = (payload) => {
28642
+ if (client.cache)
28643
+ ingestInCache(payload);
28644
+ callback(payload.polls[0]);
28645
+ };
28646
+ return createEventSubscriber(client, 'poll/onPollUpdated', 'poll.updated', filter);
28647
+ };
28648
+
28649
+ /**
28650
+ * ```js
28651
+ * import { onPollDeleted } from '@amityco/ts-sdk'
28652
+ * const dispose = onPollDeleted(poll => {
28653
+ * // ...
28654
+ * })
28655
+ * ```
28656
+ *
28657
+ * Fired when an {@link Amity.Poll} has been deleted
28658
+ *
28659
+ * @param callback The function to call when the event was fired
28660
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
28661
+ *
28662
+ * @category Poll Events
28663
+ */
28664
+ const onPollDeleted = (callback) => {
28665
+ const client = getActiveClient();
28666
+ const filter = (payload) => {
28667
+ if (client.cache)
28668
+ ingestInCache(payload);
28669
+ callback(payload.polls[0]);
28670
+ };
28671
+ return createEventSubscriber(client, 'poll/onPollDeleted', 'poll.deleted', filter);
28672
+ };
28673
+
28674
+ /* begin_public_function
28675
+ id: poll.get
28676
+ */
28677
+ /**
28678
+ * ```js
28679
+ * import { PollRepository } from '@amityco/ts-sdk';
28680
+ *
28681
+ * let poll;
28682
+ *
28683
+ * const unsub = PollRepository.getPoll(commentId, response => {
28684
+ * poll = response.data;
28685
+ * });
28686
+ * ```
28687
+ *
28688
+ * Observe all mutation on a given {@link Amity.Poll}
28689
+ *
28690
+ * @param pollId the ID of the poll to observe
28691
+ * @param callback the function to call when new data are available
28692
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the poll
28693
+ *
28694
+ * @category Poll Live Object
28695
+ */
28696
+ const getPoll = (pollId, callback) => {
28697
+ return liveObject(pollId, callback, 'pollId', getPoll$1, [onPollUpdated, onPollDeleted]);
28698
+ };
28699
+ /* end_public_function */
28700
+
28701
+ var index$6 = /*#__PURE__*/Object.freeze({
28702
+ __proto__: null,
28703
+ createPoll: createPoll,
28704
+ closePoll: closePoll,
28705
+ deletePoll: deletePoll,
28706
+ votePoll: votePoll,
28707
+ unvotePoll: unvotePoll,
28708
+ onPollUpdated: onPollUpdated,
28709
+ onPollDeleted: onPollDeleted,
28710
+ getPoll: getPoll
28711
+ });
28712
+
28713
+ const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
28714
+ /*
28715
+ * The crypto algorithm used for importing key and signing string
28716
+ */
28717
+ const ALGORITHM = {
28718
+ name: 'RSASSA-PKCS1-v1_5',
28719
+ hash: { name: 'SHA-256' },
28720
+ };
28721
+ /*
28722
+ * IMPORTANT!
28723
+ * If you are recieving key from other platforms use an online tool to convert
28724
+ * the PKCS1 to PKCS8. For instance the key from Android SDK is of the format
28725
+ * PKCS1.
28726
+ *
28727
+ * If recieving from the platform, verify if it's already in the expected
28728
+ * format. Otherwise the crypto.subtle.importKey will throw a DOMException
28729
+ */
28730
+ const PRIVATE_KEY_SIGNATURE = 'pkcs8';
28731
+ /*
28038
28732
  * Ensure that the private key in the .env follows this format
28039
28733
  */
28040
28734
  const PEM_HEADER = '-----BEGIN PRIVATE KEY-----';
@@ -28387,7 +29081,7 @@ const getPlayer = async (parameters) => {
28387
29081
  return video;
28388
29082
  };
28389
29083
 
28390
- var index$6 = /*#__PURE__*/Object.freeze({
29084
+ var index$5 = /*#__PURE__*/Object.freeze({
28391
29085
  __proto__: null,
28392
29086
  getPlayer: getPlayer
28393
29087
  });
@@ -29560,7 +30254,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
29560
30254
  };
29561
30255
  };
29562
30256
 
29563
- var index$5 = /*#__PURE__*/Object.freeze({
30257
+ var index$4 = /*#__PURE__*/Object.freeze({
29564
30258
  __proto__: null,
29565
30259
  createImageStory: createImageStory,
29566
30260
  createVideoStory: createVideoStory,
@@ -29597,7 +30291,7 @@ const getNetworkAds = async () => {
29597
30291
  };
29598
30292
  };
29599
30293
 
29600
- var index$4 = /*#__PURE__*/Object.freeze({
30294
+ var index$3 = /*#__PURE__*/Object.freeze({
29601
30295
  __proto__: null,
29602
30296
  getNetworkAds: getNetworkAds
29603
30297
  });
@@ -29988,7 +30682,7 @@ const markTraySeen = async (lastSeenAt) => {
29988
30682
  };
29989
30683
  /* end_public_function */
29990
30684
 
29991
- var index$3 = /*#__PURE__*/Object.freeze({
30685
+ var index$2 = /*#__PURE__*/Object.freeze({
29992
30686
  __proto__: null,
29993
30687
  getNotificationTraySeen: getNotificationTraySeen,
29994
30688
  getNotificationTrayItems: getNotificationTrayItems,
@@ -30189,7 +30883,7 @@ const getMyCommunityInvitations = (params, callback, config) => {
30189
30883
  };
30190
30884
  };
30191
30885
 
30192
- var index$2 = /*#__PURE__*/Object.freeze({
30886
+ var index$1 = /*#__PURE__*/Object.freeze({
30193
30887
  __proto__: null,
30194
30888
  onLocalInvitationCreated: onLocalInvitationCreated,
30195
30889
  onLocalInvitationUpdated: onLocalInvitationUpdated,
@@ -30330,289 +31024,15 @@ const getReactions = (postId, callback) => {
30330
31024
  };
30331
31025
  };
30332
31026
 
30333
- var index$1 = /*#__PURE__*/Object.freeze({
31027
+ var index = /*#__PURE__*/Object.freeze({
30334
31028
  __proto__: null,
30335
31029
  createReaction: createReaction,
30336
31030
  onLiveReactionCreated: onLiveReactionCreated,
30337
31031
  getReactions: getReactions
30338
31032
  });
30339
31033
 
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
- *
30502
- * @category Event API
30503
- * @async
30504
- */
30505
- const deleteEvent = async (eventId) => {
30506
- const client = getActiveClient();
30507
- client.log('event/deleteEvent', eventId);
30508
- const event = await getEvent$1(eventId);
30509
- await client.http.delete(`/api/v3/events/${eventId}`);
30510
- const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
30511
- upsertInCache(['event', 'get', eventId], deletedEvent);
30512
- fireEvent('event.deleted', {
30513
- users: [],
30514
- files: [],
30515
- communities: [],
30516
- videoStreamings: [],
30517
- events: [deletedEvent],
30518
- discussionCommunities: [],
30519
- });
30520
- };
30521
- /* end_public_function */
30522
-
30523
- /**
30524
- * ```js
30525
- * import { EventRepository } from '@amityco/ts-sdk'
30526
- * const dispose = EventRepository.onEventCreated(event => {
30527
- * // ...
30528
- * })
30529
- * ```
30530
- *
30531
- * Fired when a {@link Amity.Event} has been created
30532
- *
30533
- * @param callback The function to call when the event was fired
30534
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30535
- *
30536
- * @category Event Events
30537
- */
30538
- const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
30539
-
30540
- /**
30541
- * ```js
30542
- * import { EventRepository } from '@amityco/ts-sdk'
30543
- * const dispose = EventRepository.onEventUpdated(event => {
30544
- * // ...
30545
- * })
30546
- * ```
30547
- *
30548
- * Fired when a {@link Amity.Event} has been updated
30549
- *
30550
- * @param callback The function to call when the event was fired
30551
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30552
- *
30553
- * @category Event Events
30554
- */
30555
- const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
30556
-
30557
- /**
30558
- * ```js
30559
- * import { EventRepository } from '@amityco/ts-sdk'
30560
- * const dispose = EventRepository.onEventDeleted(event => {
30561
- * // ...
30562
- * })
30563
- * ```
30564
- *
30565
- * Fired when a {@link Amity.Event} has been deleted
30566
- *
30567
- * @param callback The function to call when the event was fired
30568
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30569
- *
30570
- * @category Event Events
30571
- */
30572
- const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
30573
-
30574
- /* begin_public_function
30575
- id: event.get
30576
- */
30577
- /**
30578
- * ```js
30579
- * import { EventRepository } from '@amityco/ts-sdk';
30580
- *
30581
- * let event;
30582
- *
30583
- * const unsubscribe = EventRepository.getEvent(eventId, response => {
30584
- * event = response.data;
30585
- * });
30586
- * ```
30587
- *
30588
- * Observe all mutation on a given {@link Amity.Event}
30589
- *
30590
- * @param eventId the ID of the event to observe
30591
- * @param callback the function to call when new snapshot of event are available
30592
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the event
30593
- *
30594
- * @category Event Live Object
30595
- */
30596
- const getEvent = (eventId, callback) => {
30597
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
30598
- callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
30599
- });
30600
- };
30601
- /* end_public_function */
30602
-
30603
- var index = /*#__PURE__*/Object.freeze({
30604
- __proto__: null,
30605
- createEvent: createEvent,
30606
- updateEvent: updateEvent,
30607
- deleteEvent: deleteEvent,
30608
- onEventCreated: onEventCreated,
30609
- onEventUpdated: onEventUpdated,
30610
- onEventDeleted: onEventDeleted,
30611
- getEvent: getEvent
30612
- });
30613
-
30614
31034
  exports.API_REGIONS = API_REGIONS;
30615
- exports.AdRepository = index$4;
31035
+ exports.AdRepository = index$3;
30616
31036
  exports.CategoryRepository = index$c;
30617
31037
  exports.ChannelRepository = index$g;
30618
31038
  exports.Client = index$p;
@@ -30622,22 +31042,22 @@ exports.CommunityPostSettings = CommunityPostSettings;
30622
31042
  exports.CommunityRepository = index$d;
30623
31043
  exports.ContentFeedType = ContentFeedType;
30624
31044
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
30625
- exports.EventRepository = index;
30626
31045
  exports.FeedRepository = index$a;
30627
31046
  exports.FileRepository = index$m;
30628
31047
  exports.FileType = FileType;
30629
31048
  exports.GET_WATCHER_URLS = GET_WATCHER_URLS;
30630
- exports.InvitationRepository = index$2;
30631
- exports.LiveReactionRepository = index$1;
30632
- exports.LiveStreamPlayer = index$6;
31049
+ exports.InvitationRepository = index$1;
31050
+ exports.LiveReactionRepository = index;
31051
+ exports.LiveStreamPlayer = index$5;
30633
31052
  exports.MessageContentType = MessageContentType;
30634
31053
  exports.MessageRepository = index$k;
30635
- exports.PollRepository = index$7;
31054
+ exports.PollRepository = index$6;
30636
31055
  exports.PostContentType = PostContentType;
30637
31056
  exports.PostRepository = index$9;
30638
31057
  exports.PostStructureType = PostStructureType;
30639
31058
  exports.ReactionRepository = index$l;
30640
- exports.StoryRepository = index$5;
31059
+ exports.RoomRepository = index$7;
31060
+ exports.StoryRepository = index$4;
30641
31061
  exports.StreamRepository = index$8;
30642
31062
  exports.SubChannelRepository = index$j;
30643
31063
  exports.UserRepository = index$n;
@@ -30694,7 +31114,7 @@ exports.isPaged = isPaged;
30694
31114
  exports.isReportedByMe = isReportedByMe;
30695
31115
  exports.isSkip = isSkip;
30696
31116
  exports.mergeInCache = mergeInCache;
30697
- exports.notificationTray = index$3;
31117
+ exports.notificationTray = index$2;
30698
31118
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
30699
31119
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
30700
31120
  exports.onFeedMarkerUpdated = onFeedMarkerUpdated;