@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.cjs.js CHANGED
@@ -9,7 +9,6 @@ var HttpAgent = require('agentkeepalive');
9
9
  var io = require('socket.io-client');
10
10
  var mitt = require('mitt');
11
11
  var AsyncStorage = require('@react-native-async-storage/async-storage');
12
- var isMatch = require('lodash.ismatch');
13
12
 
14
13
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
15
14
 
@@ -19,13 +18,15 @@ var HttpAgent__default = /*#__PURE__*/_interopDefaultLegacy(HttpAgent);
19
18
  var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
20
19
  var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt);
21
20
  var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
22
- var isMatch__default = /*#__PURE__*/_interopDefaultLegacy(isMatch);
23
21
 
24
- var _a;
25
- // used in createClient
26
- const VERSION$1 = (_a = 'v0.0.1-beta.10-cjs') !== null && _a !== void 0 ? _a : '__dev__';
22
+ var _a$1;
23
+ const theGlobal = globalThis || global || window;
24
+ const { process: safeProcess = {} } = theGlobal;
25
+ const isProduction = ((_a$1 = safeProcess.env) === null || _a$1 === void 0 ? void 0 : _a$1.NODE_ENV) === 'production';
26
+
27
+ var _a, _b;
28
+ const VERSION$1 = (_b = (_a = safeProcess.env) === null || _a === void 0 ? void 0 : _a.VERSION) !== null && _b !== void 0 ? _b : '__dev__';
27
29
 
28
- // @ts-ignore
29
30
  /**
30
31
  * Type guard to find if the a given decoded backend token uses "skip/limit" pagination style
31
32
  *
@@ -43,7 +44,7 @@ const isSkipLimit = (json) => (['skip', 'limit'].some(prop => prop in json));
43
44
  *
44
45
  * @hidden
45
46
  */
46
- const isAfterBefore = (json) => (['after', 'before', 'first', 'last'].some(prop => prop in json));
47
+ const isAfterBefore = (json) => (['after', 'before', 'first', 'last', 'limit'].some(prop => prop in json));
47
48
  /**
48
49
  * Type guard to find if the a given decoded backend token uses v4 or newer "after/before" pagination style
49
50
  *
@@ -52,7 +53,7 @@ const isAfterBefore = (json) => (['after', 'before', 'first', 'last'].some(prop
52
53
  *
53
54
  * @hidden
54
55
  */
55
- const isAfterBeforeRaw = (json) => (['after', 'before'].some(prop => prop in json));
56
+ const isAfterBeforeRaw = (json) => ('limit' in json);
56
57
  /**
57
58
  * Type guard to find if the a given object is wrapped around Amity.Paged<>
58
59
  *
@@ -87,7 +88,7 @@ const toToken = (paging, style) => {
87
88
  limit: paging.limit,
88
89
  };
89
90
  }
90
- else if (style === 'afterbefore') {
91
+ else if (style === 'afterbefore' && isAfterBefore(paging)) {
91
92
  /*
92
93
  Caution: this testing style is only valid because
93
94
  our backend expects nothing else than a number as
@@ -173,35 +174,6 @@ const toPageRaw = (token) => {
173
174
  return json;
174
175
  }
175
176
  return null;
176
- };
177
- /**
178
- * Slices a collection according to its paging
179
- *
180
- * @param type the type of collection (for unique id identification with after/before)
181
- * @param collection the collection to slice
182
- * @param paging the paging object
183
- * @returns the sliced collection according to the paging definition
184
- *
185
- * @hidden
186
- */
187
- const sliceByPaging = (type, collection, page) => {
188
- console.log('slice by paging', page);
189
- if (!page)
190
- return collection.slice();
191
- let start = 0;
192
- let end = undefined;
193
- // next page behavior
194
- if (page.after) {
195
- start = page.after;
196
- end = start + page.limit;
197
- // prev page behavior
198
- }
199
- else if (page.before) {
200
- end = page.before + 1;
201
- start = end > page.limit ? end - page.limit : 0;
202
- }
203
- const paged = collection.slice(start, end);
204
- return paged.length === page.limit ? paged : undefined;
205
177
  };
206
178
 
207
179
  /**
@@ -515,7 +487,7 @@ const setActiveClient = (client) => {
515
487
  */
516
488
  const createLogger = (session) => {
517
489
  const active = (`${session === null || session === void 0 ? void 0 : session.trim()}`.length > 0
518
- && process.env.NODE_ENV !== 'production');
490
+ && !isProduction);
519
491
  const logger = debug__default['default'](session);
520
492
  const print = (topic, ...args) => {
521
493
  active && logger(topic, args);
@@ -14742,6 +14714,22 @@ const createMqttTransport = (endpoint) => {
14742
14714
  };
14743
14715
  };
14744
14716
 
14717
+ let tasks = [];
14718
+ let timer;
14719
+ /**
14720
+ * Add a function to run just before the next tick
14721
+ *
14722
+ * @param task function to schedule for later execution
14723
+ */
14724
+ const scheduleTask = (task) => {
14725
+ clearTimeout(timer);
14726
+ tasks.push(task);
14727
+ timer = setTimeout(() => {
14728
+ tasks.forEach(fn => fn());
14729
+ tasks = [];
14730
+ }, 0);
14731
+ };
14732
+
14745
14733
  // need to sync up the list
14746
14734
  const WS_EVENTS = [
14747
14735
  'disconnected',
@@ -14832,7 +14820,7 @@ const createEventSubscriber = (client, namespace, event, fn) => {
14832
14820
  */
14833
14821
  const fireEvent = (event, payload) => {
14834
14822
  const { emitter } = getActiveClient();
14835
- setTimeout(() => { emitter.emit(event, payload); }, 0);
14823
+ scheduleTask(() => { emitter.emit(event, payload); });
14836
14824
  };
14837
14825
 
14838
14826
  /**
@@ -14906,13 +14894,11 @@ const disconnectClient = async () => {
14906
14894
  client.ws.removeAllListeners();
14907
14895
  client.mqtt.removeAllListeners();
14908
14896
  client.userId = undefined;
14909
- client.user = undefined;
14910
14897
  client.accessToken = undefined;
14911
14898
  return !client.ws.connected;
14912
14899
  };
14913
14900
 
14914
14901
  // TODO: find a way to uniquely identify the device
14915
- // import { getStorage } from './storage'
14916
14902
  /** @hidden */
14917
14903
  const VERSION = '11.0.0';
14918
14904
  /** @hidden */
@@ -14927,8 +14913,8 @@ const getDeviceId = () => {
14927
14913
  /** @hidden */
14928
14914
  const getDeviceModel = () => {
14929
14915
  var _a, _b;
14930
- if ((_a = process === null || process === void 0 ? void 0 : process.versions) === null || _a === void 0 ? void 0 : _a.node)
14931
- return process.versions.node;
14916
+ if ((_a = safeProcess.versions) === null || _a === void 0 ? void 0 : _a.node)
14917
+ return safeProcess.versions.node;
14932
14918
  if (navigator)
14933
14919
  return `${navigator.product.toLowerCase()}#${(_b = navigator.userAgent) !== null && _b !== void 0 ? _b : 'unknown_agent'}`;
14934
14920
  return 'unknown_model';
@@ -14992,7 +14978,7 @@ const EVENTS = [
14992
14978
  const onConnectionError = (callback) => {
14993
14979
  const client = getActiveClient();
14994
14980
  const subscribers = EVENTS.map(event => (createEventSubscriber(client, `client/onConnectionError(${event})`, event, (response) => {
14995
- const error = (response && 'code' in response)
14981
+ const error = (response === null || response === void 0 ? void 0 : response.code)
14996
14982
  ? new ASCError(response.message, response.code, "fatal" /* FATAL */)
14997
14983
  : new ASCConnectionError(event);
14998
14984
  callback(error);
@@ -15091,7 +15077,7 @@ const connectClient = async (params) => {
15091
15077
  unsubscribe();
15092
15078
  });
15093
15079
  client.userId = params.userId;
15094
- client.user = users[0];
15080
+ client._internalUserId = users[0]._id;
15095
15081
  client.accessToken = accessToken;
15096
15082
  return client.ws.connected;
15097
15083
  };
@@ -15153,11 +15139,11 @@ const getCommentTopic = ({ path }) => {
15153
15139
  let mqttAccessToken;
15154
15140
  let mqttUserId;
15155
15141
  function subscribeTopic(topic, callback) {
15156
- const { mqtt, emitter, accessToken, user } = getActiveClient();
15157
- if (mqttAccessToken !== accessToken || mqttUserId !== user._id) {
15142
+ const { mqtt, emitter, accessToken, _internalUserId } = getActiveClient();
15143
+ if (mqttAccessToken !== accessToken || mqttUserId !== _internalUserId) {
15158
15144
  mqttAccessToken = accessToken;
15159
- mqttUserId = user._id;
15160
- mqtt.connect({ accessToken: accessToken, userId: user._id });
15145
+ mqttUserId = _internalUserId;
15146
+ mqtt.connect({ accessToken: mqttAccessToken, userId: mqttUserId });
15161
15147
  proxyMqttEvents(mqtt, emitter);
15162
15148
  }
15163
15149
  return mqtt.subscribe(topic, callback);
@@ -15633,7 +15619,7 @@ const getUser = async (userId) => {
15633
15619
  const client = getActiveClient();
15634
15620
  client.log('user/getUser', userId);
15635
15621
  // API-FIX: endpoint should not be /list, parameters should be querystring.
15636
- const { data } = await client.http.get(`/api/v3/users/${userId}`);
15622
+ const { data } = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
15637
15623
  const cachedAt = client.cache && Date.now();
15638
15624
  if (client.cache)
15639
15625
  ingestInCache(data, { cachedAt });
@@ -15679,8 +15665,9 @@ getUser.locally = (userId) => {
15679
15665
  const getUsers = async (userIds) => {
15680
15666
  const client = getActiveClient();
15681
15667
  client.log('user/getUsers', userIds);
15668
+ const encodedUserIds = userIds.map(userId => encodeURIComponent(userId));
15682
15669
  // API-FIX: endpoint should not be /list, parameters should be querystring.
15683
- const { data } = await client.http.get(`/api/v3/users/list`, { params: { userIds } });
15670
+ const { data } = await client.http.get(`/api/v3/users/list`, { params: { userIds: encodedUserIds } });
15684
15671
  const cachedAt = client.cache && Date.now();
15685
15672
  if (client.cache)
15686
15673
  ingestInCache(data, { cachedAt });
@@ -16275,7 +16262,7 @@ const getMessage = async (messageId) => {
16275
16262
  const client = getActiveClient();
16276
16263
  client.log('message/getMessage', messageId);
16277
16264
  // API-FIX: endpoint should not be /list, parameters should be querystring.
16278
- const { data } = await client.http.get(`/api/v3/messages/${messageId}`);
16265
+ const { data } = await client.http.get(`/api/v3/messages/${encodeURIComponent(messageId)}`);
16279
16266
  const cachedAt = client.cache && Date.now();
16280
16267
  if (client.cache)
16281
16268
  ingestInCache(data, { cachedAt });
@@ -16534,7 +16521,7 @@ createMessage.optimistically = (bundle) => {
16534
16521
  const updateMessage = async (messageId, patch) => {
16535
16522
  const client = getActiveClient();
16536
16523
  client.log('user/updateMessage', patch);
16537
- const { data } = await client.http.put(`/api/v3/messages/${messageId}`, patch);
16524
+ const { data } = await client.http.put(`/api/v3/messages/${encodeURIComponent(messageId)}`, patch);
16538
16525
  const cachedAt = client.cache && Date.now();
16539
16526
  if (client.cache)
16540
16527
  ingestInCache(data, { cachedAt });
@@ -16596,7 +16583,7 @@ const deleteMessage = async (messageId) => {
16596
16583
  const client = getActiveClient();
16597
16584
  client.log('message/deleteMessage', messageId);
16598
16585
  // API-FIX: This endpoint has not been implemented yet.
16599
- await client.http.delete(`/api/v3/messages/${messageId}`);
16586
+ await client.http.delete(`/api/v3/messages/${encodeURIComponent(messageId)}`);
16600
16587
  const deleted = await getMessage(messageId);
16601
16588
  // no need for event, fired by server
16602
16589
  return deleted.data;
@@ -16650,11 +16637,11 @@ const queryPosts = async (query) => {
16650
16637
  const { page = { limit: 10 } } = query, params = __rest(query
16651
16638
  // API-FIX: parameters should be querystring. (1)
16652
16639
  // API-FIX: backend should answer Amity.Response (2)
16653
- // const { data } = await client.http.get<Amity.Response<Amity.PagedRawResponse<Amity.PostPayload>>>(
16640
+ // const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
16654
16641
  , ["page"]);
16655
16642
  // API-FIX: parameters should be querystring. (1)
16656
16643
  // API-FIX: backend should answer Amity.Response (2)
16657
- // const { data } = await client.http.get<Amity.Response<Amity.PagedRawResponse<Amity.PostPayload>>>(
16644
+ // const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
16658
16645
  const { data } = await client.http.get(`/api/v4/posts`, { params: Object.assign(Object.assign({}, params), { options: {
16659
16646
  token: toToken(page, 'afterbeforeraw'),
16660
16647
  } }), });
@@ -16725,8 +16712,9 @@ queryPosts.locally = (query) => {
16725
16712
  const getPosts = async (postIds) => {
16726
16713
  const client = getActiveClient();
16727
16714
  client.log('post/getPosts', postIds);
16715
+ const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
16728
16716
  // API-FIX: endpoint should not be /list, parameters should be querystring.
16729
- const { data } = await client.http.get(`/api/v3/posts/list`, { params: { postIds } });
16717
+ const { data } = await client.http.get(`/api/v3/posts/list`, { params: { postIds: encodedPostIds } });
16730
16718
  const cachedAt = client.cache && Date.now();
16731
16719
  if (client.cache)
16732
16720
  ingestInCache(data, { cachedAt });
@@ -16788,7 +16776,7 @@ const getPost = async (postId) => {
16788
16776
  let data;
16789
16777
  try {
16790
16778
  // API-FIX: endpoint should not be /list, parameters should be querystring.
16791
- const response = await client.http.get(`/api/v3/posts/${postId}`);
16779
+ const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
16792
16780
  data = response.data;
16793
16781
  }
16794
16782
  catch (error) {
@@ -16855,13 +16843,12 @@ const createPost = async (bundle) => {
16855
16843
  const client = getActiveClient();
16856
16844
  client.log('post/createPost', bundle);
16857
16845
  // API-FIX: backend rejects that we pass the dataType manually T_T
16858
- if (!bundle.dataType || ['text', 'image', 'file'].includes(bundle.dataType))
16846
+ if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType))
16859
16847
  delete bundle.dataType;
16860
- const { data } = await client.http.post('/api/v3/posts', bundle);
16848
+ const { data } = await client.http.post('/api/v4/posts', bundle);
16861
16849
  const cachedAt = client.cache && Date.now();
16862
16850
  if (client.cache)
16863
16851
  ingestInCache(data, { cachedAt });
16864
- fireEvent('community.updated', { communities: data.communities });
16865
16852
  fireEvent('post.created', data);
16866
16853
  const { posts } = data;
16867
16854
  return {
@@ -16890,7 +16877,7 @@ const createPost = async (bundle) => {
16890
16877
  const updatePost = async (postId, patch) => {
16891
16878
  const client = getActiveClient();
16892
16879
  client.log('user/updatePost', patch);
16893
- const { data } = await client.http.put(`/api/v3/posts/${postId}`, patch);
16880
+ const { data } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
16894
16881
  const cachedAt = client.cache && Date.now();
16895
16882
  if (client.cache)
16896
16883
  ingestInCache(data, { cachedAt });
@@ -17177,9 +17164,7 @@ const joinCommunity = async (communityId) => {
17177
17164
  const cachedAt = client.cache && Date.now();
17178
17165
  if (client.cache)
17179
17166
  ingestInCache(data, { cachedAt });
17180
- fireEvent('community.joined', {
17181
- communities: data.communities
17182
- });
17167
+ fireEvent('community.joined', data);
17183
17168
  const { communityUsers } = data;
17184
17169
  return !!communityUsers.find(communityUser => (communityUser.communityId === communityId
17185
17170
  && communityUser.communityMembership === 'member'));
@@ -17206,9 +17191,7 @@ const leaveCommunity = async (communityId) => {
17206
17191
  const cachedAt = client.cache && Date.now();
17207
17192
  if (client.cache)
17208
17193
  ingestInCache(data, { cachedAt });
17209
- fireEvent('community.left', {
17210
- communities: data.communities,
17211
- });
17194
+ fireEvent('community.left', data);
17212
17195
  const { communityUsers } = data;
17213
17196
  return !!communityUsers.find(communityUser => (communityUser.communityId === communityId
17214
17197
  && communityUser.communityMembership !== 'member'));
@@ -17245,7 +17228,7 @@ const queryCommunityMembers = async (query) => {
17245
17228
  }
17246
17229
  const nextPage = toPage(paging.next);
17247
17230
  const prevPage = toPage(paging.previous);
17248
- return { data: communityUsers, nextPage, prevPage };
17231
+ return { data: communityUsers, cachedAt, nextPage, prevPage };
17249
17232
  };
17250
17233
  /**
17251
17234
  * ```js
@@ -17287,9 +17270,7 @@ const addCommunityMembers = async (communityId, userIds) => {
17287
17270
  const { data } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
17288
17271
  if (client.cache)
17289
17272
  ingestInCache(data);
17290
- fireEvent('community.userAdded', {
17291
- communities: data.communities,
17292
- });
17273
+ fireEvent('community.userAdded', data);
17293
17274
  const { communityUsers } = data;
17294
17275
  return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
17295
17276
  communityUser.communityMembership === 'member');
@@ -17316,9 +17297,7 @@ const removeCommunityMembers = async (communityId, userIds) => {
17316
17297
  const { data } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
17317
17298
  if (client.cache)
17318
17299
  ingestInCache(data);
17319
- fireEvent('community.userRemoved', {
17320
- communities: data.communities,
17321
- });
17300
+ fireEvent('community.userRemoved', data);
17322
17301
  const { communityUsers } = data;
17323
17302
  return !!communityUsers.find(communityUser => communityUser.communityId === communityId &&
17324
17303
  communityUser.communityMembership !== 'member');
@@ -17395,7 +17374,7 @@ const deletePost = async (postId, permanent = false) => {
17395
17374
  client.log('post/deletePost', postId);
17396
17375
  let post = await getPost(postId);
17397
17376
  // API-FIX: This endpoint has not been implemented yet.
17398
- await client.http.delete(`/api/v4/posts/${postId}`, {
17377
+ await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
17399
17378
  params: {
17400
17379
  postId,
17401
17380
  permanent,
@@ -17523,8 +17502,9 @@ queryComments.locally = (query) => {
17523
17502
  const getComments = async (commentIds) => {
17524
17503
  const client = getActiveClient();
17525
17504
  client.log('comment/getComments', commentIds);
17505
+ const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
17526
17506
  // API-FIX: endpoint should not be /list, parameters should be querystring.
17527
- const { data } = await client.http.get(`/api/v3/comments/list`, { params: { commentIds } });
17507
+ const { data } = await client.http.get(`/api/v3/comments/list`, { params: { commentIds: encodedCommentIds } });
17528
17508
  const cachedAt = client.cache && Date.now();
17529
17509
  if (client.cache)
17530
17510
  ingestInCache(data, { cachedAt });
@@ -17586,7 +17566,7 @@ const getComment = async (commentId) => {
17586
17566
  let data;
17587
17567
  try {
17588
17568
  // API-FIX: endpoint should not be /list, parameters should be querystring.
17589
- const response = await client.http.get(`/api/v3/comments/${commentId}`);
17569
+ const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
17590
17570
  data = response.data;
17591
17571
  }
17592
17572
  catch (error) {
@@ -17682,7 +17662,7 @@ const createComment = async (bundle) => {
17682
17662
  const updateComment = async (commentId, patch) => {
17683
17663
  const client = getActiveClient();
17684
17664
  client.log('user/updateComment', patch);
17685
- const { data } = await client.http.put(`/api/v3/comments/${commentId}`, patch);
17665
+ const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
17686
17666
  const cachedAt = client.cache && Date.now();
17687
17667
  if (client.cache)
17688
17668
  ingestInCache(data, { cachedAt });
@@ -17713,7 +17693,7 @@ const deleteComment = async (commentId, permanent = false) => {
17713
17693
  client.log('comment/deleteComment', commentId);
17714
17694
  const comment = await getComment(commentId);
17715
17695
  // API-FIX: This endpoint has not been implemented yet.
17716
- await client.http.delete(`/api/v4/comments/${commentId}`, {
17696
+ await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
17717
17697
  params: {
17718
17698
  commentId,
17719
17699
  permanent,
@@ -17916,16 +17896,12 @@ const createPostEventSubscriber = (event, callback) => {
17916
17896
  callback(payload.posts[0]);
17917
17897
  }
17918
17898
  else {
17919
- const cached = pullFromCache(['post', 'get', payload.posts[0].postId]);
17920
17899
  const { communities } = payload, others = __rest(payload, ["communities"]);
17921
17900
  ingestInCache(others);
17922
- if (communities === null || communities === void 0 ? void 0 : communities[0]) {
17901
+ if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['post.updated'].includes(event)) {
17923
17902
  fireEvent('community.updated', { communities });
17924
17903
  }
17925
17904
  const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
17926
- if (cached && isMatch__default['default'](cached.data, post.data)) {
17927
- return;
17928
- }
17929
17905
  if (['post.created', 'post.approved', 'post.declined'].includes(event)) {
17930
17906
  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; });
17931
17907
  if (event === 'post.declined') {
@@ -18081,14 +18057,10 @@ const onPostReactionAdded = (callback) => {
18081
18057
  callback(payload.posts[0]);
18082
18058
  }
18083
18059
  else {
18084
- const cached = pullFromCache(['post', 'get', payload.posts[0].postId]);
18085
18060
  preparePayloadForCache('post.addReaction', payload);
18086
18061
  const postPayload = __rest(payload, ["reactor"]);
18087
18062
  ingestInCache(postPayload);
18088
18063
  const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
18089
- if (cached && isMatch__default['default'](cached.data, post.data)) {
18090
- return;
18091
- }
18092
18064
  callback(post.data);
18093
18065
  }
18094
18066
  };
@@ -18117,14 +18089,10 @@ const onPostReactionRemoved = (callback) => {
18117
18089
  callback(payload.posts[0]);
18118
18090
  }
18119
18091
  else {
18120
- const cached = pullFromCache(['post', 'get', payload.posts[0].postId]);
18121
18092
  preparePayloadForCache('post.removeReaction', payload);
18122
18093
  const postPayload = __rest(payload, ["reactor"]);
18123
18094
  ingestInCache(postPayload);
18124
18095
  const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
18125
- if (cached && isMatch__default['default'](cached.data, post.data)) {
18126
- return;
18127
- }
18128
18096
  callback(post.data);
18129
18097
  }
18130
18098
  };
@@ -18136,15 +18104,12 @@ const createCommentEventSubscriber = (event, callback) => {
18136
18104
  const filter = (payload) => {
18137
18105
  var _a;
18138
18106
  if (!client.cache) {
18107
+ // TODO: here we are missing specific properties here!
18139
18108
  callback(payload.comments[0]);
18140
18109
  }
18141
18110
  else {
18142
- const cached = pullFromCache(['comment', 'get', payload.comments[0].commentId]);
18143
18111
  ingestInCache(payload);
18144
18112
  const comment = pullFromCache(['comment', 'get', payload.comments[0].commentId]);
18145
- if (cached && isMatch__default['default'](cached.data, comment.data)) {
18146
- return;
18147
- }
18148
18113
  if (['comment.created'].includes(event)) {
18149
18114
  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; });
18150
18115
  queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
@@ -18262,14 +18227,10 @@ const onCommentReactionAdded = (callback) => {
18262
18227
  callback(payload.comments[0]);
18263
18228
  }
18264
18229
  else {
18265
- const cached = pullFromCache(['comment', 'get', payload.comments[0].commentId]);
18266
18230
  preparePayloadForCache('comment.addReaction', payload);
18267
18231
  const commentPayload = __rest(payload, ["reactor"]);
18268
18232
  ingestInCache(commentPayload);
18269
18233
  const comment = pullFromCache(['comment', 'get', payload.comments[0].commentId]);
18270
- if (cached && isMatch__default['default'](cached.data, comment.data)) {
18271
- return;
18272
- }
18273
18234
  callback(comment.data);
18274
18235
  }
18275
18236
  };
@@ -18298,14 +18259,10 @@ const onCommentReactionRemoved = (callback) => {
18298
18259
  callback(payload.comments[0]);
18299
18260
  }
18300
18261
  else {
18301
- const cached = pullFromCache(['comment', 'get', payload.comments[0].commentId]);
18302
18262
  preparePayloadForCache('comment.removeReaction', payload);
18303
18263
  const commentPayload = __rest(payload, ["reactor"]);
18304
18264
  ingestInCache(commentPayload);
18305
18265
  const comment = pullFromCache(['comment', 'get', payload.comments[0].commentId]);
18306
- if (cached && isMatch__default['default'](cached.data, comment.data)) {
18307
- return;
18308
- }
18309
18266
  callback(comment.data);
18310
18267
  }
18311
18268
  };
@@ -18394,12 +18351,12 @@ const createReport = async (referenceType, referenceId) => {
18394
18351
  const client = getActiveClient();
18395
18352
  client.log('report/createReport', { referenceType, referenceId });
18396
18353
  const { domainName } = REFERENCE_TYPES[referenceType];
18397
- const { data } = await client.http.post(`/api/v3/${domainName}/${referenceId}/flag`);
18354
+ const { data } = await client.http.post(`/api/v3/${domainName}/${(encodeURIComponent(referenceId))}/flag`);
18398
18355
  if (client.cache)
18399
18356
  ingestInCache(data);
18400
18357
  const event = referenceType === 'message'
18401
18358
  ? 'v3.message.didUpdate'
18402
- : `${referenceType}.updated`;
18359
+ : `${referenceType}.flagged`;
18403
18360
  fireEvent(event, data);
18404
18361
  return !!data;
18405
18362
  };
@@ -18421,12 +18378,12 @@ const deleteReport = async (referenceType, referenceId) => {
18421
18378
  const client = getActiveClient();
18422
18379
  client.log('report/deleteReport', { referenceType, referenceId });
18423
18380
  const { domainName } = REFERENCE_TYPES[referenceType];
18424
- const { data } = await client.http.delete(`/api/v3/${domainName}/${referenceId}/unflag`);
18381
+ const { data } = await client.http.delete(`/api/v3/${domainName}/${encodeURIComponent(referenceId)}/unflag`);
18425
18382
  if (client.cache)
18426
18383
  ingestInCache(data);
18427
18384
  const event = referenceType === 'message'
18428
18385
  ? 'v3.message.didUpdate'
18429
- : `${referenceType}.updated`;
18386
+ : `${referenceType}.unflagged`;
18430
18387
  fireEvent(event, data);
18431
18388
  return !!data;
18432
18389
  };
@@ -18529,8 +18486,9 @@ queryChannels.locally = (query) => {
18529
18486
  const getChannels = async (channelIds) => {
18530
18487
  const client = getActiveClient();
18531
18488
  client.log('channel/getChannels', channelIds);
18489
+ const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
18532
18490
  // API-FIX: endpoint should not be /list, parameters should be querystring.
18533
- const { data } = await client.http.get(`/api/v3/channels/list`, { params: { channelIds } });
18491
+ const { data } = await client.http.get(`/api/v3/channels/list`, { params: { channelIds: encodedChannelIds } });
18534
18492
  const cachedAt = client.cache && Date.now();
18535
18493
  if (client.cache)
18536
18494
  ingestInCache(data, { cachedAt });
@@ -18589,7 +18547,7 @@ const getChannel = async (channelId) => {
18589
18547
  const client = getActiveClient();
18590
18548
  client.log('channel/getChannel', channelId);
18591
18549
  // API-FIX: endpoint should not be /list, parameters should be querystring.
18592
- const { data } = await client.http.get(`/api/v3/channels/${channelId}`);
18550
+ const { data } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}`);
18593
18551
  const cachedAt = client.cache && Date.now();
18594
18552
  if (client.cache)
18595
18553
  ingestInCache(data, { cachedAt });
@@ -18678,7 +18636,7 @@ const createChannel = async (bundle) => {
18678
18636
  const updateChannel = async (channelId, patch) => {
18679
18637
  const client = getActiveClient();
18680
18638
  client.log('channel/updateChannel', channelId, patch);
18681
- const { data } = await client.http.put(`/api/v3/channels/${channelId}`, patch);
18639
+ const { data } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}`, patch);
18682
18640
  const cachedAt = client.cache && Date.now();
18683
18641
  if (client.cache)
18684
18642
  ingestInCache(data, { cachedAt });
@@ -18707,7 +18665,7 @@ const deleteChannel = async (channelId) => {
18707
18665
  const client = getActiveClient();
18708
18666
  client.log('channel/deleteChannel', channelId);
18709
18667
  // API-FIX: This endpoint has not been implemented yet.
18710
- await client.http.delete(`/api/v3/channels/${channelId}`);
18668
+ await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}`);
18711
18669
  const deleted = await getChannel(channelId);
18712
18670
  // no need for event, fired by server
18713
18671
  return deleted.data;
@@ -18730,7 +18688,7 @@ const deleteChannel = async (channelId) => {
18730
18688
  const joinChannel = async (channelId) => {
18731
18689
  const client = getActiveClient();
18732
18690
  client.log('channel/joinChannel', channelId);
18733
- const { data } = await client.http.post(`/api/v3/channels/${channelId}/join`);
18691
+ const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/join`);
18734
18692
  if (client.cache)
18735
18693
  ingestInCache(data);
18736
18694
  const { channelUsers } = data;
@@ -18755,7 +18713,7 @@ const joinChannel = async (channelId) => {
18755
18713
  const leaveChannel = async (channelId) => {
18756
18714
  const client = getActiveClient();
18757
18715
  client.log('channel/leaveChannel', channelId);
18758
- const { data } = await client.http.delete(`/api/v3/channels/${channelId}/leave`);
18716
+ const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/leave`);
18759
18717
  if (client.cache)
18760
18718
  ingestInCache(data);
18761
18719
  const { channelUsers } = data;
@@ -18781,19 +18739,20 @@ const queryChannelMembers = async (query) => {
18781
18739
  const client = getActiveClient();
18782
18740
  client.log('channel/queryChannelMembers', query);
18783
18741
  const _a = query !== null && query !== void 0 ? query : {}, { page, channelId, membership } = _a, params = __rest(_a, ["page", "channelId", "membership"]);
18784
- const { data } = await client.http.get(`/api/v3/channels/${channelId}/users`, {
18742
+ const { data } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, {
18785
18743
  params: Object.assign(Object.assign({}, params), { filter: membership, options: {
18786
18744
  token: toToken(page, 'skiplimit'),
18787
18745
  } }),
18788
18746
  });
18789
18747
  const { paging } = data, payload = __rest(data, ["paging"]);
18790
18748
  const { channelUsers } = payload;
18749
+ const cachedAt = client.cache && Date.now();
18791
18750
  if (client.cache) {
18792
18751
  ingestInCache(payload);
18793
18752
  }
18794
18753
  const nextPage = toPage(paging.next);
18795
18754
  const prevPage = toPage(paging.previous);
18796
- return { data: channelUsers, nextPage, prevPage };
18755
+ return { data: channelUsers, cachedAt, nextPage, prevPage };
18797
18756
  };
18798
18757
  /**
18799
18758
  * ```js
@@ -18832,7 +18791,7 @@ queryChannelMembers.locally = (query) => {
18832
18791
  const addChannelMembers = async (channelId, userIds) => {
18833
18792
  const client = getActiveClient();
18834
18793
  client.log('channel/addChannelMembers', channelId, userIds);
18835
- const { data } = await client.http.post(`/api/v3/channels/${channelId}/users`, { channelId, userIds });
18794
+ const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { channelId, userIds });
18836
18795
  if (client.cache)
18837
18796
  ingestInCache(data);
18838
18797
  fireEvent('v3.channel.didAddUsers', {
@@ -18860,7 +18819,7 @@ const addChannelMembers = async (channelId, userIds) => {
18860
18819
  const removeChannelMembers = async (channelId, userIds) => {
18861
18820
  const client = getActiveClient();
18862
18821
  client.log('channel/removeChannelMembers', channelId, userIds);
18863
- const { data } = await client.http.delete(`/api/v3/channels/${channelId}/users`, { data: { channelId, userIds } });
18822
+ const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { data: { channelId, userIds } });
18864
18823
  if (client.cache)
18865
18824
  ingestInCache(data);
18866
18825
  fireEvent('v3.channel.didRemoveUsers', {
@@ -18889,7 +18848,7 @@ const removeChannelMembers = async (channelId, userIds) => {
18889
18848
  const addChannelMembersRole = async (channelId, roleId, userIds) => {
18890
18849
  const client = getActiveClient();
18891
18850
  client.log('channel/addChannelMembersRole', channelId, roleId, userIds);
18892
- const { data } = await client.http.post(`/api/v3/channels/${channelId}/users/roles`, { channelId, role: roleId, userIds });
18851
+ const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { channelId, role: roleId, userIds });
18893
18852
  if (client.cache)
18894
18853
  ingestInCache(data);
18895
18854
  const { channelUsers } = data;
@@ -18915,7 +18874,7 @@ const addChannelMembersRole = async (channelId, roleId, userIds) => {
18915
18874
  const removeChannelMembersRole = async (channelId, roleId, userIds) => {
18916
18875
  const client = getActiveClient();
18917
18876
  client.log('channel/removeChannelMembersRole', channelId, roleId, userIds);
18918
- const { data } = await client.http.delete(`/api/v3/channels/${channelId}/users/roles`, { data: { channelId, role: roleId, userIds } });
18877
+ const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { data: { channelId, role: roleId, userIds } });
18919
18878
  if (client.cache)
18920
18879
  ingestInCache(data);
18921
18880
  const { channelUsers } = data;
@@ -19266,15 +19225,12 @@ const createCommunityEventSubscriber = (event, callback) => {
19266
19225
  const client = getActiveClient();
19267
19226
  const filter = (payload) => {
19268
19227
  if (!client.cache) {
19228
+ // TODO: here we are missing specific properties here!
19269
19229
  callback(payload.communities[0]);
19270
19230
  }
19271
19231
  else {
19272
- const cached = pullFromCache(['community', 'get', payload.communities[0].communityId]);
19273
19232
  ingestInCache(payload);
19274
19233
  const community = pullFromCache(['community', 'get', payload.communities[0].communityId]);
19275
- if (cached && isMatch__default['default'](cached.data, community === null || community === void 0 ? void 0 : community.data)) {
19276
- return;
19277
- }
19278
19234
  callback(community.data);
19279
19235
  }
19280
19236
  };
@@ -19309,24 +19265,20 @@ function getEventRelatedMember(event, payload) {
19309
19265
  const createCommunityMemberEventSubscriber = (event, callback) => {
19310
19266
  const client = getActiveClient();
19311
19267
  const filter = (payload) => {
19312
- const cachedCommunity = pullFromCache(['community', 'get', payload.communities[0].communityId]);
19313
- const cachedMember = pullFromCache([
19314
- 'communityUsers',
19315
- 'get',
19316
- getResolver('communityUsers')(getEventRelatedMember(event, payload))
19317
- ]);
19318
- ingestInCache(payload);
19319
- const community = pullFromCache(['community', 'get', payload.communities[0].communityId]);
19320
- const member = pullFromCache([
19321
- 'communityUsers',
19322
- 'get',
19323
- getResolver('communityUsers')(getEventRelatedMember(event, payload))
19324
- ]);
19325
- if (cachedCommunity && isMatch__default['default'](cachedCommunity.data, community.data)
19326
- && cachedMember && isMatch__default['default'](cachedMember.data, member.data)) {
19327
- return;
19268
+ if (!client.cache) {
19269
+ // TODO: here we are missing specific properties here!
19270
+ callback(payload.communities[0], getEventRelatedMember(event, payload));
19271
+ }
19272
+ else {
19273
+ ingestInCache(payload);
19274
+ const community = pullFromCache(['community', 'get', payload.communities[0].communityId]);
19275
+ const member = pullFromCache([
19276
+ 'communityUsers',
19277
+ 'get',
19278
+ getResolver('communityUsers')(getEventRelatedMember(event, payload))
19279
+ ]);
19280
+ callback(community.data, member.data);
19328
19281
  }
19329
- callback(community.data, member.data);
19330
19282
  };
19331
19283
  return createEventSubscriber(client, event, event, filter);
19332
19284
  };
@@ -19545,17 +19497,56 @@ const observeCommunity = (communityId, callback) => {
19545
19497
  const queryGlobalFeed = async (query) => {
19546
19498
  const client = getActiveClient();
19547
19499
  client.log('feed/queryGlobalFeed', query);
19548
- const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
19549
- const { data } = await client.http.get(`/api/v4/me/global-feeds`, { params: Object.assign(Object.assign({}, params), { options: {
19500
+ const _a = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _a, params = __rest(_a, ["useCustomRanking", "page"]);
19501
+ const { data } = await client.http.get(useCustomRanking ? `/api/v5/me/global-feeds` : `/api/v4/me/global-feeds`, { params: Object.assign(Object.assign({}, params), { options: {
19550
19502
  token: toToken(page, 'skiplimit')
19551
19503
  } }) });
19552
19504
  const { paging } = data, payload = __rest(data, ["paging"]);
19553
19505
  const { posts } = payload;
19554
- if (client.cache)
19506
+ const cachedAt = client.cache && Date.now();
19507
+ if (client.cache) {
19555
19508
  ingestInCache(payload);
19509
+ const cacheKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) })];
19510
+ pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
19511
+ }
19556
19512
  const nextPage = toPage(paging.next);
19557
19513
  const prevPage = toPage(paging.previous);
19558
- return { data: posts, prevPage, nextPage };
19514
+ return { data: posts, cachedAt, prevPage, nextPage };
19515
+ };
19516
+ /**
19517
+ * ```js
19518
+ * import { queryGlobalFeed } from '@amityco/ts-sdk'
19519
+ * const posts = await queryGlobalFeed.locally()
19520
+ * ```
19521
+ *
19522
+ * Queries a paginable list of {@link Amity.Post} objects from cache
19523
+ *
19524
+ * @param query The query parameters
19525
+ * @returns A page of {@link Amity.Post} objects
19526
+ *
19527
+ * @category Feed API
19528
+ * @async
19529
+ **/
19530
+ queryGlobalFeed.locally = (query) => {
19531
+ var _a, _b;
19532
+ const client = getActiveClient();
19533
+ client.log('post/queryGlobalFeed.locally', query);
19534
+ if (!client.cache)
19535
+ return;
19536
+ const _c = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _c, params = __rest(_c, ["useCustomRanking", "page"]);
19537
+ const queryKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) })];
19538
+ const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
19539
+ if (!(data === null || data === void 0 ? void 0 : data.posts.length))
19540
+ return;
19541
+ const posts = data.posts
19542
+ .map(postId => pullFromCache(['post', 'get', postId]))
19543
+ .filter(Boolean)
19544
+ .map(({ data }) => data);
19545
+ const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
19546
+ const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
19547
+ return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
19548
+ ? { data: posts, cachedAt, prevPage, nextPage }
19549
+ : undefined;
19559
19550
  };
19560
19551
 
19561
19552
  /**
@@ -20163,7 +20154,6 @@ exports.removeCommunityMembersRole = removeCommunityMembersRole;
20163
20154
  exports.removeReaction = removeReaction;
20164
20155
  exports.restoreCache = restoreCache;
20165
20156
  exports.runQuery = runQuery;
20166
- exports.sliceByPaging = sliceByPaging;
20167
20157
  exports.sortByChannelSegment = sortByChannelSegment;
20168
20158
  exports.sortByDisplayName = sortByDisplayName;
20169
20159
  exports.sortByFirstCreated = sortByFirstCreated;