@amityco/ts-sdk 6.35.3-024c022.0 → 6.35.3-3272722.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (31) hide show
  1. package/dist/@types/domains/community.d.ts +4 -2
  2. package/dist/@types/domains/community.d.ts.map +1 -1
  3. package/dist/@types/domains/user.d.ts +2 -1
  4. package/dist/@types/domains/user.d.ts.map +1 -1
  5. package/dist/channelRepository/internalApi/getChannelByIds.d.ts +2 -2
  6. package/dist/channelRepository/internalApi/getChannelByIds.d.ts.map +1 -1
  7. package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
  8. package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
  9. package/dist/channelRepository/utils/constructChannelObject.d.ts.map +1 -1
  10. package/dist/channelRepository/utils/updateChannelCache.d.ts +1 -1
  11. package/dist/channelRepository/utils/updateChannelCache.d.ts.map +1 -1
  12. package/dist/communityRepository/observers/searchCommunities.d.ts +1 -1
  13. package/dist/communityRepository/observers/searchCommunities.d.ts.map +1 -1
  14. package/dist/index.cjs.js +134 -23
  15. package/dist/index.esm.js +134 -23
  16. package/dist/index.umd.js +1 -1
  17. package/dist/messageRepository/api/createMessage.d.ts.map +1 -1
  18. package/package.json +1 -1
  19. package/src/@types/domains/community.ts +2 -0
  20. package/src/@types/domains/user.ts +1 -0
  21. package/src/channelRepository/api/getChannelByIds.ts +5 -5
  22. package/src/channelRepository/internalApi/getChannelByIds.ts +5 -7
  23. package/src/channelRepository/observers/getChannel.ts +33 -13
  24. package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +6 -12
  25. package/src/channelRepository/utils/constructChannelObject.ts +7 -0
  26. package/src/channelRepository/utils/resolveChannels.ts +1 -1
  27. package/src/channelRepository/utils/updateChannelCache.ts +4 -1
  28. package/src/communityRepository/observers/searchCommunities.ts +1 -1
  29. package/src/messageRepository/api/createMessage.ts +6 -2
  30. package/src/messageRepository/api/tests/createMessage.test.ts +1 -0
  31. package/src/messageRepository/api/tests/deleteMessage.test.ts +5 -1
package/dist/index.esm.js CHANGED
@@ -23105,6 +23105,16 @@ const constructChannelDynamicValue = (channel) => {
23105
23105
  });
23106
23106
  };
23107
23107
 
23108
+ const constructChannelObject = (channel) => {
23109
+ /**
23110
+ * convert internal cache data to be public channel data
23111
+ * 1. [getChannelMessagePreviewWithUser] add messagePreview >> Amity.InternalChannel -> Amity.InternalChannel
23112
+ * 2. [constructChannelDynamicValue] construct getter value >> Amity.StaticInternalChannel -> Amity.Channel
23113
+ * 3. [LinkedObject.channel] add markAsRead >> Amity.InternalChannel -> Amity.Channel
23114
+ */
23115
+ return LinkedObject.channel(constructChannelDynamicValue(getChannelMessagePreviewWithUser(channel)));
23116
+ };
23117
+
23108
23118
  /**
23109
23119
  * ```js
23110
23120
  * import { getChannelByIds } from '@amityco/ts-sdk'
@@ -23119,7 +23129,7 @@ const constructChannelDynamicValue = (channel) => {
23119
23129
  * @category Channel API
23120
23130
  * @async
23121
23131
  */
23122
- const getChannelByIds = async (channelIds) => {
23132
+ const getChannelByIds$1 = async (channelIds) => {
23123
23133
  const client = getActiveClient();
23124
23134
  client.log('channel/getChannelByIds', channelIds);
23125
23135
  const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
@@ -23149,7 +23159,7 @@ const getChannelByIds = async (channelIds) => {
23149
23159
  ingestInCache(data, { cachedAt });
23150
23160
  fireEvent('local.channel.fetched', data.channels);
23151
23161
  return {
23152
- data: data.channels.map(channel => LinkedObject.channel(constructChannelDynamicValue(channel))),
23162
+ data: data.channels.map(channel => constructChannelObject(channel)),
23153
23163
  cachedAt,
23154
23164
  };
23155
23165
  };
@@ -23166,7 +23176,7 @@ const getChannelByIds = async (channelIds) => {
23166
23176
  *
23167
23177
  * @category Channel API
23168
23178
  */
23169
- getChannelByIds.locally = (channelIds) => {
23179
+ getChannelByIds$1.locally = (channelIds) => {
23170
23180
  var _a, _b;
23171
23181
  const client = getActiveClient();
23172
23182
  client.log('channel/getChannelByIds.locally', channelIds);
@@ -23180,7 +23190,7 @@ getChannelByIds.locally = (channelIds) => {
23180
23190
  const channels = cached.map(({ data }) => data);
23181
23191
  const oldest = (_b = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _b === void 0 ? void 0 : _b[0];
23182
23192
  return {
23183
- data: channels.map(channel => LinkedObject.channel(channel)),
23193
+ data: channels.map(channel => constructChannelObject(channel)),
23184
23194
  cachedAt: oldest.cachedAt,
23185
23195
  };
23186
23196
  };
@@ -23469,7 +23479,7 @@ const initializeMessagePreviewSetting = async () => {
23469
23479
  * 2. channel and subChannel which isDelete = true
23470
23480
  */
23471
23481
  if (channelWithIsDeletedTrue.length !== 0)
23472
- await getChannelByIds(channelWithIsDeletedTrue);
23482
+ await getChannelByIds$1(channelWithIsDeletedTrue);
23473
23483
  if (subChannelWithIsDeletedTrue.length !== 0)
23474
23484
  await getSubChannels$1(subChannelWithIsDeletedTrue);
23475
23485
  }
@@ -23895,6 +23905,86 @@ const onOffline = (callback) => {
23895
23905
  return () => console.error('Unsupported environment');
23896
23906
  };
23897
23907
 
23908
+ /**
23909
+ * ```js
23910
+ * import { getChannelByIds } from '@amityco/ts-sdk'
23911
+ * const channels = await getChannelByIds(['foo', 'bar'])
23912
+ * ```
23913
+ *
23914
+ * Fetches a collection of {@link Amity.Channel} objects
23915
+ *
23916
+ * @param channelIds the IDs of the {@link Amity.Channel} to fetch
23917
+ * @returns the associated collection of {@link Amity.Channel} objects
23918
+ *
23919
+ * @category Channel API
23920
+ * @async
23921
+ */
23922
+ const getChannelByIds = async (channelIds) => {
23923
+ const client = getActiveClient();
23924
+ client.log('channel/getChannelByIds', channelIds);
23925
+ const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
23926
+ let payload;
23927
+ try {
23928
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
23929
+ const response = await client.http.get(`/api/v3/channels/list`, {
23930
+ params: { channelIds: encodedChannelIds },
23931
+ });
23932
+ payload = response.data;
23933
+ }
23934
+ catch (error) {
23935
+ channelIds.forEach(channelId => {
23936
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
23937
+ // NOTE: use channelPublicId as tombstone cache key since we cannot get the channelPrivateId that come along with channel data from server
23938
+ pushToTombstone('channel', channelId);
23939
+ }
23940
+ });
23941
+ throw error;
23942
+ }
23943
+ const data = await prepareChannelPayload(payload);
23944
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
23945
+ await prepareUnreadCountInfo(payload);
23946
+ }
23947
+ const cachedAt = client.cache && Date.now();
23948
+ if (client.cache)
23949
+ ingestInCache(data, { cachedAt });
23950
+ fireEvent('local.channel.fetched', data.channels);
23951
+ return {
23952
+ data: data.channels,
23953
+ cachedAt,
23954
+ };
23955
+ };
23956
+ /**
23957
+ * ```js
23958
+ * import { getChannelByIds } from '@amityco/ts-sdk'
23959
+ * const channels = getChannelByIds.locally(['foo', 'bar']) ?? []
23960
+ * ```
23961
+ *
23962
+ * Fetches a collection of {@link Amity.Channel} objects from cache
23963
+ *
23964
+ * @param channelIds the IDs of the {@link Amity.Channel} to fetch
23965
+ * @returns the associated collection of {@link Amity.Channel} objects
23966
+ *
23967
+ * @category Channel API
23968
+ */
23969
+ getChannelByIds.locally = (channelIds) => {
23970
+ var _a, _b;
23971
+ const client = getActiveClient();
23972
+ client.log('channel/getChannelByIds.locally', channelIds);
23973
+ if (!client.cache)
23974
+ return;
23975
+ const cached = (_a = queryCache(['channel', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
23976
+ return channelIds.includes(data.channelPublicId);
23977
+ });
23978
+ if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) < channelIds.length)
23979
+ return;
23980
+ const channels = cached.map(({ data }) => data);
23981
+ const oldest = (_b = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _b === void 0 ? void 0 : _b[0];
23982
+ return {
23983
+ data: channels,
23984
+ cachedAt: oldest.cachedAt,
23985
+ };
23986
+ };
23987
+
23898
23988
  const resolveChannels = async (channelIds) => {
23899
23989
  var _a, _b, _c;
23900
23990
  await getChannelByIds(channelIds);
@@ -30939,9 +31029,13 @@ const createMessageOptimistic = (bundle) => {
30939
31029
  if (subChannel) {
30940
31030
  upsertInCache(['subChannel', 'get', bundle.subChannelId], Object.assign(Object.assign({}, subChannel.data), { messageCount: subChannel.data.messageCount + 1 }));
30941
31031
  if (subChannel.data.channelId === subChannel.data.subChannelId) {
30942
- const channel = pullFromCache(['channel', 'get', subChannel.data.channelId]);
31032
+ const channel = pullFromCache([
31033
+ 'channel',
31034
+ 'get',
31035
+ subChannel.data.channelId,
31036
+ ]);
30943
31037
  if (channel === null || channel === void 0 ? void 0 : channel.data) {
30944
- upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_a = subChannel.data.messageCount) !== null && _a !== void 0 ? _a : 0) + 1 }));
31038
+ upsertInCache(['channel', 'get', subChannel.data.channelId], Object.assign(Object.assign({}, channel.data), { messageCount: ((_a = channel.data.messageCount) !== null && _a !== void 0 ? _a : 0) + 1 }));
30945
31039
  }
30946
31040
  }
30947
31041
  }
@@ -32547,9 +32641,7 @@ const getChannel = (channelId, callback) => {
32547
32641
  const reactor = async (response) => {
32548
32642
  if (!response.data)
32549
32643
  return callback(response);
32550
- const data = Object.assign(Object.assign({}, response), {
32551
- // TODO: refactor to be a function to construct public channel object
32552
- data: LinkedObject.channel(constructChannelDynamicValue(getChannelMessagePreviewWithUser(response.data))) });
32644
+ const data = Object.assign(Object.assign({}, response), { data: constructChannelObject(response.data) });
32553
32645
  const newSnapshot = __rest(data, ["origin"]);
32554
32646
  /**
32555
32647
  * check equality of previous data and current data to avoid redundancy
@@ -32583,7 +32675,11 @@ const getChannel = (channelId, callback) => {
32583
32675
  if (message.channelId !== channelId)
32584
32676
  return;
32585
32677
  // channelId from message is channelInternalId
32586
- const channel = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
32678
+ const channel = (_a = pullFromCache([
32679
+ 'channel',
32680
+ 'get',
32681
+ channelId,
32682
+ ])) === null || _a === void 0 ? void 0 : _a.data;
32587
32683
  if (!channel)
32588
32684
  return;
32589
32685
  updateChannelCache(channel, {
@@ -32606,7 +32702,11 @@ const getChannel = (channelId, callback) => {
32606
32702
  if (message.channelId !== channelId)
32607
32703
  return;
32608
32704
  // channelId from message is channelInternalId
32609
- const channel = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
32705
+ const channel = (_a = pullFromCache([
32706
+ 'channel',
32707
+ 'get',
32708
+ channelId,
32709
+ ])) === null || _a === void 0 ? void 0 : _a.data;
32610
32710
  if (!channel)
32611
32711
  return;
32612
32712
  updateChannelCache(channel, {
@@ -32619,7 +32719,11 @@ const getChannel = (channelId, callback) => {
32619
32719
  convertEventPayload((callback) => {
32620
32720
  const updateMessagePreview = async (message) => {
32621
32721
  var _a;
32622
- const channel = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
32722
+ const channel = (_a = pullFromCache([
32723
+ 'channel',
32724
+ 'get',
32725
+ channelId,
32726
+ ])) === null || _a === void 0 ? void 0 : _a.data;
32623
32727
  if (!channel || channel.messagePreviewId !== message.messageId)
32624
32728
  return;
32625
32729
  const messagePreviewSetting = await client.getMessagePreviewSetting(false);
@@ -32633,7 +32737,11 @@ const getChannel = (channelId, callback) => {
32633
32737
  convertEventPayload((callback) => {
32634
32738
  const updateMessagePreview = async (message) => {
32635
32739
  var _a;
32636
- const channel = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
32740
+ const channel = (_a = pullFromCache([
32741
+ 'channel',
32742
+ 'get',
32743
+ channelId,
32744
+ ])) === null || _a === void 0 ? void 0 : _a.data;
32637
32745
  if (!channel || channel.messagePreviewId !== message.messageId)
32638
32746
  return;
32639
32747
  const messagePreviewSetting = await client.getMessagePreviewSetting(false);
@@ -32666,7 +32774,11 @@ const getChannel = (channelId, callback) => {
32666
32774
  if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
32667
32775
  return;
32668
32776
  await getChannel$1(channelId);
32669
- const channel = (_b = pullFromCache(['channel', 'get', channelId])) === null || _b === void 0 ? void 0 : _b.data;
32777
+ const channel = (_b = pullFromCache([
32778
+ 'channel',
32779
+ 'get',
32780
+ channelId,
32781
+ ])) === null || _b === void 0 ? void 0 : _b.data;
32670
32782
  if (!channel)
32671
32783
  return;
32672
32784
  callback(subChannel);
@@ -32688,7 +32800,11 @@ const getChannel = (channelId, callback) => {
32688
32800
  if (!messagePreviewCache ||
32689
32801
  messagePreviewCache.subChannelId !== subChannel.subChannelId)
32690
32802
  return;
32691
- const channel = (_b = pullFromCache(['channel', 'get', channelId])) === null || _b === void 0 ? void 0 : _b.data;
32803
+ const channel = (_b = pullFromCache([
32804
+ 'channel',
32805
+ 'get',
32806
+ channelId,
32807
+ ])) === null || _b === void 0 ? void 0 : _b.data;
32692
32808
  if (!channel)
32693
32809
  return;
32694
32810
  callback(subChannel);
@@ -32884,12 +33000,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
32884
33000
  .map(channelId => pullFromCache(['channel', 'get', channelId]))
32885
33001
  .filter(Boolean)
32886
33002
  .map(({ data }) => data)
32887
- // add messagePreview >> Amity.InternalChannel -> Amity.InternalChannel
32888
- .map(getChannelMessagePreviewWithUser)
32889
- // construct getter value >> Amity.StaticInternalChannel -> Amity.Channel
32890
- .map(constructChannelDynamicValue)
32891
- // add markAsRead >> Amity.InternalChannel -> Amity.Channel
32892
- .map(LinkedObject.channel)) !== null && _b !== void 0 ? _b : [];
33003
+ .map(constructChannelObject)) !== null && _b !== void 0 ? _b : [];
32893
33004
  if (this.paginationController instanceof ChannelPaginationController) {
32894
33005
  data = this.applyFilter(data);
32895
33006
  }
@@ -33860,7 +33971,7 @@ var index$c = /*#__PURE__*/Object.freeze({
33860
33971
  __proto__: null,
33861
33972
  Membership: index$e,
33862
33973
  Moderation: index$d,
33863
- getChannelByIds: getChannelByIds,
33974
+ getChannelByIds: getChannelByIds$1,
33864
33975
  createChannel: createChannel,
33865
33976
  updateChannel: updateChannel,
33866
33977
  deleteChannel: deleteChannel,