@amityco/ts-sdk 6.35.3-3272722.0 → 6.35.3-c7e7d80.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/linkPreview.d.ts +12 -0
- package/dist/@types/core/linkPreview.d.ts.map +1 -0
- package/dist/@types/domains/community.d.ts +2 -4
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +1 -2
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/client/api/fetchLinkPreview.d.ts +14 -0
- package/dist/client/api/fetchLinkPreview.d.ts.map +1 -0
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/communityRepository/utils/communityQueryFilter.d.ts.map +1 -1
- package/dist/index.cjs.js +24 -2
- package/dist/index.esm.js +24 -2
- package/dist/index.umd.js +2 -2
- package/dist/messageRepository/observers/getMessages/getMessages.d.ts +0 -1
- package/dist/messageRepository/observers/getMessages/getMessages.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/linkPreview.ts +12 -0
- package/src/@types/domains/community.ts +0 -2
- package/src/@types/domains/user.ts +0 -1
- package/src/client/api/fetchLinkPreview.ts +30 -0
- package/src/client/api/index.ts +2 -0
- package/src/communityRepository/communityMembership/observers/tests/getMembers.test.ts +0 -1
- package/src/communityRepository/observers/tests/getCommunities.test.ts +0 -1
- package/src/communityRepository/utils/communityQueryFilter.ts +1 -8
- package/src/core/events.ts +1 -1
- package/src/messageRepository/observers/getMessages/getMessages.ts +0 -34
- package/src/userRepository/observers/tests/getUsers.test.ts +1 -43
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMessages.d.ts","sourceRoot":"","sources":["../../../../src/messageRepository/observers/getMessages/getMessages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getMessages.d.ts","sourceRoot":"","sources":["../../../../src/messageRepository/observers/getMessages/getMessages.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,WACd,MAAM,sBAAsB,YAC1B,MAAM,sBAAsB,CAAC,MAAM,OAAO,CAAC,WAC5C,MAAM,oBAAoB,KAClC,MAAM,YAuBR,CAAC"}
|
package/package.json
CHANGED
|
@@ -28,7 +28,6 @@ declare global {
|
|
|
28
28
|
const enum CommunitySortByEnum {
|
|
29
29
|
FirstCreated = 'firstCreated',
|
|
30
30
|
LastCreated = 'lastCreated',
|
|
31
|
-
DisplayName = 'displayName',
|
|
32
31
|
}
|
|
33
32
|
|
|
34
33
|
type CommunitySortBy = `${Amity.CommunitySortByEnum}`;
|
|
@@ -44,7 +43,6 @@ declare global {
|
|
|
44
43
|
const enum CommunityMemberSortByEnum {
|
|
45
44
|
FirstCreated = 'firstCreated',
|
|
46
45
|
LastCreated = 'lastCreated',
|
|
47
|
-
DisplayName = 'displayName',
|
|
48
46
|
}
|
|
49
47
|
|
|
50
48
|
type CommunityMemberSortBy = `${Amity.CommunityMemberSortByEnum}`;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getActiveClient } from './activeClient';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ```js
|
|
5
|
+
* import { fetchLinkPreview } from '@amityco/ts-sdk'
|
|
6
|
+
* const { title, description, imageUrl } = fetchLinkPreview('https://www.example.com/')
|
|
7
|
+
* ```
|
|
8
|
+
*
|
|
9
|
+
*
|
|
10
|
+
* @param url the url to fetch link preview
|
|
11
|
+
* @returns A {@link Amity.LinkPreview} instance
|
|
12
|
+
*
|
|
13
|
+
* @category Client API
|
|
14
|
+
* */
|
|
15
|
+
|
|
16
|
+
export const fetchLinkPreview = async (url: string): Promise<Amity.LinkPreview> => {
|
|
17
|
+
const client = getActiveClient();
|
|
18
|
+
|
|
19
|
+
let fetchUrl = url;
|
|
20
|
+
|
|
21
|
+
if (!/^https?:\/\//i.test(url)) {
|
|
22
|
+
fetchUrl = `https://${url}`;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const { data } = await client.http.get<Amity.LinkPreview>(
|
|
26
|
+
`/api/v1/link-preview?url=${encodeURIComponent(fetchUrl)}`,
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
return data;
|
|
30
|
+
};
|
package/src/client/api/index.ts
CHANGED
|
@@ -87,7 +87,6 @@ describe('getCommunities', () => {
|
|
|
87
87
|
const filters: [string, Amity.CommunityLiveCollection, Amity.Community[]][] = [
|
|
88
88
|
['not deleted', { includeDeleted: false }, [community2]],
|
|
89
89
|
['categoryId', { categoryId: 'test-category-id', includeDeleted: true }, [community1]],
|
|
90
|
-
['displayName', { displayName: 'community 1', includeDeleted: true }, [community1]],
|
|
91
90
|
['tagged', { tags: ['test-community-tag'], includeDeleted: true }, [community1]],
|
|
92
91
|
];
|
|
93
92
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
filterByCommunityMembership,
|
|
3
3
|
filterByPropEquality,
|
|
4
|
-
sortByDisplayName,
|
|
5
4
|
sortByFirstCreated,
|
|
6
5
|
sortByLastCreated,
|
|
7
6
|
} from '~/core/query';
|
|
@@ -12,7 +11,6 @@ export const communityQueryFilter = (
|
|
|
12
11
|
userId: string,
|
|
13
12
|
): Amity.Community[] => {
|
|
14
13
|
let communities = data;
|
|
15
|
-
communities = filterByPropEquality(communities, 'displayName', params.displayName);
|
|
16
14
|
|
|
17
15
|
if (!params.includeDeleted) {
|
|
18
16
|
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
@@ -44,11 +42,6 @@ export const communityQueryFilter = (
|
|
|
44
42
|
*
|
|
45
43
|
* This section needs to be updated as displayNames can be null as well
|
|
46
44
|
*/
|
|
47
|
-
|
|
48
|
-
communities = communities
|
|
49
|
-
// this needs to be aligned with the backend data type
|
|
50
|
-
.map(c => (c.displayName ? c : { ...c, displayName: '' }))
|
|
51
|
-
.sort(sortByDisplayName);
|
|
52
|
-
}
|
|
45
|
+
|
|
53
46
|
return communities;
|
|
54
47
|
};
|
package/src/core/events.ts
CHANGED
|
@@ -1,42 +1,8 @@
|
|
|
1
|
-
/* eslint-disable no-use-before-define */
|
|
2
1
|
import { getActiveClient } from '~/client/api';
|
|
3
2
|
import { dropFromCache } from '~/cache/api';
|
|
4
|
-
import { filterByPropEquality } from '~/core/query';
|
|
5
|
-
|
|
6
3
|
import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
|
|
7
4
|
import { MessageLiveCollectionController } from './MessageLiveCollectionController';
|
|
8
5
|
|
|
9
|
-
/*
|
|
10
|
-
* Exported for testing
|
|
11
|
-
* @hidden
|
|
12
|
-
*/
|
|
13
|
-
export const applyFilter = <T extends Amity.Message>(
|
|
14
|
-
data: T[],
|
|
15
|
-
params: Amity.MessagesLiveCollection,
|
|
16
|
-
): T[] => {
|
|
17
|
-
let messages = data;
|
|
18
|
-
|
|
19
|
-
/*
|
|
20
|
-
* for cases when message is deleted via RTE, this flag is used to get
|
|
21
|
-
* items from cache that are !deleted
|
|
22
|
-
*/
|
|
23
|
-
if (!params.includeDeleted) {
|
|
24
|
-
messages = filterByPropEquality(messages, 'isDeleted', false);
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
messages = messages.sort((message1, message2) => {
|
|
28
|
-
if (params.sortBy === 'segmentAsc') {
|
|
29
|
-
return message1.channelSegment - message2.channelSegment;
|
|
30
|
-
}
|
|
31
|
-
if (params.sortBy === 'segmentDesc') {
|
|
32
|
-
return message2.channelSegment - message1.channelSegment;
|
|
33
|
-
}
|
|
34
|
-
return 0;
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
return messages;
|
|
38
|
-
};
|
|
39
|
-
|
|
40
6
|
/* begin_public_function
|
|
41
7
|
id: message.query
|
|
42
8
|
*/
|
|
@@ -14,7 +14,7 @@ import {
|
|
|
14
14
|
// makes it easier to spy on applyFilter
|
|
15
15
|
import * as getUsersModule from '../getUsers';
|
|
16
16
|
|
|
17
|
-
const { getUsers
|
|
17
|
+
const { getUsers } = getUsersModule;
|
|
18
18
|
|
|
19
19
|
const getSnapshot = (params?: Record<string, any>) => {
|
|
20
20
|
return {
|
|
@@ -174,47 +174,5 @@ describe('getUsers', () => {
|
|
|
174
174
|
),
|
|
175
175
|
);
|
|
176
176
|
});
|
|
177
|
-
|
|
178
|
-
test('it should apply filters on RTE only', async () => {
|
|
179
|
-
const callback = jest.fn();
|
|
180
|
-
const applyFilterSpy = jest.spyOn(getUsersModule, 'applyFilter');
|
|
181
|
-
client.http.get = jest.fn().mockResolvedValue(userQueryResponse);
|
|
182
|
-
|
|
183
|
-
getUsers(params, callback);
|
|
184
|
-
await pause();
|
|
185
|
-
|
|
186
|
-
expect(applyFilterSpy).not.toHaveBeenCalled();
|
|
187
|
-
|
|
188
|
-
client.emitter.emit('user.updated', { users: [updatedUser], files: [] });
|
|
189
|
-
await pause();
|
|
190
|
-
|
|
191
|
-
expect(applyFilterSpy).toHaveBeenCalled();
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
describe('getUsers > applyFilter', () => {
|
|
197
|
-
const u1 = {
|
|
198
|
-
userId: 'test',
|
|
199
|
-
displayName: 'a',
|
|
200
|
-
createdAt: new Date().toISOString(),
|
|
201
|
-
} as Amity.InternalUser;
|
|
202
|
-
|
|
203
|
-
const u2 = {
|
|
204
|
-
userId: 'searchable',
|
|
205
|
-
displayName: 'b',
|
|
206
|
-
createdAt: getPastDate(),
|
|
207
|
-
} as Amity.InternalUser;
|
|
208
|
-
|
|
209
|
-
const filters: [string, Amity.UserLiveCollection, Amity.InternalUser[], Amity.InternalUser[]][] =
|
|
210
|
-
[
|
|
211
|
-
['it should filter by display name', { displayName: 'a' }, [u1, u2], [u1]],
|
|
212
|
-
['it should sort by dispaly name', {}, [u1, u2], [u1, u2]],
|
|
213
|
-
['it should sort by last created', { sortBy: 'lastCreated' }, [u1, u2], [u1, u2]],
|
|
214
|
-
['it should sort by first created', { sortBy: 'firstCreated' }, [u1, u2], [u2, u1]],
|
|
215
|
-
];
|
|
216
|
-
|
|
217
|
-
test.each(filters)('%s', (test, param, input, expected) => {
|
|
218
|
-
expect(applyFilter(input, param)).toStrictEqual(expected);
|
|
219
177
|
});
|
|
220
178
|
});
|