@amityco/ts-sdk-react-native 7.3.1-1cd86e2.0 → 7.4.1-9a54e83.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 +129 -14
  19. package/dist/index.esm.js +130 -15
  20. package/dist/index.umd.js +3 -3
  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 +20 -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 +19 -3
  38. package/src/utils/linkedObject/postLinkedObject.ts +29 -0
  39. package/src/utils/postTypePredicate.ts +27 -0
@@ -1 +1 @@
1
- {"version":3,"file":"flagMessage.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/api/flagMessage.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;KAWK;AACL,eAAO,MAAM,WAAW,cAAqB,MAAM,OAAO,CAAC,WAAW,CAAC,KAAG,QAAQ,OAAO,CAgBxF,CAAC"}
1
+ {"version":3,"file":"flagMessage.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/api/flagMessage.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;KAWK;AACL,eAAO,MAAM,WAAW,cAAqB,MAAM,OAAO,CAAC,WAAW,CAAC,KAAG,QAAQ,OAAO,CAgBxF,CAAC"}
@@ -1,14 +1,15 @@
1
1
  /**
2
2
  * ```js
3
3
  * import { PostRepository } from '@amityco/ts-sdk-react-native'
4
- * const flagged = await PostRepository.flagPost(postId)
4
+ * const flagged = await PostRepository.flagPost(postId, reason)
5
5
  * ```
6
6
  *
7
7
  * @param postId of the post to flag
8
+ * @param reason the reason to flag the post
8
9
  * @returns a boolean
9
10
  *
10
11
  * @category Post API
11
12
  * @async
12
13
  * */
13
- export declare const flagPost: (postId: Amity.Post['postId']) => Promise<boolean>;
14
+ export declare const flagPost: (postId: Amity.Post['postId'], reason?: Amity.ContentFlagReason) => Promise<boolean>;
14
15
  //# sourceMappingURL=flagPost.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"flagPost.d.ts","sourceRoot":"","sources":["../../../src/postRepository/api/flagPost.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;KAWK;AACL,eAAO,MAAM,QAAQ,WAAkB,MAAM,IAAI,CAAC,QAAQ,CAAC,KAAG,QAAQ,OAAO,CAe5E,CAAC"}
1
+ {"version":3,"file":"flagPost.d.ts","sourceRoot":"","sources":["../../../src/postRepository/api/flagPost.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;KAYK;AACL,eAAO,MAAM,QAAQ,WACX,MAAM,IAAI,CAAC,QAAQ,CAAC,WACnB,MAAM,iBAAiB,KAC/B,QAAQ,OAAO,CA2BjB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"postLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/postLinkedObject.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,gBAAgB,SAAU,MAAM,YAAY,KAAG,MAAM,IAiCjE,CAAC"}
1
+ {"version":3,"file":"postLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/postLinkedObject.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,gBAAgB,SAAU,MAAM,YAAY,KAAG,MAAM,IA6DjE,CAAC"}
@@ -0,0 +1,4 @@
1
+ export declare function isAmityImagePost(post: Amity.InternalPost): post is Amity.Post<'image'>;
2
+ export declare function isAmityFilePost(post: Amity.InternalPost): post is Amity.Post<'file'>;
3
+ export declare function isAmityVideoPost(post: Amity.InternalPost): post is Amity.Post<'video'>;
4
+ //# sourceMappingURL=postTypePredicate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"postTypePredicate.d.ts","sourceRoot":"","sources":["../../src/utils/postTypePredicate.ts"],"names":[],"mappings":"AAAA,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAOtF;AAED,wBAAgB,eAAe,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAOpF;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,KAAK,CAAC,YAAY,GAAG,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,CAQtF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk-react-native",
3
- "version": "7.3.1-1cd86e2.0",
3
+ "version": "7.4.1-9a54e83.0",
4
4
  "license": "CC-BY-ND-4.0",
5
5
  "author": "amity.co <developers@amity.co> (https://amity.co)",
6
6
  "description": "Amity Social Cloud Typescript SDK",
@@ -55,7 +55,29 @@ declare global {
55
55
 
56
56
  // API-FIX: backend should return a payload like { files: Amity.File<T>[] }
57
57
  type CreateFilePayload<T extends Amity.FileType = any> = Amity.File<T>[];
58
- type FilePayload<T extends Amity.FileType = any> = Amity.File<T>;
58
+
59
+ type VideoFileExtraPayload = {
60
+ feedType: Amity.ContentFeedType;
61
+ status: Amity.VideoTranscodingStatus;
62
+ videoUrl?: { [name in Amity.VideoResolution]?: string } | null;
63
+ };
64
+
65
+ type FilePayload<T extends Amity.FileType = any> = {
66
+ fileId: string;
67
+ type: T;
68
+ altText?: string;
69
+ fileUrl: string;
70
+ attributes: {
71
+ name: string;
72
+ extension: string;
73
+ size: string;
74
+ mimeType: string;
75
+ metadata: Amity.MetadataFor<T>;
76
+ };
77
+ accessType: Amity.FileAccessType;
78
+ } & (T extends 'video' ? Amity.VideoFileExtraPayload : unknown) &
79
+ Amity.Timestamps &
80
+ Amity.SoftDelete;
59
81
 
60
82
  type RolePayload = {
61
83
  roles: Amity.Role[];
@@ -6,8 +6,24 @@ export const ContentFeedType = Object.freeze({
6
6
  MESSAGE: 'message',
7
7
  });
8
8
 
9
+ export enum ContentFlagReasonEnum {
10
+ CommunityGuidelines = 'Against community guidelines',
11
+ HarassmentOrBullying = 'Harassment or bullying',
12
+ SelfHarmOrSuicide = 'Self-harm or suicide',
13
+ ViolenceOrThreateningContent = 'Violence or threatening content',
14
+ SellingRestrictedItems = 'Selling and promoting restricted items',
15
+ SexualContentOrNudity = 'Sexual message or nudity',
16
+ SpamOrScams = 'Spam or scams',
17
+ FalseInformation = 'False information or misinformation',
18
+ Others = 'Others',
19
+ }
20
+
9
21
  declare global {
10
22
  namespace Amity {
23
+ type ContentFlagReason =
24
+ | Exclude<`${ContentFlagReasonEnum}`, `${ContentFlagReasonEnum.Others}`>
25
+ | (string & {});
26
+
11
27
  type ContentType = 'text' | 'image' | 'file' | 'video' | 'poll' | 'json' | string;
12
28
 
13
29
  type ContentFeedType = ValueOf<typeof ContentFeedType>;
@@ -63,26 +63,6 @@ declare global {
63
63
  ? VideoMetadata
64
64
  : never;
65
65
 
66
- type VideoFileExtraPayload = {
67
- feedType: Amity.ContentFeedType;
68
- status: VideoTranscodingStatus;
69
- videoUrl?: { [name in VideoResolution]?: string } | null;
70
- };
71
-
72
- type File<T extends FileType = any> = {
73
- fileId: string;
74
- type: T;
75
- fileUrl: string;
76
- attributes: {
77
- name: string;
78
- extension: string;
79
- size: string;
80
- mimeType: string;
81
- metadata: MetadataFor<T>;
82
- };
83
- accessType: FileAccessType;
84
- } & (T extends 'video' ? VideoFileExtraPayload : unknown) &
85
- Amity.Timestamps &
86
- Amity.SoftDelete;
66
+ type File<T extends FileType = any> = Amity.FilePayload<T>;
87
67
  }
88
68
  }
@@ -61,6 +61,10 @@ declare global {
61
61
  analytics: {
62
62
  markAsViewed: () => void;
63
63
  };
64
+ getImageInfo: () => Amity.File<'image'> | undefined;
65
+ getVideoInfo: () => Amity.File<'video'> | undefined;
66
+ getVideoThumbnailInfo: () => Amity.File<'image'> | undefined;
67
+ getFileInfo: () => Amity.File<'file'> | undefined;
64
68
  };
65
69
 
66
70
  type Post<T extends PostContentType = any> = Amity.InternalPost<T> & Amity.PostLinkObject;
@@ -1,7 +1,8 @@
1
1
  import { getActiveClient } from '~/client/api/activeClient';
2
-
3
2
  import { ingestInCache } from '~/cache/api/ingestInCache';
4
3
  import { fireEvent } from '~/core/events';
4
+ import { prepareMembershipPayload } from '~/group/utils';
5
+ import { ContentFlagReasonEnum } from '~/@types';
5
6
 
6
7
  /* begin_public_function
7
8
  id: comment.flag
@@ -9,21 +10,37 @@ import { fireEvent } from '~/core/events';
9
10
  /**
10
11
  * ```js
11
12
  * import { CommentRepository } from '@amityco/ts-sdk-react-native'
12
- * const flagged = await CommentRepository.flagComment('commentId')
13
+ * const flagged = await CommentRepository.flagComment(commentId, reason)
13
14
  * ```
14
15
  *
15
16
  * @param commentId The ID of the comment to flag
17
+ * @param reason the reason to flag the comment
16
18
  * @returns the created report result
17
19
  *
18
20
  * @category Comment API
19
21
  * @async
20
22
  * */
21
- export const flagComment = async (commentId: Amity.Comment['commentId']): Promise<boolean> => {
23
+ export const flagComment = async (
24
+ commentId: Amity.Comment['commentId'],
25
+ reason?: Amity.ContentFlagReason,
26
+ ): Promise<boolean> => {
22
27
  const client = getActiveClient();
23
28
  client.log('comment/flagComment', commentId);
24
29
 
30
+ const isPredefinedReason =
31
+ reason &&
32
+ Object.entries(ContentFlagReasonEnum).some(
33
+ ([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason,
34
+ );
35
+
36
+ const body = {
37
+ reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
38
+ detail: reason && !isPredefinedReason ? reason : '',
39
+ };
40
+
25
41
  const { data: payload } = await client.http.post<Amity.CommentPayload>(
26
42
  `/api/v3/comments/${encodeURIComponent(commentId)}/flag`,
43
+ body,
27
44
  );
28
45
 
29
46
  if (client.cache) {
@@ -4,3 +4,4 @@ export * from './deleteFile';
4
4
  export * from './fileUrlWithSize';
5
5
  export * from './uploadVideo';
6
6
  export * from './uploadImage';
7
+ export * from './updateAltText';
@@ -0,0 +1,39 @@
1
+ import { ingestInCache } from '~/cache/api/ingestInCache';
2
+ import { getActiveClient } from '~/client';
3
+
4
+ /* begin_public_function
5
+ id: file.update.altText
6
+ */
7
+ /**
8
+ * ```js
9
+ * import { FileRepository } from '@amityco/ts-sdk'
10
+ * const updated = await FileRepository.updateAltText(fileId, altText)
11
+ * ```
12
+ *
13
+ * Updates an {@link Amity.File<'image'>['altText']}.
14
+ *
15
+ * @param fileId The ID of the {@link Amity.File<'image'>} to edit
16
+ * @param altText The new alt text for the {@link Amity.File<'image'>}
17
+ * @returns the updated {@link Amity.File<'image'>} object
18
+ *
19
+ * @category File API
20
+ * @async
21
+ */
22
+ export const updateAltText = async (
23
+ fileId: Amity.File['fileId'],
24
+ altText: string,
25
+ ): Promise<boolean> => {
26
+ const client = getActiveClient();
27
+ client.log('file/updateAltText', altText);
28
+
29
+ const { data } = await client.http.put<Amity.FilePayload<'image'>>(`/api/v3/files/${fileId}`, {
30
+ altText,
31
+ });
32
+
33
+ const cachedAt = client.cache && Date.now();
34
+
35
+ if (client.cache) ingestInCache({ files: [data] }, { cachedAt });
36
+
37
+ return true;
38
+ };
39
+ /* end_public_function */
@@ -16,26 +16,45 @@ import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
16
16
  *
17
17
  * @param formData The data necessary to create a new {@link Amity.File<'image'>}
18
18
  * @param onProgress The callback to track the upload progress
19
+ * @param altText The alt text for the image
19
20
  * @returns The newly created {@link Amity.File<'image'>}
20
21
  *
21
22
  * @category File API
22
23
  * @async
23
24
  */
25
+
24
26
  export const uploadImage = async (
25
27
  formData: FormData,
26
28
  onProgress?: (percent: number) => void,
29
+ altText?: string,
27
30
  ): Promise<Amity.Cached<Amity.File<'image'>[]>> => {
28
31
  const client = getActiveClient();
29
32
  client.log('file/uploadImage', formData);
30
33
 
31
34
  const files = formData.getAll('files');
32
35
 
33
- if (!files.length) throw new Error('The formData object must have a `files` key.');
36
+ if (files?.length) {
37
+ console.warn('Deprecation Warning: `files` is deprecated, please use `file` instead.');
38
+
39
+ formData.append('preferredFilename', (files[0] as File).name);
40
+ } else {
41
+ const file = formData.get('file') as File;
42
+
43
+ if (!file) {
44
+ throw new Error('The formData object must have a `file` or `files` key');
45
+ }
46
+
47
+ formData.append('preferredFilename', file.name);
48
+
49
+ // alt is for single image
50
+ if (altText) {
51
+ formData.append('altText', altText);
52
+ }
53
+ }
34
54
 
35
55
  const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
36
- formData.append('accessType', accessType);
37
56
 
38
- formData.append('preferredFilename', (files[0] as File).name);
57
+ formData.append('accessType', accessType);
39
58
 
40
59
  const headers =
41
60
  'getHeaders' in formData
@@ -1,8 +1,6 @@
1
- import { getActiveClient } from '~/client/api/activeClient';
2
-
3
- import { ingestInCache } from '~/cache/api/ingestInCache';
4
1
  import { fireEvent } from '~/core/events';
5
-
2
+ import { ingestInCache } from '~/cache/api/ingestInCache';
3
+ import { getActiveClient } from '~/client/api/activeClient';
6
4
  import { prepareMessagePayload } from '~/messageRepository/utils';
7
5
 
8
6
  /* begin_public_function
@@ -1,8 +1,8 @@
1
1
  import { getActiveClient } from '~/client/api/activeClient';
2
-
3
2
  import { ingestInCache } from '~/cache/api/ingestInCache';
4
3
  import { fireEvent } from '~/core/events';
5
4
  import { prepareMembershipPayload } from '~/group/utils';
5
+ import { ContentFlagReasonEnum } from '~/@types';
6
6
 
7
7
  /* begin_public_function
8
8
  id: post.flag
@@ -10,21 +10,37 @@ import { prepareMembershipPayload } from '~/group/utils';
10
10
  /**
11
11
  * ```js
12
12
  * import { PostRepository } from '@amityco/ts-sdk-react-native'
13
- * const flagged = await PostRepository.flagPost(postId)
13
+ * const flagged = await PostRepository.flagPost(postId, reason)
14
14
  * ```
15
15
  *
16
16
  * @param postId of the post to flag
17
+ * @param reason the reason to flag the post
17
18
  * @returns a boolean
18
19
  *
19
20
  * @category Post API
20
21
  * @async
21
22
  * */
22
- export const flagPost = async (postId: Amity.Post['postId']): Promise<boolean> => {
23
+ export const flagPost = async (
24
+ postId: Amity.Post['postId'],
25
+ reason?: Amity.ContentFlagReason,
26
+ ): Promise<boolean> => {
23
27
  const client = getActiveClient();
24
28
  client.log('post/flagPost', postId);
25
29
 
30
+ const isPredefinedReason =
31
+ reason &&
32
+ Object.entries(ContentFlagReasonEnum).some(
33
+ ([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason,
34
+ );
35
+
36
+ const body = {
37
+ reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
38
+ detail: reason && !isPredefinedReason ? reason : '',
39
+ };
40
+
26
41
  const { data: payload } = await client.http.post<Amity.PostPayload>(
27
42
  `/api/v3/posts/${encodeURIComponent(postId)}/flag`,
43
+ body,
28
44
  );
29
45
 
30
46
  if (client.cache) {
@@ -2,16 +2,19 @@ import { pullFromCache } from '~/cache/api';
2
2
  import { commentLinkedObject } from '~/utils/linkedObject/commentLinkedObject';
3
3
  import AnalyticsEngine from '../../analytic/service/analytic/AnalyticsEngine';
4
4
  import { userLinkedObject } from './userLinkedObject';
5
+ import { isAmityFilePost, isAmityImagePost, isAmityVideoPost } from '../postTypePredicate';
5
6
 
6
7
  export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
7
8
  return {
8
9
  ...post,
10
+
9
11
  analytics: {
10
12
  markAsViewed: () => {
11
13
  const analyticsEngineInstance = AnalyticsEngine.getInstance();
12
14
  analyticsEngineInstance.markPostAsViewed(post.postId);
13
15
  },
14
16
  },
17
+
15
18
  get latestComments(): (Amity.Comment | null)[] {
16
19
  if (!post.comments) return [];
17
20
  return (
@@ -30,10 +33,36 @@ export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
30
33
  .filter(Boolean) || []
31
34
  );
32
35
  },
36
+
33
37
  get creator(): Amity.User | undefined {
34
38
  const cacheData = pullFromCache<Amity.User>(['user', 'get', post.postedUserId]);
35
39
  if (!cacheData?.data) return;
36
40
  return userLinkedObject(cacheData.data);
37
41
  },
42
+
43
+ getImageInfo(): Amity.File<'image'> | undefined {
44
+ return isAmityImagePost(post)
45
+ ? pullFromCache<Amity.File<'image'>>(['file', 'get', post?.data?.fileId])?.data
46
+ : undefined;
47
+ },
48
+
49
+ getVideoInfo(): Amity.File<'video'> | undefined {
50
+ return isAmityVideoPost(post)
51
+ ? pullFromCache<Amity.File<'video'>>(['file', 'get', post?.data?.videoFileId?.original])
52
+ ?.data
53
+ : undefined;
54
+ },
55
+
56
+ getVideoThumbnailInfo(): Amity.File<'image'> | undefined {
57
+ return isAmityVideoPost(post)
58
+ ? pullFromCache<Amity.File<'image'>>(['file', 'get', post?.data?.thumbnailFileId])?.data
59
+ : undefined;
60
+ },
61
+
62
+ getFileInfo(): Amity.File<'file'> | undefined {
63
+ return isAmityFilePost(post)
64
+ ? pullFromCache<Amity.File<'file'>>(['file', 'get', post?.data?.fileId])?.data
65
+ : undefined;
66
+ },
38
67
  };
39
68
  };
@@ -0,0 +1,27 @@
1
+ export function isAmityImagePost(post: Amity.InternalPost): post is Amity.Post<'image'> {
2
+ return !!(
3
+ post.data &&
4
+ typeof post.data !== 'string' &&
5
+ 'fileId' in post.data &&
6
+ post.dataType === 'image'
7
+ );
8
+ }
9
+
10
+ export function isAmityFilePost(post: Amity.InternalPost): post is Amity.Post<'file'> {
11
+ return !!(
12
+ post.data &&
13
+ typeof post.data !== 'string' &&
14
+ 'fileId' in post.data &&
15
+ post.dataType === 'file'
16
+ );
17
+ }
18
+
19
+ export function isAmityVideoPost(post: Amity.InternalPost): post is Amity.Post<'video'> {
20
+ return !!(
21
+ post.data &&
22
+ typeof post.data !== 'string' &&
23
+ 'videoFileId' in post.data &&
24
+ 'thumbnailFileId' in post.data &&
25
+ post.dataType === 'video'
26
+ );
27
+ }