@amityco/ts-sdk 0.0.1-beta.42.2 → 0.0.1-beta.42.3
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/channel/api/getChannels.d.ts.map +1 -1
- package/dist/comment/api/getComments.d.ts.map +1 -1
- package/dist/index.cjs.js +51 -15
- package/dist/index.esm.js +51 -15
- package/dist/index.umd.js +2 -2
- package/dist/post/api/getPosts.d.ts.map +1 -1
- package/dist/post/api/tests/getPosts.test.d.ts +2 -0
- package/dist/post/api/tests/getPosts.test.d.ts.map +1 -0
- package/dist/utils/tests/dummy/comment.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/channel/api/getChannels.ts +20 -4
- package/src/channel/api/queryChannels.ts +2 -2
- package/src/channel/api/tests/getChannels.test.ts +3 -3
- package/src/comment/api/getComments.ts +20 -4
- package/src/comment/api/tests/getComments.test.ts +12 -1
- package/src/post/api/getPosts.ts +20 -4
- package/src/post/api/tests/getPosts.test.ts +18 -0
- package/src/utils/tests/dummy/comment.ts +2 -2
- package/src/utils/tests/dummy/message.ts +1 -1
- package/src/utils/tests/dummy/post.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getPosts.d.ts","sourceRoot":"","sources":["../../../src/post/api/getPosts.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getPosts.d.ts","sourceRoot":"","sources":["../../../src/post/api/getPosts.ts"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,QAAQ;cACV,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,GAC9B,QAAQ,MAAM,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,CAAC;IAoCtC;;;;;;;;;;;;OAYG;qBAC0B,MAAM,IAAI,CAAC,QAAQ,CAAC,EAAE,GAAG,MAAM,MAAM,CAAC,MAAM,IAAI,EAAE,CAAC,GAAG,SAAS;CAf3F,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getPosts.test.d.ts","sourceRoot":"","sources":["../../../../src/post/api/tests/getPosts.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"comment.d.ts","sourceRoot":"","sources":["../../../../src/utils/tests/dummy/comment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"comment.d.ts","sourceRoot":"","sources":["../../../../src/utils/tests/dummy/comment.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAK9C,wBAAgB,eAAe,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,KAAK,CAAC,OAAO,CA4B9E;AAED,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,OAA2B,CAAC;AAE1D,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,OASjC,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,OASrC,CAAC;AAEH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,OAOvC,CAAC;AAEH,eAAO,MAAM,SAAS,EAAE,KAAK,CAAC,OAG5B,CAAC;AAEH,eAAO,MAAM,cAAc,EAAE,KAAK,CAAC,OAGjC,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,OAGrC,CAAC;AAEH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,cAKtC,CAAC;AAEF,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,cAKpC,CAAC;AAEF,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,cAKvC,CAAC;AAEF,eAAO,MAAM,uBAAuB,EAAE,KAAK,CAAC,cAK3C,CAAC;AAEF,eAAO,MAAM,yBAAyB,EAAE,KAAK,CAAC,cAK7C,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,oBAU/B,CAAC;AAEF,eAAO,MAAM,+BAA+B,EAAE,KAAK,CAAC,cAKnD,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,KAAK,CAAC,cAkBzC,CAAC;AAGF,eAAO,MAAM,mBAAmB;;;;;;;;CAO/B,CAAC;AAEF,eAAO,MAAM,oBAAoB;;;;;;;;CAOhC,CAAC;AAEF,eAAO,MAAM,wBAAwB;;;;;;;;CAOpC,CAAC;AAEF,eAAO,MAAM,0BAA0B;;;;;;;;CAOtC,CAAC;AAEF,eAAO,MAAM,2BAA2B;;;;;;;;CAOvC,CAAC;AAEF,eAAO,MAAM,sBAAsB;;;;;;;;CAOlC,CAAC;AAGF,eAAO,MAAM,yBAAyB,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAMzE,CAAC;AAEF,eAAO,MAAM,iCAAiC,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAOjF,CAAC;AAEF,eAAO,MAAM,0BAA0B,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAS1E,CAAC;AAEF,eAAO,MAAM,8BAA8B,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAY9E,CAAC;AAEF,eAAO,MAAM,oCAAoC,EAAE,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC,CAYpF,CAAC"}
|
package/package.json
CHANGED
|
@@ -3,6 +3,8 @@ import { getActiveClient } from '~/client/api';
|
|
|
3
3
|
import { pullFromCache } from '~/cache/api';
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
+
import { checkIfShouldGoesToTombstone } from '~/cache/utils';
|
|
7
|
+
import { pushToTombstone } from '~/cache/api/pushToTombstone';
|
|
6
8
|
import { prepareChannelPayload } from '../utils';
|
|
7
9
|
|
|
8
10
|
/**
|
|
@@ -27,10 +29,24 @@ export const getChannels = async (
|
|
|
27
29
|
|
|
28
30
|
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
let payload: Amity.ChannelPayload;
|
|
33
|
+
|
|
34
|
+
try {
|
|
35
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
36
|
+
const response = await client.http.get<Amity.ChannelPayload>(`/api/v3/channels/list`, {
|
|
37
|
+
params: { channelIds: encodedChannelIds },
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
payload = response.data;
|
|
41
|
+
} catch (error) {
|
|
42
|
+
channelIds.forEach(channelId => {
|
|
43
|
+
if (checkIfShouldGoesToTombstone((error as Amity.ErrorResponse)?.code)) {
|
|
44
|
+
pushToTombstone('channel', channelId);
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
throw error;
|
|
49
|
+
}
|
|
34
50
|
|
|
35
51
|
const data = prepareChannelPayload(payload);
|
|
36
52
|
|
|
@@ -3,7 +3,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
3
3
|
import { toPage, toToken } from '~/core/query';
|
|
4
4
|
import { getResolver } from '~/core/model';
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
7
7
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
8
8
|
|
|
9
9
|
import { prepareChannelPayload } from '../utils';
|
|
@@ -36,7 +36,7 @@ export const queryChannels = async (
|
|
|
36
36
|
const { page = { limit: 10 }, displayName, membership, ...params } = query ?? {};
|
|
37
37
|
|
|
38
38
|
// API-FIX: parameters should be querystring.
|
|
39
|
-
// API-FIX: backend
|
|
39
|
+
// API-FIX: backend doesn't answer Amity.Response
|
|
40
40
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<ChannelPayload>>>(
|
|
41
41
|
const { data: queryPayload } = await client.http.get<Amity.ChannelPayload & Amity.Pagination>(
|
|
42
42
|
`/api/v3/channels`,
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { disableCache, enableCache, pushToCache
|
|
1
|
+
import { disableCache, enableCache, pushToCache } from '~/cache/api';
|
|
2
2
|
import { client, getChannelsResponse } from '~/utils/tests';
|
|
3
|
-
|
|
4
|
-
import { getChannels } from '../getChannels';
|
|
5
3
|
import { prepareChannelPayload } from '~/channel/utils';
|
|
6
4
|
import { ASCApiError } from '~/core/errors';
|
|
7
5
|
|
|
6
|
+
import { getChannels } from '../getChannels';
|
|
7
|
+
|
|
8
8
|
const channelIds = [
|
|
9
9
|
getChannelsResponse.data.channels[0].channelId,
|
|
10
10
|
getChannelsResponse.data.channels[1].channelId,
|
|
@@ -2,6 +2,8 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
|
|
3
3
|
import { pullFromCache } from '~/cache/api';
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
import { checkIfShouldGoesToTombstone } from '~/cache/utils';
|
|
6
|
+
import { pushToTombstone } from '~/cache/api/pushToTombstone';
|
|
5
7
|
|
|
6
8
|
/* begin_public_function
|
|
7
9
|
id: comment.get_by_ids
|
|
@@ -28,10 +30,24 @@ export const getComments = async (
|
|
|
28
30
|
|
|
29
31
|
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
30
32
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
let data: Amity.CommentPayload;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
37
|
+
const response = await client.http.get<Amity.CommentPayload>(`/api/v3/comments/list`, {
|
|
38
|
+
params: { commentIds: encodedCommentIds },
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
data = response.data;
|
|
42
|
+
} catch (error) {
|
|
43
|
+
commentIds.forEach(commentId => {
|
|
44
|
+
if (checkIfShouldGoesToTombstone((error as Amity.ErrorResponse)?.code)) {
|
|
45
|
+
pushToTombstone('comment', commentId);
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
35
51
|
|
|
36
52
|
const cachedAt = client.cache && Date.now();
|
|
37
53
|
if (client.cache) ingestInCache(data, { cachedAt });
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { enableCache } from '~/cache/api';
|
|
2
|
-
import { client, connectClient, disconnectClient,
|
|
2
|
+
import { client, comment11, connectClient, disconnectClient, user11 } from '~/utils/tests';
|
|
3
|
+
import { ASCApiError } from '~/core/errors';
|
|
3
4
|
import { getComments } from '../getComments';
|
|
4
5
|
|
|
5
6
|
const apiResponse = {
|
|
@@ -33,4 +34,14 @@ describe('getComments', () => {
|
|
|
33
34
|
|
|
34
35
|
expect(comments?.data).toEqual(commentsListResponse.data);
|
|
35
36
|
});
|
|
37
|
+
|
|
38
|
+
test('Should return Error: 400400 when getComments from invalid commentId', async () => {
|
|
39
|
+
client.http.get = jest
|
|
40
|
+
.fn()
|
|
41
|
+
.mockRejectedValueOnce(
|
|
42
|
+
new ASCApiError('not found!', Amity.ServerError.ITEM_NOT_FOUND, Amity.ErrorLevel.ERROR),
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
await expect(getComments([comment11.commentId])).rejects.toThrow();
|
|
46
|
+
});
|
|
36
47
|
});
|
package/src/post/api/getPosts.ts
CHANGED
|
@@ -3,6 +3,8 @@ import { getActiveClient } from '~/client/api';
|
|
|
3
3
|
import { pullFromCache } from '~/cache/api';
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
import { prepareMembershipPayload } from '~/group/utils';
|
|
6
|
+
import { checkIfShouldGoesToTombstone } from '~/cache/utils';
|
|
7
|
+
import { pushToTombstone } from '~/cache/api/pushToTombstone';
|
|
6
8
|
|
|
7
9
|
/* begin_public_function
|
|
8
10
|
id: post.get_by_ids
|
|
@@ -29,10 +31,24 @@ export const getPosts = async (
|
|
|
29
31
|
|
|
30
32
|
const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
|
|
31
33
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
34
|
+
let payload: Amity.PostPayload;
|
|
35
|
+
|
|
36
|
+
try {
|
|
37
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
38
|
+
const response = await client.http.get<Amity.PostPayload>(`/api/v3/posts/list`, {
|
|
39
|
+
params: { postIds: encodedPostIds },
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
payload = response.data;
|
|
43
|
+
} catch (error) {
|
|
44
|
+
postIds.forEach(postId => {
|
|
45
|
+
if (checkIfShouldGoesToTombstone((error as Amity.ErrorResponse)?.code)) {
|
|
46
|
+
pushToTombstone('post', postId);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
throw error;
|
|
51
|
+
}
|
|
36
52
|
|
|
37
53
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
38
54
|
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getPosts } from '~/post/api';
|
|
2
|
+
import { client, connectClient, disconnectClient, post11, post12 } from '~/utils/tests';
|
|
3
|
+
import { ASCApiError } from '~/core/errors';
|
|
4
|
+
|
|
5
|
+
describe('getPosts', () => {
|
|
6
|
+
beforeAll(connectClient);
|
|
7
|
+
afterAll(disconnectClient);
|
|
8
|
+
|
|
9
|
+
test('Should return Error: 400400 when getPosts from invalid postId', async () => {
|
|
10
|
+
client.http.get = jest
|
|
11
|
+
.fn()
|
|
12
|
+
.mockRejectedValueOnce(
|
|
13
|
+
new ASCApiError('not found!', Amity.ServerError.ITEM_NOT_FOUND, Amity.ErrorLevel.ERROR),
|
|
14
|
+
);
|
|
15
|
+
|
|
16
|
+
await expect(getPosts([post11.postId, post12.postId])).rejects.toThrow();
|
|
17
|
+
});
|
|
18
|
+
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { createComment
|
|
1
|
+
import { createComment } from '~/comment/api';
|
|
2
2
|
import { file11 } from './file';
|
|
3
|
-
import { post11
|
|
3
|
+
import { post11 } from './post';
|
|
4
4
|
import { user11, user12 } from './user';
|
|
5
5
|
|
|
6
6
|
export function generateComment(params?: Partial<Amity.Comment>): Amity.Comment {
|