@amityco/ts-sdk 6.2.1-ca3e600.0 → 6.2.1-d2d529b.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/communityRepository/communityModeration/api/banMembers.d.ts +16 -0
- package/dist/communityRepository/communityModeration/api/banMembers.d.ts.map +1 -0
- package/dist/communityRepository/communityModeration/api/index.d.ts +2 -0
- package/dist/communityRepository/communityModeration/api/index.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/api/test/banMembers.test.d.ts +2 -0
- package/dist/communityRepository/communityModeration/api/test/banMembers.test.d.ts.map +1 -0
- package/dist/communityRepository/communityModeration/api/test/unbanMembers.test.d.ts +2 -0
- package/dist/communityRepository/communityModeration/api/test/unbanMembers.test.d.ts.map +1 -0
- package/dist/communityRepository/communityModeration/api/unbanMembers.d.ts +16 -0
- package/dist/communityRepository/communityModeration/api/unbanMembers.d.ts.map +1 -0
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/index.cjs.js +81 -5
- package/dist/index.esm.js +81 -5
- package/dist/index.umd.js +4 -4
- package/package.json +1 -1
- package/src/communityRepository/communityModeration/api/banMembers.ts +50 -0
- package/src/communityRepository/communityModeration/api/index.ts +4 -0
- package/src/communityRepository/communityModeration/api/test/banMembers.test.ts +70 -0
- package/src/communityRepository/communityModeration/api/test/unbanMembers.test.ts +70 -0
- package/src/communityRepository/communityModeration/api/unbanMembers.ts +50 -0
- package/src/core/query/filtering.ts +4 -0
- package/src/core/query/tests/filtering.test.ts +6 -0
package/package.json
CHANGED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
|
|
5
|
+
import { prepareMembershipPayload } from '~/group/utils';
|
|
6
|
+
|
|
7
|
+
/* begin_public_function
|
|
8
|
+
id: community.moderation.ban_members
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* ```js
|
|
12
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
13
|
+
*
|
|
14
|
+
* await CommunityRepository.Moderation.banMembers('communityId', ['userId1', 'userId2'])
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param communityId of {@link Amity.Community} from which the users should be banned
|
|
18
|
+
* @param userIds of the {@link Amity.User}'s to be banned
|
|
19
|
+
* @returns the updated {@link Amity.Membership}'s object
|
|
20
|
+
*
|
|
21
|
+
* @category Community API
|
|
22
|
+
* @async
|
|
23
|
+
* */
|
|
24
|
+
export const banMembers = async (
|
|
25
|
+
communityId: Amity.Community['communityId'],
|
|
26
|
+
userIds: Amity.User['userId'][],
|
|
27
|
+
): Promise<Amity.Cached<Amity.Membership<'community'>[]>> => {
|
|
28
|
+
const client = getActiveClient();
|
|
29
|
+
client.log('community/banMembers', { userIds, communityId });
|
|
30
|
+
|
|
31
|
+
const { data: payload } = await client.http.put<Amity.CommunityMembershipPayload>(
|
|
32
|
+
`/api/v3/communities/${communityId}/users/ban`,
|
|
33
|
+
{
|
|
34
|
+
userIds,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
39
|
+
|
|
40
|
+
const cachedAt = client.cache && Date.now();
|
|
41
|
+
if (client.cache) ingestInCache(data, { cachedAt });
|
|
42
|
+
|
|
43
|
+
const { communityUsers } = data;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
data: communityUsers.filter(u => userIds.includes(u.userId)),
|
|
47
|
+
cachedAt,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
/* end_public_function */
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache } from '~/cache/api';
|
|
2
|
+
import { prepareMembershipPayload } from '~/group/utils';
|
|
3
|
+
import { getResolver } from '~/core/model';
|
|
4
|
+
import { ASCError } from '~/core/errors';
|
|
5
|
+
|
|
6
|
+
import { client, community11, communityUser11, user11 } from '~/utils/tests';
|
|
7
|
+
|
|
8
|
+
import { banMembers } from '../banMembers';
|
|
9
|
+
|
|
10
|
+
const userCommunity = community11;
|
|
11
|
+
const user = {
|
|
12
|
+
...communityUser11,
|
|
13
|
+
communityMebership: 'banned',
|
|
14
|
+
};
|
|
15
|
+
const resolvedCommunityValue = {
|
|
16
|
+
data: {
|
|
17
|
+
communities: [userCommunity],
|
|
18
|
+
communityUsers: [user],
|
|
19
|
+
files: [],
|
|
20
|
+
users: [user11],
|
|
21
|
+
categories: [],
|
|
22
|
+
feeds: [],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('community/ moderation/ banMembers', () => {
|
|
27
|
+
beforeEach(enableCache);
|
|
28
|
+
afterEach(disableCache);
|
|
29
|
+
|
|
30
|
+
const { communityId } = communityUser11;
|
|
31
|
+
const { userId } = communityUser11;
|
|
32
|
+
|
|
33
|
+
const preparedPayload = prepareMembershipPayload(resolvedCommunityValue.data, 'communityUsers');
|
|
34
|
+
const { communityUsers: expectedUser } = preparedPayload;
|
|
35
|
+
|
|
36
|
+
// integration_test_id: d344e314-4a49-4947-b4d5-8fa2d55f8ecd
|
|
37
|
+
test('it should return banned members', async () => {
|
|
38
|
+
client.http.put = jest.fn().mockResolvedValue(resolvedCommunityValue);
|
|
39
|
+
|
|
40
|
+
const { data: recieved } = await banMembers(communityId, [userId]);
|
|
41
|
+
|
|
42
|
+
expect(recieved).toStrictEqual(expectedUser);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('it should update cache', async () => {
|
|
46
|
+
client.http.put = jest.fn().mockResolvedValue(resolvedCommunityValue);
|
|
47
|
+
|
|
48
|
+
await banMembers(communityId, [userId]);
|
|
49
|
+
const recieved = pullFromCache([
|
|
50
|
+
'communityUsers',
|
|
51
|
+
'get',
|
|
52
|
+
getResolver('communityUsers')({ communityId, userId }),
|
|
53
|
+
])?.data;
|
|
54
|
+
|
|
55
|
+
expect([recieved]).toStrictEqual(expectedUser);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// integration_test_id: 59b58ec8-8380-49b2-aa39-6da361692c2e
|
|
59
|
+
test('it should throw valid error', async () => {
|
|
60
|
+
const err = new ASCError(
|
|
61
|
+
'Permission Denied',
|
|
62
|
+
Amity.ServerError.UNAUTHORIZED,
|
|
63
|
+
Amity.ErrorLevel.ERROR,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
client.http.put = jest.fn().mockRejectedValue(err);
|
|
67
|
+
|
|
68
|
+
await expect(banMembers(communityId, [userId])).rejects.toThrow(err);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { disableCache, enableCache, pullFromCache } from '~/cache/api';
|
|
2
|
+
import { prepareMembershipPayload } from '~/group/utils';
|
|
3
|
+
import { getResolver } from '~/core/model';
|
|
4
|
+
import { ASCError } from '~/core/errors';
|
|
5
|
+
|
|
6
|
+
import { client, community11, communityUser11, user11 } from '~/utils/tests';
|
|
7
|
+
|
|
8
|
+
import { unbanMembers } from '../unbanMembers';
|
|
9
|
+
|
|
10
|
+
const userCommunity = community11;
|
|
11
|
+
const user = {
|
|
12
|
+
...communityUser11,
|
|
13
|
+
communityMebership: 'none',
|
|
14
|
+
};
|
|
15
|
+
const resolvedCommunityValue = {
|
|
16
|
+
data: {
|
|
17
|
+
communities: [userCommunity],
|
|
18
|
+
communityUsers: [user],
|
|
19
|
+
files: [],
|
|
20
|
+
users: [user11],
|
|
21
|
+
categories: [],
|
|
22
|
+
feeds: [],
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
describe('community/ moderation/ unbanMembers', () => {
|
|
27
|
+
beforeEach(enableCache);
|
|
28
|
+
afterEach(disableCache);
|
|
29
|
+
|
|
30
|
+
const { communityId } = communityUser11;
|
|
31
|
+
const { userId } = communityUser11;
|
|
32
|
+
|
|
33
|
+
const preparedPayload = prepareMembershipPayload(resolvedCommunityValue.data, 'communityUsers');
|
|
34
|
+
const { communityUsers: expectedUser } = preparedPayload;
|
|
35
|
+
|
|
36
|
+
// integration_test_id: bee19fd4-63f4-403f-9771-6424d94cf144
|
|
37
|
+
test('it should return banned members', async () => {
|
|
38
|
+
client.http.put = jest.fn().mockResolvedValue(resolvedCommunityValue);
|
|
39
|
+
|
|
40
|
+
const { data: recieved } = await unbanMembers(communityId, [userId]);
|
|
41
|
+
|
|
42
|
+
expect(recieved).toStrictEqual(expectedUser);
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
test('it should update cache', async () => {
|
|
46
|
+
client.http.put = jest.fn().mockResolvedValue(resolvedCommunityValue);
|
|
47
|
+
|
|
48
|
+
await unbanMembers(communityId, [userId]);
|
|
49
|
+
const recieved = pullFromCache([
|
|
50
|
+
'communityUsers',
|
|
51
|
+
'get',
|
|
52
|
+
getResolver('communityUsers')({ communityId, userId }),
|
|
53
|
+
])?.data;
|
|
54
|
+
|
|
55
|
+
expect([recieved]).toStrictEqual(expectedUser);
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// integration_test_id: 22ce5ced-641a-48e2-9a89-d3f51119d8ac
|
|
59
|
+
test('it should throw valid error', async () => {
|
|
60
|
+
const err = new ASCError(
|
|
61
|
+
'Permission Denied',
|
|
62
|
+
Amity.ServerError.UNAUTHORIZED,
|
|
63
|
+
Amity.ErrorLevel.ERROR,
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
client.http.put = jest.fn().mockRejectedValue(err);
|
|
67
|
+
|
|
68
|
+
await expect(unbanMembers(communityId, [userId])).rejects.toThrow(err);
|
|
69
|
+
});
|
|
70
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
|
|
5
|
+
import { prepareMembershipPayload } from '~/group/utils';
|
|
6
|
+
|
|
7
|
+
/* begin_public_function
|
|
8
|
+
id: community.moderation.unban_members
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* ```js
|
|
12
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
13
|
+
*
|
|
14
|
+
* await CommunityRepository.Moderation.unbanMembers('communityId', ['userId1', 'userId2'])
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* @param communityId of {@link Amity.Community} from which the users should be unbanned
|
|
18
|
+
* @param userIds of the {@link Amity.User}'s to be unbanned
|
|
19
|
+
* @returns the updated {@link Amity.Membership}'s object
|
|
20
|
+
*
|
|
21
|
+
* @category Community API
|
|
22
|
+
* @async
|
|
23
|
+
* */
|
|
24
|
+
export const unbanMembers = async (
|
|
25
|
+
communityId: Amity.Community['communityId'],
|
|
26
|
+
userIds: Amity.User['userId'][],
|
|
27
|
+
): Promise<Amity.Cached<Amity.Membership<'community'>[]>> => {
|
|
28
|
+
const client = getActiveClient();
|
|
29
|
+
client.log('community/unbanMembers', { userIds, communityId });
|
|
30
|
+
|
|
31
|
+
const { data: payload } = await client.http.put<Amity.CommunityMembershipPayload>(
|
|
32
|
+
`/api/v3/communities/${communityId}/users/unban`,
|
|
33
|
+
{
|
|
34
|
+
userIds,
|
|
35
|
+
},
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
39
|
+
|
|
40
|
+
const cachedAt = client.cache && Date.now();
|
|
41
|
+
if (client.cache) ingestInCache(data, { cachedAt });
|
|
42
|
+
|
|
43
|
+
const { communityUsers } = data;
|
|
44
|
+
|
|
45
|
+
return {
|
|
46
|
+
data: communityUsers.filter(u => userIds.includes(u.userId)),
|
|
47
|
+
cachedAt,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
/* end_public_function */
|
|
@@ -192,6 +192,10 @@ export const filterBySearchTerm = <T extends { userId: Amity.User['userId']; use
|
|
|
192
192
|
collection: T[],
|
|
193
193
|
searchTerm: string,
|
|
194
194
|
): T[] => {
|
|
195
|
+
/*
|
|
196
|
+
* Search term should match regardless of the case.
|
|
197
|
+
* Hence, the flag "i", is passed to the created regex
|
|
198
|
+
*/
|
|
195
199
|
const containsMatcher = new RegExp(searchTerm, 'i');
|
|
196
200
|
|
|
197
201
|
return collection.filter(m => {
|
|
@@ -13,6 +13,12 @@ describe('filtering:', () => {
|
|
|
13
13
|
]);
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
+
test('it should ignore search term case', () => {
|
|
17
|
+
expect(filterBySearchTerm(searchTermCollection, 'USER')).toStrictEqual([
|
|
18
|
+
searchTermCollection[0],
|
|
19
|
+
]);
|
|
20
|
+
});
|
|
21
|
+
|
|
16
22
|
test('it should return items that match displayName', () => {
|
|
17
23
|
expect(filterBySearchTerm(searchTermCollection, 'displ')).toStrictEqual([
|
|
18
24
|
searchTermCollection[0],
|