@amityco/ts-sdk 7.3.1-76699b0.0 → 7.3.1-e2dead4.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 (34) hide show
  1. package/.eslintrc.json +2 -1
  2. package/dist/@types/core/payload.d.ts +21 -1
  3. package/dist/@types/core/payload.d.ts.map +1 -1
  4. package/dist/@types/domains/content.d.ts +12 -0
  5. package/dist/@types/domains/content.d.ts.map +1 -1
  6. package/dist/@types/domains/file.d.ts +1 -20
  7. package/dist/@types/domains/file.d.ts.map +1 -1
  8. package/dist/@types/domains/post.d.ts +4 -0
  9. package/dist/@types/domains/post.d.ts.map +1 -1
  10. package/dist/fileRepository/api/index.d.ts +1 -0
  11. package/dist/fileRepository/api/index.d.ts.map +1 -1
  12. package/dist/fileRepository/api/updateAltText.d.ts +17 -0
  13. package/dist/fileRepository/api/updateAltText.d.ts.map +1 -0
  14. package/dist/fileRepository/api/uploadImage.d.ts +2 -1
  15. package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
  16. package/dist/index.cjs.js +116 -9
  17. package/dist/index.esm.js +117 -10
  18. package/dist/index.umd.js +4 -4
  19. package/dist/messageRepository/api/flagMessage.d.ts +3 -2
  20. package/dist/messageRepository/api/flagMessage.d.ts.map +1 -1
  21. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  22. package/dist/utils/postTypePredicate.d.ts +4 -0
  23. package/dist/utils/postTypePredicate.d.ts.map +1 -0
  24. package/package.json +1 -1
  25. package/src/@types/core/payload.ts +23 -1
  26. package/src/@types/domains/content.ts +16 -0
  27. package/src/@types/domains/file.ts +1 -21
  28. package/src/@types/domains/post.ts +4 -0
  29. package/src/fileRepository/api/index.ts +1 -0
  30. package/src/fileRepository/api/updateAltText.ts +39 -0
  31. package/src/fileRepository/api/uploadImage.ts +22 -3
  32. package/src/messageRepository/api/flagMessage.ts +19 -6
  33. package/src/utils/linkedObject/postLinkedObject.ts +29 -0
  34. package/src/utils/postTypePredicate.ts +27 -0
package/dist/index.esm.js CHANGED
@@ -65,7 +65,19 @@ const ContentFeedType = Object.freeze({
65
65
  CHAT: 'chat',
66
66
  POST: 'post',
67
67
  MESSAGE: 'message',
68
- });
68
+ });
69
+ var ContentFlagReasonEnum;
70
+ (function (ContentFlagReasonEnum) {
71
+ ContentFlagReasonEnum["CommunityGuidelines"] = "Against community guidelines";
72
+ ContentFlagReasonEnum["HarassmentOrBullying"] = "Harassment or bullying";
73
+ ContentFlagReasonEnum["SelfHarmOrSuicide"] = "Self-harm or suicide";
74
+ ContentFlagReasonEnum["ViolenceOrThreateningContent"] = "Violence or threatening content";
75
+ ContentFlagReasonEnum["SellingRestrictedItems"] = "Selling and promoting restricted items";
76
+ ContentFlagReasonEnum["SexualContentOrNudity"] = "Sexual message or nudity";
77
+ ContentFlagReasonEnum["SpamOrScams"] = "Spam or scams";
78
+ ContentFlagReasonEnum["FalseInformation"] = "False information or misinformation";
79
+ ContentFlagReasonEnum["Others"] = "Others";
80
+ })(ContentFlagReasonEnum || (ContentFlagReasonEnum = {}));
69
81
 
70
82
  const MessageContentType = Object.freeze({
71
83
  TEXT: 'text',
@@ -21626,6 +21638,26 @@ const commentLinkedObject = (comment) => {
21626
21638
  } });
21627
21639
  };
21628
21640
 
21641
+ function isAmityImagePost(post) {
21642
+ return !!(post.data &&
21643
+ typeof post.data !== 'string' &&
21644
+ 'fileId' in post.data &&
21645
+ post.dataType === 'image');
21646
+ }
21647
+ function isAmityFilePost(post) {
21648
+ return !!(post.data &&
21649
+ typeof post.data !== 'string' &&
21650
+ 'fileId' in post.data &&
21651
+ post.dataType === 'file');
21652
+ }
21653
+ function isAmityVideoPost(post) {
21654
+ return !!(post.data &&
21655
+ typeof post.data !== 'string' &&
21656
+ 'videoFileId' in post.data &&
21657
+ 'thumbnailFileId' in post.data &&
21658
+ post.dataType === 'video');
21659
+ }
21660
+
21629
21661
  const postLinkedObject = (post) => {
21630
21662
  return Object.assign(Object.assign({}, post), { analytics: {
21631
21663
  markAsViewed: () => {
@@ -21654,6 +21686,30 @@ const postLinkedObject = (post) => {
21654
21686
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
21655
21687
  return;
21656
21688
  return userLinkedObject(cacheData.data);
21689
+ },
21690
+ getImageInfo() {
21691
+ var _a, _b;
21692
+ return isAmityImagePost(post)
21693
+ ? (_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
21694
+ : undefined;
21695
+ },
21696
+ getVideoInfo() {
21697
+ var _a, _b, _c;
21698
+ return isAmityVideoPost(post)
21699
+ ? (_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
21700
+ : undefined;
21701
+ },
21702
+ getVideoThumbnailInfo() {
21703
+ var _a, _b;
21704
+ return isAmityVideoPost(post)
21705
+ ? (_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
21706
+ : undefined;
21707
+ },
21708
+ getFileInfo() {
21709
+ var _a, _b;
21710
+ return isAmityFilePost(post)
21711
+ ? (_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
21712
+ : undefined;
21657
21713
  } });
21658
21714
  };
21659
21715
 
@@ -28693,20 +28749,33 @@ const uploadVideo = async (formData, feedType, onProgress) => {
28693
28749
  *
28694
28750
  * @param formData The data necessary to create a new {@link Amity.File<'image'>}
28695
28751
  * @param onProgress The callback to track the upload progress
28752
+ * @param altText The alt text for the image
28696
28753
  * @returns The newly created {@link Amity.File<'image'>}
28697
28754
  *
28698
28755
  * @category File API
28699
28756
  * @async
28700
28757
  */
28701
- const uploadImage = async (formData, onProgress) => {
28758
+ const uploadImage = async (formData, onProgress, altText) => {
28702
28759
  const client = getActiveClient();
28703
28760
  client.log('file/uploadImage', formData);
28704
28761
  const files = formData.getAll('files');
28705
- if (!files.length)
28706
- throw new Error('The formData object must have a `files` key.');
28762
+ if (files === null || files === void 0 ? void 0 : files.length) {
28763
+ console.warn('Deprecation Warning: `files` is deprecated, please use `file` instead.');
28764
+ formData.append('preferredFilename', files[0].name);
28765
+ }
28766
+ else {
28767
+ const file = formData.get('file');
28768
+ if (!file) {
28769
+ throw new Error('The formData object must have a `file` or `files` key');
28770
+ }
28771
+ formData.append('preferredFilename', file.name);
28772
+ // alt is for single image
28773
+ if (altText) {
28774
+ formData.append('altText', altText);
28775
+ }
28776
+ }
28707
28777
  const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
28708
28778
  formData.append('accessType', accessType);
28709
- formData.append('preferredFilename', files[0].name);
28710
28779
  const headers = 'getHeaders' in formData
28711
28780
  ? formData.getHeaders()
28712
28781
  : { 'content-type': 'multipart/form-data' };
@@ -28728,6 +28797,37 @@ const uploadImage = async (formData, onProgress) => {
28728
28797
  };
28729
28798
  /* end_public_function */
28730
28799
 
28800
+ /* begin_public_function
28801
+ id: file.update.altText
28802
+ */
28803
+ /**
28804
+ * ```js
28805
+ * import { FileRepository } from '@amityco/ts-sdk'
28806
+ * const updated = await FileRepository.updateAltText(fileId, altText)
28807
+ * ```
28808
+ *
28809
+ * Updates an {@link Amity.File<'image'>['altText']}.
28810
+ *
28811
+ * @param fileId The ID of the {@link Amity.File<'image'>} to edit
28812
+ * @param altText The new alt text for the {@link Amity.File<'image'>}
28813
+ * @returns the updated {@link Amity.File<'image'>} object
28814
+ *
28815
+ * @category File API
28816
+ * @async
28817
+ */
28818
+ const updateAltText = async (fileId, altText) => {
28819
+ const client = getActiveClient();
28820
+ client.log('file/updateAltText', altText);
28821
+ const { data } = await client.http.put(`/api/v3/files/${fileId}`, {
28822
+ altText,
28823
+ });
28824
+ const cachedAt = client.cache && Date.now();
28825
+ if (client.cache)
28826
+ ingestInCache({ files: [data] }, { cachedAt });
28827
+ return true;
28828
+ };
28829
+ /* end_public_function */
28830
+
28731
28831
  var index$j = /*#__PURE__*/Object.freeze({
28732
28832
  __proto__: null,
28733
28833
  getFile: getFile,
@@ -28735,7 +28835,8 @@ var index$j = /*#__PURE__*/Object.freeze({
28735
28835
  deleteFile: deleteFile,
28736
28836
  fileUrlWithSize: fileUrlWithSize,
28737
28837
  uploadVideo: uploadVideo,
28738
- uploadImage: uploadImage
28838
+ uploadImage: uploadImage,
28839
+ updateAltText: updateAltText
28739
28840
  });
28740
28841
 
28741
28842
  /**
@@ -31912,19 +32013,25 @@ getDeliveredUsers.locally = (query) => {
31912
32013
  /**
31913
32014
  * ```js
31914
32015
  * import { MessageRepository } from '@amityco/ts-sdk'
31915
- * const flagged = await MessageRepository.flagMessage(messageId)
32016
+ * const flagged = await MessageRepository.flagMessage(messageId, reason)
31916
32017
  * ```
31917
32018
  *
31918
32019
  * @param messageId of the message to flag
32020
+ * @param reason the reason to flag the message
31919
32021
  * @returns the created report result
31920
32022
  *
31921
32023
  * @category Message API
31922
32024
  * @async
31923
32025
  * */
31924
- const flagMessage = async (messageId) => {
32026
+ const flagMessage = async (messageId, reason) => {
31925
32027
  const client = getActiveClient();
31926
32028
  client.log('message/flag', messageId);
31927
- const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`);
32029
+ const isPredefinedReason = Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
32030
+ const body = {
32031
+ reason: isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
32032
+ detail: isPredefinedReason ? '' : reason,
32033
+ };
32034
+ const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`, body);
31928
32035
  if (client.cache) {
31929
32036
  const messagePayload = await prepareMessagePayload(payload);
31930
32037
  ingestInCache(messagePayload);
@@ -42408,4 +42515,4 @@ var index = /*#__PURE__*/Object.freeze({
42408
42515
  onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
42409
42516
  });
42410
42517
 
42411
- export { API_REGIONS, index$1 as AdRepository, index$9 as CategoryRepository, index$d as ChannelRepository, index$m as Client, index$7 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$a as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$8 as FeedRepository, FileAccessTypeEnum, index$j as FileRepository, FileType, index$3 as LiveStreamPlayer, MessageContentType, index$h as MessageRepository, index$4 as PollRepository, PostContentType, index$6 as PostRepository, index$i as ReactionRepository, index$2 as StoryRepository, index$5 as StreamRepository, index$g as SubChannelRepository, SubscriptionLevels, index$k as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
42518
+ export { API_REGIONS, index$1 as AdRepository, index$9 as CategoryRepository, index$d as ChannelRepository, index$m as Client, index$7 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$a as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$8 as FeedRepository, FileAccessTypeEnum, index$j as FileRepository, FileType, index$3 as LiveStreamPlayer, MessageContentType, index$h as MessageRepository, index$4 as PollRepository, PostContentType, index$6 as PostRepository, index$i as ReactionRepository, index$2 as StoryRepository, index$5 as StreamRepository, index$g as SubChannelRepository, SubscriptionLevels, index$k as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };