@amityco/ts-sdk 7.2.1-3663404.0 → 7.2.1-50ce75a.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 +1 -21
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/ad.d.ts +1 -1
- package/dist/@types/domains/ad.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +20 -1
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +0 -4
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/fileRepository/api/index.d.ts +0 -1
- package/dist/fileRepository/api/index.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadImage.d.ts +1 -2
- package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
- package/dist/index.cjs.js +5 -94
- package/dist/index.esm.js +5 -94
- package/dist/index.umd.js +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/payload.ts +1 -23
- package/src/@types/domains/ad.ts +1 -1
- package/src/@types/domains/file.ts +21 -1
- package/src/@types/domains/post.ts +0 -4
- package/src/fileRepository/api/index.ts +0 -1
- package/src/fileRepository/api/uploadImage.ts +3 -22
- package/src/utils/linkedObject/postLinkedObject.ts +0 -29
- package/dist/fileRepository/api/updateAltText.d.ts +0 -17
- package/dist/fileRepository/api/updateAltText.d.ts.map +0 -1
- package/dist/utils/postTypePredicate.d.ts +0 -4
- package/dist/utils/postTypePredicate.d.ts.map +0 -1
- package/src/fileRepository/api/updateAltText.ts +0 -39
- package/src/utils/postTypePredicate.ts +0 -27
|
@@ -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":"AAKA,eAAO,MAAM,gBAAgB,SAAU,MAAM,YAAY,KAAG,MAAM,IAiCjE,CAAC"}
|
package/package.json
CHANGED
|
@@ -55,29 +55,7 @@ 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
|
-
|
|
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;
|
|
58
|
+
type FilePayload<T extends Amity.FileType = any> = Amity.File<T>;
|
|
81
59
|
|
|
82
60
|
type RolePayload = {
|
|
83
61
|
roles: Amity.Role[];
|
package/src/@types/domains/ad.ts
CHANGED
|
@@ -63,6 +63,26 @@ declare global {
|
|
|
63
63
|
? VideoMetadata
|
|
64
64
|
: never;
|
|
65
65
|
|
|
66
|
-
type
|
|
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;
|
|
67
87
|
}
|
|
68
88
|
}
|
|
@@ -61,10 +61,6 @@ 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;
|
|
68
64
|
};
|
|
69
65
|
|
|
70
66
|
type Post<T extends PostContentType = any> = Amity.InternalPost<T> & Amity.PostLinkObject;
|
|
@@ -16,46 +16,27 @@ 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
|
|
20
19
|
* @returns The newly created {@link Amity.File<'image'>}
|
|
21
20
|
*
|
|
22
21
|
* @category File API
|
|
23
22
|
* @async
|
|
24
23
|
*/
|
|
25
|
-
|
|
26
24
|
export const uploadImage = async (
|
|
27
25
|
formData: FormData,
|
|
28
26
|
onProgress?: (percent: number) => void,
|
|
29
|
-
altText?: string,
|
|
30
27
|
): Promise<Amity.Cached<Amity.File<'image'>[]>> => {
|
|
31
28
|
const client = getActiveClient();
|
|
32
29
|
client.log('file/uploadImage', formData);
|
|
33
30
|
|
|
34
31
|
const files = formData.getAll('files');
|
|
35
32
|
|
|
36
|
-
if (files
|
|
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
|
-
}
|
|
33
|
+
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
54
34
|
|
|
55
35
|
const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
|
|
56
|
-
|
|
57
36
|
formData.append('accessType', accessType);
|
|
58
37
|
|
|
38
|
+
formData.append('preferredFilename', (files[0] as File).name);
|
|
39
|
+
|
|
59
40
|
const headers =
|
|
60
41
|
'getHeaders' in formData
|
|
61
42
|
? (formData as any).getHeaders()
|
|
@@ -2,19 +2,16 @@ 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';
|
|
6
5
|
|
|
7
6
|
export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
|
|
8
7
|
return {
|
|
9
8
|
...post,
|
|
10
|
-
|
|
11
9
|
analytics: {
|
|
12
10
|
markAsViewed: () => {
|
|
13
11
|
const analyticsEngineInstance = AnalyticsEngine.getInstance();
|
|
14
12
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
15
13
|
},
|
|
16
14
|
},
|
|
17
|
-
|
|
18
15
|
get latestComments(): (Amity.Comment | null)[] {
|
|
19
16
|
if (!post.comments) return [];
|
|
20
17
|
return (
|
|
@@ -33,36 +30,10 @@ export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
|
|
|
33
30
|
.filter(Boolean) || []
|
|
34
31
|
);
|
|
35
32
|
},
|
|
36
|
-
|
|
37
33
|
get creator(): Amity.User | undefined {
|
|
38
34
|
const cacheData = pullFromCache<Amity.User>(['user', 'get', post.postedUserId]);
|
|
39
35
|
if (!cacheData?.data) return;
|
|
40
36
|
return userLinkedObject(cacheData.data);
|
|
41
37
|
},
|
|
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
|
-
},
|
|
67
38
|
};
|
|
68
39
|
};
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ```js
|
|
3
|
-
* import { FileRepository } from '@amityco/ts-sdk'
|
|
4
|
-
* const updated = await FileRepository.updateAltText(fileId, altText)
|
|
5
|
-
* ```
|
|
6
|
-
*
|
|
7
|
-
* Updates an {@link Amity.File<'image'>['altText']}.
|
|
8
|
-
*
|
|
9
|
-
* @param fileId The ID of the {@link Amity.File<'image'>} to edit
|
|
10
|
-
* @param altText The new alt text for the {@link Amity.File<'image'>}
|
|
11
|
-
* @returns the updated {@link Amity.File<'image'>} object
|
|
12
|
-
*
|
|
13
|
-
* @category File API
|
|
14
|
-
* @async
|
|
15
|
-
*/
|
|
16
|
-
export declare const updateAltText: (fileId: Amity.File['fileId'], altText: string) => Promise<boolean>;
|
|
17
|
-
//# sourceMappingURL=updateAltText.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"updateAltText.d.ts","sourceRoot":"","sources":["../../../src/fileRepository/api/updateAltText.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,WAChB,UAAU,CAAC,QAAQ,CAAC,WACnB,MAAM,KACd,QAAQ,OAAO,CAajB,CAAC"}
|
|
@@ -1,4 +0,0 @@
|
|
|
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
|
|
@@ -1 +0,0 @@
|
|
|
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"}
|
|
@@ -1,39 +0,0 @@
|
|
|
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 */
|
|
@@ -1,27 +0,0 @@
|
|
|
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
|
-
}
|