@amityco/ts-sdk 7.3.1-56cdb841.0 → 7.3.1-b3a17de.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 (37) hide show
  1. package/.eslintrc.json +1 -2
  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 +0 -12
  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 +2 -3
  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 +101 -36
  19. package/dist/index.esm.js +102 -37
  20. package/dist/index.umd.js +4 -4
  21. package/dist/postRepository/api/flagPost.d.ts +2 -3
  22. package/dist/postRepository/api/flagPost.d.ts.map +1 -1
  23. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  24. package/dist/utils/postTypePredicate.d.ts +4 -0
  25. package/dist/utils/postTypePredicate.d.ts.map +1 -0
  26. package/package.json +1 -1
  27. package/src/@types/core/payload.ts +23 -1
  28. package/src/@types/domains/content.ts +0 -16
  29. package/src/@types/domains/file.ts +1 -21
  30. package/src/@types/domains/post.ts +4 -0
  31. package/src/commentRepository/api/flagComment.ts +3 -18
  32. package/src/fileRepository/api/index.ts +1 -0
  33. package/src/fileRepository/api/updateAltText.ts +39 -0
  34. package/src/fileRepository/api/uploadImage.ts +22 -3
  35. package/src/postRepository/api/flagPost.ts +3 -17
  36. package/src/utils/linkedObject/postLinkedObject.ts +29 -0
  37. package/src/utils/postTypePredicate.ts +27 -0
package/dist/index.esm.js CHANGED
@@ -65,19 +65,7 @@ const ContentFeedType = Object.freeze({
65
65
  CHAT: 'chat',
66
66
  POST: 'post',
67
67
  MESSAGE: 'message',
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 = {}));
68
+ });
81
69
 
82
70
  const MessageContentType = Object.freeze({
83
71
  TEXT: 'text',
@@ -21638,6 +21626,26 @@ const commentLinkedObject = (comment) => {
21638
21626
  } });
21639
21627
  };
21640
21628
 
21629
+ function isAmityImagePost(post) {
21630
+ return !!(post.data &&
21631
+ typeof post.data !== 'string' &&
21632
+ 'fileId' in post.data &&
21633
+ post.dataType === 'image');
21634
+ }
21635
+ function isAmityFilePost(post) {
21636
+ return !!(post.data &&
21637
+ typeof post.data !== 'string' &&
21638
+ 'fileId' in post.data &&
21639
+ post.dataType === 'file');
21640
+ }
21641
+ function isAmityVideoPost(post) {
21642
+ return !!(post.data &&
21643
+ typeof post.data !== 'string' &&
21644
+ 'videoFileId' in post.data &&
21645
+ 'thumbnailFileId' in post.data &&
21646
+ post.dataType === 'video');
21647
+ }
21648
+
21641
21649
  const postLinkedObject = (post) => {
21642
21650
  return Object.assign(Object.assign({}, post), { analytics: {
21643
21651
  markAsViewed: () => {
@@ -21666,6 +21674,30 @@ const postLinkedObject = (post) => {
21666
21674
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
21667
21675
  return;
21668
21676
  return userLinkedObject(cacheData.data);
21677
+ },
21678
+ getImageInfo() {
21679
+ var _a, _b;
21680
+ return isAmityImagePost(post)
21681
+ ? (_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
21682
+ : undefined;
21683
+ },
21684
+ getVideoInfo() {
21685
+ var _a, _b, _c;
21686
+ return isAmityVideoPost(post)
21687
+ ? (_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
21688
+ : undefined;
21689
+ },
21690
+ getVideoThumbnailInfo() {
21691
+ var _a, _b;
21692
+ return isAmityVideoPost(post)
21693
+ ? (_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
21694
+ : undefined;
21695
+ },
21696
+ getFileInfo() {
21697
+ var _a, _b;
21698
+ return isAmityFilePost(post)
21699
+ ? (_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
21700
+ : undefined;
21669
21701
  } });
21670
21702
  };
21671
21703
 
@@ -28705,20 +28737,33 @@ const uploadVideo = async (formData, feedType, onProgress) => {
28705
28737
  *
28706
28738
  * @param formData The data necessary to create a new {@link Amity.File<'image'>}
28707
28739
  * @param onProgress The callback to track the upload progress
28740
+ * @param altText The alt text for the image
28708
28741
  * @returns The newly created {@link Amity.File<'image'>}
28709
28742
  *
28710
28743
  * @category File API
28711
28744
  * @async
28712
28745
  */
28713
- const uploadImage = async (formData, onProgress) => {
28746
+ const uploadImage = async (formData, onProgress, altText) => {
28714
28747
  const client = getActiveClient();
28715
28748
  client.log('file/uploadImage', formData);
28716
28749
  const files = formData.getAll('files');
28717
- if (!files.length)
28718
- throw new Error('The formData object must have a `files` key.');
28750
+ if (files === null || files === void 0 ? void 0 : files.length) {
28751
+ console.warn('Deprecation Warning: `files` is deprecated, please use `file` instead.');
28752
+ formData.append('preferredFilename', files[0].name);
28753
+ }
28754
+ else {
28755
+ const file = formData.get('file');
28756
+ if (!file) {
28757
+ throw new Error('The formData object must have a `file` or `files` key');
28758
+ }
28759
+ formData.append('preferredFilename', file.name);
28760
+ // alt is for single image
28761
+ if (altText) {
28762
+ formData.append('altText', altText);
28763
+ }
28764
+ }
28719
28765
  const accessType = GlobalFileAccessType$1.getInstance().getFileAccessType();
28720
28766
  formData.append('accessType', accessType);
28721
- formData.append('preferredFilename', files[0].name);
28722
28767
  const headers = 'getHeaders' in formData
28723
28768
  ? formData.getHeaders()
28724
28769
  : { 'content-type': 'multipart/form-data' };
@@ -28740,6 +28785,37 @@ const uploadImage = async (formData, onProgress) => {
28740
28785
  };
28741
28786
  /* end_public_function */
28742
28787
 
28788
+ /* begin_public_function
28789
+ id: file.update.altText
28790
+ */
28791
+ /**
28792
+ * ```js
28793
+ * import { FileRepository } from '@amityco/ts-sdk'
28794
+ * const updated = await FileRepository.updateAltText(fileId, altText)
28795
+ * ```
28796
+ *
28797
+ * Updates an {@link Amity.File<'image'>['altText']}.
28798
+ *
28799
+ * @param fileId The ID of the {@link Amity.File<'image'>} to edit
28800
+ * @param altText The new alt text for the {@link Amity.File<'image'>}
28801
+ * @returns the updated {@link Amity.File<'image'>} object
28802
+ *
28803
+ * @category File API
28804
+ * @async
28805
+ */
28806
+ const updateAltText = async (fileId, altText) => {
28807
+ const client = getActiveClient();
28808
+ client.log('file/updateAltText', altText);
28809
+ const { data } = await client.http.put(`/api/v3/files/${fileId}`, {
28810
+ altText,
28811
+ });
28812
+ const cachedAt = client.cache && Date.now();
28813
+ if (client.cache)
28814
+ ingestInCache({ files: [data] }, { cachedAt });
28815
+ return true;
28816
+ };
28817
+ /* end_public_function */
28818
+
28743
28819
  var index$j = /*#__PURE__*/Object.freeze({
28744
28820
  __proto__: null,
28745
28821
  getFile: getFile,
@@ -28747,7 +28823,8 @@ var index$j = /*#__PURE__*/Object.freeze({
28747
28823
  deleteFile: deleteFile,
28748
28824
  fileUrlWithSize: fileUrlWithSize,
28749
28825
  uploadVideo: uploadVideo,
28750
- uploadImage: uploadImage
28826
+ uploadImage: uploadImage,
28827
+ updateAltText: updateAltText
28751
28828
  });
28752
28829
 
28753
28830
  /**
@@ -37669,25 +37746,19 @@ const declinePost = async (postId) => {
37669
37746
  /**
37670
37747
  * ```js
37671
37748
  * import { PostRepository } from '@amityco/ts-sdk'
37672
- * const flagged = await PostRepository.flagPost(postId, reason)
37749
+ * const flagged = await PostRepository.flagPost(postId)
37673
37750
  * ```
37674
37751
  *
37675
37752
  * @param postId of the post to flag
37676
- * @param reason the reason to flag the post
37677
37753
  * @returns a boolean
37678
37754
  *
37679
37755
  * @category Post API
37680
37756
  * @async
37681
37757
  * */
37682
- const flagPost = async (postId, reason) => {
37758
+ const flagPost = async (postId) => {
37683
37759
  const client = getActiveClient();
37684
37760
  client.log('post/flagPost', postId);
37685
- const isPredefinedReason = Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
37686
- const body = {
37687
- reason: isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
37688
- detail: isPredefinedReason ? '' : reason,
37689
- };
37690
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
37761
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`);
37691
37762
  if (client.cache) {
37692
37763
  ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
37693
37764
  }
@@ -38150,25 +38221,19 @@ const hardDeleteComment = async (commentId) => {
38150
38221
  /**
38151
38222
  * ```js
38152
38223
  * import { CommentRepository } from '@amityco/ts-sdk'
38153
- * const flagged = await CommentRepository.flagComment(commentId, reason)
38224
+ * const flagged = await CommentRepository.flagComment('commentId')
38154
38225
  * ```
38155
38226
  *
38156
38227
  * @param commentId The ID of the comment to flag
38157
- * @param reason the reason to flag the comment
38158
38228
  * @returns the created report result
38159
38229
  *
38160
38230
  * @category Comment API
38161
38231
  * @async
38162
38232
  * */
38163
- const flagComment = async (commentId, reason) => {
38233
+ const flagComment = async (commentId) => {
38164
38234
  const client = getActiveClient();
38165
38235
  client.log('comment/flagComment', commentId);
38166
- const isPredefinedReason = Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
38167
- const body = {
38168
- reason: isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
38169
- detail: isPredefinedReason ? '' : reason,
38170
- };
38171
- const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
38236
+ const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`);
38172
38237
  if (client.cache) {
38173
38238
  ingestInCache(payload);
38174
38239
  }
@@ -42432,4 +42497,4 @@ var index = /*#__PURE__*/Object.freeze({
42432
42497
  onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
42433
42498
  });
42434
42499
 
42435
- 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 };
42500
+ 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 };