@amityco/ts-sdk 7.3.1-76699b0.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.
- package/dist/@types/core/payload.d.ts +21 -1
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +1 -20
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +4 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/fileRepository/api/index.d.ts +1 -0
- package/dist/fileRepository/api/index.d.ts.map +1 -1
- package/dist/fileRepository/api/updateAltText.d.ts +17 -0
- package/dist/fileRepository/api/updateAltText.d.ts.map +1 -0
- package/dist/fileRepository/api/uploadImage.d.ts +2 -1
- package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
- package/dist/index.cjs.js +94 -5
- package/dist/index.esm.js +94 -5
- package/dist/index.umd.js +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/postTypePredicate.d.ts +4 -0
- package/dist/utils/postTypePredicate.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/@types/core/payload.ts +23 -1
- package/src/@types/domains/file.ts +1 -21
- package/src/@types/domains/post.ts +4 -0
- package/src/fileRepository/api/index.ts +1 -0
- package/src/fileRepository/api/updateAltText.ts +39 -0
- package/src/fileRepository/api/uploadImage.ts +22 -3
- package/src/utils/linkedObject/postLinkedObject.ts +29 -0
- package/src/utils/postTypePredicate.ts +27 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"postLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/postLinkedObject.ts"],"names":[],"mappings":"
|
|
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
|
@@ -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
|
-
|
|
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[];
|
|
@@ -63,26 +63,6 @@ declare global {
|
|
|
63
63
|
? VideoMetadata
|
|
64
64
|
: never;
|
|
65
65
|
|
|
66
|
-
type
|
|
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;
|
|
@@ -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 (
|
|
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('
|
|
57
|
+
formData.append('accessType', accessType);
|
|
39
58
|
|
|
40
59
|
const headers =
|
|
41
60
|
'getHeaders' in formData
|
|
@@ -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
|
+
}
|