@amityco/ts-sdk 7.5.4-2d34fd5f.0 → 7.5.4-54f750e3.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/domains/channel.d.ts +1 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +2 -8
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +1 -2
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +1 -3
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/group.d.ts +2 -0
- package/dist/@types/domains/group.d.ts.map +1 -1
- package/dist/@types/domains/invitation.d.ts +4 -2
- package/dist/@types/domains/invitation.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +0 -3
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts +2 -2
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/resumeSession.d.ts +32 -0
- package/dist/client/api/resumeSession.d.ts.map +1 -0
- package/dist/client/api/tests/resumeSession.test.d.ts +2 -0
- package/dist/client/api/tests/resumeSession.test.d.ts.map +1 -0
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +1 -1
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +1 -1
- package/dist/feedRepository/api/queryGlobalFeed.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/index.cjs.js +223 -129
- package/dist/index.esm.js +222 -129
- package/dist/index.umd.js +4 -4
- package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/postRepository/api/index.d.ts +0 -1
- package/dist/postRepository/api/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/channelMemberLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/channelMemberLinkedObject.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +1 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/postTypePredicate.d.ts +0 -1
- package/dist/utils/postTypePredicate.d.ts.map +1 -1
- package/dist/utils/tests/dummy/comment.d.ts +1 -1
- package/dist/utils/tests/dummy/community.d.ts +2 -0
- package/dist/utils/tests/dummy/community.d.ts.map +1 -1
- package/package.json +2 -1
- package/src/@types/domains/channel.ts +1 -0
- package/src/@types/domains/content.ts +0 -10
- package/src/@types/domains/feed.ts +1 -2
- package/src/@types/domains/file.ts +0 -5
- package/src/@types/domains/group.ts +2 -0
- package/src/@types/domains/invitation.ts +8 -3
- package/src/@types/domains/post.ts +0 -4
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +3 -1
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.ts +2 -1
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.ts +2 -2
- package/src/client/api/index.ts +1 -0
- package/src/client/api/resumeSession.ts +282 -0
- package/src/client/api/tests/resumeSession.test.ts +173 -0
- package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +1 -1
- package/src/feedRepository/api/queryGlobalFeed.ts +1 -3
- package/src/fileRepository/api/index.ts +0 -1
- package/src/postRepository/api/index.ts +0 -2
- package/src/postRepository/api/queryPosts.ts +1 -1
- package/src/postRepository/observers/getPosts/PostPaginationController.ts +1 -1
- package/src/utils/linkedObject/channelLinkedObject.ts +19 -0
- package/src/utils/linkedObject/channelMemberLinkedObject.ts +20 -0
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/invitationLinkedObject.ts +4 -2
- package/src/utils/linkedObject/postLinkedObject.ts +1 -12
- package/src/utils/postTypePredicate.ts +0 -10
- package/dist/fileRepository/api/uploadClip.d.ts +0 -17
- package/dist/fileRepository/api/uploadClip.d.ts.map +0 -1
- package/dist/postRepository/api/createClipPost.d.ts +0 -32
- package/dist/postRepository/api/createClipPost.d.ts.map +0 -1
- package/src/fileRepository/api/uploadClip.ts +0 -71
- package/src/postRepository/api/createClipPost.ts +0 -62
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { ASCApiError } from '~/core/errors';
|
|
2
|
+
import { user11, disconnectClient } from '~/utils/tests';
|
|
3
|
+
import { resumeSession, createClient } from '..';
|
|
4
|
+
import { setActiveClient } from '../activeClient';
|
|
5
|
+
|
|
6
|
+
let client: Amity.Client;
|
|
7
|
+
|
|
8
|
+
const sessionHandler: Amity.SessionHandler = {
|
|
9
|
+
sessionWillRenewAccessToken(_) {
|
|
10
|
+
// do nothing
|
|
11
|
+
},
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
const mockToken = {
|
|
15
|
+
accessToken: 'mock-access-token',
|
|
16
|
+
issuedAt: '2023-01-01T00:00:00Z',
|
|
17
|
+
expiresAt: '2025-01-01T00:00:00Z',
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const mockUserResponse = {
|
|
21
|
+
data: {
|
|
22
|
+
users: [user11],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const onConnect = () =>
|
|
27
|
+
setTimeout(() => {
|
|
28
|
+
const CONNECT_PACKET = { type: 0, nsp: client.ws?.nsp };
|
|
29
|
+
|
|
30
|
+
client.ws?.emit('connect');
|
|
31
|
+
|
|
32
|
+
// simulate a connection ack packet from server
|
|
33
|
+
client.ws?.io.emit('packet', CONNECT_PACKET);
|
|
34
|
+
}, 50);
|
|
35
|
+
|
|
36
|
+
describe('resumeSession', () => {
|
|
37
|
+
beforeEach(() => {
|
|
38
|
+
client = createClient('key', 'sg');
|
|
39
|
+
client.mqtt?.connect && (client.mqtt.connect = jest.fn());
|
|
40
|
+
client.mqtt?.subscribe && (client.mqtt.subscribe = jest.fn());
|
|
41
|
+
client.http.get = jest.fn().mockResolvedValueOnce(mockUserResponse);
|
|
42
|
+
|
|
43
|
+
setActiveClient(client);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
afterEach(async () => {
|
|
47
|
+
if (client.sessionState === Amity.SessionStates.ESTABLISHED) await disconnectClient();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
test('it should connect client with access token', async () => {
|
|
51
|
+
onConnect().unref();
|
|
52
|
+
|
|
53
|
+
const received = await resumeSession(
|
|
54
|
+
{ userId: user11.userId, token: mockToken },
|
|
55
|
+
sessionHandler,
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
expect(received).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
test('it should establish connection', async () => {
|
|
62
|
+
onConnect().unref();
|
|
63
|
+
|
|
64
|
+
await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
|
|
65
|
+
const { sessionState } = client;
|
|
66
|
+
|
|
67
|
+
expect(sessionState).toBe(Amity.SessionStates.ESTABLISHED);
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
test('it should have session state establishing while connecting client', () => {
|
|
71
|
+
resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
|
|
72
|
+
|
|
73
|
+
expect(client.sessionState).toBe(Amity.SessionStates.ESTABLISHING);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
test('it should have session state notLoggedIn on failure', async () => {
|
|
77
|
+
client.http.get = jest
|
|
78
|
+
.fn()
|
|
79
|
+
.mockRejectedValue(
|
|
80
|
+
new ASCApiError('unauthorized', Amity.ServerError.UNAUTHORIZED, Amity.ErrorLevel.FATAL),
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
await expect(
|
|
84
|
+
resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler),
|
|
85
|
+
).rejects.toThrow('unauthorized');
|
|
86
|
+
expect(client.sessionState).toBe(Amity.SessionStates.NOT_LOGGED_IN);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('it should set authorization header with token', async () => {
|
|
90
|
+
onConnect().unref();
|
|
91
|
+
|
|
92
|
+
await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
|
|
93
|
+
|
|
94
|
+
expect(client.http.defaults.headers.common.Authorization).toBe(
|
|
95
|
+
`Bearer ${mockToken.accessToken}`,
|
|
96
|
+
);
|
|
97
|
+
expect(client.upload.defaults.headers.common.Authorization).toBe(
|
|
98
|
+
`Bearer ${mockToken.accessToken}`,
|
|
99
|
+
);
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
test('it should set token metadata', async () => {
|
|
103
|
+
onConnect().unref();
|
|
104
|
+
|
|
105
|
+
await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
|
|
106
|
+
|
|
107
|
+
expect(client.token).toEqual(mockToken);
|
|
108
|
+
expect(client.http.defaults.metadata).toEqual({
|
|
109
|
+
tokenExpiry: mockToken.expiresAt,
|
|
110
|
+
isGlobalBanned: false,
|
|
111
|
+
isUserDeleted: false,
|
|
112
|
+
});
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
test('it should call user endpoint to validate token', async () => {
|
|
116
|
+
onConnect().unref();
|
|
117
|
+
|
|
118
|
+
await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
|
|
119
|
+
|
|
120
|
+
expect(client.http.get).toHaveBeenCalledWith(`/api/v3/users/${user11.userId}`);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
test('it should terminate session on ban', async () => {
|
|
124
|
+
onConnect().unref();
|
|
125
|
+
|
|
126
|
+
await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
|
|
127
|
+
|
|
128
|
+
// ban user
|
|
129
|
+
client.emitter.emit('user.didGlobalBan', {} as Amity.UserPayload);
|
|
130
|
+
|
|
131
|
+
expect(client.sessionState).toBe(Amity.SessionStates.TERMINATED);
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
test('it should reset client state when user is already connected with same userId', async () => {
|
|
135
|
+
onConnect().unref();
|
|
136
|
+
|
|
137
|
+
// First connection
|
|
138
|
+
await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
|
|
139
|
+
expect(client.sessionState).toBe(Amity.SessionStates.ESTABLISHED);
|
|
140
|
+
expect(client.userId).toBe(user11.userId);
|
|
141
|
+
|
|
142
|
+
// Mock the HTTP call for second connection
|
|
143
|
+
client.http.get = jest.fn().mockResolvedValueOnce(mockUserResponse);
|
|
144
|
+
|
|
145
|
+
// Second connection with same userId should treat as token expiry (preserve cache)
|
|
146
|
+
onConnect().unref();
|
|
147
|
+
await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
|
|
148
|
+
|
|
149
|
+
// Verify that the client is properly reset and reconnected
|
|
150
|
+
expect(client.sessionState).toBe(Amity.SessionStates.ESTABLISHED);
|
|
151
|
+
expect(client.userId).toBe(user11.userId);
|
|
152
|
+
});
|
|
153
|
+
|
|
154
|
+
test('it should preserve cache when resuming session with same userId', async () => {
|
|
155
|
+
onConnect().unref();
|
|
156
|
+
|
|
157
|
+
// First connection - set some cache data
|
|
158
|
+
await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
|
|
159
|
+
if (client.cache) {
|
|
160
|
+
client.cache.data = { test: 'data' };
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
// Mock the HTTP call for second connection
|
|
164
|
+
client.http.get = jest.fn().mockResolvedValueOnce(mockUserResponse);
|
|
165
|
+
|
|
166
|
+
// Second connection with same userId
|
|
167
|
+
onConnect().unref();
|
|
168
|
+
await resumeSession({ userId: user11.userId, token: mockToken }, sessionHandler);
|
|
169
|
+
|
|
170
|
+
// Cache should be preserved when same userId is used
|
|
171
|
+
expect(client.cache?.data).toEqual({ test: 'data' });
|
|
172
|
+
});
|
|
173
|
+
});
|
|
@@ -23,7 +23,7 @@ import { LinkedObject } from '~/utils/linkedObject';
|
|
|
23
23
|
* @async
|
|
24
24
|
* */
|
|
25
25
|
export const getCustomRankingGlobalFeed = async (query?: {
|
|
26
|
-
dataTypes?: ('video' | 'image' | 'file' | 'liveStream'
|
|
26
|
+
dataTypes?: ('video' | 'image' | 'file' | 'liveStream')[];
|
|
27
27
|
limit?: number;
|
|
28
28
|
queryToken?: string;
|
|
29
29
|
}): Promise<
|
|
@@ -32,7 +32,7 @@ export const queryGlobalFeed = async (
|
|
|
32
32
|
const client = getActiveClient();
|
|
33
33
|
client.log('feed/queryGlobalFeed', query);
|
|
34
34
|
|
|
35
|
-
const { queryToken,
|
|
35
|
+
const { queryToken, ...params } = query ?? {};
|
|
36
36
|
|
|
37
37
|
const options = (() => {
|
|
38
38
|
if (queryToken) return { token: queryToken };
|
|
@@ -44,8 +44,6 @@ export const queryGlobalFeed = async (
|
|
|
44
44
|
{
|
|
45
45
|
params: {
|
|
46
46
|
...params,
|
|
47
|
-
dataTypes,
|
|
48
|
-
resolveParent: resolveParent ?? true,
|
|
49
47
|
options,
|
|
50
48
|
},
|
|
51
49
|
},
|
|
@@ -43,7 +43,7 @@ export const queryPosts = async (
|
|
|
43
43
|
// API-FIX: parameters should be querystring. (1)
|
|
44
44
|
// API-FIX: backend should answer Amity.Response (2)
|
|
45
45
|
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
46
|
-
const { data } = await client.http.get<Amity.PostPayload & Amity.Pagination>(`/api/
|
|
46
|
+
const { data } = await client.http.get<Amity.PostPayload & Amity.Pagination>(`/api/v4/posts`, {
|
|
47
47
|
params: {
|
|
48
48
|
...params,
|
|
49
49
|
isDeleted: inferIsDeleted(includeDeleted),
|
|
@@ -23,7 +23,7 @@ export class PostPaginationController extends PaginationController<
|
|
|
23
23
|
const options = token ? { ...baseOptions, token } : { ...baseOptions, limit };
|
|
24
24
|
|
|
25
25
|
const { data: queryResponse } = await this.http.get<Amity.PostPayload & Amity.Pagination>(
|
|
26
|
-
`/api/
|
|
26
|
+
`/api/v4/posts`,
|
|
27
27
|
{
|
|
28
28
|
params: {
|
|
29
29
|
...params,
|
|
@@ -1,8 +1,27 @@
|
|
|
1
1
|
import { markAsRead } from '~/channelRepository/internalApi/markAsRead';
|
|
2
2
|
import { shallowClone } from '../shallowClone';
|
|
3
|
+
import { queryCache } from '~/cache/api';
|
|
4
|
+
import { channelMemberLinkedObject } from './channelMemberLinkedObject';
|
|
3
5
|
|
|
4
6
|
export const channelLinkedObject = (channel: Amity.InternalChannel): Amity.Channel => {
|
|
7
|
+
let previewMembers: Amity.Membership<'channel'>[] = [];
|
|
8
|
+
|
|
9
|
+
if (channel.type === 'conversation') {
|
|
10
|
+
const channelUsers = queryCache<Amity.Membership<'channel'>>(['channelUsers', 'get']);
|
|
11
|
+
if (channelUsers && channelUsers?.length > 0) {
|
|
12
|
+
previewMembers = (
|
|
13
|
+
channelUsers?.filter(({ data }) => data.channelId === channel.channelId) ?? []
|
|
14
|
+
)
|
|
15
|
+
// sort in ascending order by userInternalId
|
|
16
|
+
.sort((a, b) => a.data.userInternalId.localeCompare(b.data.userInternalId))
|
|
17
|
+
// Select only first 4 members
|
|
18
|
+
.slice(0, 4)
|
|
19
|
+
.map(({ data }) => channelMemberLinkedObject(data));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
5
23
|
return shallowClone(channel, {
|
|
6
24
|
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
25
|
+
previewMembers,
|
|
7
26
|
});
|
|
8
27
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { pullFromCache } from '~/cache/api/pullFromCache';
|
|
2
|
+
import { userLinkedObject } from './userLinkedObject';
|
|
3
|
+
|
|
4
|
+
export const channelMemberLinkedObject = (
|
|
5
|
+
channelMember: Amity.Membership<'channel'>,
|
|
6
|
+
): Amity.Membership<'channel'> => {
|
|
7
|
+
const getUser = (): Amity.User | undefined => {
|
|
8
|
+
const cacheKey = ['user', 'get', channelMember.userId];
|
|
9
|
+
const internalUser = pullFromCache<Amity.InternalUser>(cacheKey)?.data;
|
|
10
|
+
|
|
11
|
+
return internalUser ? userLinkedObject(internalUser) : undefined;
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
return {
|
|
15
|
+
...channelMember,
|
|
16
|
+
get user() {
|
|
17
|
+
return getUser();
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
};
|
|
@@ -14,6 +14,7 @@ import { notificationTrayLinkedObject } from './notificationTrayLinkedObject';
|
|
|
14
14
|
import { communityLinkedObject } from './communityLinkedObject';
|
|
15
15
|
import { invitationLinkedObject } from './invitationLinkedObject';
|
|
16
16
|
import { joinRequestLinkedObject } from './joinRequestLinkedObject';
|
|
17
|
+
import { channelMemberLinkedObject } from './channelMemberLinkedObject';
|
|
17
18
|
|
|
18
19
|
export const LinkedObject = {
|
|
19
20
|
ad: adLinkedObject,
|
|
@@ -32,4 +33,5 @@ export const LinkedObject = {
|
|
|
32
33
|
community: communityLinkedObject,
|
|
33
34
|
invitation: invitationLinkedObject,
|
|
34
35
|
joinRequest: joinRequestLinkedObject,
|
|
36
|
+
channelMember: channelMemberLinkedObject,
|
|
35
37
|
};
|
|
@@ -22,8 +22,10 @@ export const invitationLinkedObject = (invitation: Amity.InternalInvitation): Am
|
|
|
22
22
|
'get',
|
|
23
23
|
invitation.targetId,
|
|
24
24
|
]);
|
|
25
|
-
|
|
26
|
-
|
|
25
|
+
return {
|
|
26
|
+
community: cacheData?.data,
|
|
27
|
+
communityId: invitation.communityId,
|
|
28
|
+
};
|
|
27
29
|
}
|
|
28
30
|
return undefined;
|
|
29
31
|
},
|
|
@@ -2,12 +2,7 @@ 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 {
|
|
6
|
-
isAmityClipPost,
|
|
7
|
-
isAmityFilePost,
|
|
8
|
-
isAmityImagePost,
|
|
9
|
-
isAmityVideoPost,
|
|
10
|
-
} from '../postTypePredicate';
|
|
5
|
+
import { isAmityFilePost, isAmityImagePost, isAmityVideoPost } from '../postTypePredicate';
|
|
11
6
|
|
|
12
7
|
export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
|
|
13
8
|
return {
|
|
@@ -69,11 +64,5 @@ export const postLinkedObject = (post: Amity.InternalPost): Amity.Post => {
|
|
|
69
64
|
? pullFromCache<Amity.File<'file'>>(['file', 'get', post?.data?.fileId])?.data
|
|
70
65
|
: undefined;
|
|
71
66
|
},
|
|
72
|
-
|
|
73
|
-
getClipInfo(): Amity.File<'clip'> | undefined {
|
|
74
|
-
return isAmityClipPost(post)
|
|
75
|
-
? pullFromCache<Amity.File<'clip'>>(['file', 'get', post?.data?.fileId])?.data
|
|
76
|
-
: undefined;
|
|
77
|
-
},
|
|
78
67
|
};
|
|
79
68
|
};
|
|
@@ -25,13 +25,3 @@ export function isAmityVideoPost(post: Amity.InternalPost): post is Amity.Post<'
|
|
|
25
25
|
post.dataType === 'video'
|
|
26
26
|
);
|
|
27
27
|
}
|
|
28
|
-
|
|
29
|
-
export function isAmityClipPost(post: Amity.InternalPost): post is Amity.Post<'clip'> {
|
|
30
|
-
return !!(
|
|
31
|
-
post.data &&
|
|
32
|
-
typeof post.data !== 'string' &&
|
|
33
|
-
'fileId' in post.data &&
|
|
34
|
-
'thumbnailFileId' in post.data &&
|
|
35
|
-
post.dataType === 'clip'
|
|
36
|
-
);
|
|
37
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ```js
|
|
3
|
-
* import { FileRepository } from '@amityco/ts-sdk'
|
|
4
|
-
* const created = await FileRepository.uploadClip(formData)
|
|
5
|
-
* ```
|
|
6
|
-
*
|
|
7
|
-
* Creates an {@link Amity.File}
|
|
8
|
-
*
|
|
9
|
-
* @param formData The data necessary to create a new {@link Amity.File}
|
|
10
|
-
* @param onProgress The callback to track the upload progress
|
|
11
|
-
* @returns The newly created {@link Amity.File}
|
|
12
|
-
*
|
|
13
|
-
* @category File API
|
|
14
|
-
* @async
|
|
15
|
-
*/
|
|
16
|
-
export declare const uploadClip: (formData: FormData, feedType?: Amity.ContentFeedType, onProgress?: ((percent: number) => void) | undefined) => Promise<Amity.Cached<Amity.File<'clip'>[]>>;
|
|
17
|
-
//# sourceMappingURL=uploadClip.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"uploadClip.d.ts","sourceRoot":"","sources":["../../../src/fileRepository/api/uploadClip.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,aACX,QAAQ,aACP,MAAM,eAAe,0BACT,MAAM,KAAK,IAAI,kBACrC,QAAQ,MAAM,MAAM,CAAC,UAAU,CAAC,MAAM,CAAC,EAAE,CAAC,CA2C5C,CAAC"}
|
|
@@ -1,32 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* ```js
|
|
3
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
4
|
-
* const created = await PostRepository.createClipPost({
|
|
5
|
-
* targetType: 'user',
|
|
6
|
-
* targetId: 'foobar',
|
|
7
|
-
* dataType: 'clip',
|
|
8
|
-
* data: { text: 'hello world' },
|
|
9
|
-
* attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
|
|
10
|
-
* }))
|
|
11
|
-
* ```
|
|
12
|
-
*
|
|
13
|
-
* Creates an {@link Amity.Post}
|
|
14
|
-
*
|
|
15
|
-
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
16
|
-
* @returns The newly created {@link Amity.Post}
|
|
17
|
-
*
|
|
18
|
-
* @category Post API
|
|
19
|
-
* @async
|
|
20
|
-
*/
|
|
21
|
-
export declare const createClipPost: <T extends string>(bundle: Pick<Amity.Post<T>, "targetType" | "targetId"> & Partial<Pick<Amity.Post<T>, "metadata" | "tags" | "mentionees">> & {
|
|
22
|
-
data: {
|
|
23
|
-
[k: string]: any;
|
|
24
|
-
};
|
|
25
|
-
attachments: {
|
|
26
|
-
type: T;
|
|
27
|
-
fileId: Amity.File['fileId'];
|
|
28
|
-
displayMode?: Amity.ClipDisplayMode | undefined;
|
|
29
|
-
isMuted?: boolean | undefined;
|
|
30
|
-
}[];
|
|
31
|
-
}) => Promise<Amity.Cached<Amity.Post>>;
|
|
32
|
-
//# sourceMappingURL=createClipPost.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"createClipPost.d.ts","sourceRoot":"","sources":["../../../src/postRepository/api/createClipPost.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,cAAc;;;;;;gBAMX,UAAU,CAAC,QAAQ,CAAC;;;;MAKjC,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,CAAC,CAmBlC,CAAC"}
|
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
-
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
3
|
-
import GlobalFileAccessType from '~/client/utils/GlobalFileAccessType';
|
|
4
|
-
|
|
5
|
-
/* begin_public_function
|
|
6
|
-
id: file.upload.clip
|
|
7
|
-
*/
|
|
8
|
-
/**
|
|
9
|
-
* ```js
|
|
10
|
-
* import { FileRepository } from '@amityco/ts-sdk'
|
|
11
|
-
* const created = await FileRepository.uploadClip(formData)
|
|
12
|
-
* ```
|
|
13
|
-
*
|
|
14
|
-
* Creates an {@link Amity.File}
|
|
15
|
-
*
|
|
16
|
-
* @param formData The data necessary to create a new {@link Amity.File}
|
|
17
|
-
* @param onProgress The callback to track the upload progress
|
|
18
|
-
* @returns The newly created {@link Amity.File}
|
|
19
|
-
*
|
|
20
|
-
* @category File API
|
|
21
|
-
* @async
|
|
22
|
-
*/
|
|
23
|
-
export const uploadClip = async (
|
|
24
|
-
formData: FormData,
|
|
25
|
-
feedType?: Amity.ContentFeedType,
|
|
26
|
-
onProgress?: (percent: number) => void,
|
|
27
|
-
): Promise<Amity.Cached<Amity.File<'clip'>[]>> => {
|
|
28
|
-
const client = getActiveClient();
|
|
29
|
-
client.log('file/uploadClip', formData);
|
|
30
|
-
|
|
31
|
-
const file = formData.get('files');
|
|
32
|
-
|
|
33
|
-
if (!file) throw new Error('The formData object must have a `files` key.');
|
|
34
|
-
|
|
35
|
-
const accessType = GlobalFileAccessType.getInstance().getFileAccessType();
|
|
36
|
-
formData.append('accessType', accessType);
|
|
37
|
-
|
|
38
|
-
formData.append('preferredFilename', (file as File).name);
|
|
39
|
-
|
|
40
|
-
if (feedType) {
|
|
41
|
-
formData.append('feedType', feedType);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const headers =
|
|
45
|
-
'getHeaders' in formData
|
|
46
|
-
? (formData as any).getHeaders()
|
|
47
|
-
: { 'content-type': 'multipart/form-data' };
|
|
48
|
-
|
|
49
|
-
const { data } = await client.upload.post<Amity.CreateFilePayload<'clip'>>(
|
|
50
|
-
'/api/v4/clips',
|
|
51
|
-
formData,
|
|
52
|
-
{
|
|
53
|
-
headers,
|
|
54
|
-
onUploadProgress({ loaded, total = 100 }) {
|
|
55
|
-
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
56
|
-
},
|
|
57
|
-
},
|
|
58
|
-
);
|
|
59
|
-
|
|
60
|
-
// API-FIX: payload should be serialized properly
|
|
61
|
-
// const { files } = data
|
|
62
|
-
|
|
63
|
-
const cachedAt = client.cache && Date.now();
|
|
64
|
-
if (client.cache) ingestInCache({ files: data }, { cachedAt });
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
data,
|
|
68
|
-
cachedAt,
|
|
69
|
-
};
|
|
70
|
-
};
|
|
71
|
-
/* end_public_function */
|
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
-
|
|
3
|
-
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
-
import { fireEvent } from '~/core/events';
|
|
5
|
-
import { prepareMembershipPayload } from '~/group/utils';
|
|
6
|
-
import { LinkedObject } from '~/utils/linkedObject';
|
|
7
|
-
|
|
8
|
-
/* begin_public_function
|
|
9
|
-
id: post.create.clip_post
|
|
10
|
-
*/
|
|
11
|
-
/**
|
|
12
|
-
* ```js
|
|
13
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
14
|
-
* const created = await PostRepository.createClipPost({
|
|
15
|
-
* targetType: 'user',
|
|
16
|
-
* targetId: 'foobar',
|
|
17
|
-
* dataType: 'clip',
|
|
18
|
-
* data: { text: 'hello world' },
|
|
19
|
-
* attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
|
|
20
|
-
* }))
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* Creates an {@link Amity.Post}
|
|
24
|
-
*
|
|
25
|
-
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
26
|
-
* @returns The newly created {@link Amity.Post}
|
|
27
|
-
*
|
|
28
|
-
* @category Post API
|
|
29
|
-
* @async
|
|
30
|
-
*/
|
|
31
|
-
export const createClipPost = async <T extends Amity.PostContentType | string>(
|
|
32
|
-
bundle: Pick<Amity.Post<T>, 'targetType' | 'targetId'> &
|
|
33
|
-
Partial<Pick<Amity.Post<T>, 'metadata' | 'mentionees' | 'tags'>> & {
|
|
34
|
-
data: { [k: string]: any };
|
|
35
|
-
attachments: {
|
|
36
|
-
type: T;
|
|
37
|
-
fileId: Amity.File['fileId'];
|
|
38
|
-
displayMode?: Amity.ClipDisplayMode;
|
|
39
|
-
isMuted?: boolean;
|
|
40
|
-
}[];
|
|
41
|
-
},
|
|
42
|
-
): Promise<Amity.Cached<Amity.Post>> => {
|
|
43
|
-
const client = getActiveClient();
|
|
44
|
-
client.log('post/createPost', bundle);
|
|
45
|
-
|
|
46
|
-
const { data: payload } = await client.http.post<Amity.PostPayload>('/api/v4/posts', bundle);
|
|
47
|
-
|
|
48
|
-
fireEvent('post.created', payload);
|
|
49
|
-
|
|
50
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
51
|
-
const cachedAt = client.cache && Date.now();
|
|
52
|
-
|
|
53
|
-
if (client.cache) ingestInCache(data, { cachedAt });
|
|
54
|
-
|
|
55
|
-
const { posts } = data;
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
data: LinkedObject.post(posts[0]),
|
|
59
|
-
cachedAt,
|
|
60
|
-
};
|
|
61
|
-
};
|
|
62
|
-
/* end_public_function */
|