@amityco/ts-sdk 0.0.1-9440dbc.0 → 0.0.1-952db63.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/@types/domains/client.d.ts +1 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/getToken.d.ts.map +1 -1
- package/dist/comment/api/deleteComment.d.ts +35 -2
- package/dist/comment/api/deleteComment.d.ts.map +1 -1
- package/dist/comment/api/queryComments.d.ts +1 -1
- package/dist/core/query/paging.d.ts.map +1 -1
- package/dist/file/api/deleteFile.d.ts +3 -1
- package/dist/file/api/deleteFile.d.ts.map +1 -1
- package/dist/index.cjs.js +59 -48
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +59 -49
- package/dist/index.umd.js +17 -5205
- package/dist/post/api/deletePost.d.ts +38 -2
- package/dist/post/api/deletePost.d.ts.map +1 -1
- package/dist/version.d.ts +2 -0
- package/dist/version.d.ts.map +1 -0
- package/package.json +4 -2
- package/rollup.config.js +61 -21
- package/src/@types/domains/client.ts +2 -0
- package/src/client/api/createClient.ts +16 -8
- package/src/client/api/getToken.ts +2 -1
- package/src/comment/api/deleteComment.ts +15 -18
- package/src/comment/api/queryComments.ts +9 -8
- package/src/core/query/paging.ts +4 -0
- package/src/file/api/deleteFile.ts +5 -6
- package/src/index.ts +2 -0
- package/src/post/api/deletePost.ts +20 -20
- package/src/version.ts +2 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/@types/domains/client.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAE9B,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC;QACd,KAAK,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;QAErD,KAAK,MAAM,GAAG;YACZ,GAAG,EAAE,MAAM,CAAA;YACX,IAAI,EAAE,aAAa,CAAA;YACnB,EAAE,EAAE,cAAc,CAAC,MAAM,CAAA;YACzB,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YAE9B,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,CAAA;YAEnB,MAAM,CAAC,EAAE,MAAM,CAAA;YACf,MAAM,CAAC,EAAE,MAAM,CAAA;YAEf,GAAG,EAAE,MAAM,IAAI,CAAA;SAChB,CAAA;QAED,KAAK,MAAM,GAAG;YACZ,QAAQ,EAAE,MAAM,CAAA;YAChB,UAAU,EAAE;gBACV,OAAO,EAAE,MAAM,CAAA;gBACf,IAAI,EAAE,MAAM,GAAG,KAAK,CAAA;gBACpB,KAAK,CAAC,EAAE,MAAM,CAAA;aACf,CAAA;SACF,CAAA;QAED,KAAK,MAAM,GAAG;YACZ,WAAW,EAAE,MAAM,CAAA;YACnB,YAAY,EAAE,MAAM,CAAA;SACrB,CAAA;KACF;CACF"}
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../../src/@types/domains/client.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,OAAO,EAAE,MAAM,MAAM,CAAA;AAE9B,OAAO,CAAC,MAAM,CAAC;IACb,UAAU,KAAK,CAAC;QACd,KAAK,MAAM,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,IAAI,CAAA;QAErD,KAAK,MAAM,GAAG;YACZ,OAAO,EAAE,MAAM,CAAA;YAEf,GAAG,EAAE,MAAM,CAAA;YACX,IAAI,EAAE,aAAa,CAAA;YACnB,EAAE,EAAE,cAAc,CAAC,MAAM,CAAA;YACzB,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,CAAA;YAE9B,KAAK,CAAC,EAAE,KAAK,CAAC,KAAK,CAAA;YAEnB,MAAM,CAAC,EAAE,MAAM,CAAA;YACf,MAAM,CAAC,EAAE,MAAM,CAAA;YAEf,GAAG,EAAE,MAAM,IAAI,CAAA;SAChB,CAAA;QAED,KAAK,MAAM,GAAG;YACZ,QAAQ,EAAE,MAAM,CAAA;YAChB,UAAU,EAAE;gBACV,OAAO,EAAE,MAAM,CAAA;gBACf,IAAI,EAAE,MAAM,GAAG,KAAK,CAAA;gBACpB,KAAK,CAAC,EAAE,MAAM,CAAA;aACf,CAAA;SACF,CAAA;QAED,KAAK,MAAM,GAAG;YACZ,WAAW,EAAE,MAAM,CAAA;YACnB,YAAY,EAAE,MAAM,CAAA;SACrB,CAAA;KACF;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"createClient.d.ts","sourceRoot":"","sources":["../../../src/client/api/createClient.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"createClient.d.ts","sourceRoot":"","sources":["../../../src/client/api/createClient.ts"],"names":[],"mappings":"AAaA;;;;;;;;;;;;;;IAcI;AACJ,eAAO,MAAM,YAAY,WACf,MAAM,gBACD,MAAM,iBACL,MAAM,KACnB,MAAM,MA+BR,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getToken.d.ts","sourceRoot":"","sources":["../../../src/client/api/getToken.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,QAAQ,WAAkB;IACrC,MAAM,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7B,WAAW,EAAE,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;CACpC,
|
|
1
|
+
{"version":3,"file":"getToken.d.ts","sourceRoot":"","sources":["../../../src/client/api/getToken.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,QAAQ,WAAkB;IACrC,MAAM,EAAE,MAAM,IAAI,CAAC,QAAQ,CAAC,CAAC;IAC7B,WAAW,EAAE,MAAM,IAAI,CAAC,aAAa,CAAC,CAAC;IACvC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,MAAM,CAAC,UAAU,CAAC,CAAC;CACpC,0BAcA,CAAA"}
|
|
@@ -12,7 +12,40 @@
|
|
|
12
12
|
* @category Comment API
|
|
13
13
|
* @async
|
|
14
14
|
*/
|
|
15
|
-
export declare const deleteComment: (commentId: Amity.Comment['commentId'], permanent?: boolean) => Promise<
|
|
16
|
-
|
|
15
|
+
export declare const deleteComment: (commentId: Amity.Comment['commentId'], permanent?: boolean) => Promise<{
|
|
16
|
+
isDeleted: boolean;
|
|
17
|
+
commentId: string;
|
|
18
|
+
userId: string;
|
|
19
|
+
parentId?: string | undefined;
|
|
20
|
+
rootId: string;
|
|
21
|
+
childrenNumber: number;
|
|
22
|
+
children: string[];
|
|
23
|
+
segmentNumber: number;
|
|
24
|
+
referenceId: string;
|
|
25
|
+
referenceType: Amity.CommentReferenceType;
|
|
26
|
+
dataType?: any;
|
|
27
|
+
data: any;
|
|
28
|
+
metadata?: Record<string, any> | undefined;
|
|
29
|
+
flagCount: number;
|
|
30
|
+
hashFlag: {
|
|
31
|
+
bits: number;
|
|
32
|
+
hashes: number;
|
|
33
|
+
hash: string;
|
|
34
|
+
} | null;
|
|
35
|
+
reactionsCount: number;
|
|
36
|
+
reactions: Record<string, number>;
|
|
37
|
+
myReactions?: string[] | undefined;
|
|
38
|
+
latestReaction?: ({
|
|
39
|
+
reactionId: string;
|
|
40
|
+
userId: string;
|
|
41
|
+
reactionName: string;
|
|
42
|
+
} & Amity.CreatedAt & Amity.Relationship<Amity.ReactableType> & {
|
|
43
|
+
eventName: "added" | "removed";
|
|
44
|
+
}) | undefined;
|
|
45
|
+
createdAt: string;
|
|
46
|
+
updatedAt?: string | undefined;
|
|
47
|
+
deletedAt?: string | undefined;
|
|
48
|
+
localId: string;
|
|
49
|
+
syncedAt: number;
|
|
17
50
|
}>;
|
|
18
51
|
//# sourceMappingURL=deleteComment.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"deleteComment.d.ts","sourceRoot":"","sources":["../../../src/comment/api/deleteComment.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"deleteComment.d.ts","sourceRoot":"","sources":["../../../src/comment/api/deleteComment.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,aAAa,cACb,aAAa,CAAC,WAAW,CAAC,cAC1B,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAmCnB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"paging.d.ts","sourceRoot":"","sources":["../../../src/core/query/paging.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,SAAU,MAAM,sCAEvC,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,SAAU,MAAM,wCAEzC,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,YAAa,GAAG,gCAMnC,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,WACV,MAAM,IAAI,GAAG,SAAS,SACvB,WAAW,GAAG,aAAa,KAEjC,MAAM,KAAK,GAAG,
|
|
1
|
+
{"version":3,"file":"paging.d.ts","sourceRoot":"","sources":["../../../src/core/query/paging.ts"],"names":[],"mappings":"AAGA;;;;;;;GAOG;AACH,eAAO,MAAM,WAAW,SAAU,MAAM,sCAEvC,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,SAAU,MAAM,wCAEzC,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,YAAa,GAAG,gCAMnC,CAAA;AAED;;;;;;;;GAQG;AACH,eAAO,MAAM,OAAO,WACV,MAAM,IAAI,GAAG,SAAS,SACvB,WAAW,GAAG,aAAa,KAEjC,MAAM,KAAK,GAAG,SA2ChB,CAAA;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,MAAM,kCAA0B,MAAM,IAAI,GAAG,IA0BzD,CAAA;AAED;;;;;;;;;GASG;AACH,eAAO,MAAM,aAAa,qIAsBzB,CAAA"}
|
|
@@ -12,5 +12,7 @@
|
|
|
12
12
|
* @category File API
|
|
13
13
|
* @async
|
|
14
14
|
*/
|
|
15
|
-
export declare const deleteFile: (fileId: Amity.File<any>['fileId']) => Promise<
|
|
15
|
+
export declare const deleteFile: (fileId: Amity.File<any>['fileId']) => Promise<{
|
|
16
|
+
success: boolean;
|
|
17
|
+
}>;
|
|
16
18
|
//# sourceMappingURL=deleteFile.d.ts.map
|
|
@@ -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,
|
|
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
|
@@ -21,6 +21,10 @@ var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
|
|
|
21
21
|
var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt);
|
|
22
22
|
var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
|
|
23
23
|
|
|
24
|
+
var _a;
|
|
25
|
+
// used in createClient
|
|
26
|
+
const VERSION$1 = (_a = 'v0.0.1-beta.7-cjs') !== null && _a !== void 0 ? _a : '__dev__';
|
|
27
|
+
|
|
24
28
|
/**
|
|
25
29
|
* Generic ASC error
|
|
26
30
|
* @category Errors
|
|
@@ -422,6 +426,11 @@ const toToken = (paging, style) => {
|
|
|
422
426
|
first: paging.limit,
|
|
423
427
|
};
|
|
424
428
|
}
|
|
429
|
+
else if (!isNaN(paging === null || paging === void 0 ? void 0 : paging.limit)) {
|
|
430
|
+
payload = {
|
|
431
|
+
last: paging.limit,
|
|
432
|
+
};
|
|
433
|
+
}
|
|
425
434
|
}
|
|
426
435
|
// avoid sending {} as it seems backend flips when we do
|
|
427
436
|
if (!Object.keys(payload).length)
|
|
@@ -984,7 +993,12 @@ const createClient = (apiKey, apiEndpoint = 'https://api.amity.co', debugSession
|
|
|
984
993
|
const ws = createWebsocketTransport(apiEndpoint);
|
|
985
994
|
const emitter = createEventEmitter();
|
|
986
995
|
const client = {
|
|
987
|
-
|
|
996
|
+
version: `${VERSION$1}`,
|
|
997
|
+
apiKey,
|
|
998
|
+
log,
|
|
999
|
+
http,
|
|
1000
|
+
ws,
|
|
1001
|
+
emitter,
|
|
988
1002
|
use: () => setActiveClient(client),
|
|
989
1003
|
};
|
|
990
1004
|
try {
|
|
@@ -1046,6 +1060,7 @@ const getToken = async (params) => {
|
|
|
1046
1060
|
client.log('client/api/getToken', params);
|
|
1047
1061
|
const deviceInfo = await getDeviceInfo();
|
|
1048
1062
|
const { data } = await client.http.post('/v1/device', Object.assign(Object.assign({}, params), { deviceInfo }), {
|
|
1063
|
+
//@ts-ignore
|
|
1049
1064
|
headers: { 'X-API-Key': client.apiKey }
|
|
1050
1065
|
});
|
|
1051
1066
|
return data;
|
|
@@ -1813,11 +1828,10 @@ const createFile = async (formData, onProgress) => {
|
|
|
1813
1828
|
const deleteFile = async (fileId) => {
|
|
1814
1829
|
const client = getActiveClient();
|
|
1815
1830
|
client.log('file/deleteFile', fileId);
|
|
1831
|
+
// API-FIX: payload is different than swagger docs!!
|
|
1816
1832
|
const { data } = await client.http.delete(`/api/v3/files/${fileId}`);
|
|
1817
|
-
|
|
1818
|
-
|
|
1819
|
-
mergeInCache('file', { fileId, isDeleted: true });
|
|
1820
|
-
return success;
|
|
1833
|
+
dropFromCache('file', { fileId: data.fileId });
|
|
1834
|
+
return { success: true };
|
|
1821
1835
|
};
|
|
1822
1836
|
|
|
1823
1837
|
/**
|
|
@@ -2994,9 +3008,9 @@ const removeCommunityMembersRole = async (communityId, roleId, userIds) => {
|
|
|
2994
3008
|
* @async
|
|
2995
3009
|
*/
|
|
2996
3010
|
const deletePost = async (postId, permanent = false) => {
|
|
2997
|
-
var _a;
|
|
2998
3011
|
const client = getActiveClient();
|
|
2999
3012
|
client.log('post/deletePost', postId);
|
|
3013
|
+
let post = await getPost(postId);
|
|
3000
3014
|
// API-FIX: This endpoint has not been implemented yet.
|
|
3001
3015
|
await client.http.delete(`/api/v4/posts/${postId}`, {
|
|
3002
3016
|
params: {
|
|
@@ -3004,26 +3018,25 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
3004
3018
|
permanent,
|
|
3005
3019
|
},
|
|
3006
3020
|
});
|
|
3007
|
-
|
|
3008
|
-
|
|
3009
|
-
|
|
3010
|
-
|
|
3011
|
-
|
|
3012
|
-
|
|
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
|
-
}
|
|
3022
|
-
if (deleted.targetType === 'community') {
|
|
3023
|
-
const community = await getCommunity(deleted.targetId);
|
|
3021
|
+
// there is currently a limitation which doesn't allow us to fire event to tell that community
|
|
3022
|
+
// has been updated. reason is that, when the object is deleted, we don't have its `communityId`
|
|
3023
|
+
// and so we cannot refetch the community or advertise on events. hopefully this should be solved
|
|
3024
|
+
// later when realtime events covers that for us.
|
|
3025
|
+
if (post.targetType === 'community') {
|
|
3026
|
+
const community = await getCommunity(post.targetId);
|
|
3024
3027
|
fireEvent('v3.community.didUpdate', { communities: [community] });
|
|
3025
3028
|
}
|
|
3029
|
+
// to support hard deletion
|
|
3030
|
+
const deleted = Object.assign(Object.assign({}, post), { isDeleted: true });
|
|
3026
3031
|
fireEvent('v3.post.didDelete', { posts: [deleted] });
|
|
3032
|
+
if (permanent) {
|
|
3033
|
+
setTimeout(() => {
|
|
3034
|
+
dropFromCache('post', { postId });
|
|
3035
|
+
}, 0);
|
|
3036
|
+
}
|
|
3037
|
+
else {
|
|
3038
|
+
mergeInCache('post', { postId, isDeleted: true });
|
|
3039
|
+
}
|
|
3027
3040
|
return deleted;
|
|
3028
3041
|
};
|
|
3029
3042
|
|
|
@@ -3084,8 +3097,6 @@ queryComments.locally = (query) => {
|
|
|
3084
3097
|
const client = getActiveClient();
|
|
3085
3098
|
client.log('post/queryComments.locally', query);
|
|
3086
3099
|
const { referenceId, referenceType, parentId, isDeleted, page = { before: 0, limit: 5 }, } = query;
|
|
3087
|
-
if (isNaN(page.after) && isNaN(page.before))
|
|
3088
|
-
page.before = 0;
|
|
3089
3100
|
if (isNaN(page.limit))
|
|
3090
3101
|
page.limit = 5;
|
|
3091
3102
|
let comments = (_a = pullFromCache('comment')) !== null && _a !== void 0 ? _a : [];
|
|
@@ -3115,8 +3126,8 @@ queryComments.locally = (query) => {
|
|
|
3115
3126
|
if (afterIndex < 0 || beforeIndex < 0)
|
|
3116
3127
|
return;
|
|
3117
3128
|
let slice = comments.slice(afterIndex !== -1 ? afterIndex : 0, beforeIndex !== -1 ? beforeIndex : undefined);
|
|
3118
|
-
//
|
|
3119
|
-
if (
|
|
3129
|
+
// check if slice data is correct (complete)
|
|
3130
|
+
if (slice.length < page.limit)
|
|
3120
3131
|
return;
|
|
3121
3132
|
if (!isNaN(page.after) && !isNaN(page.before)) ;
|
|
3122
3133
|
else if (!isNaN(page.after)) {
|
|
@@ -3125,16 +3136,20 @@ queryComments.locally = (query) => {
|
|
|
3125
3136
|
else if (!isNaN(page.before)) {
|
|
3126
3137
|
slice = slice.slice(-page.limit);
|
|
3127
3138
|
}
|
|
3139
|
+
else {
|
|
3140
|
+
slice = slice.slice(-page.limit);
|
|
3141
|
+
}
|
|
3128
3142
|
for (let i = 0; i < slice.length - 1; i++)
|
|
3129
3143
|
if (slice[i].segmentNumber !== slice[i + 1].segmentNumber - 1)
|
|
3130
3144
|
return;
|
|
3131
3145
|
const prevPage = slice[0].segmentNumber > 1
|
|
3132
3146
|
? { before: slice[0].segmentNumber, limit: page.limit }
|
|
3133
3147
|
: undefined;
|
|
3134
|
-
const nextPage =
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3148
|
+
const nextPage = slice[slice.length - 1].segmentNumber < comments[comments.length - 1].segmentNumber
|
|
3149
|
+
? {
|
|
3150
|
+
after: slice[slice.length - 1].segmentNumber,
|
|
3151
|
+
limit: page.limit,
|
|
3152
|
+
} : undefined;
|
|
3138
3153
|
return { data: toRecord(slice), nextPage, prevPage };
|
|
3139
3154
|
};
|
|
3140
3155
|
|
|
@@ -3310,9 +3325,9 @@ const updateComment = async (commentId, patch) => {
|
|
|
3310
3325
|
* @async
|
|
3311
3326
|
*/
|
|
3312
3327
|
const deleteComment = async (commentId, permanent = false) => {
|
|
3313
|
-
var _a;
|
|
3314
3328
|
const client = getActiveClient();
|
|
3315
3329
|
client.log('comment/deleteComment', commentId);
|
|
3330
|
+
const comment = await getComment(commentId);
|
|
3316
3331
|
// API-FIX: This endpoint has not been implemented yet.
|
|
3317
3332
|
await client.http.delete(`/api/v4/comments/${commentId}`, {
|
|
3318
3333
|
params: {
|
|
@@ -3320,24 +3335,19 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
3320
3335
|
permanent,
|
|
3321
3336
|
},
|
|
3322
3337
|
});
|
|
3323
|
-
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
deleted = await getComment(commentId);
|
|
3327
|
-
}
|
|
3328
|
-
catch (error) {
|
|
3329
|
-
if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
|
|
3330
|
-
// there is currently a limitation which doesnt allow us to fire event to tell that post
|
|
3331
|
-
// has been updated. reason is that, when the object is deleted, we don't have its `postId`
|
|
3332
|
-
// and so we cannot refetch the post or advertise on events. hopefully this should be solved
|
|
3333
|
-
// later when realtime events covers that for us.
|
|
3334
|
-
return { success: true };
|
|
3335
|
-
}
|
|
3336
|
-
throw (error);
|
|
3337
|
-
}
|
|
3338
|
-
const post = await getPost(deleted.referenceId);
|
|
3338
|
+
// to support hard deletion
|
|
3339
|
+
const deleted = Object.assign(Object.assign({}, comment), { isDeleted: true });
|
|
3340
|
+
const post = await getPost(comment.referenceId);
|
|
3339
3341
|
fireEvent('v3.post.didUpdate', { posts: [post] });
|
|
3340
3342
|
fireEvent('v3.comment.didDelete', { comments: [deleted] });
|
|
3343
|
+
if (permanent) {
|
|
3344
|
+
setTimeout(() => {
|
|
3345
|
+
dropFromCache('comment', { commentId });
|
|
3346
|
+
}, 0);
|
|
3347
|
+
}
|
|
3348
|
+
else {
|
|
3349
|
+
mergeInCache('comment', { commentId, isDeleted: true });
|
|
3350
|
+
}
|
|
3341
3351
|
return deleted;
|
|
3342
3352
|
};
|
|
3343
3353
|
|
|
@@ -5062,6 +5072,7 @@ const disposeStream = async (streamId) => {
|
|
|
5062
5072
|
return videoStreamings.find(stream => stream.streamId === streamId);
|
|
5063
5073
|
};
|
|
5064
5074
|
|
|
5075
|
+
exports.VERSION = VERSION$1;
|
|
5065
5076
|
exports.addChannelMembers = addChannelMembers;
|
|
5066
5077
|
exports.addChannelMembersRole = addChannelMembersRole;
|
|
5067
5078
|
exports.addCommunityMembers = addCommunityMembers;
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,UAAU,CAAA;AAEjB,cAAc,WAAW,CAAA;AAGzB,cAAc,cAAc,CAAA;AAC5B,cAAc,cAAc,CAAA;AAC5B,cAAc,eAAe,CAAA;AAE7B,cAAc,cAAc,CAAA;AAC5B,cAAc,iBAAiB,CAAA;AAG/B,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,YAAY,CAAA;AAC1B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,YAAY,CAAA;AAG1B,cAAc,gBAAgB,CAAA;AAC9B,cAAc,mBAAmB,CAAA;AAEjC,cAAc,cAAc,CAAA;AAG5B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AAEnC,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AAGnC,cAAc,iBAAiB,CAAA;AAC/B,cAAc,oBAAoB,CAAA;AAClC,cAAc,uBAAuB,CAAA;AAErC,cAAc,YAAY,CAAA;AAE1B,cAAc,YAAY,CAAA;AAC1B,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAEhC,cAAc,eAAe,CAAA;AAC7B,cAAc,kBAAkB,CAAA;AAChC,cAAc,qBAAqB,CAAA;AAEnC,cAAc,cAAc,CAAA"}
|
package/dist/index.esm.js
CHANGED
|
@@ -7,6 +7,10 @@ import io from 'socket.io-client';
|
|
|
7
7
|
import mitt from 'mitt';
|
|
8
8
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
9
9
|
|
|
10
|
+
var _a;
|
|
11
|
+
// used in createClient
|
|
12
|
+
const VERSION$1 = (_a = 'v0.0.1-beta.7-esm') !== null && _a !== void 0 ? _a : '__dev__';
|
|
13
|
+
|
|
10
14
|
/**
|
|
11
15
|
* Generic ASC error
|
|
12
16
|
* @category Errors
|
|
@@ -408,6 +412,11 @@ const toToken = (paging, style) => {
|
|
|
408
412
|
first: paging.limit,
|
|
409
413
|
};
|
|
410
414
|
}
|
|
415
|
+
else if (!isNaN(paging === null || paging === void 0 ? void 0 : paging.limit)) {
|
|
416
|
+
payload = {
|
|
417
|
+
last: paging.limit,
|
|
418
|
+
};
|
|
419
|
+
}
|
|
411
420
|
}
|
|
412
421
|
// avoid sending {} as it seems backend flips when we do
|
|
413
422
|
if (!Object.keys(payload).length)
|
|
@@ -970,7 +979,12 @@ const createClient = (apiKey, apiEndpoint = 'https://api.amity.co', debugSession
|
|
|
970
979
|
const ws = createWebsocketTransport(apiEndpoint);
|
|
971
980
|
const emitter = createEventEmitter();
|
|
972
981
|
const client = {
|
|
973
|
-
|
|
982
|
+
version: `${VERSION$1}`,
|
|
983
|
+
apiKey,
|
|
984
|
+
log,
|
|
985
|
+
http,
|
|
986
|
+
ws,
|
|
987
|
+
emitter,
|
|
974
988
|
use: () => setActiveClient(client),
|
|
975
989
|
};
|
|
976
990
|
try {
|
|
@@ -1032,6 +1046,7 @@ const getToken = async (params) => {
|
|
|
1032
1046
|
client.log('client/api/getToken', params);
|
|
1033
1047
|
const deviceInfo = await getDeviceInfo();
|
|
1034
1048
|
const { data } = await client.http.post('/v1/device', Object.assign(Object.assign({}, params), { deviceInfo }), {
|
|
1049
|
+
//@ts-ignore
|
|
1035
1050
|
headers: { 'X-API-Key': client.apiKey }
|
|
1036
1051
|
});
|
|
1037
1052
|
return data;
|
|
@@ -1799,11 +1814,10 @@ const createFile = async (formData, onProgress) => {
|
|
|
1799
1814
|
const deleteFile = async (fileId) => {
|
|
1800
1815
|
const client = getActiveClient();
|
|
1801
1816
|
client.log('file/deleteFile', fileId);
|
|
1817
|
+
// API-FIX: payload is different than swagger docs!!
|
|
1802
1818
|
const { data } = await client.http.delete(`/api/v3/files/${fileId}`);
|
|
1803
|
-
|
|
1804
|
-
|
|
1805
|
-
mergeInCache('file', { fileId, isDeleted: true });
|
|
1806
|
-
return success;
|
|
1819
|
+
dropFromCache('file', { fileId: data.fileId });
|
|
1820
|
+
return { success: true };
|
|
1807
1821
|
};
|
|
1808
1822
|
|
|
1809
1823
|
/**
|
|
@@ -2980,9 +2994,9 @@ const removeCommunityMembersRole = async (communityId, roleId, userIds) => {
|
|
|
2980
2994
|
* @async
|
|
2981
2995
|
*/
|
|
2982
2996
|
const deletePost = async (postId, permanent = false) => {
|
|
2983
|
-
var _a;
|
|
2984
2997
|
const client = getActiveClient();
|
|
2985
2998
|
client.log('post/deletePost', postId);
|
|
2999
|
+
let post = await getPost(postId);
|
|
2986
3000
|
// API-FIX: This endpoint has not been implemented yet.
|
|
2987
3001
|
await client.http.delete(`/api/v4/posts/${postId}`, {
|
|
2988
3002
|
params: {
|
|
@@ -2990,26 +3004,25 @@ const deletePost = async (postId, permanent = false) => {
|
|
|
2990
3004
|
permanent,
|
|
2991
3005
|
},
|
|
2992
3006
|
});
|
|
2993
|
-
|
|
2994
|
-
|
|
2995
|
-
|
|
2996
|
-
|
|
2997
|
-
|
|
2998
|
-
|
|
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
|
-
}
|
|
3008
|
-
if (deleted.targetType === 'community') {
|
|
3009
|
-
const community = await getCommunity(deleted.targetId);
|
|
3007
|
+
// there is currently a limitation which doesn't allow us to fire event to tell that community
|
|
3008
|
+
// has been updated. reason is that, when the object is deleted, we don't have its `communityId`
|
|
3009
|
+
// and so we cannot refetch the community or advertise on events. hopefully this should be solved
|
|
3010
|
+
// later when realtime events covers that for us.
|
|
3011
|
+
if (post.targetType === 'community') {
|
|
3012
|
+
const community = await getCommunity(post.targetId);
|
|
3010
3013
|
fireEvent('v3.community.didUpdate', { communities: [community] });
|
|
3011
3014
|
}
|
|
3015
|
+
// to support hard deletion
|
|
3016
|
+
const deleted = Object.assign(Object.assign({}, post), { isDeleted: true });
|
|
3012
3017
|
fireEvent('v3.post.didDelete', { posts: [deleted] });
|
|
3018
|
+
if (permanent) {
|
|
3019
|
+
setTimeout(() => {
|
|
3020
|
+
dropFromCache('post', { postId });
|
|
3021
|
+
}, 0);
|
|
3022
|
+
}
|
|
3023
|
+
else {
|
|
3024
|
+
mergeInCache('post', { postId, isDeleted: true });
|
|
3025
|
+
}
|
|
3013
3026
|
return deleted;
|
|
3014
3027
|
};
|
|
3015
3028
|
|
|
@@ -3070,8 +3083,6 @@ queryComments.locally = (query) => {
|
|
|
3070
3083
|
const client = getActiveClient();
|
|
3071
3084
|
client.log('post/queryComments.locally', query);
|
|
3072
3085
|
const { referenceId, referenceType, parentId, isDeleted, page = { before: 0, limit: 5 }, } = query;
|
|
3073
|
-
if (isNaN(page.after) && isNaN(page.before))
|
|
3074
|
-
page.before = 0;
|
|
3075
3086
|
if (isNaN(page.limit))
|
|
3076
3087
|
page.limit = 5;
|
|
3077
3088
|
let comments = (_a = pullFromCache('comment')) !== null && _a !== void 0 ? _a : [];
|
|
@@ -3101,8 +3112,8 @@ queryComments.locally = (query) => {
|
|
|
3101
3112
|
if (afterIndex < 0 || beforeIndex < 0)
|
|
3102
3113
|
return;
|
|
3103
3114
|
let slice = comments.slice(afterIndex !== -1 ? afterIndex : 0, beforeIndex !== -1 ? beforeIndex : undefined);
|
|
3104
|
-
//
|
|
3105
|
-
if (
|
|
3115
|
+
// check if slice data is correct (complete)
|
|
3116
|
+
if (slice.length < page.limit)
|
|
3106
3117
|
return;
|
|
3107
3118
|
if (!isNaN(page.after) && !isNaN(page.before)) ;
|
|
3108
3119
|
else if (!isNaN(page.after)) {
|
|
@@ -3111,16 +3122,20 @@ queryComments.locally = (query) => {
|
|
|
3111
3122
|
else if (!isNaN(page.before)) {
|
|
3112
3123
|
slice = slice.slice(-page.limit);
|
|
3113
3124
|
}
|
|
3125
|
+
else {
|
|
3126
|
+
slice = slice.slice(-page.limit);
|
|
3127
|
+
}
|
|
3114
3128
|
for (let i = 0; i < slice.length - 1; i++)
|
|
3115
3129
|
if (slice[i].segmentNumber !== slice[i + 1].segmentNumber - 1)
|
|
3116
3130
|
return;
|
|
3117
3131
|
const prevPage = slice[0].segmentNumber > 1
|
|
3118
3132
|
? { before: slice[0].segmentNumber, limit: page.limit }
|
|
3119
3133
|
: undefined;
|
|
3120
|
-
const nextPage =
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3134
|
+
const nextPage = slice[slice.length - 1].segmentNumber < comments[comments.length - 1].segmentNumber
|
|
3135
|
+
? {
|
|
3136
|
+
after: slice[slice.length - 1].segmentNumber,
|
|
3137
|
+
limit: page.limit,
|
|
3138
|
+
} : undefined;
|
|
3124
3139
|
return { data: toRecord(slice), nextPage, prevPage };
|
|
3125
3140
|
};
|
|
3126
3141
|
|
|
@@ -3296,9 +3311,9 @@ const updateComment = async (commentId, patch) => {
|
|
|
3296
3311
|
* @async
|
|
3297
3312
|
*/
|
|
3298
3313
|
const deleteComment = async (commentId, permanent = false) => {
|
|
3299
|
-
var _a;
|
|
3300
3314
|
const client = getActiveClient();
|
|
3301
3315
|
client.log('comment/deleteComment', commentId);
|
|
3316
|
+
const comment = await getComment(commentId);
|
|
3302
3317
|
// API-FIX: This endpoint has not been implemented yet.
|
|
3303
3318
|
await client.http.delete(`/api/v4/comments/${commentId}`, {
|
|
3304
3319
|
params: {
|
|
@@ -3306,24 +3321,19 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
3306
3321
|
permanent,
|
|
3307
3322
|
},
|
|
3308
3323
|
});
|
|
3309
|
-
|
|
3310
|
-
|
|
3311
|
-
|
|
3312
|
-
deleted = await getComment(commentId);
|
|
3313
|
-
}
|
|
3314
|
-
catch (error) {
|
|
3315
|
-
if (((_a = error) === null || _a === void 0 ? void 0 : _a.code) === 400400 /* ITEM_NOT_FOUND */) {
|
|
3316
|
-
// there is currently a limitation which doesnt allow us to fire event to tell that post
|
|
3317
|
-
// has been updated. reason is that, when the object is deleted, we don't have its `postId`
|
|
3318
|
-
// and so we cannot refetch the post or advertise on events. hopefully this should be solved
|
|
3319
|
-
// later when realtime events covers that for us.
|
|
3320
|
-
return { success: true };
|
|
3321
|
-
}
|
|
3322
|
-
throw (error);
|
|
3323
|
-
}
|
|
3324
|
-
const post = await getPost(deleted.referenceId);
|
|
3324
|
+
// to support hard deletion
|
|
3325
|
+
const deleted = Object.assign(Object.assign({}, comment), { isDeleted: true });
|
|
3326
|
+
const post = await getPost(comment.referenceId);
|
|
3325
3327
|
fireEvent('v3.post.didUpdate', { posts: [post] });
|
|
3326
3328
|
fireEvent('v3.comment.didDelete', { comments: [deleted] });
|
|
3329
|
+
if (permanent) {
|
|
3330
|
+
setTimeout(() => {
|
|
3331
|
+
dropFromCache('comment', { commentId });
|
|
3332
|
+
}, 0);
|
|
3333
|
+
}
|
|
3334
|
+
else {
|
|
3335
|
+
mergeInCache('comment', { commentId, isDeleted: true });
|
|
3336
|
+
}
|
|
3327
3337
|
return deleted;
|
|
3328
3338
|
};
|
|
3329
3339
|
|
|
@@ -5048,4 +5058,4 @@ const disposeStream = async (streamId) => {
|
|
|
5048
5058
|
return videoStreamings.find(stream => stream.streamId === streamId);
|
|
5049
5059
|
};
|
|
5050
5060
|
|
|
5051
|
-
export { addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRole, addReaction, clearCache, connectClient, createCache, createChannel, createClient, createComment, createCommunity, createFile, createMessage, createPost, createQuery, createReport, createStream, decorateModel, decorateModels, decoratePayload, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePost, deleteReport, deleteStream, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, getActiveClient, getChannel, getChannels, getComment, getComments, getCommunities, getCommunity, getFile, getMessage, getMessages, getPost, getPosts, getRole, getStream, getUser, getUsers, ingestInCache, isAfterBefore, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, isSyncable, isSynced, joinChannel, joinCommunity, leaveChannel, leaveCommunity, memoryStore, memoryStores, mergeInCache, mutateCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeMessage, observeMessages, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onConnectionError, onMemberAdded, onMemberRemoved, onMessageCreated, onMessageDeleted, onMessageUpdated, onPostCreated, onPostDeleted, onPostUpdated, onReactionRemoved, onUserUpdated, persistentStore, pullFromCache, pushToCache, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRole, removeReaction, runQuery, sliceByPaging, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, syncInCache, toPage, toToken, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser };
|
|
5061
|
+
export { VERSION$1 as VERSION, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRole, addReaction, clearCache, connectClient, createCache, createChannel, createClient, createComment, createCommunity, createFile, createMessage, createPost, createQuery, createReport, createStream, decorateModel, decorateModels, decoratePayload, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePost, deleteReport, deleteStream, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, getActiveClient, getChannel, getChannels, getComment, getComments, getCommunities, getCommunity, getFile, getMessage, getMessages, getPost, getPosts, getRole, getStream, getUser, getUsers, ingestInCache, isAfterBefore, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, isSyncable, isSynced, joinChannel, joinCommunity, leaveChannel, leaveCommunity, memoryStore, memoryStores, mergeInCache, mutateCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeMessage, observeMessages, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onConnectionError, onMemberAdded, onMemberRemoved, onMessageCreated, onMessageDeleted, onMessageUpdated, onPostCreated, onPostDeleted, onPostUpdated, onReactionRemoved, onUserUpdated, persistentStore, pullFromCache, pushToCache, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRole, removeReaction, runQuery, sliceByPaging, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, syncInCache, toPage, toToken, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser };
|