@amityco/ts-sdk 7.3.1-76699b0.0 → 7.3.1-be858577.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 (39) 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/commentRepository/api/flagComment.d.ts +3 -2
  11. package/dist/commentRepository/api/flagComment.d.ts.map +1 -1
  12. package/dist/fileRepository/api/index.d.ts +1 -0
  13. package/dist/fileRepository/api/index.d.ts.map +1 -1
  14. package/dist/fileRepository/api/updateAltText.d.ts +17 -0
  15. package/dist/fileRepository/api/updateAltText.d.ts.map +1 -0
  16. package/dist/fileRepository/api/uploadImage.d.ts +2 -1
  17. package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
  18. package/dist/index.cjs.js +125 -12
  19. package/dist/index.esm.js +126 -13
  20. package/dist/index.umd.js +4 -4
  21. package/dist/messageRepository/api/flagMessage.d.ts.map +1 -1
  22. package/dist/postRepository/api/flagPost.d.ts +3 -2
  23. package/dist/postRepository/api/flagPost.d.ts.map +1 -1
  24. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  25. package/dist/utils/postTypePredicate.d.ts +4 -0
  26. package/dist/utils/postTypePredicate.d.ts.map +1 -0
  27. package/package.json +1 -1
  28. package/src/@types/core/payload.ts +23 -1
  29. package/src/@types/domains/content.ts +16 -0
  30. package/src/@types/domains/file.ts +1 -21
  31. package/src/@types/domains/post.ts +4 -0
  32. package/src/commentRepository/api/flagComment.ts +18 -3
  33. package/src/fileRepository/api/index.ts +1 -0
  34. package/src/fileRepository/api/updateAltText.ts +39 -0
  35. package/src/fileRepository/api/uploadImage.ts +22 -3
  36. package/src/messageRepository/api/flagMessage.ts +2 -4
  37. package/src/postRepository/api/flagPost.ts +17 -3
  38. package/src/utils/linkedObject/postLinkedObject.ts +29 -0
  39. 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
  /**
@@ -37657,19 +37758,25 @@ const declinePost = async (postId) => {
37657
37758
  /**
37658
37759
  * ```js
37659
37760
  * import { PostRepository } from '@amityco/ts-sdk'
37660
- * const flagged = await PostRepository.flagPost(postId)
37761
+ * const flagged = await PostRepository.flagPost(postId, reason)
37661
37762
  * ```
37662
37763
  *
37663
37764
  * @param postId of the post to flag
37765
+ * @param reason the reason to flag the post
37664
37766
  * @returns a boolean
37665
37767
  *
37666
37768
  * @category Post API
37667
37769
  * @async
37668
37770
  * */
37669
- const flagPost = async (postId) => {
37771
+ const flagPost = async (postId, reason) => {
37670
37772
  const client = getActiveClient();
37671
37773
  client.log('post/flagPost', postId);
37672
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`);
37774
+ const isPredefinedReason = Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
37775
+ const body = {
37776
+ reason: isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
37777
+ detail: isPredefinedReason ? '' : reason,
37778
+ };
37779
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
37673
37780
  if (client.cache) {
37674
37781
  ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
37675
37782
  }
@@ -38132,19 +38239,25 @@ const hardDeleteComment = async (commentId) => {
38132
38239
  /**
38133
38240
  * ```js
38134
38241
  * import { CommentRepository } from '@amityco/ts-sdk'
38135
- * const flagged = await CommentRepository.flagComment('commentId')
38242
+ * const flagged = await CommentRepository.flagComment(commentId, reason)
38136
38243
  * ```
38137
38244
  *
38138
38245
  * @param commentId The ID of the comment to flag
38246
+ * @param reason the reason to flag the comment
38139
38247
  * @returns the created report result
38140
38248
  *
38141
38249
  * @category Comment API
38142
38250
  * @async
38143
38251
  * */
38144
- const flagComment = async (commentId) => {
38252
+ const flagComment = async (commentId, reason) => {
38145
38253
  const client = getActiveClient();
38146
38254
  client.log('comment/flagComment', commentId);
38147
- const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`);
38255
+ const isPredefinedReason = Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
38256
+ const body = {
38257
+ reason: isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
38258
+ detail: isPredefinedReason ? '' : reason,
38259
+ };
38260
+ const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
38148
38261
  if (client.cache) {
38149
38262
  ingestInCache(payload);
38150
38263
  }
@@ -42408,4 +42521,4 @@ var index = /*#__PURE__*/Object.freeze({
42408
42521
  onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
42409
42522
  });
42410
42523
 
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 };
42524
+ 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 };