@amityco/ts-sdk 0.0.1-4bc3872.0 → 0.0.1-4fb63bf.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.
@@ -12,5 +12,7 @@
12
12
  * @category Comment API
13
13
  * @async
14
14
  */
15
- export declare const deleteComment: (commentId: Amity.Comment['commentId'], permanent?: boolean) => Promise<Amity.Comment<any>>;
15
+ export declare const deleteComment: (commentId: Amity.Comment['commentId'], permanent?: boolean) => Promise<Amity.Comment<any> | {
16
+ success: boolean;
17
+ }>;
16
18
  //# sourceMappingURL=deleteComment.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"deleteComment.d.ts","sourceRoot":"","sources":["../../../src/comment/api/deleteComment.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,cACb,aAAa,CAAC,WAAW,CAAC,cAC1B,OAAO,gCAsBnB,CAAA"}
1
+ {"version":3,"file":"deleteComment.d.ts","sourceRoot":"","sources":["../../../src/comment/api/deleteComment.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,cACb,aAAa,CAAC,WAAW,CAAC,cAC1B,OAAO;;EAuCnB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"getComment.d.ts","sourceRoot":"","sources":["../../../src/comment/api/getComment.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU;gBACV,aAAa,CAAC,WAAW,CAAC;IAiBvC;;;;;;;;;;;;OAYG;uBAEU,aAAa,CAAC,WAAW,CAAC;CAhBtC,CAAA"}
1
+ {"version":3,"file":"getComment.d.ts","sourceRoot":"","sources":["../../../src/comment/api/getComment.ts"],"names":[],"mappings":"AAKA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU;gBACV,aAAa,CAAC,WAAW,CAAC;IA6BvC;;;;;;;;;;;;OAYG;uBAEU,aAAa,CAAC,WAAW,CAAC;CAhBtC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"deleteFile.d.ts","sourceRoot":"","sources":["../../../src/file/api/deleteFile.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,WACb,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;;EAalC,CAAA"}
1
+ {"version":3,"file":"deleteFile.d.ts","sourceRoot":"","sources":["../../../src/file/api/deleteFile.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,UAAU,WACb,UAAU,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC;;EAclC,CAAA"}
package/dist/index.cjs.js CHANGED
@@ -1815,7 +1815,7 @@ const deleteFile = async (fileId) => {
1815
1815
  client.log('file/deleteFile', fileId);
1816
1816
  // API-FIX: payload is different than swagger docs!!
1817
1817
  const { data } = await client.http.delete(`/api/v3/files/${fileId}`);
1818
- mergeInCache('file', { fileId: data.fileId, isDeleted: true });
1818
+ dropFromCache('file', { fileId: data.fileId });
1819
1819
  return { success: true };
1820
1820
  };
1821
1821
 
@@ -2440,10 +2440,21 @@ getPosts.locally = (postIds) => {
2440
2440
  * @async
2441
2441
  */
2442
2442
  const getPost = async (postId) => {
2443
+ var _a;
2443
2444
  const client = getActiveClient();
2444
2445
  client.log('post/getPost', postId);
2445
- // API-FIX: endpoint should not be /list, parameters should be querystring.
2446
- const { data } = await client.http.get(`/api/v3/posts/${postId}`);
2446
+ let data;
2447
+ try {
2448
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
2449
+ const response = await client.http.get(`/api/v3/posts/${postId}`);
2450
+ data = response.data;
2451
+ }
2452
+ catch (error) {
2453
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
2454
+ dropFromCache('post', { postId });
2455
+ }
2456
+ throw error;
2457
+ }
2447
2458
  decoratePayload(data);
2448
2459
  ingestInCache(data);
2449
2460
  const { posts } = data;
@@ -2982,6 +2993,7 @@ const removeCommunityMembersRole = async (communityId, roleId, userIds) => {
2982
2993
  * @async
2983
2994
  */
2984
2995
  const deletePost = async (postId, permanent = false) => {
2996
+ var _a;
2985
2997
  const client = getActiveClient();
2986
2998
  client.log('post/deletePost', postId);
2987
2999
  // API-FIX: This endpoint has not been implemented yet.
@@ -2991,8 +3003,21 @@ const deletePost = async (postId, permanent = false) => {
2991
3003
  permanent,
2992
3004
  },
2993
3005
  });
2994
- // API-FIX: as for now we have no choice but to refetch
2995
- const deleted = await getPost(postId);
3006
+ let deleted;
3007
+ try {
3008
+ // API-FIX: as for now we have no choice but to refetch
3009
+ deleted = await getPost(postId);
3010
+ }
3011
+ catch (error) {
3012
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
3013
+ // there is currently a limitation which doesnt allow us to fire event to tell that community
3014
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
3015
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
3016
+ // later when realtime events covers that for us.
3017
+ return { success: true };
3018
+ }
3019
+ throw (error);
3020
+ }
2996
3021
  if (deleted.targetType === 'community') {
2997
3022
  const community = await getCommunity(deleted.targetId);
2998
3023
  fireEvent('v3.community.didUpdate', { communities: [community] });
@@ -3173,10 +3198,21 @@ getComments.locally = (commentIds) => {
3173
3198
  * @async
3174
3199
  */
3175
3200
  const getComment = async (commentId) => {
3201
+ var _a;
3176
3202
  const client = getActiveClient();
3177
3203
  client.log('comment/getComment', commentId);
3178
- // API-FIX: endpoint should not be /list, parameters should be querystring.
3179
- const { data } = await client.http.get(`/api/v3/comments/${commentId}`);
3204
+ let data;
3205
+ try {
3206
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
3207
+ const response = await client.http.get(`/api/v3/comments/${commentId}`);
3208
+ data = response.data;
3209
+ }
3210
+ catch (error) {
3211
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
3212
+ dropFromCache('comment', { commentId });
3213
+ }
3214
+ throw error;
3215
+ }
3180
3216
  decoratePayload(data);
3181
3217
  ingestInCache(data);
3182
3218
  const { comments } = data;
@@ -3273,6 +3309,7 @@ const updateComment = async (commentId, patch) => {
3273
3309
  * @async
3274
3310
  */
3275
3311
  const deleteComment = async (commentId, permanent = false) => {
3312
+ var _a;
3276
3313
  const client = getActiveClient();
3277
3314
  client.log('comment/deleteComment', commentId);
3278
3315
  // API-FIX: This endpoint has not been implemented yet.
@@ -3282,7 +3319,21 @@ const deleteComment = async (commentId, permanent = false) => {
3282
3319
  permanent,
3283
3320
  },
3284
3321
  });
3285
- const deleted = await getComment(commentId);
3322
+ let deleted;
3323
+ try {
3324
+ // API-FIX: as for now we have no choice but to refetch
3325
+ deleted = await getComment(commentId);
3326
+ }
3327
+ catch (error) {
3328
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
3329
+ // there is currently a limitation which doesnt allow us to fire event to tell that post
3330
+ // has been updated. reason is that, when the object is deleted, we don't have its `postId`
3331
+ // and so we cannot refetch the post or advertise on events. hopefully this should be solved
3332
+ // later when realtime events covers that for us.
3333
+ return { success: true };
3334
+ }
3335
+ throw (error);
3336
+ }
3286
3337
  const post = await getPost(deleted.referenceId);
3287
3338
  fireEvent('v3.post.didUpdate', { posts: [post] });
3288
3339
  fireEvent('v3.comment.didDelete', { comments: [deleted] });
package/dist/index.esm.js CHANGED
@@ -1801,7 +1801,7 @@ const deleteFile = async (fileId) => {
1801
1801
  client.log('file/deleteFile', fileId);
1802
1802
  // API-FIX: payload is different than swagger docs!!
1803
1803
  const { data } = await client.http.delete(`/api/v3/files/${fileId}`);
1804
- mergeInCache('file', { fileId: data.fileId, isDeleted: true });
1804
+ dropFromCache('file', { fileId: data.fileId });
1805
1805
  return { success: true };
1806
1806
  };
1807
1807
 
@@ -2426,10 +2426,21 @@ getPosts.locally = (postIds) => {
2426
2426
  * @async
2427
2427
  */
2428
2428
  const getPost = async (postId) => {
2429
+ var _a;
2429
2430
  const client = getActiveClient();
2430
2431
  client.log('post/getPost', postId);
2431
- // API-FIX: endpoint should not be /list, parameters should be querystring.
2432
- const { data } = await client.http.get(`/api/v3/posts/${postId}`);
2432
+ let data;
2433
+ try {
2434
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
2435
+ const response = await client.http.get(`/api/v3/posts/${postId}`);
2436
+ data = response.data;
2437
+ }
2438
+ catch (error) {
2439
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
2440
+ dropFromCache('post', { postId });
2441
+ }
2442
+ throw error;
2443
+ }
2433
2444
  decoratePayload(data);
2434
2445
  ingestInCache(data);
2435
2446
  const { posts } = data;
@@ -2968,6 +2979,7 @@ const removeCommunityMembersRole = async (communityId, roleId, userIds) => {
2968
2979
  * @async
2969
2980
  */
2970
2981
  const deletePost = async (postId, permanent = false) => {
2982
+ var _a;
2971
2983
  const client = getActiveClient();
2972
2984
  client.log('post/deletePost', postId);
2973
2985
  // API-FIX: This endpoint has not been implemented yet.
@@ -2977,8 +2989,21 @@ const deletePost = async (postId, permanent = false) => {
2977
2989
  permanent,
2978
2990
  },
2979
2991
  });
2980
- // API-FIX: as for now we have no choice but to refetch
2981
- const deleted = await getPost(postId);
2992
+ let deleted;
2993
+ try {
2994
+ // API-FIX: as for now we have no choice but to refetch
2995
+ deleted = await getPost(postId);
2996
+ }
2997
+ catch (error) {
2998
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
2999
+ // there is currently a limitation which doesnt allow us to fire event to tell that community
3000
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
3001
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
3002
+ // later when realtime events covers that for us.
3003
+ return { success: true };
3004
+ }
3005
+ throw (error);
3006
+ }
2982
3007
  if (deleted.targetType === 'community') {
2983
3008
  const community = await getCommunity(deleted.targetId);
2984
3009
  fireEvent('v3.community.didUpdate', { communities: [community] });
@@ -3159,10 +3184,21 @@ getComments.locally = (commentIds) => {
3159
3184
  * @async
3160
3185
  */
3161
3186
  const getComment = async (commentId) => {
3187
+ var _a;
3162
3188
  const client = getActiveClient();
3163
3189
  client.log('comment/getComment', commentId);
3164
- // API-FIX: endpoint should not be /list, parameters should be querystring.
3165
- const { data } = await client.http.get(`/api/v3/comments/${commentId}`);
3190
+ let data;
3191
+ try {
3192
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
3193
+ const response = await client.http.get(`/api/v3/comments/${commentId}`);
3194
+ data = response.data;
3195
+ }
3196
+ catch (error) {
3197
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
3198
+ dropFromCache('comment', { commentId });
3199
+ }
3200
+ throw error;
3201
+ }
3166
3202
  decoratePayload(data);
3167
3203
  ingestInCache(data);
3168
3204
  const { comments } = data;
@@ -3259,6 +3295,7 @@ const updateComment = async (commentId, patch) => {
3259
3295
  * @async
3260
3296
  */
3261
3297
  const deleteComment = async (commentId, permanent = false) => {
3298
+ var _a;
3262
3299
  const client = getActiveClient();
3263
3300
  client.log('comment/deleteComment', commentId);
3264
3301
  // API-FIX: This endpoint has not been implemented yet.
@@ -3268,7 +3305,21 @@ const deleteComment = async (commentId, permanent = false) => {
3268
3305
  permanent,
3269
3306
  },
3270
3307
  });
3271
- const deleted = await getComment(commentId);
3308
+ let deleted;
3309
+ try {
3310
+ // API-FIX: as for now we have no choice but to refetch
3311
+ deleted = await getComment(commentId);
3312
+ }
3313
+ catch (error) {
3314
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
3315
+ // there is currently a limitation which doesnt allow us to fire event to tell that post
3316
+ // has been updated. reason is that, when the object is deleted, we don't have its `postId`
3317
+ // and so we cannot refetch the post or advertise on events. hopefully this should be solved
3318
+ // later when realtime events covers that for us.
3319
+ return { success: true };
3320
+ }
3321
+ throw (error);
3322
+ }
3272
3323
  const post = await getPost(deleted.referenceId);
3273
3324
  fireEvent('v3.post.didUpdate', { posts: [post] });
3274
3325
  fireEvent('v3.comment.didDelete', { comments: [deleted] });
package/dist/index.umd.js CHANGED
@@ -1805,7 +1805,7 @@ var Amity = (function (exports, jsBase64, nativeIdGenerator, debug, axios, HttpA
1805
1805
  client.log('file/deleteFile', fileId);
1806
1806
  // API-FIX: payload is different than swagger docs!!
1807
1807
  const { data } = await client.http.delete(`/api/v3/files/${fileId}`);
1808
- mergeInCache('file', { fileId: data.fileId, isDeleted: true });
1808
+ dropFromCache('file', { fileId: data.fileId });
1809
1809
  return { success: true };
1810
1810
  };
1811
1811
 
@@ -2430,10 +2430,21 @@ var Amity = (function (exports, jsBase64, nativeIdGenerator, debug, axios, HttpA
2430
2430
  * @async
2431
2431
  */
2432
2432
  const getPost = async (postId) => {
2433
+ var _a;
2433
2434
  const client = getActiveClient();
2434
2435
  client.log('post/getPost', postId);
2435
- // API-FIX: endpoint should not be /list, parameters should be querystring.
2436
- const { data } = await client.http.get(`/api/v3/posts/${postId}`);
2436
+ let data;
2437
+ try {
2438
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
2439
+ const response = await client.http.get(`/api/v3/posts/${postId}`);
2440
+ data = response.data;
2441
+ }
2442
+ catch (error) {
2443
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
2444
+ dropFromCache('post', { postId });
2445
+ }
2446
+ throw error;
2447
+ }
2437
2448
  decoratePayload(data);
2438
2449
  ingestInCache(data);
2439
2450
  const { posts } = data;
@@ -2972,6 +2983,7 @@ var Amity = (function (exports, jsBase64, nativeIdGenerator, debug, axios, HttpA
2972
2983
  * @async
2973
2984
  */
2974
2985
  const deletePost = async (postId, permanent = false) => {
2986
+ var _a;
2975
2987
  const client = getActiveClient();
2976
2988
  client.log('post/deletePost', postId);
2977
2989
  // API-FIX: This endpoint has not been implemented yet.
@@ -2981,8 +2993,21 @@ var Amity = (function (exports, jsBase64, nativeIdGenerator, debug, axios, HttpA
2981
2993
  permanent,
2982
2994
  },
2983
2995
  });
2984
- // API-FIX: as for now we have no choice but to refetch
2985
- const deleted = await getPost(postId);
2996
+ let deleted;
2997
+ try {
2998
+ // API-FIX: as for now we have no choice but to refetch
2999
+ deleted = await getPost(postId);
3000
+ }
3001
+ catch (error) {
3002
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
3003
+ // there is currently a limitation which doesnt allow us to fire event to tell that community
3004
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
3005
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
3006
+ // later when realtime events covers that for us.
3007
+ return { success: true };
3008
+ }
3009
+ throw (error);
3010
+ }
2986
3011
  if (deleted.targetType === 'community') {
2987
3012
  const community = await getCommunity(deleted.targetId);
2988
3013
  fireEvent('v3.community.didUpdate', { communities: [community] });
@@ -3163,10 +3188,21 @@ var Amity = (function (exports, jsBase64, nativeIdGenerator, debug, axios, HttpA
3163
3188
  * @async
3164
3189
  */
3165
3190
  const getComment = async (commentId) => {
3191
+ var _a;
3166
3192
  const client = getActiveClient();
3167
3193
  client.log('comment/getComment', commentId);
3168
- // API-FIX: endpoint should not be /list, parameters should be querystring.
3169
- const { data } = await client.http.get(`/api/v3/comments/${commentId}`);
3194
+ let data;
3195
+ try {
3196
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
3197
+ const response = await client.http.get(`/api/v3/comments/${commentId}`);
3198
+ data = response.data;
3199
+ }
3200
+ catch (error) {
3201
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
3202
+ dropFromCache('comment', { commentId });
3203
+ }
3204
+ throw error;
3205
+ }
3170
3206
  decoratePayload(data);
3171
3207
  ingestInCache(data);
3172
3208
  const { comments } = data;
@@ -3263,6 +3299,7 @@ var Amity = (function (exports, jsBase64, nativeIdGenerator, debug, axios, HttpA
3263
3299
  * @async
3264
3300
  */
3265
3301
  const deleteComment = async (commentId, permanent = false) => {
3302
+ var _a;
3266
3303
  const client = getActiveClient();
3267
3304
  client.log('comment/deleteComment', commentId);
3268
3305
  // API-FIX: This endpoint has not been implemented yet.
@@ -3272,7 +3309,21 @@ var Amity = (function (exports, jsBase64, nativeIdGenerator, debug, axios, HttpA
3272
3309
  permanent,
3273
3310
  },
3274
3311
  });
3275
- const deleted = await getComment(commentId);
3312
+ let deleted;
3313
+ try {
3314
+ // API-FIX: as for now we have no choice but to refetch
3315
+ deleted = await getComment(commentId);
3316
+ }
3317
+ catch (error) {
3318
+ if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
3319
+ // there is currently a limitation which doesnt allow us to fire event to tell that post
3320
+ // has been updated. reason is that, when the object is deleted, we don't have its `postId`
3321
+ // and so we cannot refetch the post or advertise on events. hopefully this should be solved
3322
+ // later when realtime events covers that for us.
3323
+ return { success: true };
3324
+ }
3325
+ throw (error);
3326
+ }
3276
3327
  const post = await getPost(deleted.referenceId);
3277
3328
  fireEvent('v3.post.didUpdate', { posts: [post] });
3278
3329
  fireEvent('v3.comment.didDelete', { comments: [deleted] });
@@ -12,5 +12,7 @@
12
12
  * @category Post API
13
13
  * @async
14
14
  */
15
- export declare const deletePost: (postId: Amity.Post['postId'], permanent?: boolean) => 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,cACjB,OAAO,6BA0BnB,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "0.0.1-4bc3872.0",
3
+ "version": "0.0.1-4fb63bf.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",
@@ -36,7 +36,24 @@ export const deleteComment = async (
36
36
  },
37
37
  )
38
38
 
39
- const deleted = await getComment(commentId)
39
+ let deleted: Amity.Comment;
40
+
41
+ try {
42
+ // API-FIX: as for now we have no choice but to refetch
43
+ deleted = await getComment(commentId)
44
+ } catch (error) {
45
+ if ((error as Amity.ErrorResponse)?.code === Amity.ServerError.ITEM_NOT_FOUND) {
46
+ // there is currently a limitation which doesnt allow us to fire event to tell that post
47
+ // has been updated. reason is that, when the object is deleted, we don't have its `postId`
48
+ // and so we cannot refetch the post or advertise on events. hopefully this should be solved
49
+ // later when realtime events covers that for us.
50
+
51
+ return { success: true }
52
+ }
53
+
54
+ throw(error);
55
+ }
56
+
40
57
  const post = await getPost(deleted.referenceId)
41
58
 
42
59
  fireEvent('v3.post.didUpdate', { posts: [post] })
@@ -1,6 +1,6 @@
1
1
  import { getActiveClient } from '~/client/api'
2
2
 
3
- import { ingestInCache, pullFromCache } from '~/core/cache'
3
+ import { ingestInCache, pullFromCache, dropFromCache } from '~/core/cache'
4
4
  import { decoratePayload } from '~/core/query'
5
5
 
6
6
  /**
@@ -23,10 +23,22 @@ export const getComment = async (
23
23
  const client = getActiveClient()
24
24
  client.log('comment/getComment', commentId)
25
25
 
26
- // API-FIX: endpoint should not be /list, parameters should be querystring.
27
- const { data } = await client.http.get<Amity.CommentPayload>(
28
- `/api/v3/comments/${commentId}`,
29
- )
26
+ let data: Amity.CommentPayload;
27
+
28
+ try {
29
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
30
+ const response = await client.http.get<Amity.CommentPayload>(
31
+ `/api/v3/comments/${commentId}`,
32
+ )
33
+
34
+ data = response.data;
35
+ } catch (error) {
36
+ if ((error as Amity.ErrorResponse)?.code === Amity.ServerError.ITEM_NOT_FOUND) {
37
+ dropFromCache('comment', {commentId})
38
+ }
39
+
40
+ throw error;
41
+ }
30
42
 
31
43
  decoratePayload(data)
32
44
  ingestInCache(data)
@@ -1,6 +1,6 @@
1
1
  import { getActiveClient } from '~/client/api'
2
2
 
3
- import { mergeInCache } from '~/core/cache'
3
+ import { dropFromCache } from '~/core/cache'
4
4
 
5
5
  /**
6
6
  * ```js
@@ -27,7 +27,8 @@ export const deleteFile = async (
27
27
  `/api/v3/files/${fileId}`,
28
28
  )
29
29
 
30
- mergeInCache('file', { fileId: data.fileId, isDeleted: true })
30
+ dropFromCache('file', {fileId: data.fileId})
31
+
31
32
 
32
33
  return { success: true }
33
34
  }
@@ -35,8 +35,23 @@ export const deletePost = async (
35
35
  },
36
36
  )
37
37
 
38
- // API-FIX: as for now we have no choice but to refetch
39
- 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
+ }
40
55
 
41
56
  if (deleted.targetType === 'community') {
42
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)