@amityco/ts-sdk 0.0.1-beta.10 → 0.0.1-beta.14

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/dist/@types/core/cache.d.ts +2 -2
  2. package/dist/@types/core/cache.d.ts.map +1 -1
  3. package/dist/@types/core/events.d.ts +6 -6
  4. package/dist/@types/core/events.d.ts.map +1 -1
  5. package/dist/@types/core/paging.d.ts +19 -38
  6. package/dist/@types/core/paging.d.ts.map +1 -1
  7. package/dist/@types/core/payload.d.ts +2 -2
  8. package/dist/@types/core/payload.d.ts.map +1 -1
  9. package/dist/@types/core/query.d.ts +12 -4
  10. package/dist/@types/core/query.d.ts.map +1 -1
  11. package/dist/@types/domains/client.d.ts +1 -1
  12. package/dist/@types/domains/client.d.ts.map +1 -1
  13. package/dist/@types/domains/comment.d.ts +1 -1
  14. package/dist/@types/domains/comment.d.ts.map +1 -1
  15. package/dist/@types/domains/file.d.ts +2 -2
  16. package/dist/@types/domains/file.d.ts.map +1 -1
  17. package/dist/@types/domains/mention.d.ts +23 -0
  18. package/dist/@types/domains/mention.d.ts.map +1 -0
  19. package/dist/@types/domains/message.d.ts +1 -1
  20. package/dist/@types/domains/message.d.ts.map +1 -1
  21. package/dist/@types/domains/post.d.ts +2 -2
  22. package/dist/@types/domains/post.d.ts.map +1 -1
  23. package/dist/@types/index.d.ts +1 -0
  24. package/dist/@types/index.d.ts.map +1 -1
  25. package/dist/category/api/queryCategories.d.ts +3 -3
  26. package/dist/channel/api/getChannels.d.ts.map +1 -1
  27. package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
  28. package/dist/channel/api/queryChannels.d.ts +1 -1
  29. package/dist/channel/events/onChannelCreated.d.ts.map +1 -1
  30. package/dist/client/api/disconnectClient.d.ts.map +1 -1
  31. package/dist/comment/api/createComment.d.ts +1 -1
  32. package/dist/comment/api/createComment.d.ts.map +1 -1
  33. package/dist/comment/api/getComments.d.ts.map +1 -1
  34. package/dist/comment/api/updateComment.d.ts +1 -1
  35. package/dist/comment/api/updateComment.d.ts.map +1 -1
  36. package/dist/comment/events/onCommentReactionAdded.d.ts.map +1 -1
  37. package/dist/comment/events/onCommentReactionRemoved.d.ts.map +1 -1
  38. package/dist/comment/events/utils.d.ts.map +1 -1
  39. package/dist/community/api/addCommunityMembers.d.ts.map +1 -1
  40. package/dist/community/api/joinCommunity.d.ts.map +1 -1
  41. package/dist/community/api/leaveCommunity.d.ts.map +1 -1
  42. package/dist/community/api/queryCommunities.d.ts +1 -1
  43. package/dist/community/api/removeCommunityMembers.d.ts.map +1 -1
  44. package/dist/community/events/utils.d.ts.map +1 -1
  45. package/dist/core/debug.d.ts.map +1 -1
  46. package/dist/core/device.d.ts.map +1 -1
  47. package/dist/core/events.d.ts.map +1 -1
  48. package/dist/core/microtasks.d.ts +13 -0
  49. package/dist/core/microtasks.d.ts.map +1 -0
  50. package/dist/core/query/paging.d.ts +2 -13
  51. package/dist/core/query/paging.d.ts.map +1 -1
  52. package/dist/core/query/query.d.ts +1 -1
  53. package/dist/core/query/query.d.ts.map +1 -1
  54. package/dist/feed/api/queryGlobalFeed.d.ts +22 -4
  55. package/dist/feed/api/queryGlobalFeed.d.ts.map +1 -1
  56. package/dist/index.cjs.js +138 -148
  57. package/dist/index.esm.js +139 -147
  58. package/dist/index.umd.js +5 -5
  59. package/dist/message/api/createMessage.d.ts +2 -2
  60. package/dist/message/api/createMessage.d.ts.map +1 -1
  61. package/dist/message/api/updateMessage.d.ts +2 -2
  62. package/dist/message/api/updateMessage.d.ts.map +1 -1
  63. package/dist/post/api/createPost.d.ts +7 -3
  64. package/dist/post/api/createPost.d.ts.map +1 -1
  65. package/dist/post/api/getPosts.d.ts.map +1 -1
  66. package/dist/post/api/queryPosts.d.ts +3 -3
  67. package/dist/post/api/queryPosts.d.ts.map +1 -1
  68. package/dist/post/api/updatePost.d.ts +1 -1
  69. package/dist/post/api/updatePost.d.ts.map +1 -1
  70. package/dist/post/events/onPostReactionAdded.d.ts.map +1 -1
  71. package/dist/post/events/onPostReactionRemoved.d.ts.map +1 -1
  72. package/dist/post/events/utils.d.ts.map +1 -1
  73. package/dist/role/api/queryRoles.d.ts +1 -1
  74. package/dist/stream/api/queryStreams.d.ts +1 -1
  75. package/dist/user/api/getUsers.d.ts.map +1 -1
  76. package/dist/utils/env.d.ts +5 -0
  77. package/dist/utils/env.d.ts.map +1 -0
  78. package/dist/version.d.ts.map +1 -1
  79. package/package.json +1 -3
  80. package/rollup.config.js +3 -0
  81. package/src/@types/core/cache.ts +2 -2
  82. package/src/@types/core/events.ts +6 -6
  83. package/src/@types/core/paging.ts +29 -44
  84. package/src/@types/core/payload.ts +2 -2
  85. package/src/@types/core/query.ts +7 -3
  86. package/src/@types/domains/client.ts +1 -1
  87. package/src/@types/domains/comment.ts +1 -0
  88. package/src/@types/domains/file.ts +2 -1
  89. package/src/@types/domains/mention.ts +26 -0
  90. package/src/@types/domains/message.ts +1 -0
  91. package/src/@types/domains/post.ts +2 -1
  92. package/src/@types/index.ts +2 -0
  93. package/src/channel/api/addChannelMembers.ts +1 -1
  94. package/src/channel/api/addChannelMembersRole.ts +1 -1
  95. package/src/channel/api/deleteChannel.ts +1 -1
  96. package/src/channel/api/getChannel.ts +1 -1
  97. package/src/channel/api/getChannels.ts +3 -1
  98. package/src/channel/api/joinChannel.ts +1 -1
  99. package/src/channel/api/leaveChannel.ts +1 -1
  100. package/src/channel/api/queryChannelMembers.ts +3 -2
  101. package/src/channel/api/removeChannelMembers.ts +1 -1
  102. package/src/channel/api/removeChannelMembersRole.ts +1 -1
  103. package/src/channel/api/updateChannel.ts +1 -1
  104. package/src/channel/events/onChannelCreated.ts +1 -3
  105. package/src/client/api/connectClient.ts +1 -1
  106. package/src/client/api/disconnectClient.ts +0 -1
  107. package/src/client/events/onConnectionError.ts +1 -1
  108. package/src/comment/api/createComment.ts +1 -2
  109. package/src/comment/api/deleteComment.ts +1 -1
  110. package/src/comment/api/getComment.ts +1 -1
  111. package/src/comment/api/getComments.ts +3 -1
  112. package/src/comment/api/updateComment.ts +2 -2
  113. package/src/comment/events/onCommentReactionAdded.ts +0 -7
  114. package/src/comment/events/onCommentReactionRemoved.ts +0 -7
  115. package/src/comment/events/utils.ts +3 -10
  116. package/src/community/api/addCommunityMembers.ts +3 -5
  117. package/src/community/api/joinCommunity.ts +1 -3
  118. package/src/community/api/leaveCommunity.ts +1 -3
  119. package/src/community/api/queryCommunityMembers.ts +1 -1
  120. package/src/community/api/removeCommunityMembers.ts +1 -3
  121. package/src/community/events/utils.ts +19 -33
  122. package/src/core/debug.ts +3 -1
  123. package/src/core/device.ts +3 -2
  124. package/src/core/events.ts +3 -1
  125. package/src/core/microtasks.ts +27 -0
  126. package/src/core/query/paging.ts +6 -41
  127. package/src/core/query/query.ts +5 -5
  128. package/src/core/subscription.ts +4 -4
  129. package/src/feed/api/queryGlobalFeed.ts +58 -5
  130. package/src/message/api/createMessage.ts +2 -2
  131. package/src/message/api/deleteMessage.ts +1 -1
  132. package/src/message/api/getMessage.ts +1 -1
  133. package/src/message/api/updateMessage.ts +3 -3
  134. package/src/post/api/createPost.ts +6 -5
  135. package/src/post/api/deletePost.ts +1 -1
  136. package/src/post/api/getPost.ts +1 -1
  137. package/src/post/api/getPosts.ts +3 -1
  138. package/src/post/api/queryPosts.ts +5 -5
  139. package/src/post/api/updatePost.ts +2 -2
  140. package/src/post/events/onPostReactionAdded.ts +0 -7
  141. package/src/post/events/onPostReactionRemoved.ts +0 -7
  142. package/src/post/events/utils.ts +2 -10
  143. package/src/report/api/createReport.ts +2 -2
  144. package/src/report/api/deleteReport.ts +2 -2
  145. package/src/user/api/getUser.ts +1 -1
  146. package/src/user/api/getUsers.ts +3 -1
  147. package/src/utils/env.ts +7 -0
  148. package/src/version.ts +3 -1
package/dist/index.esm.js CHANGED
@@ -5,13 +5,15 @@ import HttpAgent, { HttpsAgent } from 'agentkeepalive';
5
5
  import io from 'socket.io-client';
6
6
  import mitt from 'mitt';
7
7
  import AsyncStorage from '@react-native-async-storage/async-storage';
8
- import isMatch from 'lodash.ismatch';
9
8
 
10
- var _a;
11
- // used in createClient
12
- const VERSION$1 = (_a = 'v0.0.1-beta.10-esm') !== null && _a !== void 0 ? _a : '__dev__';
9
+ var _a$1;
10
+ const theGlobal = globalThis || global || window;
11
+ const { process: safeProcess = {} } = theGlobal;
12
+ const isProduction = ((_a$1 = safeProcess.env) === null || _a$1 === void 0 ? void 0 : _a$1.NODE_ENV) === 'production';
13
+
14
+ var _a, _b;
15
+ const VERSION$1 = (_b = (_a = safeProcess.env) === null || _a === void 0 ? void 0 : _a.VERSION) !== null && _b !== void 0 ? _b : '__dev__';
13
16
 
14
- // @ts-ignore
15
17
  /**
16
18
  * Type guard to find if the a given decoded backend token uses "skip/limit" pagination style
17
19
  *
@@ -29,7 +31,7 @@ const isSkipLimit = (json) => (['skip', 'limit'].some(prop => prop in json));
29
31
  *
30
32
  * @hidden
31
33
  */
32
- const isAfterBefore = (json) => (['after', 'before', 'first', 'last'].some(prop => prop in json));
34
+ const isAfterBefore = (json) => (['after', 'before', 'first', 'last', 'limit'].some(prop => prop in json));
33
35
  /**
34
36
  * Type guard to find if the a given decoded backend token uses v4 or newer "after/before" pagination style
35
37
  *
@@ -38,7 +40,7 @@ const isAfterBefore = (json) => (['after', 'before', 'first', 'last'].some(prop
38
40
  *
39
41
  * @hidden
40
42
  */
41
- const isAfterBeforeRaw = (json) => (['after', 'before'].some(prop => prop in json));
43
+ const isAfterBeforeRaw = (json) => ('limit' in json);
42
44
  /**
43
45
  * Type guard to find if the a given object is wrapped around Amity.Paged<>
44
46
  *
@@ -73,7 +75,7 @@ const toToken = (paging, style) => {
73
75
  limit: paging.limit,
74
76
  };
75
77
  }
76
- else if (style === 'afterbefore') {
78
+ else if (style === 'afterbefore' && isAfterBefore(paging)) {
77
79
  /*
78
80
  Caution: this testing style is only valid because
79
81
  our backend expects nothing else than a number as
@@ -159,35 +161,6 @@ const toPageRaw = (token) => {
159
161
  return json;
160
162
  }
161
163
  return null;
162
- };
163
- /**
164
- * Slices a collection according to its paging
165
- *
166
- * @param type the type of collection (for unique id identification with after/before)
167
- * @param collection the collection to slice
168
- * @param paging the paging object
169
- * @returns the sliced collection according to the paging definition
170
- *
171
- * @hidden
172
- */
173
- const sliceByPaging = (type, collection, page) => {
174
- console.log('slice by paging', page);
175
- if (!page)
176
- return collection.slice();
177
- let start = 0;
178
- let end = undefined;
179
- // next page behavior
180
- if (page.after) {
181
- start = page.after;
182
- end = start + page.limit;
183
- // prev page behavior
184
- }
185
- else if (page.before) {
186
- end = page.before + 1;
187
- start = end > page.limit ? end - page.limit : 0;
188
- }
189
- const paged = collection.slice(start, end);
190
- return paged.length === page.limit ? paged : undefined;
191
164
  };
192
165
 
193
166
  /**
@@ -501,7 +474,7 @@ const setActiveClient = (client) => {
501
474
  */
502
475
  const createLogger = (session) => {
503
476
  const active = (`${session === null || session === void 0 ? void 0 : session.trim()}`.length > 0
504
- && process.env.NODE_ENV !== 'production');
477
+ && !isProduction);
505
478
  const logger = debug(session);
506
479
  const print = (topic, ...args) => {
507
480
  active && logger(topic, args);
@@ -14728,6 +14701,22 @@ const createMqttTransport = (endpoint) => {
14728
14701
  };
14729
14702
  };
14730
14703
 
14704
+ let tasks = [];
14705
+ let timer;
14706
+ /**
14707
+ * Add a function to run just before the next tick
14708
+ *
14709
+ * @param task function to schedule for later execution
14710
+ */
14711
+ const scheduleTask = (task) => {
14712
+ clearTimeout(timer);
14713
+ tasks.push(task);
14714
+ timer = setTimeout(() => {
14715
+ tasks.forEach(fn => fn());
14716
+ tasks = [];
14717
+ }, 0);
14718
+ };
14719
+
14731
14720
  // need to sync up the list
14732
14721
  const WS_EVENTS = [
14733
14722
  'disconnected',
@@ -14818,7 +14807,7 @@ const createEventSubscriber = (client, namespace, event, fn) => {
14818
14807
  */
14819
14808
  const fireEvent = (event, payload) => {
14820
14809
  const { emitter } = getActiveClient();
14821
- setTimeout(() => { emitter.emit(event, payload); }, 0);
14810
+ scheduleTask(() => { emitter.emit(event, payload); });
14822
14811
  };
14823
14812
 
14824
14813
  /**
@@ -14892,13 +14881,11 @@ const disconnectClient = async () => {
14892
14881
  client.ws.removeAllListeners();
14893
14882
  client.mqtt.removeAllListeners();
14894
14883
  client.userId = undefined;
14895
- client.user = undefined;
14896
14884
  client.accessToken = undefined;
14897
14885
  return !client.ws.connected;
14898
14886
  };
14899
14887
 
14900
14888
  // TODO: find a way to uniquely identify the device
14901
- // import { getStorage } from './storage'
14902
14889
  /** @hidden */
14903
14890
  const VERSION = '11.0.0';
14904
14891
  /** @hidden */
@@ -14913,8 +14900,8 @@ const getDeviceId = () => {
14913
14900
  /** @hidden */
14914
14901
  const getDeviceModel = () => {
14915
14902
  var _a, _b;
14916
- if ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node)
14917
- return process.versions.node;
14903
+ if ((_a = safeProcess.versions) === null || _a === void 0 ? void 0 : _a.node)
14904
+ return safeProcess.versions.node;
14918
14905
  if (navigator)
14919
14906
  return `${navigator.product.toLowerCase()}#${(_b = navigator.userAgent) !== null && _b !== void 0 ? _b : 'unknown_agent'}`;
14920
14907
  return 'unknown_model';
@@ -14978,7 +14965,7 @@ const EVENTS = [
14978
14965
  const onConnectionError = (callback) => {
14979
14966
  const client = getActiveClient();
14980
14967
  const subscribers = EVENTS.map(event => (createEventSubscriber(client, `client/onConnectionError(${event})`, event, (response) => {
14981
- const error = (response && 'code' in response)
14968
+ const error = (response === null || response === void 0 ? void 0 : response.code)
14982
14969
  ? new ASCError(response.message, response.code, "fatal" /* FATAL */)
14983
14970
  : new ASCConnectionError(event);
14984
14971
  callback(error);
@@ -15077,7 +15064,7 @@ const connectClient = async (params) => {
15077
15064
  unsubscribe();
15078
15065
  });
15079
15066
  client.userId = params.userId;
15080
- client.user = users[0];
15067
+ client._internalUserId = users[0]._id;
15081
15068
  client.accessToken = accessToken;
15082
15069
  return client.ws.connected;
15083
15070
  };
@@ -15139,11 +15126,11 @@ const getCommentTopic = ({ path }) => {
15139
15126
  let mqttAccessToken;
15140
15127
  let mqttUserId;
15141
15128
  function subscribeTopic(topic, callback) {
15142
- const { mqtt, emitter, accessToken, user } = getActiveClient();
15143
- if (mqttAccessToken !== accessToken || mqttUserId !== user._id) {
15129
+ const { mqtt, emitter, accessToken, _internalUserId } = getActiveClient();
15130
+ if (mqttAccessToken !== accessToken || mqttUserId !== _internalUserId) {
15144
15131
  mqttAccessToken = accessToken;
15145
- mqttUserId = user._id;
15146
- mqtt.connect({ accessToken: accessToken, userId: user._id });
15132
+ mqttUserId = _internalUserId;
15133
+ mqtt.connect({ accessToken: mqttAccessToken, userId: mqttUserId });
15147
15134
  proxyMqttEvents(mqtt, emitter);
15148
15135
  }
15149
15136
  return mqtt.subscribe(topic, callback);
@@ -15619,7 +15606,7 @@ const getUser = async (userId) => {
15619
15606
  const client = getActiveClient();
15620
15607
  client.log('user/getUser', userId);
15621
15608
  // API-FIX: endpoint should not be /list, parameters should be querystring.
15622
- const { data } = await client.http.get(`/api/v3/users/${userId}`);
15609
+ const { data } = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
15623
15610
  const cachedAt = client.cache && Date.now();
15624
15611
  if (client.cache)
15625
15612
  ingestInCache(data, { cachedAt });
@@ -15665,8 +15652,9 @@ getUser.locally = (userId) => {
15665
15652
  const getUsers = async (userIds) => {
15666
15653
  const client = getActiveClient();
15667
15654
  client.log('user/getUsers', userIds);
15655
+ const encodedUserIds = userIds.map(userId => encodeURIComponent(userId));
15668
15656
  // API-FIX: endpoint should not be /list, parameters should be querystring.
15669
- const { data } = await client.http.get(`/api/v3/users/list`, { params: { userIds } });
15657
+ const { data } = await client.http.get(`/api/v3/users/list`, { params: { userIds: encodedUserIds } });
15670
15658
  const cachedAt = client.cache && Date.now();
15671
15659
  if (client.cache)
15672
15660
  ingestInCache(data, { cachedAt });
@@ -16261,7 +16249,7 @@ const getMessage = async (messageId) => {
16261
16249
  const client = getActiveClient();
16262
16250
  client.log('message/getMessage', messageId);
16263
16251
  // API-FIX: endpoint should not be /list, parameters should be querystring.
16264
- const { data } = await client.http.get(`/api/v3/messages/${messageId}`);
16252
+ const { data } = await client.http.get(`/api/v3/messages/${encodeURIComponent(messageId)}`);
16265
16253
  const cachedAt = client.cache && Date.now();
16266
16254
  if (client.cache)
16267
16255
  ingestInCache(data, { cachedAt });
@@ -16520,7 +16508,7 @@ createMessage.optimistically = (bundle) => {
16520
16508
  const updateMessage = async (messageId, patch) => {
16521
16509
  const client = getActiveClient();
16522
16510
  client.log('user/updateMessage', patch);
16523
- const { data } = await client.http.put(`/api/v3/messages/${messageId}`, patch);
16511
+ const { data } = await client.http.put(`/api/v3/messages/${encodeURIComponent(messageId)}`, patch);
16524
16512
  const cachedAt = client.cache && Date.now();
16525
16513
  if (client.cache)
16526
16514
  ingestInCache(data, { cachedAt });
@@ -16582,7 +16570,7 @@ const deleteMessage = async (messageId) => {
16582
16570
  const client = getActiveClient();
16583
16571
  client.log('message/deleteMessage', messageId);
16584
16572
  // API-FIX: This endpoint has not been implemented yet.
16585
- await client.http.delete(`/api/v3/messages/${messageId}`);
16573
+ await client.http.delete(`/api/v3/messages/${encodeURIComponent(messageId)}`);
16586
16574
  const deleted = await getMessage(messageId);
16587
16575
  // no need for event, fired by server
16588
16576
  return deleted.data;
@@ -16636,11 +16624,11 @@ const queryPosts = async (query) => {
16636
16624
  const { page = { limit: 10 } } = query, params = __rest(query
16637
16625
  // API-FIX: parameters should be querystring. (1)
16638
16626
  // API-FIX: backend should answer Amity.Response (2)
16639
- // const { data } = await client.http.get<Amity.Response<Amity.PagedRawResponse<Amity.PostPayload>>>(
16627
+ // const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
16640
16628
  , ["page"]);
16641
16629
  // API-FIX: parameters should be querystring. (1)
16642
16630
  // API-FIX: backend should answer Amity.Response (2)
16643
- // const { data } = await client.http.get<Amity.Response<Amity.PagedRawResponse<Amity.PostPayload>>>(
16631
+ // const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
16644
16632
  const { data } = await client.http.get(`/api/v4/posts`, { params: Object.assign(Object.assign({}, params), { options: {
16645
16633
  token: toToken(page, 'afterbeforeraw'),
16646
16634
  } }), });
@@ -16711,8 +16699,9 @@ queryPosts.locally = (query) => {
16711
16699
  const getPosts = async (postIds) => {
16712
16700
  const client = getActiveClient();
16713
16701
  client.log('post/getPosts', postIds);
16702
+ const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
16714
16703
  // API-FIX: endpoint should not be /list, parameters should be querystring.
16715
- const { data } = await client.http.get(`/api/v3/posts/list`, { params: { postIds } });
16704
+ const { data } = await client.http.get(`/api/v3/posts/list`, { params: { postIds: encodedPostIds } });
16716
16705
  const cachedAt = client.cache && Date.now();
16717
16706
  if (client.cache)
16718
16707
  ingestInCache(data, { cachedAt });
@@ -16774,7 +16763,7 @@ const getPost = async (postId) => {
16774
16763
  let data;
16775
16764
  try {
16776
16765
  // API-FIX: endpoint should not be /list, parameters should be querystring.
16777
- const response = await client.http.get(`/api/v3/posts/${postId}`);
16766
+ const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
16778
16767
  data = response.data;
16779
16768
  }
16780
16769
  catch (error) {
@@ -16841,13 +16830,12 @@ const createPost = async (bundle) => {
16841
16830
  const client = getActiveClient();
16842
16831
  client.log('post/createPost', bundle);
16843
16832
  // API-FIX: backend rejects that we pass the dataType manually T_T
16844
- if (!bundle.dataType || ['text', 'image', 'file'].includes(bundle.dataType))
16833
+ if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType))
16845
16834
  delete bundle.dataType;
16846
- const { data } = await client.http.post('/api/v3/posts', bundle);
16835
+ const { data } = await client.http.post('/api/v4/posts', bundle);
16847
16836
  const cachedAt = client.cache && Date.now();
16848
16837
  if (client.cache)
16849
16838
  ingestInCache(data, { cachedAt });
16850
- fireEvent('community.updated', { communities: data.communities });
16851
16839
  fireEvent('post.created', data);
16852
16840
  const { posts } = data;
16853
16841
  return {
@@ -16876,7 +16864,7 @@ const createPost = async (bundle) => {
16876
16864
  const updatePost = async (postId, patch) => {
16877
16865
  const client = getActiveClient();
16878
16866
  client.log('user/updatePost', patch);
16879
- const { data } = await client.http.put(`/api/v3/posts/${postId}`, patch);
16867
+ const { data } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
16880
16868
  const cachedAt = client.cache && Date.now();
16881
16869
  if (client.cache)
16882
16870
  ingestInCache(data, { cachedAt });
@@ -17163,9 +17151,7 @@ const joinCommunity = async (communityId) => {
17163
17151
  const cachedAt = client.cache && Date.now();
17164
17152
  if (client.cache)
17165
17153
  ingestInCache(data, { cachedAt });
17166
- fireEvent('community.joined', {
17167
- communities: data.communities
17168
- });
17154
+ fireEvent('community.joined', data);
17169
17155
  const { communityUsers } = data;
17170
17156
  return !!communityUsers.find(communityUser => (communityUser.communityId === communityId
17171
17157
  && communityUser.communityMembership === 'member'));
@@ -17192,9 +17178,7 @@ const leaveCommunity = async (communityId) => {
17192
17178
  const cachedAt = client.cache && Date.now();
17193
17179
  if (client.cache)
17194
17180
  ingestInCache(data, { cachedAt });
17195
- fireEvent('community.left', {
17196
- communities: data.communities,
17197
- });
17181
+ fireEvent('community.left', data);
17198
17182
  const { communityUsers } = data;
17199
17183
  return !!communityUsers.find(communityUser => (communityUser.communityId === communityId
17200
17184
  && communityUser.communityMembership !== 'member'));
@@ -17231,7 +17215,7 @@ const queryCommunityMembers = async (query) => {
17231
17215
  }
17232
17216
  const nextPage = toPage(paging.next);
17233
17217
  const prevPage = toPage(paging.previous);
17234
- return { data: communityUsers, nextPage, prevPage };
17218
+ return { data: communityUsers, cachedAt, nextPage, prevPage };
17235
17219
  };
17236
17220
  /**
17237
17221
  * ```js
@@ -17273,9 +17257,7 @@ const addCommunityMembers = async (communityId, userIds) => {
17273
17257
  const { data } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
17274
17258
  if (client.cache)
17275
17259
  ingestInCache(data);
17276
- fireEvent('community.userAdded', {
17277
- communities: data.communities,
17278
- });
17260
+ fireEvent('community.userAdded', data);
17279
17261
  const { communityUsers } = data;
17280
17262
  return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
17281
17263
  communityUser.communityMembership === 'member');
@@ -17302,9 +17284,7 @@ const removeCommunityMembers = async (communityId, userIds) => {
17302
17284
  const { data } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
17303
17285
  if (client.cache)
17304
17286
  ingestInCache(data);
17305
- fireEvent('community.userRemoved', {
17306
- communities: data.communities,
17307
- });
17287
+ fireEvent('community.userRemoved', data);
17308
17288
  const { communityUsers } = data;
17309
17289
  return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
17310
17290
  communityUser.communityMembership !== 'member');
@@ -17381,7 +17361,7 @@ const deletePost = async (postId, permanent = false) => {
17381
17361
  client.log('post/deletePost', postId);
17382
17362
  let post = await getPost(postId);
17383
17363
  // API-FIX: This endpoint has not been implemented yet.
17384
- await client.http.delete(`/api/v4/posts/${postId}`, {
17364
+ await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
17385
17365
  params: {
17386
17366
  postId,
17387
17367
  permanent,
@@ -17509,8 +17489,9 @@ queryComments.locally = (query) => {
17509
17489
  const getComments = async (commentIds) => {
17510
17490
  const client = getActiveClient();
17511
17491
  client.log('comment/getComments', commentIds);
17492
+ const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
17512
17493
  // API-FIX: endpoint should not be /list, parameters should be querystring.
17513
- const { data } = await client.http.get(`/api/v3/comments/list`, { params: { commentIds } });
17494
+ const { data } = await client.http.get(`/api/v3/comments/list`, { params: { commentIds: encodedCommentIds } });
17514
17495
  const cachedAt = client.cache && Date.now();
17515
17496
  if (client.cache)
17516
17497
  ingestInCache(data, { cachedAt });
@@ -17572,7 +17553,7 @@ const getComment = async (commentId) => {
17572
17553
  let data;
17573
17554
  try {
17574
17555
  // API-FIX: endpoint should not be /list, parameters should be querystring.
17575
- const response = await client.http.get(`/api/v3/comments/${commentId}`);
17556
+ const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
17576
17557
  data = response.data;
17577
17558
  }
17578
17559
  catch (error) {
@@ -17668,7 +17649,7 @@ const createComment = async (bundle) => {
17668
17649
  const updateComment = async (commentId, patch) => {
17669
17650
  const client = getActiveClient();
17670
17651
  client.log('user/updateComment', patch);
17671
- const { data } = await client.http.put(`/api/v3/comments/${commentId}`, patch);
17652
+ const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
17672
17653
  const cachedAt = client.cache && Date.now();
17673
17654
  if (client.cache)
17674
17655
  ingestInCache(data, { cachedAt });
@@ -17699,7 +17680,7 @@ const deleteComment = async (commentId, permanent = false) => {
17699
17680
  client.log('comment/deleteComment', commentId);
17700
17681
  const comment = await getComment(commentId);
17701
17682
  // API-FIX: This endpoint has not been implemented yet.
17702
- await client.http.delete(`/api/v4/comments/${commentId}`, {
17683
+ await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
17703
17684
  params: {
17704
17685
  commentId,
17705
17686
  permanent,
@@ -17902,16 +17883,12 @@ const createPostEventSubscriber = (event, callback) => {
17902
17883
  callback(payload.posts[0]);
17903
17884
  }
17904
17885
  else {
17905
- const cached = pullFromCache(['post', 'get', payload.posts[0].postId]);
17906
17886
  const { communities } = payload, others = __rest(payload, ["communities"]);
17907
17887
  ingestInCache(others);
17908
- if (communities === null || communities === void 0 ? void 0 : communities[0]) {
17888
+ if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['post.updated'].includes(event)) {
17909
17889
  fireEvent('community.updated', { communities });
17910
17890
  }
17911
17891
  const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
17912
- if (cached && isMatch(cached.data, post.data)) {
17913
- return;
17914
- }
17915
17892
  if (['post.created', 'post.approved', 'post.declined'].includes(event)) {
17916
17893
  let queries = (_a = queryCache(['post', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.targetId) === post.data.targetId; });
17917
17894
  if (event === 'post.declined') {
@@ -18067,14 +18044,10 @@ const onPostReactionAdded = (callback) => {
18067
18044
  callback(payload.posts[0]);
18068
18045
  }
18069
18046
  else {
18070
- const cached = pullFromCache(['post', 'get', payload.posts[0].postId]);
18071
18047
  preparePayloadForCache('post.addReaction', payload);
18072
18048
  const postPayload = __rest(payload, ["reactor"]);
18073
18049
  ingestInCache(postPayload);
18074
18050
  const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
18075
- if (cached && isMatch(cached.data, post.data)) {
18076
- return;
18077
- }
18078
18051
  callback(post.data);
18079
18052
  }
18080
18053
  };
@@ -18103,14 +18076,10 @@ const onPostReactionRemoved = (callback) => {
18103
18076
  callback(payload.posts[0]);
18104
18077
  }
18105
18078
  else {
18106
- const cached = pullFromCache(['post', 'get', payload.posts[0].postId]);
18107
18079
  preparePayloadForCache('post.removeReaction', payload);
18108
18080
  const postPayload = __rest(payload, ["reactor"]);
18109
18081
  ingestInCache(postPayload);
18110
18082
  const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
18111
- if (cached && isMatch(cached.data, post.data)) {
18112
- return;
18113
- }
18114
18083
  callback(post.data);
18115
18084
  }
18116
18085
  };
@@ -18122,15 +18091,12 @@ const createCommentEventSubscriber = (event, callback) => {
18122
18091
  const filter = (payload) => {
18123
18092
  var _a;
18124
18093
  if (!client.cache) {
18094
+ // TODO: here we are missing specific properties here!
18125
18095
  callback(payload.comments[0]);
18126
18096
  }
18127
18097
  else {
18128
- const cached = pullFromCache(['comment', 'get', payload.comments[0].commentId]);
18129
18098
  ingestInCache(payload);
18130
18099
  const comment = pullFromCache(['comment', 'get', payload.comments[0].commentId]);
18131
- if (cached && isMatch(cached.data, comment.data)) {
18132
- return;
18133
- }
18134
18100
  if (['comment.created'].includes(event)) {
18135
18101
  const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
18136
18102
  queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
@@ -18248,14 +18214,10 @@ const onCommentReactionAdded = (callback) => {
18248
18214
  callback(payload.comments[0]);
18249
18215
  }
18250
18216
  else {
18251
- const cached = pullFromCache(['comment', 'get', payload.comments[0].commentId]);
18252
18217
  preparePayloadForCache('comment.addReaction', payload);
18253
18218
  const commentPayload = __rest(payload, ["reactor"]);
18254
18219
  ingestInCache(commentPayload);
18255
18220
  const comment = pullFromCache(['comment', 'get', payload.comments[0].commentId]);
18256
- if (cached && isMatch(cached.data, comment.data)) {
18257
- return;
18258
- }
18259
18221
  callback(comment.data);
18260
18222
  }
18261
18223
  };
@@ -18284,14 +18246,10 @@ const onCommentReactionRemoved = (callback) => {
18284
18246
  callback(payload.comments[0]);
18285
18247
  }
18286
18248
  else {
18287
- const cached = pullFromCache(['comment', 'get', payload.comments[0].commentId]);
18288
18249
  preparePayloadForCache('comment.removeReaction', payload);
18289
18250
  const commentPayload = __rest(payload, ["reactor"]);
18290
18251
  ingestInCache(commentPayload);
18291
18252
  const comment = pullFromCache(['comment', 'get', payload.comments[0].commentId]);
18292
- if (cached && isMatch(cached.data, comment.data)) {
18293
- return;
18294
- }
18295
18253
  callback(comment.data);
18296
18254
  }
18297
18255
  };
@@ -18380,12 +18338,12 @@ const createReport = async (referenceType, referenceId) => {
18380
18338
  const client = getActiveClient();
18381
18339
  client.log('report/createReport', { referenceType, referenceId });
18382
18340
  const { domainName } = REFERENCE_TYPES[referenceType];
18383
- const { data } = await client.http.post(`/api/v3/${domainName}/${referenceId}/flag`);
18341
+ const { data } = await client.http.post(`/api/v3/${domainName}/${(encodeURIComponent(referenceId))}/flag`);
18384
18342
  if (client.cache)
18385
18343
  ingestInCache(data);
18386
18344
  const event = referenceType === 'message'
18387
18345
  ? 'v3.message.didUpdate'
18388
- : `${referenceType}.updated`;
18346
+ : `${referenceType}.flagged`;
18389
18347
  fireEvent(event, data);
18390
18348
  return !!data;
18391
18349
  };
@@ -18407,12 +18365,12 @@ const deleteReport = async (referenceType, referenceId) => {
18407
18365
  const client = getActiveClient();
18408
18366
  client.log('report/deleteReport', { referenceType, referenceId });
18409
18367
  const { domainName } = REFERENCE_TYPES[referenceType];
18410
- const { data } = await client.http.delete(`/api/v3/${domainName}/${referenceId}/unflag`);
18368
+ const { data } = await client.http.delete(`/api/v3/${domainName}/${encodeURIComponent(referenceId)}/unflag`);
18411
18369
  if (client.cache)
18412
18370
  ingestInCache(data);
18413
18371
  const event = referenceType === 'message'
18414
18372
  ? 'v3.message.didUpdate'
18415
- : `${referenceType}.updated`;
18373
+ : `${referenceType}.unflagged`;
18416
18374
  fireEvent(event, data);
18417
18375
  return !!data;
18418
18376
  };
@@ -18515,8 +18473,9 @@ queryChannels.locally = (query) => {
18515
18473
  const getChannels = async (channelIds) => {
18516
18474
  const client = getActiveClient();
18517
18475
  client.log('channel/getChannels', channelIds);
18476
+ const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
18518
18477
  // API-FIX: endpoint should not be /list, parameters should be querystring.
18519
- const { data } = await client.http.get(`/api/v3/channels/list`, { params: { channelIds } });
18478
+ const { data } = await client.http.get(`/api/v3/channels/list`, { params: { channelIds: encodedChannelIds } });
18520
18479
  const cachedAt = client.cache && Date.now();
18521
18480
  if (client.cache)
18522
18481
  ingestInCache(data, { cachedAt });
@@ -18575,7 +18534,7 @@ const getChannel = async (channelId) => {
18575
18534
  const client = getActiveClient();
18576
18535
  client.log('channel/getChannel', channelId);
18577
18536
  // API-FIX: endpoint should not be /list, parameters should be querystring.
18578
- const { data } = await client.http.get(`/api/v3/channels/${channelId}`);
18537
+ const { data } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}`);
18579
18538
  const cachedAt = client.cache && Date.now();
18580
18539
  if (client.cache)
18581
18540
  ingestInCache(data, { cachedAt });
@@ -18664,7 +18623,7 @@ const createChannel = async (bundle) => {
18664
18623
  const updateChannel = async (channelId, patch) => {
18665
18624
  const client = getActiveClient();
18666
18625
  client.log('channel/updateChannel', channelId, patch);
18667
- const { data } = await client.http.put(`/api/v3/channels/${channelId}`, patch);
18626
+ const { data } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}`, patch);
18668
18627
  const cachedAt = client.cache && Date.now();
18669
18628
  if (client.cache)
18670
18629
  ingestInCache(data, { cachedAt });
@@ -18693,7 +18652,7 @@ const deleteChannel = async (channelId) => {
18693
18652
  const client = getActiveClient();
18694
18653
  client.log('channel/deleteChannel', channelId);
18695
18654
  // API-FIX: This endpoint has not been implemented yet.
18696
- await client.http.delete(`/api/v3/channels/${channelId}`);
18655
+ await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}`);
18697
18656
  const deleted = await getChannel(channelId);
18698
18657
  // no need for event, fired by server
18699
18658
  return deleted.data;
@@ -18716,7 +18675,7 @@ const deleteChannel = async (channelId) => {
18716
18675
  const joinChannel = async (channelId) => {
18717
18676
  const client = getActiveClient();
18718
18677
  client.log('channel/joinChannel', channelId);
18719
- const { data } = await client.http.post(`/api/v3/channels/${channelId}/join`);
18678
+ const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/join`);
18720
18679
  if (client.cache)
18721
18680
  ingestInCache(data);
18722
18681
  const { channelUsers } = data;
@@ -18741,7 +18700,7 @@ const joinChannel = async (channelId) => {
18741
18700
  const leaveChannel = async (channelId) => {
18742
18701
  const client = getActiveClient();
18743
18702
  client.log('channel/leaveChannel', channelId);
18744
- const { data } = await client.http.delete(`/api/v3/channels/${channelId}/leave`);
18703
+ const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/leave`);
18745
18704
  if (client.cache)
18746
18705
  ingestInCache(data);
18747
18706
  const { channelUsers } = data;
@@ -18767,19 +18726,20 @@ const queryChannelMembers = async (query) => {
18767
18726
  const client = getActiveClient();
18768
18727
  client.log('channel/queryChannelMembers', query);
18769
18728
  const _a = query !== null && query !== void 0 ? query : {}, { page, channelId, membership } = _a, params = __rest(_a, ["page", "channelId", "membership"]);
18770
- const { data } = await client.http.get(`/api/v3/channels/${channelId}/users`, {
18729
+ const { data } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, {
18771
18730
  params: Object.assign(Object.assign({}, params), { filter: membership, options: {
18772
18731
  token: toToken(page, 'skiplimit'),
18773
18732
  } }),
18774
18733
  });
18775
18734
  const { paging } = data, payload = __rest(data, ["paging"]);
18776
18735
  const { channelUsers } = payload;
18736
+ const cachedAt = client.cache && Date.now();
18777
18737
  if (client.cache) {
18778
18738
  ingestInCache(payload);
18779
18739
  }
18780
18740
  const nextPage = toPage(paging.next);
18781
18741
  const prevPage = toPage(paging.previous);
18782
- return { data: channelUsers, nextPage, prevPage };
18742
+ return { data: channelUsers, cachedAt, nextPage, prevPage };
18783
18743
  };
18784
18744
  /**
18785
18745
  * ```js
@@ -18818,7 +18778,7 @@ queryChannelMembers.locally = (query) => {
18818
18778
  const addChannelMembers = async (channelId, userIds) => {
18819
18779
  const client = getActiveClient();
18820
18780
  client.log('channel/addChannelMembers', channelId, userIds);
18821
- const { data } = await client.http.post(`/api/v3/channels/${channelId}/users`, { channelId, userIds });
18781
+ const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { channelId, userIds });
18822
18782
  if (client.cache)
18823
18783
  ingestInCache(data);
18824
18784
  fireEvent('v3.channel.didAddUsers', {
@@ -18846,7 +18806,7 @@ const addChannelMembers = async (channelId, userIds) => {
18846
18806
  const removeChannelMembers = async (channelId, userIds) => {
18847
18807
  const client = getActiveClient();
18848
18808
  client.log('channel/removeChannelMembers', channelId, userIds);
18849
- const { data } = await client.http.delete(`/api/v3/channels/${channelId}/users`, { data: { channelId, userIds } });
18809
+ const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { data: { channelId, userIds } });
18850
18810
  if (client.cache)
18851
18811
  ingestInCache(data);
18852
18812
  fireEvent('v3.channel.didRemoveUsers', {
@@ -18875,7 +18835,7 @@ const removeChannelMembers = async (channelId, userIds) => {
18875
18835
  const addChannelMembersRole = async (channelId, roleId, userIds) => {
18876
18836
  const client = getActiveClient();
18877
18837
  client.log('channel/addChannelMembersRole', channelId, roleId, userIds);
18878
- const { data } = await client.http.post(`/api/v3/channels/${channelId}/users/roles`, { channelId, role: roleId, userIds });
18838
+ const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { channelId, role: roleId, userIds });
18879
18839
  if (client.cache)
18880
18840
  ingestInCache(data);
18881
18841
  const { channelUsers } = data;
@@ -18901,7 +18861,7 @@ const addChannelMembersRole = async (channelId, roleId, userIds) => {
18901
18861
  const removeChannelMembersRole = async (channelId, roleId, userIds) => {
18902
18862
  const client = getActiveClient();
18903
18863
  client.log('channel/removeChannelMembersRole', channelId, roleId, userIds);
18904
- const { data } = await client.http.delete(`/api/v3/channels/${channelId}/users/roles`, { data: { channelId, role: roleId, userIds } });
18864
+ const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { data: { channelId, role: roleId, userIds } });
18905
18865
  if (client.cache)
18906
18866
  ingestInCache(data);
18907
18867
  const { channelUsers } = data;
@@ -19252,15 +19212,12 @@ const createCommunityEventSubscriber = (event, callback) => {
19252
19212
  const client = getActiveClient();
19253
19213
  const filter = (payload) => {
19254
19214
  if (!client.cache) {
19215
+ // TODO: here we are missing specific properties here!
19255
19216
  callback(payload.communities[0]);
19256
19217
  }
19257
19218
  else {
19258
- const cached = pullFromCache(['community', 'get', payload.communities[0].communityId]);
19259
19219
  ingestInCache(payload);
19260
19220
  const community = pullFromCache(['community', 'get', payload.communities[0].communityId]);
19261
- if (cached && isMatch(cached.data, community === null || community === void 0 ? void 0 : community.data)) {
19262
- return;
19263
- }
19264
19221
  callback(community.data);
19265
19222
  }
19266
19223
  };
@@ -19295,24 +19252,20 @@ function getEventRelatedMember(event, payload) {
19295
19252
  const createCommunityMemberEventSubscriber = (event, callback) => {
19296
19253
  const client = getActiveClient();
19297
19254
  const filter = (payload) => {
19298
- const cachedCommunity = pullFromCache(['community', 'get', payload.communities[0].communityId]);
19299
- const cachedMember = pullFromCache([
19300
- 'communityUsers',
19301
- 'get',
19302
- getResolver('communityUsers')(getEventRelatedMember(event, payload))
19303
- ]);
19304
- ingestInCache(payload);
19305
- const community = pullFromCache(['community', 'get', payload.communities[0].communityId]);
19306
- const member = pullFromCache([
19307
- 'communityUsers',
19308
- 'get',
19309
- getResolver('communityUsers')(getEventRelatedMember(event, payload))
19310
- ]);
19311
- if (cachedCommunity && isMatch(cachedCommunity.data, community.data)
19312
- && cachedMember && isMatch(cachedMember.data, member.data)) {
19313
- return;
19255
+ if (!client.cache) {
19256
+ // TODO: here we are missing specific properties here!
19257
+ callback(payload.communities[0], getEventRelatedMember(event, payload));
19258
+ }
19259
+ else {
19260
+ ingestInCache(payload);
19261
+ const community = pullFromCache(['community', 'get', payload.communities[0].communityId]);
19262
+ const member = pullFromCache([
19263
+ 'communityUsers',
19264
+ 'get',
19265
+ getResolver('communityUsers')(getEventRelatedMember(event, payload))
19266
+ ]);
19267
+ callback(community.data, member.data);
19314
19268
  }
19315
- callback(community.data, member.data);
19316
19269
  };
19317
19270
  return createEventSubscriber(client, event, event, filter);
19318
19271
  };
@@ -19531,17 +19484,56 @@ const observeCommunity = (communityId, callback) => {
19531
19484
  const queryGlobalFeed = async (query) => {
19532
19485
  const client = getActiveClient();
19533
19486
  client.log('feed/queryGlobalFeed', query);
19534
- const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
19535
- const { data } = await client.http.get(`/api/v4/me/global-feeds`, { params: Object.assign(Object.assign({}, params), { options: {
19487
+ const _a = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _a, params = __rest(_a, ["useCustomRanking", "page"]);
19488
+ const { data } = await client.http.get(useCustomRanking ? `/api/v5/me/global-feeds` : `/api/v4/me/global-feeds`, { params: Object.assign(Object.assign({}, params), { options: {
19536
19489
  token: toToken(page, 'skiplimit')
19537
19490
  } }) });
19538
19491
  const { paging } = data, payload = __rest(data, ["paging"]);
19539
19492
  const { posts } = payload;
19540
- if (client.cache)
19493
+ const cachedAt = client.cache && Date.now();
19494
+ if (client.cache) {
19541
19495
  ingestInCache(payload);
19496
+ const cacheKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) })];
19497
+ pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
19498
+ }
19542
19499
  const nextPage = toPage(paging.next);
19543
19500
  const prevPage = toPage(paging.previous);
19544
- return { data: posts, prevPage, nextPage };
19501
+ return { data: posts, cachedAt, prevPage, nextPage };
19502
+ };
19503
+ /**
19504
+ * ```js
19505
+ * import { queryGlobalFeed } from '@amityco/ts-sdk'
19506
+ * const posts = await queryGlobalFeed.locally()
19507
+ * ```
19508
+ *
19509
+ * Queries a paginable list of {@link Amity.Post} objects from cache
19510
+ *
19511
+ * @param query The query parameters
19512
+ * @returns A page of {@link Amity.Post} objects
19513
+ *
19514
+ * @category Feed API
19515
+ * @async
19516
+ **/
19517
+ queryGlobalFeed.locally = (query) => {
19518
+ var _a, _b;
19519
+ const client = getActiveClient();
19520
+ client.log('post/queryGlobalFeed.locally', query);
19521
+ if (!client.cache)
19522
+ return;
19523
+ const _c = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _c, params = __rest(_c, ["useCustomRanking", "page"]);
19524
+ const queryKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) })];
19525
+ const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
19526
+ if (!(data === null || data === void 0 ? void 0 : data.posts.length))
19527
+ return;
19528
+ const posts = data.posts
19529
+ .map(postId => pullFromCache(['post', 'get', postId]))
19530
+ .filter(Boolean)
19531
+ .map(({ data }) => data);
19532
+ const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
19533
+ const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
19534
+ return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
19535
+ ? { data: posts, cachedAt, prevPage, nextPage }
19536
+ : undefined;
19545
19537
  };
19546
19538
 
19547
19539
  /**
@@ -20002,4 +19994,4 @@ const onStreamRecorded = (callback) => {
20002
19994
  return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
20003
19995
  };
20004
19996
 
20005
- export { SubscriptionLevels, VERSION$1 as VERSION, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRole, addReaction, backupCache, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createMessage, createPost, createQuery, createReport, createStream, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, getActiveClient, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getMessage, getMessages, getPost, getPostTopic, getPosts, getRole, getStream, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeMessage, observeMessages, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onMemberAdded, onMemberRemoved, onMessageCreated, onMessageDeleted, onMessageUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserFlagCleared, onUserFlagged, onUserUnflagged, onUserUpdated, pullFromCache, pushToCache, queryCache, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRole, removeReaction, restoreCache, runQuery, sliceByPaging, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser, upsertInCache, wipeCache };
19997
+ export { SubscriptionLevels, VERSION$1 as VERSION, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRole, addReaction, backupCache, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createMessage, createPost, createQuery, createReport, createStream, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, getActiveClient, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getMessage, getMessages, getPost, getPostTopic, getPosts, getRole, getStream, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeMessage, observeMessages, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onMemberAdded, onMemberRemoved, onMessageCreated, onMessageDeleted, onMessageUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserFlagCleared, onUserFlagged, onUserUnflagged, onUserUpdated, pullFromCache, pushToCache, queryCache, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRole, removeReaction, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser, upsertInCache, wipeCache };