@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.
Files changed (28) hide show
  1. package/dist/@types/core/linkPreview.d.ts +12 -0
  2. package/dist/@types/core/linkPreview.d.ts.map +1 -0
  3. package/dist/@types/domains/community.d.ts +2 -4
  4. package/dist/@types/domains/community.d.ts.map +1 -1
  5. package/dist/@types/domains/user.d.ts +1 -2
  6. package/dist/@types/domains/user.d.ts.map +1 -1
  7. package/dist/client/api/fetchLinkPreview.d.ts +14 -0
  8. package/dist/client/api/fetchLinkPreview.d.ts.map +1 -0
  9. package/dist/client/api/index.d.ts +1 -0
  10. package/dist/client/api/index.d.ts.map +1 -1
  11. package/dist/communityRepository/utils/communityQueryFilter.d.ts.map +1 -1
  12. package/dist/index.cjs.js +24 -2
  13. package/dist/index.esm.js +24 -2
  14. package/dist/index.umd.js +2 -2
  15. package/dist/messageRepository/observers/getMessages/getMessages.d.ts +0 -1
  16. package/dist/messageRepository/observers/getMessages/getMessages.d.ts.map +1 -1
  17. package/package.json +1 -1
  18. package/src/@types/core/linkPreview.ts +12 -0
  19. package/src/@types/domains/community.ts +0 -2
  20. package/src/@types/domains/user.ts +0 -1
  21. package/src/client/api/fetchLinkPreview.ts +30 -0
  22. package/src/client/api/index.ts +2 -0
  23. package/src/communityRepository/communityMembership/observers/tests/getMembers.test.ts +0 -1
  24. package/src/communityRepository/observers/tests/getCommunities.test.ts +0 -1
  25. package/src/communityRepository/utils/communityQueryFilter.ts +1 -8
  26. package/src/core/events.ts +1 -1
  27. package/src/messageRepository/observers/getMessages/getMessages.ts +0 -34
  28. package/src/userRepository/observers/tests/getUsers.test.ts +1 -43
@@ -1,4 +1,3 @@
1
- export declare const applyFilter: <T extends Amity.Message<any>>(data: T[], params: Amity.MessagesLiveCollection) => T[];
2
1
  /**
3
2
  * ```js
4
3
  * import { getMessages } from '@amityco/ts-sdk';
@@ -1 +1 @@
1
- {"version":3,"file":"getMessages.d.ts","sourceRoot":"","sources":["../../../../src/messageRepository/observers/getMessages/getMessages.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,WAAW,oDAEd,MAAM,sBAAsB,QAuBrC,CAAC;AAKF;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,WACd,MAAM,sBAAsB,YAC1B,MAAM,sBAAsB,CAAC,MAAM,OAAO,CAAC,WAC5C,MAAM,oBAAoB,KAClC,MAAM,YAuBR,CAAC"}
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "6.35.3-3272722.0",
3
+ "version": "6.35.3-c7e7d80.0",
4
4
  "license": "CC-BY-ND-4.0",
5
5
  "author": "amity.co <developers@amity.co> (https://amity.co)",
6
6
  "description": "Amity Social Cloud Typescript SDK",
@@ -0,0 +1,12 @@
1
+ export {};
2
+
3
+ declare global {
4
+ namespace Amity {
5
+ type LinkPreview = {
6
+ title: string | null;
7
+ description: string | null;
8
+ image: string | null;
9
+ video: string | null;
10
+ };
11
+ }
12
+ }
@@ -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}`;
@@ -7,7 +7,6 @@ declare global {
7
7
  const enum UserSortByEnum {
8
8
  FirstCreated = 'firstCreated',
9
9
  LastCreated = 'lastCreated',
10
- DisplayName = 'displayName',
11
10
  }
12
11
 
13
12
  type UserSearchMatchType = AmityUserSearchMatchType;
@@ -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
+ };
@@ -18,3 +18,5 @@ export * from './markerSync';
18
18
  export * from './enableUnreadCount';
19
19
 
20
20
  export * from './setUploadedFileAccessType';
21
+
22
+ export * from './fetchLinkPreview';
@@ -238,7 +238,6 @@ describe('getMembers > applyFilter', () => {
238
238
  [m1, m2],
239
239
  [m2, m1],
240
240
  ],
241
- ['it should filter by search term', { communityId, search: 'sea' }, [m1, m2], [m2]],
242
241
  ];
243
242
 
244
243
  test.each(filters)('%s', (test, param, input, expected) => {
@@ -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
- if (sortBy === 'displayName') {
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
  };
@@ -32,7 +32,7 @@ const MQTT_EVENTS = [
32
32
  'video-streaming.didFlag',
33
33
  'video-streaming.didTerminate',
34
34
 
35
- 'user.didGlobalBan',
35
+ // 'user.didGlobalBan' remove due to message event,
36
36
  ] as const;
37
37
 
38
38
  /** @hidden */
@@ -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, applyFilter } = getUsersModule;
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
  });