@amityco/ts-sdk 0.0.1-33a3f0c.0 → 0.0.1-376eede.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/index.cjs.js CHANGED
@@ -2441,10 +2441,21 @@ getPosts.locally = (postIds) => {
2441
2441
  * @async
2442
2442
  */
2443
2443
  const getPost = async (postId) => {
2444
+ var _a;
2444
2445
  const client = getActiveClient();
2445
2446
  client.log('post/getPost', postId);
2446
- // API-FIX: endpoint should not be /list, parameters should be querystring.
2447
- const { data } = await client.http.get(`/api/v3/posts/${postId}`);
2447
+ let data;
2448
+ try {
2449
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
2450
+ const response = await client.http.get(`/api/v3/posts/${postId}`);
2451
+ data = response.data;
2452
+ }
2453
+ catch (error) {
2454
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
2455
+ dropFromCache('post', { postId });
2456
+ }
2457
+ throw error;
2458
+ }
2448
2459
  decoratePayload(data);
2449
2460
  ingestInCache(data);
2450
2461
  const { posts } = data;
@@ -2474,7 +2485,11 @@ getPost.locally = (postId) => {
2474
2485
  /**
2475
2486
  * ```js
2476
2487
  * import { createPost } from '@amityco/ts-sdk'
2477
- * const newPost = await createPost(bundle)
2488
+ * const created = await createPost({
2489
+ * targetType: 'user',
2490
+ * targetId: 'foobar',
2491
+ * data: { text: 'hello world' }
2492
+ * }))
2478
2493
  * ```
2479
2494
  *
2480
2495
  * Creates an {@link Amity.Post}
@@ -2978,13 +2993,32 @@ const removeCommunityMembersRole = async (communityId, roleId, userIds) => {
2978
2993
  * @category Post API
2979
2994
  * @async
2980
2995
  */
2981
- const deletePost = async (postId) => {
2996
+ const deletePost = async (postId, permanent = false) => {
2997
+ var _a;
2982
2998
  const client = getActiveClient();
2983
2999
  client.log('post/deletePost', postId);
2984
3000
  // API-FIX: This endpoint has not been implemented yet.
2985
- await client.http.delete(`/api/v3/posts/${postId}`);
2986
- // API-FIX: as for now we have no choice but to refetch
2987
- const deleted = await getPost(postId);
3001
+ await client.http.delete(`/api/v4/posts/${postId}`, {
3002
+ params: {
3003
+ postId,
3004
+ permanent,
3005
+ },
3006
+ });
3007
+ let deleted;
3008
+ try {
3009
+ // API-FIX: as for now we have no choice but to refetch
3010
+ deleted = await getPost(postId);
3011
+ }
3012
+ catch (error) {
3013
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
3014
+ // there is currently a limitation which doesnt allow us to fire event to tell that community
3015
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
3016
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
3017
+ // later when realtime events covers that for us.
3018
+ return { success: true };
3019
+ }
3020
+ throw (error);
3021
+ }
2988
3022
  if (deleted.targetType === 'community') {
2989
3023
  const community = await getCommunity(deleted.targetId);
2990
3024
  fireEvent('v3.community.didUpdate', { communities: [community] });
package/dist/index.esm.js CHANGED
@@ -2427,10 +2427,21 @@ getPosts.locally = (postIds) => {
2427
2427
  * @async
2428
2428
  */
2429
2429
  const getPost = async (postId) => {
2430
+ var _a;
2430
2431
  const client = getActiveClient();
2431
2432
  client.log('post/getPost', postId);
2432
- // API-FIX: endpoint should not be /list, parameters should be querystring.
2433
- const { data } = await client.http.get(`/api/v3/posts/${postId}`);
2433
+ let data;
2434
+ try {
2435
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
2436
+ const response = await client.http.get(`/api/v3/posts/${postId}`);
2437
+ data = response.data;
2438
+ }
2439
+ catch (error) {
2440
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
2441
+ dropFromCache('post', { postId });
2442
+ }
2443
+ throw error;
2444
+ }
2434
2445
  decoratePayload(data);
2435
2446
  ingestInCache(data);
2436
2447
  const { posts } = data;
@@ -2460,7 +2471,11 @@ getPost.locally = (postId) => {
2460
2471
  /**
2461
2472
  * ```js
2462
2473
  * import { createPost } from '@amityco/ts-sdk'
2463
- * const newPost = await createPost(bundle)
2474
+ * const created = await createPost({
2475
+ * targetType: 'user',
2476
+ * targetId: 'foobar',
2477
+ * data: { text: 'hello world' }
2478
+ * }))
2464
2479
  * ```
2465
2480
  *
2466
2481
  * Creates an {@link Amity.Post}
@@ -2964,13 +2979,32 @@ const removeCommunityMembersRole = async (communityId, roleId, userIds) => {
2964
2979
  * @category Post API
2965
2980
  * @async
2966
2981
  */
2967
- const deletePost = async (postId) => {
2982
+ const deletePost = async (postId, permanent = false) => {
2983
+ var _a;
2968
2984
  const client = getActiveClient();
2969
2985
  client.log('post/deletePost', postId);
2970
2986
  // API-FIX: This endpoint has not been implemented yet.
2971
- await client.http.delete(`/api/v3/posts/${postId}`);
2972
- // API-FIX: as for now we have no choice but to refetch
2973
- const deleted = await getPost(postId);
2987
+ await client.http.delete(`/api/v4/posts/${postId}`, {
2988
+ params: {
2989
+ postId,
2990
+ permanent,
2991
+ },
2992
+ });
2993
+ let deleted;
2994
+ try {
2995
+ // API-FIX: as for now we have no choice but to refetch
2996
+ deleted = await getPost(postId);
2997
+ }
2998
+ catch (error) {
2999
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
3000
+ // there is currently a limitation which doesnt allow us to fire event to tell that community
3001
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
3002
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
3003
+ // later when realtime events covers that for us.
3004
+ return { success: true };
3005
+ }
3006
+ throw (error);
3007
+ }
2974
3008
  if (deleted.targetType === 'community') {
2975
3009
  const community = await getCommunity(deleted.targetId);
2976
3010
  fireEvent('v3.community.didUpdate', { communities: [community] });
package/dist/index.umd.js CHANGED
@@ -2431,10 +2431,21 @@ var Amity = (function (exports, jsBase64, nativeIdGenerator, debug, axios, HttpA
2431
2431
  * @async
2432
2432
  */
2433
2433
  const getPost = async (postId) => {
2434
+ var _a;
2434
2435
  const client = getActiveClient();
2435
2436
  client.log('post/getPost', postId);
2436
- // API-FIX: endpoint should not be /list, parameters should be querystring.
2437
- const { data } = await client.http.get(`/api/v3/posts/${postId}`);
2437
+ let data;
2438
+ try {
2439
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
2440
+ const response = await client.http.get(`/api/v3/posts/${postId}`);
2441
+ data = response.data;
2442
+ }
2443
+ catch (error) {
2444
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
2445
+ dropFromCache('post', { postId });
2446
+ }
2447
+ throw error;
2448
+ }
2438
2449
  decoratePayload(data);
2439
2450
  ingestInCache(data);
2440
2451
  const { posts } = data;
@@ -2464,7 +2475,11 @@ var Amity = (function (exports, jsBase64, nativeIdGenerator, debug, axios, HttpA
2464
2475
  /**
2465
2476
  * ```js
2466
2477
  * import { createPost } from '@amityco/ts-sdk'
2467
- * const newPost = await createPost(bundle)
2478
+ * const created = await createPost({
2479
+ * targetType: 'user',
2480
+ * targetId: 'foobar',
2481
+ * data: { text: 'hello world' }
2482
+ * }))
2468
2483
  * ```
2469
2484
  *
2470
2485
  * Creates an {@link Amity.Post}
@@ -2968,13 +2983,32 @@ var Amity = (function (exports, jsBase64, nativeIdGenerator, debug, axios, HttpA
2968
2983
  * @category Post API
2969
2984
  * @async
2970
2985
  */
2971
- const deletePost = async (postId) => {
2986
+ const deletePost = async (postId, permanent = false) => {
2987
+ var _a;
2972
2988
  const client = getActiveClient();
2973
2989
  client.log('post/deletePost', postId);
2974
2990
  // API-FIX: This endpoint has not been implemented yet.
2975
- await client.http.delete(`/api/v3/posts/${postId}`);
2976
- // API-FIX: as for now we have no choice but to refetch
2977
- const deleted = await getPost(postId);
2991
+ await client.http.delete(`/api/v4/posts/${postId}`, {
2992
+ params: {
2993
+ postId,
2994
+ permanent,
2995
+ },
2996
+ });
2997
+ let deleted;
2998
+ try {
2999
+ // API-FIX: as for now we have no choice but to refetch
3000
+ deleted = await getPost(postId);
3001
+ }
3002
+ catch (error) {
3003
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
3004
+ // there is currently a limitation which doesnt allow us to fire event to tell that community
3005
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
3006
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
3007
+ // later when realtime events covers that for us.
3008
+ return { success: true };
3009
+ }
3010
+ throw (error);
3011
+ }
2978
3012
  if (deleted.targetType === 'community') {
2979
3013
  const community = await getCommunity(deleted.targetId);
2980
3014
  fireEvent('v3.community.didUpdate', { communities: [community] });
@@ -1,7 +1,11 @@
1
1
  /**
2
2
  * ```js
3
3
  * import { createPost } from '@amityco/ts-sdk'
4
- * const newPost = await createPost(bundle)
4
+ * const created = await createPost({
5
+ * targetType: 'user',
6
+ * targetId: 'foobar',
7
+ * data: { text: 'hello world' }
8
+ * }))
5
9
  * ```
6
10
  *
7
11
  * Creates an {@link Amity.Post}
@@ -1 +1 @@
1
- {"version":3,"file":"createPost.d.ts","sourceRoot":"","sources":["../../../src/post/api/createPost.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU;;;;;8BAwBtB,CAAA"}
1
+ {"version":3,"file":"createPost.d.ts","sourceRoot":"","sources":["../../../src/post/api/createPost.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU;;;;;8BAwBtB,CAAA"}
@@ -12,5 +12,7 @@
12
12
  * @category Post API
13
13
  * @async
14
14
  */
15
- export declare const deletePost: (postId: Amity.Post['postId']) => Promise<Amity.Post<any>>;
15
+ export declare const deletePost: (postId: Amity.Post['postId'], permanent?: boolean) => Promise<Amity.Post<any> | {
16
+ success: boolean;
17
+ }>;
16
18
  //# sourceMappingURL=deletePost.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deletePost.d.ts","sourceRoot":"","sources":["../../../src/post/api/deletePost.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,WACb,MAAM,IAAI,CAAC,QAAQ,CAAC,6BAqB7B,CAAA"}
1
+ {"version":3,"file":"deletePost.d.ts","sourceRoot":"","sources":["../../../src/post/api/deletePost.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,WACb,MAAM,IAAI,CAAC,QAAQ,CAAC,cACjB,OAAO;;EAyCnB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"getPost.d.ts","sourceRoot":"","sources":["../../../src/post/api/getPost.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,OAAO;aACV,MAAM,IAAI,CAAC,QAAQ,CAAC;IAiB9B;;;;;;;;;;;;OAYG;oBAEO,MAAM,IAAI,CAAC,QAAQ,CAAC;CAhB7B,CAAA"}
1
+ {"version":3,"file":"getPost.d.ts","sourceRoot":"","sources":["../../../src/post/api/getPost.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,OAAO;aACV,MAAM,IAAI,CAAC,QAAQ,CAAC;IA6B9B;;;;;;;;;;;;OAYG;oBAEO,MAAM,IAAI,CAAC,QAAQ,CAAC;CAhB7B,CAAA"}
@@ -21,6 +21,8 @@ export declare const queryPosts: {
21
21
  isDeleted?: Amity.Post['isDeleted'];
22
22
  hasFlag?: boolean;
23
23
  feedType?: 'reviewing' | 'published';
24
+ tags?: Amity.Taggable['tags'];
25
+ matchingOnlyParentPost?: boolean;
24
26
  page?: Amity.Page;
25
27
  }): Promise<{
26
28
  data: Record<string, Amity.Post<any>>;
@@ -1 +1 @@
1
- {"version":3,"file":"queryPosts.d.ts","sourceRoot":"","sources":["../../../src/post/api/queryPosts.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU;YACd;QACL,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,IAAI,CAAC,YAAY,CAAC,CAAC;QACrC,MAAM,CAAC,EAAE,aAAa,GAAG,cAAc,GAAG,aAAa,GAAG,cAAc,CAAA;QACxE,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC,WAAW,CAAC,CAAA;QACnC,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,QAAQ,CAAC,EAAE,WAAW,GAAG,WAAW,CAAA;QACpC,IAAI,CAAC,EAAE,MAAM,IAAI,CAAA;KAClB;;;;;IAkCH;;;;;;;;;;;;OAYG;mBAEM,WAAW,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAhBxC,CAAA"}
1
+ {"version":3,"file":"queryPosts.d.ts","sourceRoot":"","sources":["../../../src/post/api/queryPosts.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU;YACd;QACL,QAAQ,EAAE,MAAM,CAAC;QACjB,UAAU,EAAE,MAAM,IAAI,CAAC,YAAY,CAAC,CAAC;QACrC,MAAM,CAAC,EAAE,aAAa,GAAG,cAAc,GAAG,aAAa,GAAG,cAAc,CAAA;QACxE,QAAQ,CAAC,EAAE,MAAM,CAAA;QACjB,SAAS,CAAC,EAAE,MAAM,IAAI,CAAC,WAAW,CAAC,CAAA;QACnC,OAAO,CAAC,EAAE,OAAO,CAAA;QACjB,QAAQ,CAAC,EAAE,WAAW,GAAG,WAAW,CAAA;QACpC,IAAI,CAAC,EAAE,MAAM,QAAQ,CAAC,MAAM,CAAC,CAAC;QAC9B,sBAAsB,CAAC,EAAE,OAAO,CAAA;QAChC,IAAI,CAAC,EAAE,MAAM,IAAI,CAAA;KAClB;;;;;IAkCH;;;;;;;;;;;;OAYG;mBAEM,WAAW,iBAAiB,CAAC,CAAC,CAAC,CAAC;CAhBxC,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "0.0.1-33a3f0c.0",
3
+ "version": "0.0.1-376eede.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",
@@ -7,7 +7,11 @@ import { fireEvent } from '~/core/events'
7
7
  /**
8
8
  * ```js
9
9
  * import { createPost } from '@amityco/ts-sdk'
10
- * const newPost = await createPost(bundle)
10
+ * const created = await createPost({
11
+ * targetType: 'user',
12
+ * targetId: 'foobar',
13
+ * data: { text: 'hello world' }
14
+ * }))
11
15
  * ```
12
16
  *
13
17
  * Creates an {@link Amity.Post}
@@ -20,17 +20,38 @@ import { getPost } from './getPost'
20
20
  */
21
21
  export const deletePost = async (
22
22
  postId: Amity.Post['postId'],
23
+ permanent: boolean = false,
23
24
  ) => {
24
25
  const client = getActiveClient()
25
26
  client.log('post/deletePost', postId)
26
27
 
27
28
  // API-FIX: This endpoint has not been implemented yet.
28
29
  await client.http.delete<{ success: boolean }>(
29
- `/api/v3/posts/${postId}`,
30
+ `/api/v4/posts/${postId}`, {
31
+ params: {
32
+ postId,
33
+ permanent,
34
+ },
35
+ },
30
36
  )
31
37
 
32
- // API-FIX: as for now we have no choice but to refetch
33
- const deleted = await getPost(postId)
38
+ let deleted: Amity.Post;
39
+
40
+ try {
41
+ // API-FIX: as for now we have no choice but to refetch
42
+ deleted = await getPost(postId)
43
+ } catch (error) {
44
+ if ((error as Amity.ErrorResponse)?.code === Amity.ServerError.ITEM_NOT_FOUND) {
45
+ // there is currently a limitation which doesnt allow us to fire event to tell that community
46
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
47
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
48
+ // later when realtime events covers that for us.
49
+
50
+ return { success: true }
51
+ }
52
+
53
+ throw(error);
54
+ }
34
55
 
35
56
  if (deleted.targetType === 'community') {
36
57
  const community = await getCommunity(deleted.targetId);
@@ -1,5 +1,5 @@
1
1
  import { getActiveClient } from '~/client/api'
2
- import { ingestInCache, pullFromCache } from '~/core/cache'
2
+ import { ingestInCache, pullFromCache, dropFromCache } from '~/core/cache'
3
3
  import { decoratePayload } from '~/core/query'
4
4
 
5
5
  import { getPosts } from './getPosts'
@@ -24,10 +24,22 @@ export const getPost = async (
24
24
  const client = getActiveClient()
25
25
  client.log('post/getPost', postId)
26
26
 
27
- // API-FIX: endpoint should not be /list, parameters should be querystring.
28
- const { data } = await client.http.get<Amity.PostPayload>(
29
- `/api/v3/posts/${postId}`,
30
- )
27
+ let data: Amity.PostPayload;
28
+
29
+ try {
30
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
31
+ const response = await client.http.get<Amity.PostPayload>(
32
+ `/api/v3/posts/${postId}`,
33
+ )
34
+
35
+ data = response.data;
36
+ } catch (error) {
37
+ if ((error as Amity.ErrorResponse)?.code === Amity.ServerError.ITEM_NOT_FOUND) {
38
+ dropFromCache('post', {postId})
39
+ }
40
+
41
+ throw error;
42
+ }
31
43
 
32
44
  decoratePayload(data)
33
45
  ingestInCache(data)
@@ -28,6 +28,8 @@ export const queryPosts = async (
28
28
  isDeleted?: Amity.Post['isDeleted']
29
29
  hasFlag?: boolean
30
30
  feedType?: 'reviewing' | 'published'
31
+ tags?: Amity.Taggable['tags'],
32
+ matchingOnlyParentPost?: boolean
31
33
  page?: Amity.Page
32
34
  }
33
35
  ) => {
package/tsconfig.json CHANGED
@@ -12,6 +12,7 @@
12
12
 
13
13
  "rootDir": "./src",
14
14
  "outDir": "./dist",
15
+ "declaration": true,
15
16
  "declarationDir": "./dist",
16
17
  "noEmit": true, // by rollup
17
18