@amityco/ts-sdk-react-native 6.23.1-d8b4c4c.0 → 6.24.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 (148) hide show
  1. package/.env +26 -26
  2. package/dist/@types/core/events.d.ts +0 -2
  3. package/dist/@types/core/events.d.ts.map +1 -1
  4. package/dist/@types/core/model.d.ts +2 -4
  5. package/dist/@types/core/model.d.ts.map +1 -1
  6. package/dist/@types/core/payload.d.ts +1 -2
  7. package/dist/@types/core/payload.d.ts.map +1 -1
  8. package/dist/@types/domains/community.d.ts +1 -15
  9. package/dist/@types/domains/community.d.ts.map +1 -1
  10. package/dist/@types/domains/stream.d.ts +3 -19
  11. package/dist/@types/domains/stream.d.ts.map +1 -1
  12. package/dist/client/api/secureLogout.d.ts +1 -1
  13. package/dist/communityRepository/api/createCommunity.d.ts.map +1 -1
  14. package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
  15. package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
  16. package/dist/communityRepository/api/queryCommunities.d.ts.map +1 -1
  17. package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
  18. package/dist/communityRepository/communityMembership/observers/getMembers.d.ts.map +1 -1
  19. package/dist/communityRepository/communityMembership/observers/index.d.ts +0 -1
  20. package/dist/communityRepository/communityMembership/observers/index.d.ts.map +1 -1
  21. package/dist/communityRepository/observers/getCommunities.d.ts.map +1 -1
  22. package/dist/communityRepository/observers/searchCommunities.d.ts +1 -1
  23. package/dist/communityRepository/utils/payload.d.ts.map +1 -1
  24. package/dist/core/events.d.ts +3 -3
  25. package/dist/core/events.d.ts.map +1 -1
  26. package/dist/core/model/idResolvers.d.ts.map +1 -1
  27. package/dist/core/model/index.d.ts.map +1 -1
  28. package/dist/index.cjs.js +463 -842
  29. package/dist/index.esm.js +438 -817
  30. package/dist/index.umd.js +4 -4
  31. package/dist/streamRepository/api/createStream.d.ts +4 -4
  32. package/dist/streamRepository/api/createStream.d.ts.map +1 -1
  33. package/dist/streamRepository/api/deleteStream.d.ts +4 -4
  34. package/dist/streamRepository/api/deleteStream.d.ts.map +1 -1
  35. package/dist/streamRepository/api/disposeStream.d.ts +4 -4
  36. package/dist/streamRepository/api/disposeStream.d.ts.map +1 -1
  37. package/dist/streamRepository/api/getStreams.d.ts +39 -0
  38. package/dist/streamRepository/api/getStreams.d.ts.map +1 -0
  39. package/dist/streamRepository/api/queryStreams.d.ts +4 -4
  40. package/dist/streamRepository/api/queryStreams.d.ts.map +1 -1
  41. package/dist/streamRepository/api/updateStream.d.ts.map +1 -1
  42. package/dist/streamRepository/events/index.d.ts +0 -2
  43. package/dist/streamRepository/events/index.d.ts.map +1 -1
  44. package/dist/streamRepository/events/onStreamRecorded.d.ts +2 -2
  45. package/dist/streamRepository/events/onStreamRecorded.d.ts.map +1 -1
  46. package/dist/streamRepository/events/onStreamStarted.d.ts +2 -2
  47. package/dist/streamRepository/events/onStreamStarted.d.ts.map +1 -1
  48. package/dist/streamRepository/events/onStreamStopped.d.ts +2 -2
  49. package/dist/streamRepository/events/onStreamStopped.d.ts.map +1 -1
  50. package/dist/streamRepository/internalApi/queryStreams.d.ts +3 -3
  51. package/dist/streamRepository/internalApi/queryStreams.d.ts.map +1 -1
  52. package/dist/streamRepository/observers/getStreamById.d.ts +0 -1
  53. package/dist/streamRepository/observers/getStreamById.d.ts.map +1 -1
  54. package/dist/streamRepository/observers/getStreams.d.ts +17 -0
  55. package/dist/streamRepository/observers/getStreams.d.ts.map +1 -0
  56. package/dist/utils/linkedObject/index.d.ts +0 -1
  57. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  58. package/dist/utils/liveObject.d.ts +0 -3
  59. package/dist/utils/liveObject.d.ts.map +1 -1
  60. package/package.json +1 -1
  61. package/src/@types/core/events.ts +1 -5
  62. package/src/@types/core/model.ts +2 -4
  63. package/src/@types/core/payload.ts +1 -2
  64. package/src/@types/domains/community.ts +1 -25
  65. package/src/@types/domains/stream.ts +3 -23
  66. package/src/client/api/secureLogout.ts +1 -1
  67. package/src/communityRepository/api/createCommunity.ts +2 -5
  68. package/src/communityRepository/api/getCommunities.ts +1 -5
  69. package/src/communityRepository/api/getCommunity.ts +1 -5
  70. package/src/communityRepository/api/queryCommunities.ts +2 -2
  71. package/src/communityRepository/api/updateCommunity.ts +1 -5
  72. package/src/communityRepository/communityMembership/observers/getMembers.ts +128 -15
  73. package/src/communityRepository/communityMembership/observers/index.ts +0 -1
  74. package/src/communityRepository/observers/getCommunities.ts +150 -7
  75. package/src/communityRepository/observers/searchCommunities.ts +1 -1
  76. package/src/communityRepository/utils/payload.ts +1 -35
  77. package/src/core/model/idResolvers.ts +0 -1
  78. package/src/core/model/index.ts +0 -1
  79. package/src/streamRepository/api/createStream.ts +5 -8
  80. package/src/streamRepository/api/deleteStream.ts +4 -6
  81. package/src/streamRepository/api/disposeStream.ts +5 -5
  82. package/src/streamRepository/api/getStreams.ts +81 -0
  83. package/src/streamRepository/api/queryStreams.ts +4 -4
  84. package/src/streamRepository/api/updateStream.ts +1 -2
  85. package/src/streamRepository/events/index.ts +0 -2
  86. package/src/streamRepository/events/onStreamRecorded.ts +2 -4
  87. package/src/streamRepository/events/onStreamStarted.ts +2 -4
  88. package/src/streamRepository/events/onStreamStopped.ts +2 -4
  89. package/src/streamRepository/internalApi/queryStreams.ts +3 -3
  90. package/src/streamRepository/observers/getStreamById.ts +5 -18
  91. package/src/streamRepository/observers/getStreams.ts +152 -0
  92. package/src/streamRepository/observers/tests/getStreamById.test.ts +1 -1
  93. package/src/utils/linkedObject/index.ts +0 -2
  94. package/src/utils/liveObject.ts +0 -3
  95. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts +0 -14
  96. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +0 -1
  97. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts +0 -9
  98. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts.map +0 -1
  99. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts +0 -15
  100. package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +0 -1
  101. package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts +0 -10
  102. package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts.map +0 -1
  103. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts +0 -14
  104. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts.map +0 -1
  105. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts +0 -9
  106. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts.map +0 -1
  107. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts +0 -15
  108. package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts.map +0 -1
  109. package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts +0 -10
  110. package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts.map +0 -1
  111. package/dist/communityRepository/communityMembership/observers/searchMembers.d.ts +0 -20
  112. package/dist/communityRepository/communityMembership/observers/searchMembers.d.ts.map +0 -1
  113. package/dist/communityRepository/utils/saveCommunityUsers.d.ts +0 -2
  114. package/dist/communityRepository/utils/saveCommunityUsers.d.ts.map +0 -1
  115. package/dist/streamRepository/events/onStreamFlagged.d.ts +0 -17
  116. package/dist/streamRepository/events/onStreamFlagged.d.ts.map +0 -1
  117. package/dist/streamRepository/events/onStreamTerminated.d.ts +0 -17
  118. package/dist/streamRepository/events/onStreamTerminated.d.ts.map +0 -1
  119. package/dist/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.d.ts +0 -14
  120. package/dist/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.d.ts.map +0 -1
  121. package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts +0 -14
  122. package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts.map +0 -1
  123. package/dist/streamRepository/observers/getStreams/GetStreamsQueryStreamController.d.ts +0 -15
  124. package/dist/streamRepository/observers/getStreams/GetStreamsQueryStreamController.d.ts.map +0 -1
  125. package/dist/streamRepository/observers/getStreams/getStreams.d.ts +0 -2
  126. package/dist/streamRepository/observers/getStreams/getStreams.d.ts.map +0 -1
  127. package/dist/streamRepository/observers/getStreams/index.d.ts +0 -2
  128. package/dist/streamRepository/observers/getStreams/index.d.ts.map +0 -1
  129. package/dist/utils/linkedObject/streamLinkedObject.d.ts +0 -2
  130. package/dist/utils/linkedObject/streamLinkedObject.d.ts.map +0 -1
  131. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +0 -152
  132. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.ts +0 -26
  133. package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +0 -114
  134. package/src/communityRepository/communityMembership/observers/getMembers/enums.ts +0 -9
  135. package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.ts +0 -130
  136. package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.ts +0 -29
  137. package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.ts +0 -105
  138. package/src/communityRepository/communityMembership/observers/searchMembers/enums.ts +0 -9
  139. package/src/communityRepository/communityMembership/observers/searchMembers.ts +0 -60
  140. package/src/communityRepository/utils/saveCommunityUsers.ts +0 -16
  141. package/src/streamRepository/events/onStreamFlagged.ts +0 -37
  142. package/src/streamRepository/events/onStreamTerminated.ts +0 -37
  143. package/src/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.ts +0 -114
  144. package/src/streamRepository/observers/getStreams/GetStreamsPageController.ts +0 -23
  145. package/src/streamRepository/observers/getStreams/GetStreamsQueryStreamController.ts +0 -83
  146. package/src/streamRepository/observers/getStreams/getStreams.ts +0 -32
  147. package/src/streamRepository/observers/getStreams/index.ts +0 -1
  148. package/src/utils/linkedObject/streamLinkedObject.ts +0 -11
package/dist/index.cjs.js CHANGED
@@ -117,8 +117,8 @@ const PostContentType = Object.freeze({
117
117
 
118
118
  function getVersion() {
119
119
  try {
120
- // the string ''v6.23.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
121
- return 'v6.23.0-cjs';
120
+ // the string ''v6.24.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
121
+ return 'v6.24.0-cjs';
122
122
  }
123
123
  catch (error) {
124
124
  return '__dev__';
@@ -546,7 +546,6 @@ const idResolvers = {
546
546
  reaction: ({ referenceType, referenceId }) => `${referenceType}#${referenceId}`,
547
547
  reactor: ({ reactionId }) => reactionId,
548
548
  stream: ({ streamId }) => streamId,
549
- streamModeration: ({ streamId }) => streamId,
550
549
  follow: ({ from, to }) => `${from}#${to}`,
551
550
  followInfo: ({ userId }) => userId,
552
551
  followCount: ({ userId }) => userId,
@@ -596,7 +595,6 @@ const PAYLOAD2MODEL = {
596
595
  reactors: 'reactor',
597
596
  reactions: 'reaction',
598
597
  videoStreamings: 'stream',
599
- videoStreamModerations: 'streamModeration',
600
598
  follows: 'follow',
601
599
  followCounts: 'followCount',
602
600
  feeds: 'feed',
@@ -5271,13 +5269,6 @@ const storyLinkedObject = (story) => {
5271
5269
  } });
5272
5270
  };
5273
5271
 
5274
- const streamLinkedObject = (stream) => {
5275
- return Object.assign(Object.assign({}, stream), { get moderation() {
5276
- var _a;
5277
- return (_a = pullFromCache(['streamModeration', 'get', stream.streamId])) === null || _a === void 0 ? void 0 : _a.data;
5278
- } });
5279
- };
5280
-
5281
5272
  const categoryLinkedObject = (category) => {
5282
5273
  return Object.assign(Object.assign({}, category), { get avatar() {
5283
5274
  var _a;
@@ -5746,7 +5737,6 @@ const LinkedObject = {
5746
5737
  post: postLinkedObject,
5747
5738
  user: userLinkedObject,
5748
5739
  category: categoryLinkedObject,
5749
- stream: streamLinkedObject,
5750
5740
  story: storyLinkedObject,
5751
5741
  storyTarget: storyTargetLinkedObject,
5752
5742
  message: messageLinkedObject,
@@ -9116,7 +9106,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
9116
9106
  */
9117
9107
  /**
9118
9108
  * ```js
9119
- * import { Client } from '@amityco/ts-sdk-react-native'
9109
+ * import { Client } from '@amityco/ts-sdk'
9120
9110
  * const success = await Client.secureLogout()
9121
9111
  * ```
9122
9112
  *
@@ -9472,9 +9462,6 @@ function isEqual(x, y) {
9472
9462
  }));
9473
9463
  }
9474
9464
 
9475
- /**
9476
- * @deprecated This function is deprecated
9477
- */
9478
9465
  const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
9479
9466
  const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
9480
9467
  const { cache } = getActiveClient();
@@ -17549,7 +17536,7 @@ const getMembers$1 = (params, callback, config) => {
17549
17536
  *
17550
17537
  * @category Channel Live Collection
17551
17538
  */
17552
- const searchMembers$1 = (params, callback, config) => {
17539
+ const searchMembers = (params, callback, config) => {
17553
17540
  return getMembers$1(params, callback);
17554
17541
  };
17555
17542
  /* end_public_function */
@@ -17560,7 +17547,7 @@ var index$d = /*#__PURE__*/Object.freeze({
17560
17547
  removeMembers: removeMembers$1,
17561
17548
  applyFilter: applyFilter$1,
17562
17549
  getMembers: getMembers$1,
17563
- searchMembers: searchMembers$1
17550
+ searchMembers: searchMembers
17564
17551
  });
17565
17552
 
17566
17553
  /* begin_public_function
@@ -17803,30 +17790,12 @@ var index$b = /*#__PURE__*/Object.freeze({
17803
17790
  prepareChannelPayload: prepareChannelPayload
17804
17791
  });
17805
17792
 
17806
- const saveCommunityUsers = (communities, communityUsers) => {
17807
- if (communities.length === 0 || communityUsers.length === 0)
17808
- return;
17809
- communities.forEach(({ communityId }) => {
17810
- const collection = communityUsers.filter(({ communityId: userCommunityId }) => communityId === userCommunityId);
17811
- pushToCache(['communityUsers', 'collection', communityId], collection);
17812
- });
17813
- };
17814
-
17815
17793
  const getMatchPostSetting = (value) => {
17816
17794
  var _a;
17817
17795
  return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
17818
17796
  CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
17819
17797
  value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
17820
17798
  };
17821
- const convertCommunityUsersToUniqueObject = (communityUsers) => {
17822
- if (!communityUsers)
17823
- return communityUsers;
17824
- const result = {};
17825
- communityUsers.forEach(user => {
17826
- result[user.userId] = user;
17827
- });
17828
- return result;
17829
- };
17830
17799
  const prepareCommunityPayload = (rawPayload) => {
17831
17800
  // Unpack community payload by mapping payload field to postSetting value.
17832
17801
  const communities = rawPayload.communities.map((_a) => {
@@ -17836,18 +17805,7 @@ const prepareCommunityPayload = (rawPayload) => {
17836
17805
  onlyAdminCanPost,
17837
17806
  }) }, restCommunityPayload));
17838
17807
  });
17839
- const mergeCommunityUsers = communities.reduce((acc, { communityId }) => {
17840
- var _a;
17841
- const users = (_a = pullFromCache([
17842
- 'communityUsers',
17843
- 'collection',
17844
- communityId,
17845
- ])) === null || _a === void 0 ? void 0 : _a.data;
17846
- if (!users)
17847
- return acc;
17848
- return Object.assign(Object.assign({}, convertCommunityUsersToUniqueObject(users)), acc);
17849
- }, convertCommunityUsersToUniqueObject(rawPayload.communityUsers));
17850
- const communityUsers = withUsers(Object.values(mergeCommunityUsers));
17808
+ const communityUsers = withUsers(rawPayload.communityUsers);
17851
17809
  const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
17852
17810
  return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers });
17853
17811
  };
@@ -17881,10 +17839,8 @@ const getCommunities$1 = async (communityIds) => {
17881
17839
  });
17882
17840
  const data = prepareCommunityPayload(payload);
17883
17841
  const cachedAt = client.cache && Date.now();
17884
- if (client.cache) {
17842
+ if (client.cache)
17885
17843
  ingestInCache(data, { cachedAt });
17886
- saveCommunityUsers(data.communities, data.communityUsers);
17887
- }
17888
17844
  return {
17889
17845
  data: data.communities,
17890
17846
  cachedAt,
@@ -17946,10 +17902,8 @@ const createCommunity = async (bundle) => {
17946
17902
  fireEvent('community.created', payload);
17947
17903
  const data = prepareCommunityPayload(payload);
17948
17904
  const cachedAt = client.cache && Date.now();
17949
- if (client.cache) {
17905
+ if (client.cache)
17950
17906
  ingestInCache(data, { cachedAt });
17951
- saveCommunityUsers(data.communities, data.communityUsers);
17952
- }
17953
17907
  const { communities } = data;
17954
17908
  return {
17955
17909
  data: communities[0],
@@ -17983,10 +17937,8 @@ const updateCommunity = async (communityId, patch) => {
17983
17937
  fireEvent('community.updated', payload);
17984
17938
  const data = prepareCommunityPayload(payload);
17985
17939
  const cachedAt = client.cache && Date.now();
17986
- if (client.cache) {
17940
+ if (client.cache)
17987
17941
  ingestInCache(data, { cachedAt });
17988
- saveCommunityUsers(data.communities, data.communityUsers);
17989
- }
17990
17942
  const { communities } = data;
17991
17943
  return {
17992
17944
  data: communities.find(community => community.communityId === communityId),
@@ -18016,10 +17968,8 @@ const getCommunity$1 = async (communityId) => {
18016
17968
  const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`);
18017
17969
  const data = prepareCommunityPayload(payload);
18018
17970
  const cachedAt = client.cache && Date.now();
18019
- if (client.cache) {
17971
+ if (client.cache)
18020
17972
  ingestInCache(data, { cachedAt });
18021
- saveCommunityUsers(data.communities, data.communityUsers);
18022
- }
18023
17973
  const { communities } = data;
18024
17974
  return {
18025
17975
  data: communities.find(community => community.communityId === communityId),
@@ -18562,7 +18512,7 @@ const observeCommunity = (communityId, callback) => {
18562
18512
  * TODO: handle cache receive cache option, and cache policy
18563
18513
  * TODO: check if querybyIds is supported
18564
18514
  */
18565
- class CommunitiesPaginationController$1 extends PaginationController {
18515
+ class CommunitiesPaginationController extends PaginationController {
18566
18516
  async getRequest(queryParams, token) {
18567
18517
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
18568
18518
  const options = token ? { token } : { limit };
@@ -18573,7 +18523,7 @@ class CommunitiesPaginationController$1 extends PaginationController {
18573
18523
  }
18574
18524
  }
18575
18525
 
18576
- class CommunitiesQueryStreamController$1 extends QueryStreamController {
18526
+ class CommunitiesQueryStreamController extends QueryStreamController {
18577
18527
  constructor(query, cacheKey, notifyChange, preparePayload) {
18578
18528
  super(query, cacheKey);
18579
18529
  this.notifyChange = notifyChange;
@@ -18615,22 +18565,22 @@ class CommunitiesQueryStreamController$1 extends QueryStreamController {
18615
18565
  }
18616
18566
  }
18617
18567
 
18618
- var EnumCommunityActions$1;
18568
+ var EnumCommunityActions;
18619
18569
  (function (EnumCommunityActions) {
18620
18570
  EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
18621
18571
  EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
18622
18572
  EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
18623
- })(EnumCommunityActions$1 || (EnumCommunityActions$1 = {}));
18573
+ })(EnumCommunityActions || (EnumCommunityActions = {}));
18624
18574
 
18625
18575
  /* eslint-disable no-use-before-define */
18626
18576
  class SearchCommunityLiveCollectionController extends LiveCollectionController {
18627
18577
  constructor(query, callback) {
18628
18578
  const queryStreamId = hash__default["default"](query);
18629
18579
  const cacheKey = ['community', 'collection', queryStreamId];
18630
- const paginationController = new CommunitiesPaginationController$1(query);
18580
+ const paginationController = new CommunitiesPaginationController(query);
18631
18581
  super(paginationController, queryStreamId, cacheKey, callback);
18632
18582
  this.query = query;
18633
- this.queryStreamController = new CommunitiesQueryStreamController$1(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
18583
+ this.queryStreamController = new CommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
18634
18584
  this.callback = callback.bind(this);
18635
18585
  this.loadPage({ initial: true });
18636
18586
  }
@@ -18652,8 +18602,8 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
18652
18602
  }
18653
18603
  startSubscription() {
18654
18604
  return this.queryStreamController.subscribeRTE([
18655
- { fn: onCommunityDeleted, action: EnumCommunityActions$1.OnCommunityDeleted },
18656
- { fn: onCommunityUpdated, action: EnumCommunityActions$1.OnCommunityUpdated },
18605
+ { fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
18606
+ { fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
18657
18607
  ]);
18658
18608
  }
18659
18609
  notifyChange({ origin, loading, error }) {
@@ -18699,7 +18649,7 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
18699
18649
  */
18700
18650
  /**
18701
18651
  * ```js
18702
- * import { CommunityRepository } from '@amityco/ts-sdk-react-native'
18652
+ * import { CommunityRepository } from '@amityco/ts-sdk'
18703
18653
  *
18704
18654
  * let communities = []
18705
18655
  * const unsub = CommunityRepository.searchCommunities({
@@ -18734,163 +18684,50 @@ const searchCommunities = (params, callback, config) => {
18734
18684
  /* end_public_function */
18735
18685
 
18736
18686
  /**
18737
- * TODO: handle cache receive cache option, and cache policy
18738
- * TODO: check if querybyIds is supported
18687
+ * ```js
18688
+ * import { queryCommunities } from '@amityco/ts-sdk-react-native'
18689
+ * const communities = await queryCommunities()
18690
+ * ```
18691
+ *
18692
+ * Queries a paginable list of {@link Amity.Community} objects
18693
+ * Search is performed by displayName such as `.startsWith(search)`
18694
+ *
18695
+ * @param query The query parameters
18696
+ * @returns A page of {@link Amity.Community} objects
18697
+ *
18698
+ * @category Community API
18699
+ * @async
18739
18700
  */
18740
- class CommunitiesPaginationController extends PaginationController {
18741
- async getRequest(queryParams, token) {
18742
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
18743
- const options = token ? { token } : { limit };
18744
- const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
18745
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
18746
- });
18747
- return queryResponse;
18748
- }
18749
- }
18750
-
18751
- var EnumCommunityActions;
18752
- (function (EnumCommunityActions) {
18753
- EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
18754
- EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
18755
- EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
18756
- })(EnumCommunityActions || (EnumCommunityActions = {}));
18757
-
18758
- class CommunitiesQueryStreamController extends QueryStreamController {
18759
- constructor(query, cacheKey, notifyChange, preparePayload) {
18760
- super(query, cacheKey);
18761
- this.notifyChange = notifyChange;
18762
- this.preparePayload = preparePayload;
18763
- }
18764
- async saveToMainDB(response) {
18765
- const processedPayload = await this.preparePayload(response);
18766
- const client = getActiveClient();
18767
- const cachedAt = client.cache && Date.now();
18768
- if (client.cache) {
18769
- ingestInCache(processedPayload, { cachedAt });
18770
- }
18771
- }
18772
- appendToQueryStream(response, direction, refresh = false) {
18773
- var _a, _b;
18774
- if (refresh) {
18775
- pushToCache(this.cacheKey, {
18776
- data: response.communities.map(getResolver('community')),
18777
- });
18778
- }
18779
- else {
18780
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
18781
- const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
18782
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
18783
- }
18784
- }
18785
- reactor(action) {
18786
- return (community) => {
18787
- var _a;
18788
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
18789
- if (!collection)
18790
- return;
18791
- if (this.query.displayName && action === EnumCommunityActions.OnCommunityCreated) {
18792
- return;
18793
- }
18794
- /*
18795
- * Simply update collection and let responder decide what to do with data
18796
- */
18797
- collection.data = [...new Set([community.communityId, ...collection.data])];
18798
- pushToCache(this.cacheKey, collection);
18799
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
18800
- };
18801
- }
18802
- subscribeRTE(createSubscriber) {
18803
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
18804
- }
18805
- }
18806
-
18807
- /* eslint-disable no-use-before-define */
18808
- class CommunityLiveCollectionController extends LiveCollectionController {
18809
- constructor(query, callback) {
18810
- const queryStreamId = hash__default["default"](query);
18811
- const cacheKey = ['community', 'collection', queryStreamId];
18812
- const paginationController = new CommunitiesPaginationController(query);
18813
- super(paginationController, queryStreamId, cacheKey, callback);
18814
- this.query = query;
18815
- this.queryStreamController = new CommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
18816
- this.callback = callback.bind(this);
18817
- this.loadPage({ initial: true });
18818
- }
18819
- setup() {
18820
- var _a;
18821
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
18822
- if (!collection) {
18823
- pushToCache(this.cacheKey, {
18824
- data: [],
18825
- params: {},
18826
- });
18827
- }
18828
- }
18829
- async persistModel(queryPayload) {
18830
- await this.queryStreamController.saveToMainDB(queryPayload);
18831
- }
18832
- persistQueryStream({ response, direction, refresh, }) {
18833
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
18834
- }
18835
- startSubscription() {
18836
- return this.queryStreamController.subscribeRTE([
18837
- { fn: onCommunityCreated, action: EnumCommunityActions.OnCommunityCreated },
18838
- { fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
18839
- { fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
18840
- ]);
18841
- }
18842
- notifyChange({ origin, loading, error }) {
18843
- var _a, _b;
18844
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
18845
- if (!collection)
18846
- return;
18847
- const data = this.applyFilter((_b = collection.data
18848
- .map(id => pullFromCache(['community', 'get', id]))
18849
- .filter(Boolean)
18850
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
18851
- if (!this.shouldNotify(data) && origin === 'event')
18852
- return;
18853
- this.callback({
18854
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
18855
- data,
18856
- hasNextPage: !!this.paginationController.getNextToken(),
18857
- loading,
18858
- error,
18859
- });
18860
- }
18861
- applyFilter(data) {
18862
- const { userId } = getActiveClient();
18863
- let communities = data;
18864
- if (this.query.includeDeleted) {
18865
- communities = filterByPropEquality(communities, 'isDeleted', false);
18866
- }
18867
- if (this.query.categoryId) {
18868
- communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(this.query.categoryId); });
18869
- }
18870
- if (this.query.tags) {
18871
- communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
18872
- }
18873
- if (this.query.membership && userId) {
18874
- communities = filterByCommunityMembership(communities, this.query.membership, userId);
18875
- }
18876
- if (!this.query.displayName) {
18877
- const sortFn = (() => {
18878
- switch (this.query.sortBy) {
18879
- case 'firstCreated':
18880
- return sortByFirstCreated;
18881
- case 'lastCreated':
18882
- return sortByLastCreated;
18883
- case 'displayName':
18884
- return sortByDisplayName;
18885
- default:
18886
- return sortByLastCreated;
18887
- }
18888
- })();
18889
- communities = communities.sort(sortFn);
18890
- }
18891
- return communities;
18701
+ const queryCommunities = async (query) => {
18702
+ const client = getActiveClient();
18703
+ client.log('channel/queryCommunities', query);
18704
+ // safe decapsulation
18705
+ const _a = query !== null && query !== void 0 ? query : {}, { page, limit = 10 } = _a, params = __rest(_a, ["page", "limit"]);
18706
+ const _b = params !== null && params !== void 0 ? params : {}, { displayName, membership, includeDeleted } = _b, restParams = __rest(_b, ["displayName", "membership", "includeDeleted"]);
18707
+ const options = (() => {
18708
+ if (page)
18709
+ return { token: page };
18710
+ if (limit)
18711
+ return { limit };
18712
+ return undefined;
18713
+ })();
18714
+ // API-FIX: parameters should be querystring.
18715
+ // API-FIX: backend doesn't answer Amity.Response
18716
+ // const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<CommunityPayload>>>(
18717
+ const { data } = await client.http.get(`/api/v3/communities`, {
18718
+ params: Object.assign(Object.assign({}, restParams), { isDeleted: inferIsDeleted(includeDeleted), keyword: displayName, filter: membership, options }),
18719
+ });
18720
+ const { paging } = data, payload = __rest(data, ["paging"]);
18721
+ const unpackedPayload = prepareCommunityPayload(payload);
18722
+ const { communities } = unpackedPayload;
18723
+ const cachedAt = client.cache && Date.now();
18724
+ if (client.cache) {
18725
+ ingestInCache(unpackedPayload, { cachedAt });
18726
+ const cacheKey = ['community', 'query', Object.assign(Object.assign({}, params), { options })];
18727
+ pushToCache(cacheKey, { communities: communities.map(getResolver('community')), paging });
18892
18728
  }
18893
- }
18729
+ return { data: communities, cachedAt, paging };
18730
+ };
18894
18731
 
18895
18732
  /* begin_public_function
18896
18733
  id: community.query
@@ -18914,41 +18751,124 @@ class CommunityLiveCollectionController extends LiveCollectionController {
18914
18751
  * @category Community Live Collection
18915
18752
  */
18916
18753
  const getCommunities = (params, callback, config) => {
18917
- const { log, cache } = getActiveClient();
18754
+ const { log, cache, userId } = getActiveClient();
18918
18755
  if (!cache) {
18919
18756
  console.log(ENABLE_CACHE_MESSAGE);
18920
18757
  }
18921
18758
  const timestamp = Date.now();
18922
18759
  log(`getCommunities(tmpid: ${timestamp}) > listen`);
18923
- const communitiesLiveCollection = new CommunityLiveCollectionController(params, callback);
18924
- const disposers = communitiesLiveCollection.startSubscription();
18925
- const cacheKey = communitiesLiveCollection.getCacheKey();
18926
- disposers.push(() => dropFromCache(cacheKey));
18927
- return () => {
18928
- log(`getCommunities(tmpid: ${timestamp}) > dispose`);
18929
- disposers.forEach(fn => fn());
18760
+ const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
18761
+ const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
18762
+ const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
18763
+ const disposers = [];
18764
+ const cacheKey = ['community', 'collection', queryParams];
18765
+ const responder = (data) => {
18766
+ var _a, _b;
18767
+ let communities = (_a = data.data
18768
+ .map(communityId => pullFromCache(['community', 'get', communityId]))
18769
+ .filter(Boolean)
18770
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
18771
+ communities = filterByStringComparePartially(communities, 'displayName', params.displayName);
18772
+ if (!params.includeDeleted) {
18773
+ communities = filterByPropEquality(communities, 'isDeleted', false);
18774
+ }
18775
+ if (params.categoryId) {
18776
+ communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(params.categoryId); });
18777
+ }
18778
+ if (params.tags) {
18779
+ communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = params.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
18780
+ }
18781
+ if (params.membership && userId) {
18782
+ communities = filterByCommunityMembership(communities, params.membership, userId);
18783
+ }
18784
+ const sortBy = params.sortBy || 'lastCreated';
18785
+ if (sortBy === 'lastCreated' || sortBy === 'firstCreated') {
18786
+ communities = communities.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
18787
+ }
18788
+ /*
18789
+ * The server returns communities with empty | null displayName's first before
18790
+ * returning sorted list of communities with displayNames
18791
+ *
18792
+ * This section needs to be updated as displayNames can be null as well
18793
+ */
18794
+ if (sortBy === 'displayName') {
18795
+ communities = communities
18796
+ // this needs to be aligned with the backend data type
18797
+ .map(c => (c.displayName ? c : Object.assign(Object.assign({}, c), { displayName: '' })))
18798
+ // @ts-ignore
18799
+ .sort(sortByDisplayName);
18800
+ }
18801
+ callback({
18802
+ onNextPage: onFetch,
18803
+ data: communities,
18804
+ hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
18805
+ loading: data.loading,
18806
+ error: data.error,
18807
+ });
18930
18808
  };
18931
- };
18932
- /* end_public_function */
18933
-
18934
- /* begin_public_function
18935
- id: community.get
18936
- */
18937
- /**
18938
- * ```js
18939
- * import { CommunityRepository } from '@amityco/ts-sdk-react-native';
18940
- *
18941
- * let community;
18942
- *
18943
- * const unsub = CommunityRepository.getCommunity(communityId, response => {
18944
- * community = response.data;
18945
- * });
18946
- * ```
18947
- *
18948
- * Observe all mutation on a given {@link Amity.Community}
18949
- *
18950
- * @param communityId the ID of the message to observe
18951
- * @param callback the function to call when new data are available
18809
+ const realtimeRouter = (_) => (community) => {
18810
+ var _a;
18811
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
18812
+ if (!collection)
18813
+ return;
18814
+ /*
18815
+ * Simply update collection and let responder decide what to do with data
18816
+ */
18817
+ collection.data = [...new Set([community.communityId, ...collection.data])];
18818
+ pushToCache(cacheKey, collection);
18819
+ responder(collection);
18820
+ };
18821
+ const onFetch = (initial = false) => {
18822
+ var _a, _b;
18823
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
18824
+ const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
18825
+ if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
18826
+ return;
18827
+ const query = createQuery(queryCommunities, Object.assign(Object.assign({}, queryParams), { limit: initial ? limit : undefined, page: !initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined }));
18828
+ runQuery(query, ({ data: result, error, loading, paging }) => {
18829
+ const data = {
18830
+ loading,
18831
+ error,
18832
+ params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
18833
+ data: communities,
18834
+ };
18835
+ if (result) {
18836
+ data.data = initial
18837
+ ? result.map(getResolver('community'))
18838
+ : [...new Set([...communities, ...result.map(getResolver('community'))])];
18839
+ }
18840
+ pushToCache(cacheKey, data);
18841
+ responder(data);
18842
+ }, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
18843
+ };
18844
+ disposers.push(onCommunityCreated(realtimeRouter()), onCommunityDeleted(realtimeRouter()), onCommunityUpdated(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityLeft(realtimeRouter()), onCommunityUserChanged(realtimeRouter()));
18845
+ onFetch(true);
18846
+ disposers.push(() => dropFromCache(cacheKey));
18847
+ return () => {
18848
+ log(`getCommunities(tmpid: ${timestamp}) > dispose`);
18849
+ disposers.forEach(fn => fn());
18850
+ };
18851
+ };
18852
+ /* end_public_function */
18853
+
18854
+ /* begin_public_function
18855
+ id: community.get
18856
+ */
18857
+ /**
18858
+ * ```js
18859
+ * import { CommunityRepository } from '@amityco/ts-sdk-react-native';
18860
+ *
18861
+ * let community;
18862
+ *
18863
+ * const unsub = CommunityRepository.getCommunity(communityId, response => {
18864
+ * community = response.data;
18865
+ * });
18866
+ * ```
18867
+ *
18868
+ * Observe all mutation on a given {@link Amity.Community}
18869
+ *
18870
+ * @param communityId the ID of the message to observe
18871
+ * @param callback the function to call when new data are available
18952
18872
  * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community
18953
18873
  *
18954
18874
  * @category Community Live Object
@@ -19451,187 +19371,87 @@ const removeMembers = async (communityId, userIds) => {
19451
19371
  /* end_public_function */
19452
19372
 
19453
19373
  /**
19454
- * TODO: handle cache receive cache option, and cache policy
19455
- * TODO: check if querybyIds is supported
19456
- */
19457
- class CommunityMembersPaginationController extends PaginationController {
19458
- async getRequest(queryParams, token) {
19459
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
19460
- const options = token ? { token } : { limit };
19461
- const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
19462
- params: Object.assign(Object.assign({}, params), { options }),
19463
- });
19464
- return queryResponse;
19465
- }
19466
- }
19467
-
19468
- var EnumCommunityMemberActions$1;
19469
- (function (EnumCommunityMemberActions) {
19470
- EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
19471
- EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
19472
- EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
19473
- EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
19474
- EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
19475
- EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
19476
- EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
19477
- })(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
19478
-
19479
- class CommunityMembersQueryStreamController extends QueryStreamController {
19480
- constructor(query, cacheKey, notifyChange, preparePayload) {
19481
- super(query, cacheKey);
19482
- this.notifyChange = notifyChange;
19483
- this.preparePayload = preparePayload;
19484
- }
19485
- async saveToMainDB(response) {
19486
- const processedPayload = await this.preparePayload(response);
19487
- const client = getActiveClient();
19488
- const cachedAt = client.cache && Date.now();
19489
- if (client.cache) {
19490
- ingestInCache(processedPayload, { cachedAt });
19491
- }
19492
- }
19493
- appendToQueryStream(response, direction, refresh = false) {
19494
- var _a, _b;
19495
- if (refresh) {
19496
- pushToCache(this.cacheKey, {
19497
- data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
19498
- });
19499
- }
19500
- else {
19501
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
19502
- const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
19503
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
19504
- ...new Set([
19505
- ...communityUsers,
19506
- ...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
19507
- ]),
19508
- ] }));
19509
- }
19510
- }
19511
- reactor(action) {
19512
- return (community, communityMembers) => {
19513
- var _a;
19514
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
19515
- if (!collection)
19516
- return;
19517
- if (action === EnumCommunityMemberActions$1.OnCommunityUserRoleAdded &&
19518
- this.query.sortBy === 'displayName') {
19519
- return;
19520
- }
19521
- communityMembers.forEach(communityMember => {
19522
- const communityMemberCacheId = getResolver('communityUsers')({
19523
- communityId: this.query.communityId,
19524
- userId: communityMember.userId,
19525
- });
19526
- if (communityMember.communityMembership === 'none') {
19527
- collection.data = collection.data.filter(m => m !== communityMemberCacheId);
19528
- }
19529
- else if (!collection.data.includes(communityMemberCacheId)) {
19530
- collection.data = [communityMemberCacheId, ...collection.data];
19531
- }
19532
- });
19533
- pushToCache(this.cacheKey, collection);
19534
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
19535
- };
19536
- }
19537
- subscribeRTE(createSubscriber) {
19538
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
19539
- }
19540
- }
19541
-
19542
- /* eslint-disable no-use-before-define */
19543
- class CommunityMembersLiveCollectionController extends LiveCollectionController {
19544
- constructor(query, callback) {
19545
- const queryStreamId = hash__default["default"](query);
19546
- const cacheKey = ['communityUsers', 'collection', queryStreamId];
19547
- const paginationController = new CommunityMembersPaginationController(query);
19548
- super(paginationController, queryStreamId, cacheKey, callback);
19549
- this.query = query;
19550
- this.queryStreamController = new CommunityMembersQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
19551
- this.callback = callback.bind(this);
19552
- this.loadPage({ initial: true });
19553
- }
19554
- setup() {
19555
- var _a;
19556
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
19557
- if (!collection) {
19558
- pushToCache(this.cacheKey, {
19559
- data: [],
19560
- params: {},
19561
- });
19562
- }
19563
- }
19564
- async persistModel(queryPayload) {
19565
- await this.queryStreamController.saveToMainDB(queryPayload);
19566
- }
19567
- persistQueryStream({ response, direction, refresh, }) {
19568
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
19569
- }
19570
- startSubscription() {
19571
- return this.queryStreamController.subscribeRTE([
19572
- { fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
19573
- { fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
19574
- { fn: onCommunityUserBanned, action: EnumCommunityMemberActions$1.OnCommunityUserBanned },
19575
- { fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnCommunityUserChanged },
19576
- { fn: onCommunityUserRoleAdded, action: EnumCommunityMemberActions$1.OnCommunityUserRoleAdded },
19577
- {
19578
- fn: onCommunityUserRoleRemoved,
19579
- action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
19580
- },
19581
- { fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions$1.OnCommunityUserUnbanned },
19582
- ]);
19583
- }
19584
- notifyChange({ origin, loading, error }) {
19585
- var _a, _b;
19586
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
19587
- if (!collection)
19588
- return;
19589
- const data = this.applyFilter((_b = collection.data
19590
- .map(id => pullFromCache(['communityUsers', 'get', id]))
19591
- .filter(isNonNullable)
19592
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
19593
- if (!this.shouldNotify(data) && origin === 'event')
19594
- return;
19595
- this.callback({
19596
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
19597
- data,
19598
- hasNextPage: !!this.paginationController.getNextToken(),
19599
- loading,
19600
- error,
19374
+ * ```js
19375
+ * import { queryCommunityMembers } from '@amityco/ts-sdk-react-native'
19376
+ * const communityMembers = await queryCommunityMembers({ communityId: 'foo' })
19377
+ * ```
19378
+ *
19379
+ * Queries a paginable list of {@link Amity.CommunityUser} objects
19380
+ *
19381
+ * @param query The query parameters
19382
+ * @returns A page of {@link Amity.CommunityUser} objects
19383
+ *
19384
+ * @category Community API
19385
+ * @async
19386
+ * */
19387
+ const queryCommunityMembers = async (query) => {
19388
+ const client = getActiveClient();
19389
+ client.log('community/queryCommunityMembers', query);
19390
+ const _a = query !== null && query !== void 0 ? query : {}, { page, limit } = _a, params = __rest(_a, ["page", "limit"]);
19391
+ const options = (() => {
19392
+ if (page)
19393
+ return { token: page };
19394
+ if (limit)
19395
+ return { limit };
19396
+ return undefined;
19397
+ })();
19398
+ const { data: queryPayload } = await client.http.get(`/api/v3/communities/${params.communityId}/users`, {
19399
+ params: Object.assign(Object.assign({}, params), { options }),
19400
+ });
19401
+ const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
19402
+ const preparedPayload = prepareMembershipPayload(payload, 'communityUsers');
19403
+ const { communityUsers } = preparedPayload;
19404
+ const cachedAt = client.cache && Date.now();
19405
+ if (client.cache) {
19406
+ ingestInCache(preparedPayload, { cachedAt });
19407
+ const cacheKey = ['communityUsers', 'query', Object.assign(Object.assign({}, params), { options })];
19408
+ pushToCache(cacheKey, {
19409
+ communityUsers: communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
19410
+ paging,
19601
19411
  });
19602
19412
  }
19603
- applyFilter(data) {
19604
- let communityMembers = filterByPropIntersection(data, 'roles', this.query.roles);
19605
- if (this.query.memberships) {
19606
- communityMembers = communityMembers.filter(({ communityMembership }) => {
19607
- const memberships = this.query.memberships || [];
19608
- return memberships.includes(communityMembership);
19609
- });
19610
- }
19611
- if (this.query.search) {
19612
- communityMembers = filterBySearchTerm(communityMembers, this.query.search);
19613
- }
19614
- switch (this.query.sortBy) {
19615
- case 'firstCreated':
19616
- communityMembers = communityMembers.sort(sortByFirstCreated);
19617
- break;
19618
- case 'displayName':
19619
- communityMembers = communityMembers.sort((a, b) => {
19620
- var _a, _b, _c, _d;
19621
- if (((_a = a === null || a === void 0 ? void 0 : a.user) === null || _a === void 0 ? void 0 : _a.displayName) && ((_b = b === null || b === void 0 ? void 0 : b.user) === null || _b === void 0 ? void 0 : _b.displayName)) {
19622
- return (_c = a === null || a === void 0 ? void 0 : a.user) === null || _c === void 0 ? void 0 : _c.displayName.localeCompare((_d = b === null || b === void 0 ? void 0 : b.user) === null || _d === void 0 ? void 0 : _d.displayName);
19623
- }
19624
- return 0;
19625
- });
19626
- break;
19627
- case 'lastCreated':
19628
- default:
19629
- communityMembers = communityMembers.sort(sortByLastCreated);
19630
- break;
19631
- }
19632
- return communityMembers;
19633
- }
19634
- }
19413
+ return { data: communityUsers, cachedAt, paging };
19414
+ };
19415
+ /**
19416
+ * ```js
19417
+ * import { queryCommunityMembers } from '@amityco/ts-sdk-react-native'
19418
+ * const communityMembers = await queryCommunityMembers(query)
19419
+ * ```
19420
+ *
19421
+ * Queries a paginable list of {@link Amity.InternalPost} objects from cache
19422
+ *
19423
+ * @param query The query parameters
19424
+ * @returns posts
19425
+ *
19426
+ * @category Post API
19427
+ */
19428
+ queryCommunityMembers.locally = (query) => {
19429
+ var _a, _b;
19430
+ const client = getActiveClient();
19431
+ client.log('community/queryCommunityMembers', query);
19432
+ if (!client.cache)
19433
+ return;
19434
+ const _c = query !== null && query !== void 0 ? query : {}, { page, limit } = _c, params = __rest(_c, ["page", "limit"]);
19435
+ const options = (() => {
19436
+ if (page)
19437
+ return { token: page };
19438
+ if (limit)
19439
+ return { limit };
19440
+ return undefined;
19441
+ })();
19442
+ const cacheKey = ['communityUsers', 'query', Object.assign(Object.assign({}, params), { options })];
19443
+ const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
19444
+ if (!(data === null || data === void 0 ? void 0 : data.communityUsers.length))
19445
+ return;
19446
+ const communityUsers = data.communityUsers
19447
+ .map(key => pullFromCache(['communityUsers', 'get', key]))
19448
+ .filter(Boolean)
19449
+ .map(({ data }) => data);
19450
+ const { paging } = data;
19451
+ return communityUsers.length === ((_b = data === null || data === void 0 ? void 0 : data.communityUsers) === null || _b === void 0 ? void 0 : _b.length)
19452
+ ? { data: communityUsers, cachedAt, paging }
19453
+ : undefined;
19454
+ };
19635
19455
 
19636
19456
  /*
19637
19457
  * Exported for testing
@@ -19680,215 +19500,79 @@ const getMembers = (params, callback, config) => {
19680
19500
  }
19681
19501
  const timestamp = Date.now();
19682
19502
  log(`getMembers(tmpid: ${timestamp}) > listen`);
19683
- const communityMemberLiveCollection = new CommunityMembersLiveCollectionController(params, resp => {
19684
- console.log('resp', resp);
19685
- callback(resp);
19686
- });
19687
- const disposers = communityMemberLiveCollection.startSubscription();
19688
- const cacheKey = communityMemberLiveCollection.getCacheKey();
19689
- disposers.push(() => {
19690
- dropFromCache(cacheKey);
19691
- });
19692
- return () => {
19693
- log(`getMembers(tmpid: ${timestamp}) > dispose`);
19694
- disposers.forEach(fn => fn());
19695
- };
19696
- };
19697
- /* end_public_function */
19698
-
19699
- /**
19700
- * TODO: handle cache receive cache option, and cache policy
19701
- * TODO: check if querybyIds is supported
19702
- */
19703
- class SearchCommunityMembersPaginationController extends PaginationController {
19704
- async getRequest(queryParams, token) {
19705
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
19706
- const options = token ? { token } : { limit };
19707
- const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
19708
- params: Object.assign(Object.assign({}, params), { options }),
19709
- });
19710
- return queryResponse;
19711
- }
19712
- }
19713
-
19714
- class SearchCommunityMembersQueryStreamController extends QueryStreamController {
19715
- constructor(query, cacheKey, notifyChange, preparePayload) {
19716
- super(query, cacheKey);
19717
- this.notifyChange = notifyChange;
19718
- this.preparePayload = preparePayload;
19719
- }
19720
- async saveToMainDB(response) {
19721
- const processedPayload = await this.preparePayload(response);
19722
- const client = getActiveClient();
19723
- const cachedAt = client.cache && Date.now();
19724
- if (client.cache) {
19725
- ingestInCache(processedPayload, { cachedAt });
19726
- }
19727
- }
19728
- appendToQueryStream(response, direction, refresh = false) {
19503
+ const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
19504
+ const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
19505
+ const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
19506
+ const disposers = [];
19507
+ const cacheKey = ['communityUsers', 'collection', queryParams];
19508
+ const cacheByCommunityIdKey = [
19509
+ 'communityUsers',
19510
+ 'collection',
19511
+ { communityId: params.communityId },
19512
+ ];
19513
+ const responder = (data, isEventModel = false) => {
19729
19514
  var _a, _b;
19730
- if (refresh) {
19731
- pushToCache(this.cacheKey, {
19732
- data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
19733
- });
19734
- }
19735
- else {
19736
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
19737
- const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
19738
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
19739
- ...new Set([
19740
- ...communityUsers,
19741
- ...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
19742
- ]),
19743
- ] }));
19744
- }
19745
- }
19746
- reactor(action) {
19747
- return (community, communityMembers) => {
19748
- var _a;
19749
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
19750
- if (!collection)
19751
- return;
19752
- communityMembers.forEach(communityMember => {
19753
- const communityMemberCacheId = getResolver('communityUsers')({
19754
- communityId: this.query.communityId,
19755
- userId: communityMember.userId,
19756
- });
19757
- if (communityMember.communityMembership === 'none') {
19758
- collection.data = collection.data.filter(m => m !== communityMemberCacheId);
19759
- }
19760
- });
19761
- pushToCache(this.cacheKey, collection);
19762
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
19763
- };
19764
- }
19765
- subscribeRTE(createSubscriber) {
19766
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
19767
- }
19768
- }
19769
-
19770
- var EnumCommunityMemberActions;
19771
- (function (EnumCommunityMemberActions) {
19772
- EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
19773
- EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
19774
- EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
19775
- EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
19776
- EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
19777
- EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
19778
- EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
19779
- })(EnumCommunityMemberActions || (EnumCommunityMemberActions = {}));
19780
-
19781
- /* eslint-disable no-use-before-define */
19782
- class SearchCommunityMembersLiveCollectionController extends LiveCollectionController {
19783
- constructor(query, callback) {
19784
- const queryStreamId = hash__default["default"](query);
19785
- const cacheKey = ['communityUsers', 'collection', queryStreamId];
19786
- const paginationController = new SearchCommunityMembersPaginationController(query);
19787
- super(paginationController, queryStreamId, cacheKey, callback);
19788
- this.query = query;
19789
- this.queryStreamController = new SearchCommunityMembersQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
19790
- this.callback = callback.bind(this);
19791
- this.loadPage({ initial: true });
19792
- }
19793
- setup() {
19515
+ const communityMembers = (_a = data.data
19516
+ .map(id => pullFromCache(['communityUsers', 'get', id]))
19517
+ .filter(Boolean)
19518
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
19519
+ callback({
19520
+ onNextPage: onFetch,
19521
+ data: isEventModel ? applyFilter(communityMembers, params) : communityMembers,
19522
+ hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
19523
+ loading: data.loading,
19524
+ error: data.error,
19525
+ });
19526
+ };
19527
+ const realtimeRouter = (_) => (_, communityMembers) => {
19794
19528
  var _a;
19795
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
19529
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
19796
19530
  if (!collection) {
19797
- pushToCache(this.cacheKey, {
19798
- data: [],
19799
- params: {},
19800
- });
19531
+ return;
19801
19532
  }
19802
- }
19803
- async persistModel(queryPayload) {
19804
- await this.queryStreamController.saveToMainDB(queryPayload);
19805
- }
19806
- persistQueryStream({ response, direction, refresh, }) {
19807
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
19808
- }
19809
- startSubscription() {
19810
- return this.queryStreamController.subscribeRTE([
19811
- { fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
19812
- { fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
19813
- { fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
19814
- { fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
19815
- {
19816
- fn: onCommunityUserRoleRemoved,
19817
- action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
19818
- },
19819
- { fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions.OnCommunityUserUnbanned },
19820
- ]);
19821
- }
19822
- notifyChange({ origin, loading, error }) {
19533
+ const communityMemberCacheIds = communityMembers
19534
+ .map(communityMember => {
19535
+ if (params.communityId !== communityMember.communityId) {
19536
+ return;
19537
+ }
19538
+ const communityMemberCacheId = getResolver('communityUsers')({
19539
+ communityId: params.communityId,
19540
+ userId: communityMember.userId,
19541
+ });
19542
+ return communityMemberCacheId;
19543
+ })
19544
+ .filter(isNonNullable);
19545
+ collection.data = [...new Set([...communityMemberCacheIds, ...collection.data])];
19546
+ pushToCache(cacheKey, collection);
19547
+ pushToCache(cacheByCommunityIdKey, collection);
19548
+ responder(collection, true);
19549
+ };
19550
+ const onFetch = (initial = false) => {
19823
19551
  var _a, _b;
19824
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
19825
- if (!collection)
19826
- return;
19827
- const data = this.applyFilter((_b = collection.data
19828
- .map(id => pullFromCache(['communityUsers', 'get', id]))
19829
- .filter(isNonNullable)
19830
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
19831
- if (!this.shouldNotify(data) && origin === 'event')
19552
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
19553
+ const communityMembers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
19554
+ if (!initial && communityMembers.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
19832
19555
  return;
19833
- this.callback({
19834
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
19835
- data,
19836
- hasNextPage: !!this.paginationController.getNextToken(),
19837
- loading,
19838
- error,
19839
- });
19840
- }
19841
- applyFilter(data) {
19842
- let communityMembers = filterByPropIntersection(data, 'roles', this.query.roles);
19843
- if (this.query.memberships) {
19844
- communityMembers = communityMembers.filter(({ communityMembership }) => {
19845
- const memberships = this.query.memberships || [];
19846
- return memberships.includes(communityMembership);
19847
- });
19848
- }
19849
- if (this.query.search) {
19850
- communityMembers = filterBySearchTerm(communityMembers, this.query.search);
19851
- }
19852
- return communityMembers;
19853
- }
19854
- }
19855
-
19856
- /* begin_public_function
19857
- id: community.membership.query
19858
- */
19859
- /**
19860
- * ```js
19861
- * import { searchMembers } from '@amityco/ts-sdk-react-native'
19862
- *
19863
- * let communityMembers = []
19864
- * const unsub = searchMembers({
19865
- * communityId: Amity.Community['communityId'],
19866
- * }, response => merge(communityMembers, response.data))
19867
- * ```
19868
- *
19869
- * Observe all mutations on a list of {@link Amity.CommunityUser}s
19870
- *
19871
- * @param params for querying community users
19872
- * @param callback the function to call when new data are available
19873
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community users
19874
- *
19875
- * @category Community Live Collection
19876
- */
19877
- const searchMembers = (params, callback, config) => {
19878
- const { log, cache } = getActiveClient();
19879
- if (!cache) {
19880
- console.log(ENABLE_CACHE_MESSAGE);
19881
- }
19882
- const timestamp = Date.now();
19883
- log(`getMembers(tmpid: ${timestamp}) > listen`);
19884
- const searchCommunityMemberLiveCollection = new SearchCommunityMembersLiveCollectionController(params, resp => {
19885
- callback(resp);
19886
- });
19887
- const disposers = searchCommunityMemberLiveCollection.startSubscription();
19888
- const cacheKey = searchCommunityMemberLiveCollection.getCacheKey();
19889
- disposers.push(() => {
19890
- dropFromCache(cacheKey);
19891
- });
19556
+ const query = createQuery(queryCommunityMembers, Object.assign(Object.assign({}, queryParams), { limit: initial ? limit : undefined, page: !initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined }));
19557
+ runQuery(query, ({ data: result, error, loading, paging }) => {
19558
+ const data = {
19559
+ loading,
19560
+ error,
19561
+ params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
19562
+ data: communityMembers,
19563
+ };
19564
+ if (result) {
19565
+ data.data = [
19566
+ ...new Set([...communityMembers, ...result.map(getResolver('communityUsers'))]),
19567
+ ];
19568
+ }
19569
+ pushToCache(cacheKey, data);
19570
+ pushToCache(cacheByCommunityIdKey, data);
19571
+ responder(data);
19572
+ }, queryOptions(policy));
19573
+ };
19574
+ disposers.push(onCommunityLeft(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityUserBanned(realtimeRouter()), onCommunityUserUnbanned(realtimeRouter()), onCommunityUserChanged(realtimeRouter()), onCommunityUserRoleAdded(realtimeRouter()), onCommunityUserRoleRemoved(realtimeRouter()));
19575
+ onFetch(true);
19892
19576
  return () => {
19893
19577
  log(`getMembers(tmpid: ${timestamp}) > dispose`);
19894
19578
  disposers.forEach(fn => fn());
@@ -19902,7 +19586,6 @@ var index$9 = /*#__PURE__*/Object.freeze({
19902
19586
  removeMembers: removeMembers,
19903
19587
  applyFilter: applyFilter,
19904
19588
  getMembers: getMembers,
19905
- searchMembers: searchMembers,
19906
19589
  onCommunityUserAdded: onCommunityUserAdded,
19907
19590
  onCommunityUserRemoved: onCommunityUserRemoved,
19908
19591
  onCommunityUserBanned: onCommunityUserBanned,
@@ -22060,10 +21743,10 @@ var index$4 = /*#__PURE__*/Object.freeze({
22060
21743
  * const created = await createStream({ title: 'my stream', 'thumbnailFileId': fileId })
22061
21744
  * ```
22062
21745
  *
22063
- * Creates an {@link Amity.InternalStream}
21746
+ * Creates an {@link Amity.Stream}
22064
21747
  *
22065
- * @param bundle The data necessary to create a new {@link Amity.InternalStream}
22066
- * @returns The newly created {@link Amity.InternalStream}
21748
+ * @param bundle The data necessary to create a new {@link Amity.Stream}
21749
+ * @returns The newly created {@link Amity.Stream}
22067
21750
  *
22068
21751
  * @category Stream API
22069
21752
  * @async
@@ -22077,7 +21760,7 @@ const createStream = async (bundle) => {
22077
21760
  ingestInCache(data, { cachedAt });
22078
21761
  const { videoStreamings } = data;
22079
21762
  return {
22080
- data: LinkedObject.stream(videoStreamings[0]),
21763
+ data: videoStreamings[0],
22081
21764
  cachedAt,
22082
21765
  };
22083
21766
  };
@@ -22110,7 +21793,7 @@ const updateStream = async (streamId, patch) => {
22110
21793
  ingestInCache(data, { cachedAt });
22111
21794
  const { videoStreamings } = data;
22112
21795
  return {
22113
- data: LinkedObject.stream(videoStreamings.find(stream => stream.streamId === streamId)),
21796
+ data: videoStreamings.find(stream => stream.streamId === streamId),
22114
21797
  cachedAt,
22115
21798
  };
22116
21799
  };
@@ -22184,10 +21867,10 @@ getStream.locally = (streamId) => {
22184
21867
  * const success = await deleteStream(streamId)
22185
21868
  * ```
22186
21869
  *
22187
- * Deletes a {@link Amity.InternalStream}
21870
+ * Deletes a {@link Amity.Stream}
22188
21871
  *
22189
- * @param streamId The {@link Amity.InternalStream} ID to delete
22190
- * @return A success boolean if the {@link Amity.InternalStream} was deleted
21872
+ * @param streamId The {@link Amity.Stream} ID to delete
21873
+ * @return A success boolean if the {@link Amity.Stream} was deleted
22191
21874
  *
22192
21875
  * @category Stream API
22193
21876
  * @async
@@ -22212,11 +21895,11 @@ const deleteStream = async (streamId) => {
22212
21895
  * const stream = await disposeStream(streamId)
22213
21896
  * ```
22214
21897
  *
22215
- * Dispose a {@link Amity.InternalStream}.
21898
+ * Dispose a {@link Amity.Stream}.
22216
21899
  * Streaming status will be updated to "ended" and streaming url will be invalidated
22217
21900
  *
22218
- * @param streamId The {@link Amity.InternalStream} ID to dispose
22219
- * @returns the associated {@link Amity.InternalStream} object
21901
+ * @param streamId The {@link Amity.Stream} ID to dispose
21902
+ * @returns the associated {@link Amity.Stream} object
22220
21903
  *
22221
21904
  * @category Stream API
22222
21905
  * @async
@@ -22247,15 +21930,15 @@ const disposeStream = async (streamId) => {
22247
21930
  * const streams = await getStreams()
22248
21931
  * ```
22249
21932
  *
22250
- * Queries a paginable list of {@link Amity.InternalStream} objects
21933
+ * Queries a paginable list of {@link Amity.Stream} objects
22251
21934
  *
22252
21935
  * @param query The query parameters
22253
- * @returns A page of {@link Amity.InternalStream} objects
21936
+ * @returns A page of {@link Amity.Stream} objects
22254
21937
  *
22255
21938
  * @category Stream API
22256
21939
  * @async
22257
21940
  */
22258
- const queryStreams = async (query) => {
21941
+ const queryStreams$1 = async (query) => {
22259
21942
  const client = getActiveClient();
22260
21943
  client.log('stream/queryStreams', query);
22261
21944
  const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
@@ -22285,7 +21968,7 @@ const queryStreams = async (query) => {
22285
21968
  * })
22286
21969
  * ```
22287
21970
  *
22288
- * Fired when a {@link Amity.InternalStream} has started airing
21971
+ * Fired when a {@link Amity.Stream} has started airing
22289
21972
  *
22290
21973
  * @param callback The function to call when the event was fired
22291
21974
  * @returns an {@link Amity.Unsubscriber} function to stop listening
@@ -22309,7 +21992,7 @@ const onStreamStarted = (callback) => {
22309
21992
  * })
22310
21993
  * ```
22311
21994
  *
22312
- * Fired when a {@link Amity.InternalStream} has stopped airing
21995
+ * Fired when a {@link Amity.Stream} has stopped airing
22313
21996
  *
22314
21997
  * @param callback The function to call when the event was fired
22315
21998
  * @returns an {@link Amity.Unsubscriber} function to stop listening
@@ -22333,7 +22016,7 @@ const onStreamStopped = (callback) => {
22333
22016
  * })
22334
22017
  * ```
22335
22018
  *
22336
- * Fired when the recordings of a {@link Amity.InternalStream} are available
22019
+ * Fired when the recordings of a {@link Amity.Stream} are available
22337
22020
  *
22338
22021
  * @param callback The function to call when the event was fired
22339
22022
  * @returns an {@link Amity.Unsubscriber} function to stop listening
@@ -22349,54 +22032,6 @@ const onStreamRecorded = (callback) => {
22349
22032
  return createEventSubscriber(client, 'stream/onStreamRecorded', 'v3.video-streaming.didRecord', filter);
22350
22033
  };
22351
22034
 
22352
- /**
22353
- * ```js
22354
- * import { onStreamFlagged } from '@amityco/ts-sdk-react-native'
22355
- * const dispose = onStreamFlagged(stream => {
22356
- * // ...
22357
- * })
22358
- * ```
22359
- *
22360
- * Fired when a {@link Amity.InternalStream} has started airing
22361
- *
22362
- * @param callback The function to call when the event was fired
22363
- * @returns an {@link Amity.Unsubscriber} function to stop listening
22364
- *
22365
- * @category Stream Events
22366
- */
22367
- const onStreamFlagged = (callback) => {
22368
- const client = getActiveClient();
22369
- const filter = (payload) => {
22370
- ingestInCache(payload);
22371
- callback(payload.videoStreamings[0]);
22372
- };
22373
- return createEventSubscriber(client, 'stream/onStreamFlagged', 'v3.video-streaming.didFlag', filter);
22374
- };
22375
-
22376
- /**
22377
- * ```js
22378
- * import { onStreamTerminated } from '@amityco/ts-sdk-react-native'
22379
- * const dispose = onStreamTerminated(stream => {
22380
- * // ...
22381
- * })
22382
- * ```
22383
- *
22384
- * Fired when a {@link Amity.InternalStream} has started airing
22385
- *
22386
- * @param callback The function to call when the event was fired
22387
- * @returns an {@link Amity.Unsubscriber} function to stop listening
22388
- *
22389
- * @category Stream Events
22390
- */
22391
- const onStreamTerminated = (callback) => {
22392
- const client = getActiveClient();
22393
- const filter = (payload) => {
22394
- ingestInCache(payload);
22395
- callback(payload.videoStreamings[0]);
22396
- };
22397
- return createEventSubscriber(client, 'stream/onStreamTerminated', 'v3.video-streaming.didTerminate', filter);
22398
- };
22399
-
22400
22035
  /* eslint-disable no-use-before-define */
22401
22036
  /* begin_public_function
22402
22037
  id: stream.get
@@ -22411,22 +22046,15 @@ const onStreamTerminated = (callback) => {
22411
22046
  * Fetches a {@link Amity.Stream} object
22412
22047
  *
22413
22048
  * @param streamId the ID of the {@link Amity.Stream} to get
22414
- * @param callback
22415
22049
  * @returns the associated {@link Amity.Stream} object
22416
22050
  *
22417
22051
  * @category Stream Live Object
22418
22052
  */
22419
22053
  const getStreamById = (streamId, callback) => {
22420
- const reactor = (snapshot) => {
22421
- const { data } = snapshot;
22422
- callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.stream(snapshot.data) : data }));
22423
- };
22424
- return liveObject(streamId, reactor, 'streamId', getStream, [
22054
+ return liveObject(streamId, callback, 'streamId', getStream, [
22425
22055
  onStreamRecorded,
22426
22056
  onStreamStarted,
22427
22057
  onStreamStopped,
22428
- onStreamFlagged,
22429
- onStreamTerminated,
22430
22058
  ]);
22431
22059
  };
22432
22060
  /* end_public_function */
@@ -22452,150 +22080,145 @@ getStreamById.locally = (streamId) => {
22452
22080
  if (!cached)
22453
22081
  return;
22454
22082
  return {
22455
- data: LinkedObject.stream(cached.data),
22083
+ data: cached.data,
22456
22084
  cachedAt: cached.cachedAt,
22457
22085
  };
22458
22086
  };
22459
22087
 
22460
- class GetStreamsPageController extends PaginationController {
22461
- async getRequest(queryParams, token) {
22462
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
22463
- const options = token ? { token } : { limit };
22464
- const { data: queryResponse } = await this.http.get(`/api/v3/video-streaming`, {
22465
- params: Object.assign(Object.assign({}, params), { options }),
22466
- });
22467
- return Object.assign(Object.assign({}, queryResponse.results), { paging: queryResponse.paging });
22468
- }
22469
- }
22470
-
22471
- class GetStreamsQueryStreamController extends QueryStreamController {
22472
- constructor(query, cacheKey, notifyChange, paginationController) {
22473
- super(query, cacheKey);
22474
- this.notifyChange = notifyChange;
22475
- this.paginationController = paginationController;
22476
- }
22477
- // eslint-disable-next-line class-methods-use-this
22478
- saveToMainDB(response) {
22479
- const client = getActiveClient();
22480
- const cachedAt = client.cache && Date.now();
22481
- if (client.cache) {
22482
- ingestInCache(response, { cachedAt });
22483
- }
22484
- }
22485
- appendToQueryStream(response, direction, refresh = false) {
22486
- var _a, _b;
22487
- if (refresh) {
22488
- pushToCache(this.cacheKey, {
22489
- data: response.videoStreamings.map(getResolver('stream')),
22490
- query: this.query,
22491
- });
22492
- }
22493
- else {
22494
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
22495
- const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
22496
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === 'next'
22497
- ? [...new Set([...messages, ...response.videoStreamings.map(getResolver('stream'))])]
22498
- : [...new Set([...response.videoStreamings.map(getResolver('stream')), ...messages])] }));
22499
- }
22500
- }
22501
- reactor(action) {
22502
- return (payload) => {
22503
- var _a;
22504
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
22505
- if (!collection)
22506
- return;
22507
- collection.data = [...new Set([payload.streamId, ...collection.data])];
22508
- pushToCache(this.cacheKey, collection);
22509
- this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
22510
- };
22511
- }
22512
- subscribeRTE(createSubscriber) {
22513
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
22514
- }
22515
- }
22516
-
22517
- class GetStreamsLiveCollectionController extends LiveCollectionController {
22518
- constructor(query, callback) {
22519
- const queryStreamId = hash__default["default"](query);
22520
- const cacheKey = ['streams', 'collection', queryStreamId];
22521
- const paginationController = new GetStreamsPageController(query);
22522
- super(paginationController, queryStreamId, cacheKey, callback);
22523
- this.applyFilter = (data) => {
22524
- let streams = filterByPropEquality(data, 'isDeleted', this.query.isDeleted);
22525
- streams = streams.sort(this.query.sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
22526
- return streams;
22527
- };
22528
- this.query = query;
22529
- this.queryStreamController = new GetStreamsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController);
22530
- this.paginationController = paginationController;
22531
- this.callback = callback.bind(this);
22532
- this.loadPage({ initial: true });
22533
- }
22534
- notifyChange({ origin, loading, error }) {
22535
- var _a;
22536
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
22537
- if (!collection)
22538
- return;
22539
- let data = collection.data
22540
- .map(streamId => pullFromCache(['stream', 'get', streamId]))
22541
- .filter(Boolean)
22542
- .map(stream => LinkedObject.stream(stream.data));
22543
- if (!this.shouldNotify(data) && origin === 'event')
22544
- return;
22545
- data = this.applyFilter(data);
22546
- this.callback({
22547
- onNextPage: () => this.loadPage({ initial: false, direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
22548
- data,
22549
- hasNextPage: !!this.paginationController.getNextToken(),
22550
- loading,
22551
- error,
22552
- });
22553
- }
22554
- startSubscription() {
22555
- return this.queryStreamController.subscribeRTE([
22556
- { fn: onStreamRecorded, action: 'onStreamRecorded' },
22557
- { fn: onStreamStarted, action: 'onStreamStarted' },
22558
- { fn: onStreamStopped, action: 'onStreamStopped' },
22559
- { fn: onStreamFlagged, action: 'onStreamFlagged' },
22560
- { fn: onStreamTerminated, action: 'onStreamTerminated' },
22561
- ]);
22562
- }
22563
- setup() {
22564
- var _a;
22565
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
22566
- if (!collection) {
22567
- pushToCache(this.cacheKey, {
22568
- data: [],
22569
- params: {},
22570
- });
22571
- }
22572
- }
22573
- persistModel(response) {
22574
- this.queryStreamController.saveToMainDB(response);
22575
- }
22576
- persistQueryStream({ response, direction, refresh, }) {
22577
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
22578
- }
22579
- }
22088
+ /* begin_public_function
22089
+ id: stream.query
22090
+ */
22091
+ /**
22092
+ * ```js
22093
+ * import { getStreams } from '@amityco/ts-sdk-react-native'
22094
+ * const streams = await getStreams()
22095
+ * ```
22096
+ *
22097
+ * Queries a paginable list of {@link Amity.Stream} objects
22098
+ *
22099
+ * @param query The query parameters
22100
+ * @returns A page of {@link Amity.Stream} objects
22101
+ *
22102
+ * @category Stream API
22103
+ * @async
22104
+ */
22105
+ const queryStreams = async (query) => {
22106
+ const client = getActiveClient();
22107
+ client.log('stream/queryStreams', query);
22108
+ const _a = query !== null && query !== void 0 ? query : {}, { page, limit } = _a, params = __rest(_a, ["page", "limit"]);
22109
+ const options = (() => {
22110
+ if (page)
22111
+ return { token: page };
22112
+ if (limit)
22113
+ return { limit };
22114
+ return undefined;
22115
+ })();
22116
+ const { data } = await client.http.get(`/api/v3/video-streaming`, {
22117
+ params: Object.assign(Object.assign({}, params), { options }),
22118
+ });
22119
+ // API-FIX: backend to response Amity.Response: const { paging, videoStreamings } = unwrapPayload(data)
22120
+ // API-FIX: seems returned data has a results identifier on top of data, like no other apis, and this is beautiful
22121
+ const { paging, results: payload } = data;
22122
+ const { videoStreamings } = payload;
22123
+ const cachedAt = client.cache && Date.now();
22124
+ if (client.cache)
22125
+ ingestInCache(payload, { cachedAt });
22126
+ return { data: videoStreamings, cachedAt, paging };
22127
+ };
22128
+ /* end_public_function */
22580
22129
 
22130
+ /* begin_public_function
22131
+ id: stream.query
22132
+ */
22133
+ /**
22134
+ * ```js
22135
+ * import { StreamRepository } from '@amityco/ts-sdk-react-native'
22136
+ * const streams = await StreamRepository.getStreams()
22137
+ * ```
22138
+ *
22139
+ * Observe all mutations on a list of {@link Amity.Stream}s
22140
+ *
22141
+ * @param params for querying streams
22142
+ * @param callback the function to call when new data are available
22143
+ * @param config
22144
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the streams
22145
+ *
22146
+ * @category Stream Live Collection
22147
+ */
22581
22148
  const getStreams = (params, callback, config) => {
22582
- const { log, cache, userId } = getActiveClient();
22149
+ const { log, cache } = getActiveClient();
22583
22150
  if (!cache) {
22584
22151
  console.log(ENABLE_CACHE_MESSAGE);
22585
22152
  }
22586
22153
  const timestamp = Date.now();
22587
22154
  log(`getStreams(tmpid: ${timestamp}) > listen`);
22588
- const liveCollection = new GetStreamsLiveCollectionController(params, callback);
22589
- const disposers = liveCollection.startSubscription();
22590
- const cacheKey = liveCollection.getCacheKey();
22591
- disposers.push(() => {
22592
- dropFromCache(cacheKey);
22593
- });
22155
+ const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
22156
+ const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
22157
+ const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
22158
+ const disposers = [];
22159
+ const cacheKey = ['streams', 'collection', params];
22160
+ const applyFilter = (data) => {
22161
+ let streams = filterByPropEquality(data, 'isDeleted', params.isDeleted);
22162
+ streams = streams.sort(params.sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
22163
+ return streams;
22164
+ };
22165
+ const responder = (data, isEventModel = false) => {
22166
+ var _a, _b;
22167
+ const streams = (_a = data.data
22168
+ .map(streamId => {
22169
+ return pullFromCache(['stream', 'get', streamId]);
22170
+ })
22171
+ .filter(Boolean)
22172
+ .map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
22173
+ callback({
22174
+ onNextPage: onFetch,
22175
+ /*
22176
+ * Only apply filter to RTE Model
22177
+ */
22178
+ data: isEventModel ? applyFilter(streams) : streams,
22179
+ hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
22180
+ loading: data.loading,
22181
+ error: data.error,
22182
+ });
22183
+ };
22184
+ const realtimeRouter = (_) => (stream) => {
22185
+ var _a;
22186
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
22187
+ if (!collection)
22188
+ return;
22189
+ collection.data = [...new Set([stream.streamId, ...collection.data])];
22190
+ pushToCache(cacheKey, collection);
22191
+ responder(collection, true);
22192
+ };
22193
+ const onFetch = (initial = false) => {
22194
+ var _a, _b;
22195
+ const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
22196
+ const streams = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
22197
+ if (!initial && streams.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
22198
+ return;
22199
+ const query = createQuery(queryStreams, Object.assign(Object.assign({}, queryParams), { limit: initial ? limit : undefined, page: !initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined }));
22200
+ runQuery(query, ({ data: result, error, loading, paging }) => {
22201
+ const data = {
22202
+ loading,
22203
+ error,
22204
+ params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
22205
+ data: streams,
22206
+ };
22207
+ if (result) {
22208
+ data.data = [...new Set([...streams, ...result.map(getResolver('stream'))])];
22209
+ }
22210
+ pushToCache(cacheKey, data);
22211
+ responder(data);
22212
+ }, queryOptions(policy));
22213
+ };
22214
+ disposers.push(onStreamRecorded(realtimeRouter()), onStreamStarted(realtimeRouter()), onStreamStopped(realtimeRouter()));
22215
+ onFetch(true);
22594
22216
  return () => {
22595
22217
  log(`getStreams(tmpid: ${timestamp}) > dispose`);
22596
22218
  disposers.forEach(fn => fn());
22597
22219
  };
22598
- };
22220
+ };
22221
+ /* end_public_function */
22599
22222
 
22600
22223
  var index$3 = /*#__PURE__*/Object.freeze({
22601
22224
  __proto__: null,
@@ -22603,13 +22226,11 @@ var index$3 = /*#__PURE__*/Object.freeze({
22603
22226
  updateStream: updateStream,
22604
22227
  deleteStream: deleteStream,
22605
22228
  disposeStream: disposeStream,
22606
- queryStreams: queryStreams,
22229
+ queryStreams: queryStreams$1,
22607
22230
  getStream: getStream,
22608
22231
  onStreamStarted: onStreamStarted,
22609
22232
  onStreamStopped: onStreamStopped,
22610
22233
  onStreamRecorded: onStreamRecorded,
22611
- onStreamFlagged: onStreamFlagged,
22612
- onStreamTerminated: onStreamTerminated,
22613
22234
  getStreamById: getStreamById,
22614
22235
  getStreams: getStreams
22615
22236
  });
@@ -22942,7 +22563,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
22942
22563
  getPoll: getPoll
22943
22564
  });
22944
22565
 
22945
- 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-----";
22566
+ const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
22946
22567
  /*
22947
22568
  * The crypto algorithm used for importing key and signing string
22948
22569
  */