@amityco/ts-sdk 7.1.1-e887d15f.0 → 7.2.1-3663404.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 (133) hide show
  1. package/dist/@types/core/events.d.ts +4 -0
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +4 -0
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +45 -1
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/channel.d.ts +2 -2
  8. package/dist/@types/domains/channel.d.ts.map +1 -1
  9. package/dist/@types/domains/client.d.ts +1 -0
  10. package/dist/@types/domains/client.d.ts.map +1 -1
  11. package/dist/@types/domains/file.d.ts +1 -20
  12. package/dist/@types/domains/file.d.ts.map +1 -1
  13. package/dist/@types/domains/notification.d.ts +78 -0
  14. package/dist/@types/domains/notification.d.ts.map +1 -0
  15. package/dist/@types/domains/post.d.ts +4 -0
  16. package/dist/@types/domains/post.d.ts.map +1 -1
  17. package/dist/@types/index.d.ts +1 -0
  18. package/dist/@types/index.d.ts.map +1 -1
  19. package/dist/channelRepository/events/onChannelDeleted.d.ts.map +1 -1
  20. package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts +11 -0
  21. package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts.map +1 -0
  22. package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts +20 -0
  23. package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts.map +1 -0
  24. package/dist/channelRepository/observers/index.d.ts +1 -0
  25. package/dist/channelRepository/observers/index.d.ts.map +1 -1
  26. package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
  27. package/dist/client/api/createClient.d.ts +1 -0
  28. package/dist/client/api/createClient.d.ts.map +1 -1
  29. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
  30. package/dist/client/utils/endpoints.d.ts +1 -0
  31. package/dist/client/utils/endpoints.d.ts.map +1 -1
  32. package/dist/client/utils/setClientToken.d.ts.map +1 -1
  33. package/dist/commentRepository/events/utils.d.ts.map +1 -1
  34. package/dist/core/events.d.ts +3 -3
  35. package/dist/core/events.d.ts.map +1 -1
  36. package/dist/core/model/idResolvers.d.ts.map +1 -1
  37. package/dist/core/model/index.d.ts.map +1 -1
  38. package/dist/fileRepository/api/index.d.ts +1 -0
  39. package/dist/fileRepository/api/index.d.ts.map +1 -1
  40. package/dist/fileRepository/api/updateAltText.d.ts +17 -0
  41. package/dist/fileRepository/api/updateAltText.d.ts.map +1 -0
  42. package/dist/fileRepository/api/uploadImage.d.ts +2 -1
  43. package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
  44. package/dist/index.cjs.js +748 -73
  45. package/dist/index.d.ts +1 -0
  46. package/dist/index.d.ts.map +1 -1
  47. package/dist/index.esm.js +731 -57
  48. package/dist/index.umd.js +4 -4
  49. package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
  50. package/dist/messageRepository/observers/getMessage.d.ts.map +1 -1
  51. package/dist/notificationTray/api/index.d.ts +3 -0
  52. package/dist/notificationTray/api/index.d.ts.map +1 -0
  53. package/dist/notificationTray/api/markItemsSeen.d.ts +16 -0
  54. package/dist/notificationTray/api/markItemsSeen.d.ts.map +1 -0
  55. package/dist/notificationTray/api/markTraySeen.d.ts +19 -0
  56. package/dist/notificationTray/api/markTraySeen.d.ts.map +1 -0
  57. package/dist/notificationTray/events/index.d.ts +2 -0
  58. package/dist/notificationTray/events/index.d.ts.map +1 -0
  59. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts +17 -0
  60. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts.map +1 -0
  61. package/dist/notificationTray/index.d.ts +4 -0
  62. package/dist/notificationTray/index.d.ts.map +1 -0
  63. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts +30 -0
  64. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts.map +1 -0
  65. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +13 -0
  66. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +1 -0
  67. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +9 -0
  68. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +1 -0
  69. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +9 -0
  70. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +1 -0
  71. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts +12 -0
  72. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts.map +1 -0
  73. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts +20 -0
  74. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts.map +1 -0
  75. package/dist/notificationTray/observers/index.d.ts +3 -0
  76. package/dist/notificationTray/observers/index.d.ts.map +1 -0
  77. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts +2 -0
  78. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts.map +1 -0
  79. package/dist/utils/linkedObject/index.d.ts +1 -0
  80. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  81. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +2 -0
  82. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -0
  83. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  84. package/dist/utils/postTypePredicate.d.ts +4 -0
  85. package/dist/utils/postTypePredicate.d.ts.map +1 -0
  86. package/package.json +1 -1
  87. package/src/@types/core/events.ts +5 -0
  88. package/src/@types/core/model.ts +6 -0
  89. package/src/@types/core/payload.ts +52 -1
  90. package/src/@types/domains/channel.ts +2 -2
  91. package/src/@types/domains/client.ts +1 -0
  92. package/src/@types/domains/file.ts +1 -21
  93. package/src/@types/domains/notification.ts +94 -0
  94. package/src/@types/domains/post.ts +4 -0
  95. package/src/@types/index.ts +1 -0
  96. package/src/channelRepository/events/onChannelDeleted.ts +9 -2
  97. package/src/channelRepository/internalApi/getTotalChannelsUnread.ts +38 -0
  98. package/src/channelRepository/observers/getTotalChannelsUnread.ts +129 -0
  99. package/src/channelRepository/observers/index.ts +1 -0
  100. package/src/channelRepository/utils/prepareChannelPayload.ts +21 -10
  101. package/src/client/api/createClient.ts +4 -1
  102. package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +5 -1
  103. package/src/client/utils/endpoints.ts +1 -0
  104. package/src/client/utils/setClientToken.ts +8 -0
  105. package/src/commentRepository/events/utils.ts +73 -0
  106. package/src/core/model/idResolvers.ts +3 -0
  107. package/src/core/model/index.ts +2 -0
  108. package/src/fileRepository/api/index.ts +1 -0
  109. package/src/fileRepository/api/updateAltText.ts +39 -0
  110. package/src/fileRepository/api/uploadFile.ts +1 -1
  111. package/src/fileRepository/api/uploadImage.ts +23 -4
  112. package/src/fileRepository/api/uploadVideo.ts +1 -1
  113. package/src/index.ts +2 -0
  114. package/src/messageRepository/events/onMessageCreated.ts +19 -9
  115. package/src/messageRepository/observers/getMessage.ts +0 -1
  116. package/src/notificationTray/api/index.ts +2 -0
  117. package/src/notificationTray/api/markItemsSeen.ts +62 -0
  118. package/src/notificationTray/api/markTraySeen.ts +65 -0
  119. package/src/notificationTray/events/index.ts +1 -0
  120. package/src/notificationTray/events/onNotificationTraySeenUpdated.ts +36 -0
  121. package/src/notificationTray/index.ts +3 -0
  122. package/src/notificationTray/internalApi/getNotificationTraySeen.ts +80 -0
  123. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +96 -0
  124. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +31 -0
  125. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +68 -0
  126. package/src/notificationTray/observers/getNotificationTrayItems.ts +44 -0
  127. package/src/notificationTray/observers/getNotificationTraySeen.ts +60 -0
  128. package/src/notificationTray/observers/index.ts +2 -0
  129. package/src/notificationTray/utils/prepareNotificationTrayItemsPayload.ts +12 -0
  130. package/src/utils/linkedObject/index.ts +2 -0
  131. package/src/utils/linkedObject/notificationTrayLinkedObject.ts +19 -0
  132. package/src/utils/linkedObject/postLinkedObject.ts +29 -0
  133. package/src/utils/postTypePredicate.ts +27 -0
package/dist/index.cjs.js CHANGED
@@ -102,8 +102,8 @@ const PostContentType = Object.freeze({
102
102
 
103
103
  function getVersion() {
104
104
  try {
105
- // the string ''v7.1.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
106
- return 'v7.1.0-cjs';
105
+ // the string ''v7.2.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
106
+ return 'v7.2.0-cjs';
107
107
  }
108
108
  catch (error) {
109
109
  return '__dev__';
@@ -121,6 +121,7 @@ const SECOND$1 = 1000;
121
121
  const MINUTE = 60 * SECOND$1;
122
122
  const HOUR = 60 * MINUTE;
123
123
  const DAY = 24 * HOUR;
124
+ const WEEK = 7 * DAY;
124
125
  const YEAR = 365 * DAY;
125
126
  const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
126
127
 
@@ -543,6 +544,8 @@ const idResolvers = {
543
544
  advertiser: ({ advertiserId }) => advertiserId,
544
545
  pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
545
546
  pinTarget: ({ targetId }) => targetId,
547
+ notificationTrayItem: ({ _id }) => _id,
548
+ notificationTraySeen: ({ userId }) => userId,
546
549
  };
547
550
  /**
548
551
  * Retrieve the id resolver matching a domain name
@@ -594,6 +597,7 @@ const PAYLOAD2MODEL = {
594
597
  advertisers: 'advertiser',
595
598
  pinTargets: 'pinTarget',
596
599
  pins: 'pin',
600
+ notificationTrayItems: 'notificationTrayItem',
597
601
  };
598
602
  /** hidden */
599
603
  const isOutdated = (prevData, nextData) => {
@@ -1562,6 +1566,7 @@ const API_REGIONS = {
1562
1566
  };
1563
1567
  const URLS = {
1564
1568
  http: 'https://apix.{region}.amity.co',
1569
+ upload: 'https://upload.{region}.amity.co',
1565
1570
  mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
1566
1571
  };
1567
1572
  function computeUrl(type, region) {
@@ -5529,6 +5534,26 @@ const commentLinkedObject = (comment) => {
5529
5534
  } });
5530
5535
  };
5531
5536
 
5537
+ function isAmityImagePost(post) {
5538
+ return !!(post.data &&
5539
+ typeof post.data !== 'string' &&
5540
+ 'fileId' in post.data &&
5541
+ post.dataType === 'image');
5542
+ }
5543
+ function isAmityFilePost(post) {
5544
+ return !!(post.data &&
5545
+ typeof post.data !== 'string' &&
5546
+ 'fileId' in post.data &&
5547
+ post.dataType === 'file');
5548
+ }
5549
+ function isAmityVideoPost(post) {
5550
+ return !!(post.data &&
5551
+ typeof post.data !== 'string' &&
5552
+ 'videoFileId' in post.data &&
5553
+ 'thumbnailFileId' in post.data &&
5554
+ post.dataType === 'video');
5555
+ }
5556
+
5532
5557
  const postLinkedObject = (post) => {
5533
5558
  return Object.assign(Object.assign({}, post), { analytics: {
5534
5559
  markAsViewed: () => {
@@ -5557,6 +5582,30 @@ const postLinkedObject = (post) => {
5557
5582
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
5558
5583
  return;
5559
5584
  return userLinkedObject(cacheData.data);
5585
+ },
5586
+ getImageInfo() {
5587
+ var _a, _b;
5588
+ return isAmityImagePost(post)
5589
+ ? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
5590
+ : undefined;
5591
+ },
5592
+ getVideoInfo() {
5593
+ var _a, _b, _c;
5594
+ return isAmityVideoPost(post)
5595
+ ? (_c = pullFromCache(['file', 'get', (_b = (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.videoFileId) === null || _b === void 0 ? void 0 : _b.original])) === null || _c === void 0 ? void 0 : _c.data
5596
+ : undefined;
5597
+ },
5598
+ getVideoThumbnailInfo() {
5599
+ var _a, _b;
5600
+ return isAmityVideoPost(post)
5601
+ ? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.thumbnailFileId])) === null || _b === void 0 ? void 0 : _b.data
5602
+ : undefined;
5603
+ },
5604
+ getFileInfo() {
5605
+ var _a, _b;
5606
+ return isAmityFilePost(post)
5607
+ ? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
5608
+ : undefined;
5560
5609
  } });
5561
5610
  };
5562
5611
 
@@ -5728,7 +5777,9 @@ class MessageReadReceiptSyncEngine {
5728
5777
  // Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
5729
5778
  const cacheKey = ['channelUnread', 'get', channelId];
5730
5779
  const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
5731
- if (channelUnread && segment > channelUnread.readToSegment) {
5780
+ if (typeof (channelUnread === null || channelUnread === void 0 ? void 0 : channelUnread.readToSegment) === 'number' &&
5781
+ channelUnread &&
5782
+ segment > channelUnread.readToSegment) {
5732
5783
  channelUnread.readToSegment = segment;
5733
5784
  channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
5734
5785
  pushToCache(cacheKey, channelUnread);
@@ -6218,6 +6269,14 @@ const pinnedPostLinkedObject = (pinnedPost) => {
6218
6269
  } });
6219
6270
  };
6220
6271
 
6272
+ const notificationTrayLinkedObject = (noti) => {
6273
+ return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
6274
+ .map(({ _id }) => pullFromCache(['user', 'get', _id]))
6275
+ .filter(isNonNullable)
6276
+ .map(({ data }) => data)
6277
+ .map(user => userLinkedObject(user)) });
6278
+ };
6279
+
6221
6280
  const LinkedObject = {
6222
6281
  ad: adLinkedObject,
6223
6282
  comment: commentLinkedObject,
@@ -6231,6 +6290,7 @@ const LinkedObject = {
6231
6290
  reactor: reactorLinkedObject,
6232
6291
  channel: channelLinkedObject,
6233
6292
  pinnedPost: pinnedPostLinkedObject,
6293
+ notificationTray: notificationTrayLinkedObject,
6234
6294
  };
6235
6295
 
6236
6296
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -7061,19 +7121,27 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
7061
7121
  const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
7062
7122
  for (let i = 0; i < channels.length; i += 1) {
7063
7123
  const cacheKey = ['channelUnread', 'get', channels[i].channelId];
7064
- const { readToSegment, lastMentionedSegment } = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId) || {
7065
- readToSegment: 0,
7066
- lastMentionedSegment: 0,
7067
- };
7068
- pushToCache(cacheKey, {
7124
+ const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
7125
+ let unreadCount = 0;
7126
+ let readToSegment = null;
7127
+ let lastMentionedSegment = null;
7128
+ let isMentioned = false;
7129
+ if (channelUser) {
7130
+ readToSegment = channelUser.readToSegment;
7131
+ lastMentionedSegment = channelUser.lastMentionedSegment;
7132
+ unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
7133
+ isMentioned = lastMentionedSegment > readToSegment;
7134
+ }
7135
+ const cacheChannelUnread = {
7069
7136
  channelId: channels[i].channelId,
7070
7137
  lastSegment: channels[i].messageCount,
7071
7138
  readToSegment,
7072
7139
  lastMentionedSegment,
7073
- unreadCount: channels[i].messageCount - readToSegment,
7074
- isMentioned: lastMentionedSegment > readToSegment,
7075
- isDeleted: channels[i].isDeleted,
7076
- });
7140
+ unreadCount,
7141
+ isMentioned,
7142
+ isDeleted: channels[i].isDeleted || false,
7143
+ };
7144
+ pushToCache(cacheKey, cacheChannelUnread);
7077
7145
  }
7078
7146
  };
7079
7147
  const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
@@ -7873,6 +7941,12 @@ const setClientToken = async (params) => {
7873
7941
  isGlobalBanned: false,
7874
7942
  isUserDeleted: false,
7875
7943
  };
7944
+ client.upload.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
7945
+ client.upload.defaults.metadata = {
7946
+ tokenExpiry: expiresAt,
7947
+ isGlobalBanned: false,
7948
+ isUserDeleted: false,
7949
+ };
7876
7950
  // manually setup the token for ws transport
7877
7951
  if (client.ws)
7878
7952
  client.ws.io.opts.query = { token: accessToken };
@@ -7925,7 +7999,11 @@ const onChannelDeleted = (callback) => {
7925
7999
  deleteChannelUnreadByChannelId(channel.channelId);
7926
8000
  }
7927
8001
  else if (isLegacyUnreadCount) {
7928
- dropFromCache(['channelUnread', 'get', channel.channelId]);
8002
+ const cacheKey = ['channelUnread', 'get', channel.channelId];
8003
+ const cache = pullFromCache(cacheKey);
8004
+ if (cache) {
8005
+ pushToCache(cacheKey, Object.assign(Object.assign({}, cache), { isDeleted: true }));
8006
+ }
7929
8007
  }
7930
8008
  });
7931
8009
  ingestInCache(data);
@@ -8912,7 +8990,10 @@ const onMessageCreatedMqtt = (callback) => {
8912
8990
  'get',
8913
8991
  message.channelId,
8914
8992
  ])) === null || _a === void 0 ? void 0 : _a.data;
8915
- if (!channelUnread || channelUnread.lastSegment >= message.segment)
8993
+ if (!channelUnread ||
8994
+ channelUnread.lastSegment >= message.segment ||
8995
+ typeof channelUnread.readToSegment !== 'number' ||
8996
+ typeof channelUnread.lastMentionedSegment !== 'number')
8916
8997
  return;
8917
8998
  const lastSegment = message.segment;
8918
8999
  const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
@@ -8921,10 +9002,12 @@ const onMessageCreatedMqtt = (callback) => {
8921
9002
  client.userId &&
8922
9003
  mention.userPublicIds.includes(client.userId)));
8923
9004
  });
8924
- const lastMentionSegment = isMentionedInMessage
9005
+ const lastMentionedSegment = isMentionedInMessage
8925
9006
  ? message.segment
8926
- : channelUnread.lastMentionSegment;
8927
- pushToCache(['channelUnread', 'get', message.channelId], Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: lastSegment - channelUnread.readToSegment, lastMentionSegment, isMentioned: !(channelUnread.readToSegment >= lastMentionSegment) }));
9007
+ : channelUnread.lastMentionedSegment;
9008
+ const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - channelUnread.readToSegment, 0), lastMentionedSegment, isMentioned: !(channelUnread.readToSegment >= lastMentionedSegment) });
9009
+ pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
9010
+ fireEvent('local.channelUnread.updated', updatedChannelUnread);
8928
9011
  });
8929
9012
  }
8930
9013
  // Update in cache
@@ -9581,15 +9664,17 @@ const DEFAULT_DEBUG_SESSION = 'amity';
9581
9664
  * @category Client API
9582
9665
  * */
9583
9666
  const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, } = {}) => {
9584
- var _a, _b;
9667
+ var _a, _b, _c;
9585
9668
  const log = createLogger(debugSession);
9586
9669
  log('client/api/createClient', {
9587
9670
  apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
9588
9671
  apiRegion,
9589
9672
  });
9590
9673
  const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
9591
- const mqttEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _b !== void 0 ? _b : computeUrl('mqtt', apiRegion);
9674
+ const uploadEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.upload) !== null && _b !== void 0 ? _b : computeUrl('upload', apiRegion);
9675
+ const mqttEndpoint = (_c = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _c !== void 0 ? _c : computeUrl('mqtt', apiRegion);
9592
9676
  const http = createHttpTransport(httpEndpoint);
9677
+ const upload = createHttpTransport(uploadEndpoint);
9593
9678
  let ws;
9594
9679
  let mqtt;
9595
9680
  if (rteEnabled) {
@@ -9620,6 +9705,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
9620
9705
  http,
9621
9706
  ws,
9622
9707
  mqtt,
9708
+ upload,
9623
9709
  emitter,
9624
9710
  /*
9625
9711
  * Session Components
@@ -9649,7 +9735,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
9649
9735
  return activeClient;
9650
9736
  setActiveClient(client);
9651
9737
  }
9652
- catch (_c) {
9738
+ catch (_d) {
9653
9739
  setActiveClient(client);
9654
9740
  }
9655
9741
  return client;
@@ -10106,7 +10192,7 @@ const getUserUnread = (callback) => {
10106
10192
  };
10107
10193
  };
10108
10194
 
10109
- var index$l = /*#__PURE__*/Object.freeze({
10195
+ var index$m = /*#__PURE__*/Object.freeze({
10110
10196
  __proto__: null,
10111
10197
  getActiveClient: getActiveClient,
10112
10198
  getActiveUser: getActiveUser,
@@ -11313,7 +11399,7 @@ const getMyFollowInfo = (callback) => {
11313
11399
  };
11314
11400
  /* end_public_function */
11315
11401
 
11316
- var index$k = /*#__PURE__*/Object.freeze({
11402
+ var index$l = /*#__PURE__*/Object.freeze({
11317
11403
  __proto__: null,
11318
11404
  blockUser: blockUser,
11319
11405
  unBlockUser: unBlockUser,
@@ -12328,9 +12414,9 @@ var AmityUserSearchMatchType;
12328
12414
  AmityUserSearchMatchType["PARTIAL"] = "partial";
12329
12415
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
12330
12416
 
12331
- var index$j = /*#__PURE__*/Object.freeze({
12417
+ var index$k = /*#__PURE__*/Object.freeze({
12332
12418
  __proto__: null,
12333
- Relationship: index$k,
12419
+ Relationship: index$l,
12334
12420
  getUserByIds: getUserByIds,
12335
12421
  updateUser: updateUser,
12336
12422
  flagUser: flagUser,
@@ -12438,7 +12524,7 @@ const uploadFile = async (formData, onProgress) => {
12438
12524
  const headers = 'getHeaders' in formData
12439
12525
  ? formData.getHeaders()
12440
12526
  : { 'content-type': 'multipart/form-data' };
12441
- const { data } = await client.http.post('/api/v4/files', formData, {
12527
+ const { data } = await client.upload.post('/api/v4/files', formData, {
12442
12528
  headers,
12443
12529
  onUploadProgress({ loaded, total = 100 }) {
12444
12530
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -12528,7 +12614,7 @@ const uploadVideo = async (formData, feedType, onProgress) => {
12528
12614
  const headers = 'getHeaders' in formData
12529
12615
  ? formData.getHeaders()
12530
12616
  : { 'content-type': 'multipart/form-data' };
12531
- const { data } = await client.http.post('/api/v4/videos', formData, {
12617
+ const { data } = await client.upload.post('/api/v4/videos', formData, {
12532
12618
  headers,
12533
12619
  onUploadProgress({ loaded, total = 100 }) {
12534
12620
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -12559,24 +12645,37 @@ const uploadVideo = async (formData, feedType, onProgress) => {
12559
12645
  *
12560
12646
  * @param formData The data necessary to create a new {@link Amity.File<'image'>}
12561
12647
  * @param onProgress The callback to track the upload progress
12648
+ * @param altText The alt text for the image
12562
12649
  * @returns The newly created {@link Amity.File<'image'>}
12563
12650
  *
12564
12651
  * @category File API
12565
12652
  * @async
12566
12653
  */
12567
- const uploadImage = async (formData, onProgress) => {
12654
+ const uploadImage = async (formData, onProgress, altText) => {
12568
12655
  const client = getActiveClient();
12569
12656
  client.log('file/uploadImage', formData);
12570
12657
  const files = formData.getAll('files');
12571
- if (!files.length)
12572
- throw new Error('The formData object must have a `files` key.');
12658
+ if (files === null || files === void 0 ? void 0 : files.length) {
12659
+ console.warn('Deprecation Warning: `files` is deprecated, please use `file` instead.');
12660
+ formData.append('preferredFilename', files[0].name);
12661
+ }
12662
+ else {
12663
+ const file = formData.get('file');
12664
+ if (!file) {
12665
+ throw new Error('The formData object must have a `file` or `files` key');
12666
+ }
12667
+ formData.append('preferredFilename', file.name);
12668
+ // alt is for single image
12669
+ if (altText) {
12670
+ formData.append('altText', altText);
12671
+ }
12672
+ }
12573
12673
  const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
12574
12674
  formData.append('accessType', accessType);
12575
- formData.append('preferredFilename', files[0].name);
12576
12675
  const headers = 'getHeaders' in formData
12577
12676
  ? formData.getHeaders()
12578
12677
  : { 'content-type': 'multipart/form-data' };
12579
- const { data } = await client.http.post('/api/v4/images', formData, {
12678
+ const { data } = await client.upload.post('/api/v4/images', formData, {
12580
12679
  headers,
12581
12680
  onUploadProgress({ loaded, total = 100 }) {
12582
12681
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -12594,14 +12693,46 @@ const uploadImage = async (formData, onProgress) => {
12594
12693
  };
12595
12694
  /* end_public_function */
12596
12695
 
12597
- var index$i = /*#__PURE__*/Object.freeze({
12696
+ /* begin_public_function
12697
+ id: file.update.altText
12698
+ */
12699
+ /**
12700
+ * ```js
12701
+ * import { FileRepository } from '@amityco/ts-sdk'
12702
+ * const updated = await FileRepository.updateAltText(fileId, altText)
12703
+ * ```
12704
+ *
12705
+ * Updates an {@link Amity.File<'image'>['altText']}.
12706
+ *
12707
+ * @param fileId The ID of the {@link Amity.File<'image'>} to edit
12708
+ * @param altText The new alt text for the {@link Amity.File<'image'>}
12709
+ * @returns the updated {@link Amity.File<'image'>} object
12710
+ *
12711
+ * @category File API
12712
+ * @async
12713
+ */
12714
+ const updateAltText = async (fileId, altText) => {
12715
+ const client = getActiveClient();
12716
+ client.log('file/updateAltText', altText);
12717
+ const { data } = await client.http.put(`/api/v3/files/${fileId}`, {
12718
+ altText,
12719
+ });
12720
+ const cachedAt = client.cache && Date.now();
12721
+ if (client.cache)
12722
+ ingestInCache({ files: [data] }, { cachedAt });
12723
+ return true;
12724
+ };
12725
+ /* end_public_function */
12726
+
12727
+ var index$j = /*#__PURE__*/Object.freeze({
12598
12728
  __proto__: null,
12599
12729
  getFile: getFile,
12600
12730
  uploadFile: uploadFile,
12601
12731
  deleteFile: deleteFile,
12602
12732
  fileUrlWithSize: fileUrlWithSize,
12603
12733
  uploadVideo: uploadVideo,
12604
- uploadImage: uploadImage
12734
+ uploadImage: uploadImage,
12735
+ updateAltText: updateAltText
12605
12736
  });
12606
12737
 
12607
12738
  /**
@@ -13661,6 +13792,29 @@ const createCommentEventSubscriber = (event, callback) => {
13661
13792
  }
13662
13793
  }
13663
13794
  }
13795
+ }
13796
+ if (['comment.deleted'].includes(event)) {
13797
+ // NOTE: skip deleting comment to parent comment children if it's the same user since we use the local event to update instead.
13798
+ if (event === 'comment.deleted' && comment.data.userId === client.userId)
13799
+ return;
13800
+ if (comments[0].parentId) {
13801
+ const parentComment = pullFromCache([
13802
+ 'comment',
13803
+ 'get',
13804
+ comments[0].parentId,
13805
+ ]);
13806
+ if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
13807
+ // Remove deleted comment in parent childComment if still exists
13808
+ if (parentComment.data.children.includes(comments[0].commentId)) {
13809
+ const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber - 1, children: [
13810
+ ...new Set([
13811
+ ...parentComment.data.children.filter(id => id !== comments[0].commentId),
13812
+ ]),
13813
+ ] });
13814
+ pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
13815
+ }
13816
+ }
13817
+ }
13664
13818
  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; });
13665
13819
  queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
13666
13820
  }
@@ -13673,7 +13827,7 @@ const createCommentEventSubscriber = (event, callback) => {
13673
13827
  const createLocalCommentEventSubscriber = (event, callback) => {
13674
13828
  const client = getActiveClient();
13675
13829
  const filter = (payload) => {
13676
- var _a;
13830
+ var _a, _b;
13677
13831
  if (!client.cache) {
13678
13832
  // TODO: here we are missing specific properties here!
13679
13833
  callback(LinkedObject.comment(payload.comments[0]));
@@ -13716,6 +13870,38 @@ const createLocalCommentEventSubscriber = (event, callback) => {
13716
13870
  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; });
13717
13871
  queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
13718
13872
  }
13873
+ if (['local.comment.deleted'].includes(event)) {
13874
+ if (comments[0].parentId) {
13875
+ const parentComment = pullFromCache([
13876
+ 'comment',
13877
+ 'get',
13878
+ comments[0].parentId,
13879
+ ]);
13880
+ if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
13881
+ // Remove deleted comment in parent childComment if still exists
13882
+ if (parentComment.data.children.includes(comments[0].commentId)) {
13883
+ const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber - 1, children: [
13884
+ ...new Set([
13885
+ ...parentComment.data.children.filter(id => id !== comments[0].commentId),
13886
+ ]),
13887
+ ] });
13888
+ pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
13889
+ setTimeout(() => {
13890
+ // NOTE: This is workaround solution for emitting event not work properly.
13891
+ fireEvent('comment.updated', {
13892
+ comments: [newParentComment],
13893
+ commentChildren: [],
13894
+ files: [],
13895
+ users: [],
13896
+ communityUsers: [],
13897
+ });
13898
+ }, 200);
13899
+ }
13900
+ }
13901
+ }
13902
+ const queries = (_b = queryCache(['comment', 'query'])) === null || _b === void 0 ? void 0 : _b.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
13903
+ queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
13904
+ }
13719
13905
  callback(LinkedObject.comment(comment.data));
13720
13906
  }
13721
13907
  }
@@ -14406,7 +14592,7 @@ const getReactions = (params, callback, config) => {
14406
14592
  };
14407
14593
  /* end_public_function */
14408
14594
 
14409
- var index$h = /*#__PURE__*/Object.freeze({
14595
+ var index$i = /*#__PURE__*/Object.freeze({
14410
14596
  __proto__: null,
14411
14597
  addReaction: addReaction,
14412
14598
  removeReaction: removeReaction,
@@ -16222,7 +16408,7 @@ const getMessages = (params, callback, config) => {
16222
16408
  };
16223
16409
  /* end_public_function */
16224
16410
 
16225
- var index$g = /*#__PURE__*/Object.freeze({
16411
+ var index$h = /*#__PURE__*/Object.freeze({
16226
16412
  __proto__: null,
16227
16413
  createMessage: createMessage,
16228
16414
  updateMessage: updateMessage,
@@ -16748,7 +16934,7 @@ const stopMessageReceiptSync = (subChannelId) => {
16748
16934
  };
16749
16935
  /* end_public_function */
16750
16936
 
16751
- var index$f = /*#__PURE__*/Object.freeze({
16937
+ var index$g = /*#__PURE__*/Object.freeze({
16752
16938
  __proto__: null,
16753
16939
  getSubChannelByIds: getSubChannels$1,
16754
16940
  createSubChannel: createSubChannel,
@@ -17584,6 +17770,120 @@ const getChannels = (params, callback, config) => {
17584
17770
  };
17585
17771
  /* end_public_function */
17586
17772
 
17773
+ /**
17774
+ *
17775
+ * Calculate user unread from {@link Amity.ChannelUnread} objects
17776
+ *
17777
+ * @returns the {@link Amity.UserUnread} objects
17778
+ *
17779
+ * @category Channel API
17780
+ * @async
17781
+ */
17782
+ const getTotalChannelsUnread$1 = () => {
17783
+ var _a;
17784
+ const client = getActiveClient();
17785
+ client.log('channel/getTotalChannelsUnread.locally');
17786
+ const cachedChannelsUnread = ((_a = queryCache(['channelUnread', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
17787
+ return !data.isDeleted;
17788
+ })) || [];
17789
+ const totalChannelsUnread = (cachedChannelsUnread === null || cachedChannelsUnread === void 0 ? void 0 : cachedChannelsUnread.reduce((acc, { data }) => {
17790
+ acc.unreadCount += data.unreadCount;
17791
+ acc.isMentioned = acc.isMentioned || data.isMentioned;
17792
+ return acc;
17793
+ }, { unreadCount: 0, isMentioned: false })) || { unreadCount: 0, isMentioned: false };
17794
+ const cachedAt = client.cache && Date.now();
17795
+ return {
17796
+ data: totalChannelsUnread,
17797
+ cachedAt,
17798
+ };
17799
+ };
17800
+
17801
+ /* begin_public_function
17802
+ id: totalChannelsUnread.get
17803
+ */
17804
+ /**
17805
+ * ```js
17806
+ * import { ChannelRepository } from '@amityco/ts-sdk';
17807
+ *
17808
+ * let totalChannelsUnread;
17809
+ *
17810
+ * const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
17811
+ * unread = response.data;
17812
+ * });
17813
+ * ```
17814
+ *
17815
+ * Observe all mutation on a given {@link Amity.UserUnread}
17816
+ *
17817
+ * @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
17818
+ *
17819
+ * @category User Unread Live Object
17820
+ *
17821
+ */
17822
+ const getTotalChannelsUnread = (callback) => {
17823
+ const { _id: userId } = getActiveUser();
17824
+ if (!userId)
17825
+ throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
17826
+ const { log, cache } = getActiveClient();
17827
+ if (!cache) {
17828
+ console.log('For using Live Object feature you need to enable Cache!');
17829
+ }
17830
+ const timestamp = Date.now();
17831
+ log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
17832
+ const disposers = [];
17833
+ let isUnsyncedModel = false; // for messages
17834
+ let model;
17835
+ const dispatcher = (data) => {
17836
+ const { data: userUnread } = data;
17837
+ const callbackModel = userUnread
17838
+ ? {
17839
+ unreadCount: userUnread.unreadCount,
17840
+ isMentioned: userUnread.isMentioned,
17841
+ }
17842
+ : undefined;
17843
+ model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
17844
+ callback({
17845
+ data: callbackModel
17846
+ ? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
17847
+ loading: data.loading,
17848
+ error: data.error,
17849
+ });
17850
+ };
17851
+ const realtimeRouter = (userUnread) => {
17852
+ if (isEqual(model, userUnread))
17853
+ return;
17854
+ dispatcher({
17855
+ loading: false,
17856
+ data: userUnread,
17857
+ });
17858
+ };
17859
+ const onFetch = () => {
17860
+ const query = createQuery(async () => getTotalChannelsUnread$1());
17861
+ runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
17862
+ if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
17863
+ dispatcher({
17864
+ data,
17865
+ origin,
17866
+ loading: false,
17867
+ error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
17868
+ });
17869
+ isUnsyncedModel = true;
17870
+ disposers.forEach(fn => fn());
17871
+ }
17872
+ else if (!isUnsyncedModel) {
17873
+ dispatcher({ loading, data, origin, error });
17874
+ }
17875
+ if (error) {
17876
+ disposers.forEach(fn => fn());
17877
+ }
17878
+ });
17879
+ };
17880
+ disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
17881
+ onFetch();
17882
+ return () => {
17883
+ disposers.forEach(fn => fn());
17884
+ };
17885
+ };
17886
+
17587
17887
  /* begin_public_function
17588
17888
  id: channel.member.add
17589
17889
  */
@@ -17948,7 +18248,7 @@ const searchMembers$1 = (params, callback, config) => {
17948
18248
  };
17949
18249
  /* end_public_function */
17950
18250
 
17951
- var index$e = /*#__PURE__*/Object.freeze({
18251
+ var index$f = /*#__PURE__*/Object.freeze({
17952
18252
  __proto__: null,
17953
18253
  addMembers: addMembers$1,
17954
18254
  removeMembers: removeMembers$1,
@@ -18151,7 +18451,7 @@ const unmuteMembers = async (channelId, userIds) => {
18151
18451
  };
18152
18452
  /* end_public_function */
18153
18453
 
18154
- var index$d = /*#__PURE__*/Object.freeze({
18454
+ var index$e = /*#__PURE__*/Object.freeze({
18155
18455
  __proto__: null,
18156
18456
  addRole: addRole,
18157
18457
  removeRole: removeRole,
@@ -18161,10 +18461,10 @@ var index$d = /*#__PURE__*/Object.freeze({
18161
18461
  unmuteMembers: unmuteMembers
18162
18462
  });
18163
18463
 
18164
- var index$c = /*#__PURE__*/Object.freeze({
18464
+ var index$d = /*#__PURE__*/Object.freeze({
18165
18465
  __proto__: null,
18166
- Membership: index$e,
18167
- Moderation: index$d,
18466
+ Membership: index$f,
18467
+ Moderation: index$e,
18168
18468
  getChannelByIds: getChannelByIds$1,
18169
18469
  createChannel: createChannel,
18170
18470
  updateChannel: updateChannel,
@@ -18187,6 +18487,7 @@ var index$c = /*#__PURE__*/Object.freeze({
18187
18487
  onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
18188
18488
  getChannel: getChannel,
18189
18489
  getChannels: getChannels,
18490
+ getTotalChannelsUnread: getTotalChannelsUnread,
18190
18491
  MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
18191
18492
  isUnreadCountSupport: isUnreadCountSupport,
18192
18493
  convertFromRaw: convertFromRaw,
@@ -19543,7 +19844,7 @@ const searchMembers = (params, callback, config) => {
19543
19844
  };
19544
19845
  /* end_public_function */
19545
19846
 
19546
- var index$b = /*#__PURE__*/Object.freeze({
19847
+ var index$c = /*#__PURE__*/Object.freeze({
19547
19848
  __proto__: null,
19548
19849
  addMembers: addMembers,
19549
19850
  removeMembers: removeMembers,
@@ -20568,7 +20869,7 @@ const unbanMembers = async (communityId, userIds) => {
20568
20869
  };
20569
20870
  /* end_public_function */
20570
20871
 
20571
- var index$a = /*#__PURE__*/Object.freeze({
20872
+ var index$b = /*#__PURE__*/Object.freeze({
20572
20873
  __proto__: null,
20573
20874
  addRoles: addRoles,
20574
20875
  removeRoles: removeRoles,
@@ -20576,10 +20877,10 @@ var index$a = /*#__PURE__*/Object.freeze({
20576
20877
  unbanMembers: unbanMembers
20577
20878
  });
20578
20879
 
20579
- var index$9 = /*#__PURE__*/Object.freeze({
20880
+ var index$a = /*#__PURE__*/Object.freeze({
20580
20881
  __proto__: null,
20581
- Moderation: index$a,
20582
- Membership: index$b,
20882
+ Moderation: index$b,
20883
+ Membership: index$c,
20583
20884
  getCommunityByIds: getCommunities$1,
20584
20885
  createCommunity: createCommunity,
20585
20886
  updateCommunity: updateCommunity,
@@ -20812,7 +21113,7 @@ const getCategories = (params, callback, config) => {
20812
21113
  };
20813
21114
  /* end_public_function */
20814
21115
 
20815
- var index$8 = /*#__PURE__*/Object.freeze({
21116
+ var index$9 = /*#__PURE__*/Object.freeze({
20816
21117
  __proto__: null,
20817
21118
  getCategory: getCategory,
20818
21119
  getCategories: getCategories
@@ -20980,7 +21281,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
20980
21281
  : undefined;
20981
21282
  };
20982
21283
 
20983
- var index$7 = /*#__PURE__*/Object.freeze({
21284
+ var index$8 = /*#__PURE__*/Object.freeze({
20984
21285
  __proto__: null,
20985
21286
  queryGlobalFeed: queryGlobalFeed,
20986
21287
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -22295,7 +22596,7 @@ const getComments = (params, callback, config) => {
22295
22596
  };
22296
22597
  /* end_public_function */
22297
22598
 
22298
- var index$6 = /*#__PURE__*/Object.freeze({
22599
+ var index$7 = /*#__PURE__*/Object.freeze({
22299
22600
  __proto__: null,
22300
22601
  getCommentByIds: getCommentByIds,
22301
22602
  createComment: createComment,
@@ -23302,7 +23603,7 @@ const semanticSearchPosts = (params, callback, config) => {
23302
23603
  };
23303
23604
  };
23304
23605
 
23305
- var index$5 = /*#__PURE__*/Object.freeze({
23606
+ var index$6 = /*#__PURE__*/Object.freeze({
23306
23607
  __proto__: null,
23307
23608
  getPostByIds: getPostByIds,
23308
23609
  createPost: createPost,
@@ -23836,7 +24137,7 @@ const getStreams = (params, callback, config) => {
23836
24137
  };
23837
24138
  };
23838
24139
 
23839
- var index$4 = /*#__PURE__*/Object.freeze({
24140
+ var index$5 = /*#__PURE__*/Object.freeze({
23840
24141
  __proto__: null,
23841
24142
  createStream: createStream,
23842
24143
  updateStream: updateStream,
@@ -24123,7 +24424,7 @@ const getPoll = (pollId, callback) => {
24123
24424
  };
24124
24425
  /* end_public_function */
24125
24426
 
24126
- var index$3 = /*#__PURE__*/Object.freeze({
24427
+ var index$4 = /*#__PURE__*/Object.freeze({
24127
24428
  __proto__: null,
24128
24429
  createPoll: createPoll,
24129
24430
  closePoll: closePoll,
@@ -24494,7 +24795,7 @@ const getPlayer = async (parameters) => {
24494
24795
  return video;
24495
24796
  };
24496
24797
 
24497
- var index$2 = /*#__PURE__*/Object.freeze({
24798
+ var index$3 = /*#__PURE__*/Object.freeze({
24498
24799
  __proto__: null,
24499
24800
  getPlayer: getPlayer
24500
24801
  });
@@ -25667,7 +25968,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
25667
25968
  };
25668
25969
  };
25669
25970
 
25670
- var index$1 = /*#__PURE__*/Object.freeze({
25971
+ var index$2 = /*#__PURE__*/Object.freeze({
25671
25972
  __proto__: null,
25672
25973
  createImageStory: createImageStory,
25673
25974
  createVideoStory: createVideoStory,
@@ -25704,7 +26005,7 @@ const getNetworkAds = async () => {
25704
26005
  };
25705
26006
  };
25706
26007
 
25707
- var index = /*#__PURE__*/Object.freeze({
26008
+ var index$1 = /*#__PURE__*/Object.freeze({
25708
26009
  __proto__: null,
25709
26010
  getNetworkAds: getNetworkAds
25710
26011
  });
@@ -25731,31 +26032,404 @@ const createUserToken = async (apiKey, apiRegion, params) => {
25731
26032
  return { accessToken: data.accessToken };
25732
26033
  };
25733
26034
 
26035
+ /* begin_public_function
26036
+ id: notificationTray.getNotificationTraySeen
26037
+ */
26038
+ /**
26039
+ * ```js
26040
+ * import { notificationTray } from '@amityco/ts-sdk'
26041
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen()
26042
+ * ```
26043
+ *
26044
+ *
26045
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
26046
+ *
26047
+ * @category NotificationTray API
26048
+ * @async
26049
+ * */
26050
+ const getNotificationTraySeen$1 = async () => {
26051
+ const client = getActiveClient();
26052
+ client.log('notificationTray/getNotificationTraySeen', {});
26053
+ const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
26054
+ const cachedAt = client.cache && Date.now();
26055
+ if (client.cache) {
26056
+ const cacheKey = ['notificationTraySeen', 'get', client.userId];
26057
+ pushToCache(cacheKey, {
26058
+ userId: client.userId,
26059
+ lastTraySeenAt: payload.lastTraySeenAt,
26060
+ lastTrayOccuredAt: payload.lastTrayOccurredAt,
26061
+ });
26062
+ }
26063
+ return {
26064
+ data: {
26065
+ userId: client.userId,
26066
+ lastTraySeenAt: payload.lastTraySeenAt,
26067
+ lastTrayOccurredAt: payload.lastTrayOccurredAt,
26068
+ isSeen: payload.lastTraySeenAt > payload.lastTrayOccurredAt,
26069
+ },
26070
+ cachedAt,
26071
+ };
26072
+ };
26073
+ /* end_public_function */
26074
+ /**
26075
+ * ```js
26076
+ * import { notificationTray } from '@amityco/ts-sdk'
26077
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen.locally()
26078
+ * ```
26079
+ *
26080
+ * Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
26081
+ *
26082
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
26083
+ *
26084
+ * @category NotificationTray API
26085
+ * @async
26086
+ * */
26087
+ getNotificationTraySeen$1.locally = () => {
26088
+ var _a;
26089
+ const client = getActiveClient();
26090
+ client.log('notificationTray/getNotificationTraySeen.locally', {});
26091
+ if (!client.cache)
26092
+ return;
26093
+ const queryKey = ['notificationTraySeen', 'get'];
26094
+ const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
26095
+ if (!data)
26096
+ return;
26097
+ return { data, cachedAt };
26098
+ };
26099
+
26100
+ /**
26101
+ * ```js
26102
+ * import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
26103
+ * const dispose = onNotificationTraySeenUpdated(data => {
26104
+ * // ...
26105
+ * })
26106
+ * ```
26107
+ *
26108
+ * Fired when an {@link Amity.NotificationTraySeen} has been updated
26109
+ *
26110
+ * @param callback The function to call when the event was fired
26111
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
26112
+ *
26113
+ * @category NotificationTraySeen Events
26114
+ */
26115
+ const onNotificationTraySeenUpdated = (callback) => {
26116
+ const client = getActiveClient();
26117
+ const disposers = [
26118
+ createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
26119
+ ];
26120
+ return () => {
26121
+ disposers.forEach(fn => fn());
26122
+ };
26123
+ };
26124
+
26125
+ /* begin_public_function
26126
+ id: notificationTray.getNotificationTraySeen
26127
+ */
26128
+ /**
26129
+ * ```js
26130
+ * import { notificationTray } from '@amityco/ts-sdk';
26131
+ *
26132
+ * let notificationTraySeen;
26133
+ *
26134
+ * const unsubscribe = getNotificationTraySeen(response => {
26135
+ * notificationTraySeen = response.data;
26136
+ * });
26137
+ * ```
26138
+ *
26139
+ * Observe all mutation on a given {@link Amity.NotificationTraySeen}
26140
+ *
26141
+ * @param callback the function to call when new data are available
26142
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
26143
+ *
26144
+ * @category NotificationTraySeen Live Object
26145
+ */
26146
+ const getNotificationTraySeen = (callback) => {
26147
+ const { userId } = getActiveUser();
26148
+ return liveObject(userId, callback, 'userId', getNotificationTraySeen$1, [onNotificationTraySeenUpdated], {
26149
+ callbackDataSelector: (data) => {
26150
+ let isSeen = true;
26151
+ if (data === null || data === void 0 ? void 0 : data.lastTrayOccurredAt) {
26152
+ if (!data.lastTraySeenAt) {
26153
+ isSeen = false;
26154
+ }
26155
+ else {
26156
+ isSeen =
26157
+ convertDateStringToTimestamp(data.lastTraySeenAt) >
26158
+ convertDateStringToTimestamp(data.lastTrayOccurredAt);
26159
+ }
26160
+ }
26161
+ return {
26162
+ lastTrayOccurredAt: data === null || data === void 0 ? void 0 : data.lastTrayOccurredAt,
26163
+ lastTraySeenAt: data === null || data === void 0 ? void 0 : data.lastTraySeenAt,
26164
+ isSeen,
26165
+ };
26166
+ },
26167
+ });
26168
+ };
26169
+ /* end_public_function */
26170
+
26171
+ /**
26172
+ * TODO: handle cache receive cache option, and cache policy
26173
+ * TODO: check if querybyIds is supported
26174
+ */
26175
+ class NotificationTrayItemsPaginationController extends PaginationController {
26176
+ async getRequest(queryParams, token) {
26177
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
26178
+ const options = token ? { token } : { limit };
26179
+ const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
26180
+ params: Object.assign(Object.assign({}, params), { options }),
26181
+ });
26182
+ return queryResponse;
26183
+ }
26184
+ }
26185
+
26186
+ class NotificationTrayItemsQuerystreamController extends QueryStreamController {
26187
+ constructor(query, cacheKey, notifyChange, preparePayload) {
26188
+ super(query, cacheKey);
26189
+ this.notifyChange = notifyChange;
26190
+ this.preparePayload = preparePayload;
26191
+ }
26192
+ async saveToMainDB(response) {
26193
+ const processedPayload = await this.preparePayload(response);
26194
+ const client = getActiveClient();
26195
+ const cachedAt = client.cache && Date.now();
26196
+ if (client.cache) {
26197
+ ingestInCache(processedPayload, { cachedAt });
26198
+ }
26199
+ }
26200
+ appendToQueryStream(response, direction, refresh = false) {
26201
+ var _a, _b;
26202
+ if (refresh) {
26203
+ pushToCache(this.cacheKey, {
26204
+ data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
26205
+ });
26206
+ }
26207
+ else {
26208
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26209
+ const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
26210
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
26211
+ ...new Set([
26212
+ ...notifications,
26213
+ ...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
26214
+ ]),
26215
+ ] }));
26216
+ }
26217
+ }
26218
+ }
26219
+
26220
+ const prepareNotificationTrayItemsPayload = (rawPayload) => {
26221
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
26222
+ return Object.assign(Object.assign({}, rawPayload), { users });
26223
+ };
26224
+
26225
+ class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
26226
+ constructor(query, callback) {
26227
+ const queryStreamId = hash__default["default"](query);
26228
+ const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
26229
+ const paginationController = new NotificationTrayItemsPaginationController(query);
26230
+ super(paginationController, queryStreamId, cacheKey, callback);
26231
+ this.query = query;
26232
+ this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
26233
+ this.callback = callback.bind(this);
26234
+ this.loadPage({ initial: true });
26235
+ }
26236
+ setup() {
26237
+ var _a;
26238
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26239
+ if (!collection) {
26240
+ pushToCache(this.cacheKey, {
26241
+ data: [],
26242
+ params: {},
26243
+ });
26244
+ }
26245
+ }
26246
+ async persistModel(queryPayload) {
26247
+ await this.queryStreamController.saveToMainDB(queryPayload);
26248
+ }
26249
+ persistQueryStream({ response, direction, refresh, }) {
26250
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
26251
+ }
26252
+ // eslint-disable-next-line class-methods-use-this
26253
+ startSubscription() {
26254
+ return [];
26255
+ }
26256
+ notifyChange({ origin, loading, error }) {
26257
+ var _a, _b;
26258
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26259
+ if (!collection)
26260
+ return;
26261
+ const data = ((_b = collection.data
26262
+ .map(id => pullFromCache(['notificationTrayItem', 'get', id]))
26263
+ .filter(isNonNullable)
26264
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
26265
+ if (!this.shouldNotify(data) && origin === 'event')
26266
+ return;
26267
+ this.callback({
26268
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
26269
+ data,
26270
+ hasNextPage: !!this.paginationController.getNextToken(),
26271
+ loading,
26272
+ error,
26273
+ });
26274
+ }
26275
+ }
26276
+
26277
+ /**
26278
+ * Get notification tray items for a notification tray page
26279
+ *
26280
+ * @param params the limit query parameters
26281
+ * @param callback the callback to be called when the notification tray items are updated
26282
+ * @returns items in the notification tray
26283
+ *
26284
+ * @category Notification tray items Live Collection
26285
+ *
26286
+ */
26287
+ const getNotificationTrayItems = (params, callback, config) => {
26288
+ const { log, cache } = getActiveClient();
26289
+ if (!cache) {
26290
+ console.log(ENABLE_CACHE_MESSAGE);
26291
+ }
26292
+ const timestamp = Date.now();
26293
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
26294
+ const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
26295
+ const disposers = notiTrayItemsLiveCollection.startSubscription();
26296
+ const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
26297
+ disposers.push(() => dropFromCache(cacheKey));
26298
+ return () => {
26299
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
26300
+ disposers.forEach(fn => fn());
26301
+ };
26302
+ };
26303
+
26304
+ /* begin_public_function
26305
+ id: notificationTrayItem.markSeen
26306
+ */
26307
+ /**
26308
+ * ```js
26309
+ * import { notificationTray } from '@amityco/ts-sdk'
26310
+ * const updated = await notificationTray.markItemsSeen()
26311
+ * ```
26312
+ *
26313
+ * Updates an {@link Amity.NotificationItemSeen}
26314
+ *
26315
+ * @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
26316
+ * @returns the updated {@link Amity.NotificationItemSeen} object
26317
+ *
26318
+ * @category NotificationItemSeen API
26319
+ * @async
26320
+ */
26321
+ const markItemsSeen = async (trayItems) => {
26322
+ const client = getActiveClient();
26323
+ client.log('notificationTray/markItemsSeen', {});
26324
+ const { data: payload } = await client.http.post(`api/v1/notification-tray/items/seen`, {
26325
+ trayItems: trayItems.map(item => ({
26326
+ id: item.id,
26327
+ lastSeenAt: item.lastSeenAt,
26328
+ })),
26329
+ });
26330
+ const updatedData = trayItems
26331
+ .map(patchItem => {
26332
+ var _a;
26333
+ const cacheData = (_a = pullFromCache([
26334
+ 'notificationTrayItem',
26335
+ 'get',
26336
+ patchItem.id,
26337
+ ])) === null || _a === void 0 ? void 0 : _a.data;
26338
+ if (!cacheData)
26339
+ return;
26340
+ const data = Object.assign(Object.assign({}, cacheData), payload);
26341
+ if (client.cache) {
26342
+ const cachedAt = Date.now();
26343
+ pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
26344
+ }
26345
+ return data;
26346
+ })
26347
+ .filter(Boolean);
26348
+ fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
26349
+ };
26350
+ /* end_public_function */
26351
+
26352
+ /* begin_public_function
26353
+ id: notificationTray.markSeen
26354
+ */
26355
+ /**
26356
+ * ```js
26357
+ * import { notificationTray } from '@amityco/ts-sdk'
26358
+ * const updated = await notificationTray.markTraySeen({
26359
+ * lastSeenAt: Amity.timestamp,
26360
+ * })
26361
+ * ```
26362
+ *
26363
+ * Updates an {@link Amity.NotificationTraySeen}
26364
+ *
26365
+ * @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
26366
+ * @param lastSeenAt The patch data to apply
26367
+ * @returns the updated {@link Amity.NotificationTraySeen} object
26368
+ *
26369
+ * @category Post API
26370
+ * @async
26371
+ */
26372
+ const markTraySeen = async (lastSeenAt) => {
26373
+ var _a;
26374
+ const client = getActiveClient();
26375
+ client.log('notificationTray/markTraySeen', {});
26376
+ const { data: payload } = await client.http.post(`api/v1/notification-tray/tray/seen`, {
26377
+ lastSeenAt,
26378
+ });
26379
+ const cacheData = (_a = pullFromCache([
26380
+ 'notificationTraySeen',
26381
+ 'get',
26382
+ ])) === null || _a === void 0 ? void 0 : _a.data;
26383
+ const data = {
26384
+ userId: client.userId,
26385
+ lastTraySeenAt: payload.lastSeenAt,
26386
+ };
26387
+ const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
26388
+ const cachedAt = client.cache && Date.now();
26389
+ if (client.cache)
26390
+ pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
26391
+ fireEvent('local.notificationTraySeen.updated', data);
26392
+ return {
26393
+ data: payload,
26394
+ cachedAt,
26395
+ };
26396
+ };
26397
+ /* end_public_function */
26398
+
26399
+ var index = /*#__PURE__*/Object.freeze({
26400
+ __proto__: null,
26401
+ getNotificationTraySeen: getNotificationTraySeen,
26402
+ getNotificationTrayItems: getNotificationTrayItems,
26403
+ markItemsSeen: markItemsSeen,
26404
+ markTraySeen: markTraySeen,
26405
+ onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
26406
+ });
26407
+
25734
26408
  exports.API_REGIONS = API_REGIONS;
25735
- exports.AdRepository = index;
25736
- exports.CategoryRepository = index$8;
25737
- exports.ChannelRepository = index$c;
25738
- exports.Client = index$l;
25739
- exports.CommentRepository = index$6;
26409
+ exports.AdRepository = index$1;
26410
+ exports.CategoryRepository = index$9;
26411
+ exports.ChannelRepository = index$d;
26412
+ exports.Client = index$m;
26413
+ exports.CommentRepository = index$7;
25740
26414
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
25741
26415
  exports.CommunityPostSettings = CommunityPostSettings;
25742
- exports.CommunityRepository = index$9;
26416
+ exports.CommunityRepository = index$a;
25743
26417
  exports.ContentFeedType = ContentFeedType;
25744
26418
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
25745
- exports.FeedRepository = index$7;
25746
- exports.FileRepository = index$i;
26419
+ exports.FeedRepository = index$8;
26420
+ exports.FileRepository = index$j;
25747
26421
  exports.FileType = FileType;
25748
- exports.LiveStreamPlayer = index$2;
26422
+ exports.LiveStreamPlayer = index$3;
25749
26423
  exports.MessageContentType = MessageContentType;
25750
- exports.MessageRepository = index$g;
25751
- exports.PollRepository = index$3;
26424
+ exports.MessageRepository = index$h;
26425
+ exports.PollRepository = index$4;
25752
26426
  exports.PostContentType = PostContentType;
25753
- exports.PostRepository = index$5;
25754
- exports.ReactionRepository = index$h;
25755
- exports.StoryRepository = index$1;
25756
- exports.StreamRepository = index$4;
25757
- exports.SubChannelRepository = index$f;
25758
- exports.UserRepository = index$j;
26427
+ exports.PostRepository = index$6;
26428
+ exports.ReactionRepository = index$i;
26429
+ exports.StoryRepository = index$2;
26430
+ exports.StreamRepository = index$5;
26431
+ exports.SubChannelRepository = index$g;
26432
+ exports.UserRepository = index$k;
25759
26433
  exports.VERSION = VERSION;
25760
26434
  exports.VideoResolution = VideoResolution;
25761
26435
  exports.VideoSize = VideoSize;
@@ -25808,6 +26482,7 @@ exports.isPaged = isPaged;
25808
26482
  exports.isReportedByMe = isReportedByMe;
25809
26483
  exports.isSkip = isSkip;
25810
26484
  exports.mergeInCache = mergeInCache;
26485
+ exports.notificationTray = index;
25811
26486
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
25812
26487
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
25813
26488
  exports.onFeedMarkerUpdated = onFeedMarkerUpdated;