@amityco/ts-sdk 0.0.1-beta.42.1 → 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/cache/utils/index.d.ts +1 -0
- package/dist/cache/utils/index.d.ts.map +1 -1
- package/dist/channel/api/getChannels.d.ts.map +1 -1
- package/dist/channel/observers/liveChannels.d.ts.map +1 -1
- package/dist/comment/api/getComments.d.ts.map +1 -1
- package/dist/comment/observers/liveComments.d.ts.map +1 -1
- package/dist/community/observers/liveCommunities.d.ts.map +1 -1
- package/dist/index.cjs.js +74 -32
- package/dist/index.esm.js +74 -32
- package/dist/index.umd.js +4 -4
- package/dist/message/observers/liveMessages.d.ts.map +1 -1
- 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/post/observers/livePosts.d.ts.map +1 -1
- package/dist/subChannel/observers/liveSubChannels.d.ts.map +1 -1
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/tests/dummy/comment.d.ts.map +1 -1
- package/dist/utils/tests/dummy/community.d.ts +1 -1
- package/package.json +1 -1
- package/src/cache/utils/index.ts +5 -2
- package/src/channel/api/getChannels.ts +20 -4
- package/src/channel/api/queryChannels.ts +2 -2
- package/src/channel/api/tests/addChannelMembers.test.ts +13 -0
- package/src/channel/api/tests/getChannels.test.ts +3 -3
- package/src/channel/api/tests/queryChannelMembers.test.ts +1 -0
- package/src/channel/api/tests/removeChannelMembers.test.ts +9 -2
- package/src/channel/observers/liveChannels.ts +11 -9
- package/src/comment/api/getComments.ts +20 -4
- package/src/comment/api/tests/getComments.test.ts +12 -1
- package/src/comment/observers/liveComments.ts +9 -6
- package/src/community/observers/liveCommunities.ts +9 -6
- package/src/message/api/tests/createMessage.test.ts +10 -3
- package/src/message/api/tests/deleteMessage.test.ts +10 -3
- package/src/message/api/tests/getMessage.test.ts +9 -3
- package/src/message/api/tests/updateMessage.test.ts +9 -2
- package/src/message/observers/liveMessages.ts +2 -1
- package/src/post/api/getPosts.ts +20 -4
- package/src/post/api/tests/getPosts.test.ts +18 -0
- package/src/post/observers/livePosts.ts +12 -9
- package/src/subChannel/observers/liveSubChannels.ts +4 -3
- package/src/utils/constants.ts +2 -1
- 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
|
@@ -2,6 +2,7 @@ export declare const CACHE_KEY_GET = "get";
|
|
|
2
2
|
export declare const CACHE_KEY_QUERY = "query";
|
|
3
3
|
export declare const CACHE_KEY_TOMBSTONE = "dead";
|
|
4
4
|
export declare const CACHE_KEY_COLLECTION = "collection";
|
|
5
|
+
export declare const CACHE_SHORTEN_LIFESPAN: number;
|
|
5
6
|
export declare const CACHE_LIFESPAN: number;
|
|
6
7
|
export declare const CACHE_LIFESPAN_TOMBSTONE: number;
|
|
7
8
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cache/utils/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/cache/utils/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,aAAa,QAAQ,CAAC;AACnC,eAAO,MAAM,eAAe,UAAU,CAAC;AACvC,eAAO,MAAM,mBAAmB,SAAS,CAAC;AAC1C,eAAO,MAAM,oBAAoB,eAAe,CAAC;AAEjD,eAAO,MAAM,sBAAsB,QAAa,CAAC;AACjD,eAAO,MAAM,cAAc,QAAa,CAAC;AACzC,eAAO,MAAM,wBAAwB,QAAa,CAAC;AAkBnD;;;;;;;;GAQG;AACH,eAAO,MAAM,SAAS,2BAA0B,MACmC,CAAC;AAEpF;;;;;;;;;GASG;AACH,eAAO,MAAM,SAAS,QAAS,MAAM,mBAAoC,CAAC;AAE1E;;;;;;;;GAQG;AACH,eAAO,MAAM,YAAY,cAAe,GAAG,aAAa,GAAG,KAAG,OAa7D,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,QAAQ,4BAA6B,GAAG,2BACU,CAAC;AAEhE;;;;;;;;;GASG;AACH,eAAO,MAAM,4BAA4B,cAAe,MAAM,WAAW,KAAG,OACS,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getChannels.d.ts","sourceRoot":"","sources":["../../../src/channel/api/getChannels.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getChannels.d.ts","sourceRoot":"","sources":["../../../src/channel/api/getChannels.ts"],"names":[],"mappings":"AASA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW;iBACV,MAAM,OAAO,CAAC,WAAW,CAAC,EAAE,GACvC,QAAQ,MAAM,MAAM,CAAC,MAAM,OAAO,EAAE,CAAC,CAAC;IAoCzC;;;;;;;;;;;;OAYG;wBAEW,MAAM,OAAO,CAAC,WAAW,CAAC,EAAE,GACvC,MAAM,MAAM,CAAC,MAAM,OAAO,EAAE,CAAC,GAAG,SAAS;CAjB3C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liveChannels.d.ts","sourceRoot":"","sources":["../../../src/channel/observers/liveChannels.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"liveChannels.d.ts","sourceRoot":"","sources":["../../../src/channel/observers/liveChannels.ts"],"names":[],"mappings":"AAkCA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,YAAY,WACf,MAAM,qBAAqB,YACzB,MAAM,sBAAsB,CAAC,MAAM,OAAO,CAAC,WAC5C,MAAM,oBAAoB,eAkJpC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getComments.d.ts","sourceRoot":"","sources":["../../../src/comment/api/getComments.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getComments.d.ts","sourceRoot":"","sources":["../../../src/comment/api/getComments.ts"],"names":[],"mappings":"AAUA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,WAAW;iBACV,aAAa,CAAC,WAAW,CAAC,EAAE,GACvC,QAAQ,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC,CAAC;IAmCzC;;;;;;;;;;;;OAYG;wBAEW,aAAa,CAAC,WAAW,CAAC,EAAE,GACvC,MAAM,MAAM,CAAC,aAAa,EAAE,CAAC,GAAG,SAAS;CAlB3C,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liveComments.d.ts","sourceRoot":"","sources":["../../../src/comment/observers/liveComments.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"liveComments.d.ts","sourceRoot":"","sources":["../../../src/comment/observers/liveComments.ts"],"names":[],"mappings":"AA+BA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,eAAO,MAAM,YAAY,WACf,MAAM,qBAAqB,YACzB,MAAM,sBAAsB,CAAC,aAAa,CAAC,WAC5C,MAAM,oBAAoB,KAClC,MAAM,YAyHR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liveCommunities.d.ts","sourceRoot":"","sources":["../../../src/community/observers/liveCommunities.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"liveCommunities.d.ts","sourceRoot":"","sources":["../../../src/community/observers/liveCommunities.ts"],"names":[],"mappings":"AA8BA;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,eAAe,WAClB,MAAM,uBAAuB,YAC3B,MAAM,sBAAsB,CAAC,MAAM,SAAS,CAAC,WAC9C,MAAM,oBAAoB,eA8IpC,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -95,8 +95,8 @@ const PostContentType = Object.freeze({
|
|
|
95
95
|
|
|
96
96
|
function getVersion() {
|
|
97
97
|
try {
|
|
98
|
-
// the string ''v0.0.1-beta.42.
|
|
99
|
-
return 'v0.0.1-beta.42.
|
|
98
|
+
// the string ''v0.0.1-beta.42.3-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
99
|
+
return 'v0.0.1-beta.42.3-cjs';
|
|
100
100
|
}
|
|
101
101
|
catch (error) {
|
|
102
102
|
return '__dev__';
|
|
@@ -104,11 +104,22 @@ function getVersion() {
|
|
|
104
104
|
}
|
|
105
105
|
const VERSION = getVersion();
|
|
106
106
|
|
|
107
|
+
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
108
|
+
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
109
|
+
const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
|
|
110
|
+
const LIVE_OBJECT_ENABLE_CACHE_MESSAGE = 'For using Live Object feature you need to enable Cache!';
|
|
111
|
+
const UNSYNCED_OBJECT_CACHED_AT_MESSAGE = 'Observing unsynced object is not supported by Live Object.';
|
|
112
|
+
const UNSYNCED_OBJECT_CACHED_AT_VALUE = -5;
|
|
113
|
+
const SECOND = 1000;
|
|
114
|
+
const MINUTE = 60 * SECOND;
|
|
115
|
+
const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
|
116
|
+
|
|
107
117
|
// cache constants
|
|
108
118
|
const CACHE_KEY_GET = 'get';
|
|
109
119
|
const CACHE_KEY_TOMBSTONE = 'dead';
|
|
110
|
-
const
|
|
111
|
-
const
|
|
120
|
+
const CACHE_SHORTEN_LIFESPAN = 2 * SECOND;
|
|
121
|
+
const CACHE_LIFESPAN = 1 * MINUTE; // 1 minute
|
|
122
|
+
const CACHE_LIFESPAN_TOMBSTONE = 3 * MINUTE; // 3 minutes
|
|
112
123
|
/**
|
|
113
124
|
* Shallow-clones an object and sort its keys
|
|
114
125
|
*
|
|
@@ -20381,15 +20392,6 @@ const getFeedSettings = async () => {
|
|
|
20381
20392
|
}));
|
|
20382
20393
|
};
|
|
20383
20394
|
|
|
20384
|
-
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
20385
|
-
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
20386
|
-
const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
|
|
20387
|
-
const LIVE_OBJECT_ENABLE_CACHE_MESSAGE = 'For using Live Object feature you need to enable Cache!';
|
|
20388
|
-
const UNSYNCED_OBJECT_CACHED_AT_MESSAGE = 'Observing unsynced object is not supported by Live Object.';
|
|
20389
|
-
const UNSYNCED_OBJECT_CACHED_AT_VALUE = -5;
|
|
20390
|
-
const MINUTE = 60 * 1000;
|
|
20391
|
-
const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
|
20392
|
-
|
|
20393
20395
|
// TODO: find a way to uniquely identify the device
|
|
20394
20396
|
/** @hidden */
|
|
20395
20397
|
const getDeviceId = () => {
|
|
@@ -22834,10 +22836,22 @@ const getPosts = async (postIds) => {
|
|
|
22834
22836
|
const client = getActiveClient();
|
|
22835
22837
|
client.log('post/getPosts', postIds);
|
|
22836
22838
|
const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
|
|
22837
|
-
|
|
22838
|
-
|
|
22839
|
-
|
|
22840
|
-
|
|
22839
|
+
let payload;
|
|
22840
|
+
try {
|
|
22841
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
22842
|
+
const response = await client.http.get(`/api/v3/posts/list`, {
|
|
22843
|
+
params: { postIds: encodedPostIds },
|
|
22844
|
+
});
|
|
22845
|
+
payload = response.data;
|
|
22846
|
+
}
|
|
22847
|
+
catch (error) {
|
|
22848
|
+
postIds.forEach(postId => {
|
|
22849
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
22850
|
+
pushToTombstone('post', postId);
|
|
22851
|
+
}
|
|
22852
|
+
});
|
|
22853
|
+
throw error;
|
|
22854
|
+
}
|
|
22841
22855
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
22842
22856
|
const cachedAt = client.cache && Date.now();
|
|
22843
22857
|
if (client.cache)
|
|
@@ -24012,10 +24026,22 @@ const getComments = async (commentIds) => {
|
|
|
24012
24026
|
const client = getActiveClient();
|
|
24013
24027
|
client.log('comment/getComments', commentIds);
|
|
24014
24028
|
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
24015
|
-
|
|
24016
|
-
|
|
24017
|
-
|
|
24018
|
-
|
|
24029
|
+
let data;
|
|
24030
|
+
try {
|
|
24031
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
24032
|
+
const response = await client.http.get(`/api/v3/comments/list`, {
|
|
24033
|
+
params: { commentIds: encodedCommentIds },
|
|
24034
|
+
});
|
|
24035
|
+
data = response.data;
|
|
24036
|
+
}
|
|
24037
|
+
catch (error) {
|
|
24038
|
+
commentIds.forEach(commentId => {
|
|
24039
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
24040
|
+
pushToTombstone('comment', commentId);
|
|
24041
|
+
}
|
|
24042
|
+
});
|
|
24043
|
+
throw error;
|
|
24044
|
+
}
|
|
24019
24045
|
const cachedAt = client.cache && Date.now();
|
|
24020
24046
|
if (client.cache)
|
|
24021
24047
|
ingestInCache(data, { cachedAt });
|
|
@@ -25441,7 +25467,7 @@ const queryChannels = async (query) => {
|
|
|
25441
25467
|
// safe decapsulation
|
|
25442
25468
|
const _a = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 }, displayName, membership } = _a, params = __rest(_a, ["page", "displayName", "membership"]);
|
|
25443
25469
|
// API-FIX: parameters should be querystring.
|
|
25444
|
-
// API-FIX: backend
|
|
25470
|
+
// API-FIX: backend doesn't answer Amity.Response
|
|
25445
25471
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<ChannelPayload>>>(
|
|
25446
25472
|
const { data: queryPayload } = await client.http.get(`/api/v3/channels`, {
|
|
25447
25473
|
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter: membership, options: {
|
|
@@ -25518,10 +25544,22 @@ const getChannels = async (channelIds) => {
|
|
|
25518
25544
|
const client = getActiveClient();
|
|
25519
25545
|
client.log('channel/getChannels', channelIds);
|
|
25520
25546
|
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
25521
|
-
|
|
25522
|
-
|
|
25523
|
-
|
|
25524
|
-
|
|
25547
|
+
let payload;
|
|
25548
|
+
try {
|
|
25549
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
25550
|
+
const response = await client.http.get(`/api/v3/channels/list`, {
|
|
25551
|
+
params: { channelIds: encodedChannelIds },
|
|
25552
|
+
});
|
|
25553
|
+
payload = response.data;
|
|
25554
|
+
}
|
|
25555
|
+
catch (error) {
|
|
25556
|
+
channelIds.forEach(channelId => {
|
|
25557
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
25558
|
+
pushToTombstone('channel', channelId);
|
|
25559
|
+
}
|
|
25560
|
+
});
|
|
25561
|
+
throw error;
|
|
25562
|
+
}
|
|
25525
25563
|
const data = prepareChannelPayload(payload);
|
|
25526
25564
|
const cachedAt = client.cache && Date.now();
|
|
25527
25565
|
if (client.cache)
|
|
@@ -26911,13 +26949,14 @@ const liveChannels = (params, callback, config) => {
|
|
|
26911
26949
|
}
|
|
26912
26950
|
pushToCache(cacheKey, data);
|
|
26913
26951
|
responder(data);
|
|
26914
|
-
}, queryOptions(policy));
|
|
26952
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
26915
26953
|
};
|
|
26916
26954
|
disposers.push(onChannelCreated(realtimeRouter()), onChannelDeleted(realtimeRouter()), onChannelUpdated(realtimeRouter()), onChannelMuted(realtimeRouter()), onChannelJoined(realtimeRouter()), onChannelLeft(realtimeRouter()), onChannelMemberAdded(realtimeRouter()), onChannelMemberRemoved(realtimeRouter()), onMessageCreated(() => null));
|
|
26917
26955
|
onFetch();
|
|
26918
26956
|
return () => {
|
|
26919
26957
|
log(`liveChannels(tmpid: ${timestamp}) > dispose`);
|
|
26920
26958
|
disposers.forEach(fn => fn());
|
|
26959
|
+
dropFromCache(cacheKey);
|
|
26921
26960
|
};
|
|
26922
26961
|
};
|
|
26923
26962
|
|
|
@@ -27561,7 +27600,7 @@ const liveSubChannels = (params, callback, config) => {
|
|
|
27561
27600
|
data: result ? merge(subChannels, result) : subChannels,
|
|
27562
27601
|
};
|
|
27563
27602
|
responder(snapshot);
|
|
27564
|
-
}, queryOptions(policy));
|
|
27603
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
27565
27604
|
};
|
|
27566
27605
|
disposers.push(onSubChannelCreated(realtimeRouter('onCreate')), onSubChannelDeleted(realtimeRouter('onDelete')), onSubChannelFetched(realtimeRouter('onFetch')), onSubChannelUpdated(realtimeRouter('onUpdate')));
|
|
27567
27606
|
onFetch();
|
|
@@ -27707,7 +27746,7 @@ const liveMessages = (params, callback, config) => {
|
|
|
27707
27746
|
}
|
|
27708
27747
|
pushToCache(cacheKey, data);
|
|
27709
27748
|
responder(data);
|
|
27710
|
-
}, queryOptions(policy));
|
|
27749
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
27711
27750
|
};
|
|
27712
27751
|
disposers.push(onMessageFetched(realtimeRouter()), onMessageCreated(realtimeRouter()), onMessageUpdated(realtimeRouter()), onMessageDeleted(realtimeRouter()), onMessageFlagged(realtimeRouter()), onMessageUnflagged(realtimeRouter()), onMessageFlagCleared(realtimeRouter()), onMessageReactionAdded(realtimeRouter()), onMessageReactionRemoved(realtimeRouter()));
|
|
27713
27752
|
onFetch();
|
|
@@ -28262,13 +28301,14 @@ const liveCommunities = (params, callback, config) => {
|
|
|
28262
28301
|
}
|
|
28263
28302
|
pushToCache(cacheKey, data);
|
|
28264
28303
|
responder(data);
|
|
28265
|
-
}, queryOptions(policy));
|
|
28304
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
28266
28305
|
};
|
|
28267
28306
|
disposers.push(onCommunityCreated(realtimeRouter()), onCommunityDeleted(realtimeRouter()), onCommunityUpdated(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityLeft(realtimeRouter()), onCommunityUserChanged(realtimeRouter()));
|
|
28268
28307
|
onFetch();
|
|
28269
28308
|
return () => {
|
|
28270
28309
|
log(`liveCommunities(tmpid: ${timestamp}) > dispose`);
|
|
28271
28310
|
disposers.forEach(fn => fn());
|
|
28311
|
+
dropFromCache(cacheKey);
|
|
28272
28312
|
};
|
|
28273
28313
|
};
|
|
28274
28314
|
|
|
@@ -29745,13 +29785,14 @@ const livePosts = (params, callback, config) => {
|
|
|
29745
29785
|
}
|
|
29746
29786
|
pushToCache(cacheKey, data);
|
|
29747
29787
|
responder(data);
|
|
29748
|
-
}, queryOptions(policy));
|
|
29788
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
29749
29789
|
};
|
|
29750
29790
|
disposers.push(onPostCreated(realtimeRouter('onCreate')), onPostApproved(realtimeRouter('onApproved')), onPostDeclined(realtimeRouter('onDeclined')), onPostDeleted(realtimeRouter('onDelete')), onPostUpdated(realtimeRouter('onUpdate')), onPostFlagged(realtimeRouter('onFlagged')), onPostUnflagged(realtimeRouter('onUnflagged')), onPostReactionAdded(realtimeRouter('onReactionAdded')), onPostReactionRemoved(realtimeRouter('onReactionRemoved')));
|
|
29751
29791
|
onFetch();
|
|
29752
29792
|
return () => {
|
|
29753
29793
|
log(`livePosts(tmpid: ${timestamp}) > dispose`);
|
|
29754
29794
|
disposers.forEach(fn => fn());
|
|
29795
|
+
dropFromCache(cacheKey);
|
|
29755
29796
|
};
|
|
29756
29797
|
};
|
|
29757
29798
|
|
|
@@ -29958,13 +29999,14 @@ const liveComments = (params, callback, config) => {
|
|
|
29958
29999
|
}
|
|
29959
30000
|
pushToCache(cacheKey, data);
|
|
29960
30001
|
responder(data);
|
|
29961
|
-
}, queryOptions(policy));
|
|
30002
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
29962
30003
|
};
|
|
29963
30004
|
disposers.push(onCommentCreated(realtimeRouter('onCreate')), onCommentUpdated(realtimeRouter('onUpdate')), onCommentDeleted(realtimeRouter('onDelete')), onCommentFlagged(realtimeRouter('onFlagged')), onCommentUnflagged(realtimeRouter('onUnflagged')), onCommentReactionAdded(realtimeRouter('onReactionAdded')), onCommentReactionRemoved(realtimeRouter('onReactionRemoved')));
|
|
29964
30005
|
onFetch();
|
|
29965
30006
|
return () => {
|
|
29966
30007
|
log(`liveComments(tmpid: ${timestamp}) > dispose`);
|
|
29967
30008
|
disposers.forEach(fn => fn());
|
|
30009
|
+
dropFromCache(cacheKey);
|
|
29968
30010
|
};
|
|
29969
30011
|
};
|
|
29970
30012
|
|
package/dist/index.esm.js
CHANGED
|
@@ -81,8 +81,8 @@ const PostContentType = Object.freeze({
|
|
|
81
81
|
|
|
82
82
|
function getVersion() {
|
|
83
83
|
try {
|
|
84
|
-
// the string ''v0.0.1-beta.42.
|
|
85
|
-
return 'v0.0.1-beta.42.
|
|
84
|
+
// the string ''v0.0.1-beta.42.3-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
85
|
+
return 'v0.0.1-beta.42.3-esm';
|
|
86
86
|
}
|
|
87
87
|
catch (error) {
|
|
88
88
|
return '__dev__';
|
|
@@ -90,11 +90,22 @@ function getVersion() {
|
|
|
90
90
|
}
|
|
91
91
|
const VERSION = getVersion();
|
|
92
92
|
|
|
93
|
+
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
94
|
+
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
95
|
+
const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
|
|
96
|
+
const LIVE_OBJECT_ENABLE_CACHE_MESSAGE = 'For using Live Object feature you need to enable Cache!';
|
|
97
|
+
const UNSYNCED_OBJECT_CACHED_AT_MESSAGE = 'Observing unsynced object is not supported by Live Object.';
|
|
98
|
+
const UNSYNCED_OBJECT_CACHED_AT_VALUE = -5;
|
|
99
|
+
const SECOND = 1000;
|
|
100
|
+
const MINUTE = 60 * SECOND;
|
|
101
|
+
const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
|
102
|
+
|
|
93
103
|
// cache constants
|
|
94
104
|
const CACHE_KEY_GET = 'get';
|
|
95
105
|
const CACHE_KEY_TOMBSTONE = 'dead';
|
|
96
|
-
const
|
|
97
|
-
const
|
|
106
|
+
const CACHE_SHORTEN_LIFESPAN = 2 * SECOND;
|
|
107
|
+
const CACHE_LIFESPAN = 1 * MINUTE; // 1 minute
|
|
108
|
+
const CACHE_LIFESPAN_TOMBSTONE = 3 * MINUTE; // 3 minutes
|
|
98
109
|
/**
|
|
99
110
|
* Shallow-clones an object and sort its keys
|
|
100
111
|
*
|
|
@@ -20367,15 +20378,6 @@ const getFeedSettings = async () => {
|
|
|
20367
20378
|
}));
|
|
20368
20379
|
};
|
|
20369
20380
|
|
|
20370
|
-
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
20371
|
-
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
20372
|
-
const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
|
|
20373
|
-
const LIVE_OBJECT_ENABLE_CACHE_MESSAGE = 'For using Live Object feature you need to enable Cache!';
|
|
20374
|
-
const UNSYNCED_OBJECT_CACHED_AT_MESSAGE = 'Observing unsynced object is not supported by Live Object.';
|
|
20375
|
-
const UNSYNCED_OBJECT_CACHED_AT_VALUE = -5;
|
|
20376
|
-
const MINUTE = 60 * 1000;
|
|
20377
|
-
const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
|
20378
|
-
|
|
20379
20381
|
// TODO: find a way to uniquely identify the device
|
|
20380
20382
|
/** @hidden */
|
|
20381
20383
|
const getDeviceId = () => {
|
|
@@ -22820,10 +22822,22 @@ const getPosts = async (postIds) => {
|
|
|
22820
22822
|
const client = getActiveClient();
|
|
22821
22823
|
client.log('post/getPosts', postIds);
|
|
22822
22824
|
const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
|
|
22823
|
-
|
|
22824
|
-
|
|
22825
|
-
|
|
22826
|
-
|
|
22825
|
+
let payload;
|
|
22826
|
+
try {
|
|
22827
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
22828
|
+
const response = await client.http.get(`/api/v3/posts/list`, {
|
|
22829
|
+
params: { postIds: encodedPostIds },
|
|
22830
|
+
});
|
|
22831
|
+
payload = response.data;
|
|
22832
|
+
}
|
|
22833
|
+
catch (error) {
|
|
22834
|
+
postIds.forEach(postId => {
|
|
22835
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
22836
|
+
pushToTombstone('post', postId);
|
|
22837
|
+
}
|
|
22838
|
+
});
|
|
22839
|
+
throw error;
|
|
22840
|
+
}
|
|
22827
22841
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
22828
22842
|
const cachedAt = client.cache && Date.now();
|
|
22829
22843
|
if (client.cache)
|
|
@@ -23998,10 +24012,22 @@ const getComments = async (commentIds) => {
|
|
|
23998
24012
|
const client = getActiveClient();
|
|
23999
24013
|
client.log('comment/getComments', commentIds);
|
|
24000
24014
|
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
24001
|
-
|
|
24002
|
-
|
|
24003
|
-
|
|
24004
|
-
|
|
24015
|
+
let data;
|
|
24016
|
+
try {
|
|
24017
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
24018
|
+
const response = await client.http.get(`/api/v3/comments/list`, {
|
|
24019
|
+
params: { commentIds: encodedCommentIds },
|
|
24020
|
+
});
|
|
24021
|
+
data = response.data;
|
|
24022
|
+
}
|
|
24023
|
+
catch (error) {
|
|
24024
|
+
commentIds.forEach(commentId => {
|
|
24025
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
24026
|
+
pushToTombstone('comment', commentId);
|
|
24027
|
+
}
|
|
24028
|
+
});
|
|
24029
|
+
throw error;
|
|
24030
|
+
}
|
|
24005
24031
|
const cachedAt = client.cache && Date.now();
|
|
24006
24032
|
if (client.cache)
|
|
24007
24033
|
ingestInCache(data, { cachedAt });
|
|
@@ -25427,7 +25453,7 @@ const queryChannels = async (query) => {
|
|
|
25427
25453
|
// safe decapsulation
|
|
25428
25454
|
const _a = query !== null && query !== void 0 ? query : {}, { page = { limit: 10 }, displayName, membership } = _a, params = __rest(_a, ["page", "displayName", "membership"]);
|
|
25429
25455
|
// API-FIX: parameters should be querystring.
|
|
25430
|
-
// API-FIX: backend
|
|
25456
|
+
// API-FIX: backend doesn't answer Amity.Response
|
|
25431
25457
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<ChannelPayload>>>(
|
|
25432
25458
|
const { data: queryPayload } = await client.http.get(`/api/v3/channels`, {
|
|
25433
25459
|
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter: membership, options: {
|
|
@@ -25504,10 +25530,22 @@ const getChannels = async (channelIds) => {
|
|
|
25504
25530
|
const client = getActiveClient();
|
|
25505
25531
|
client.log('channel/getChannels', channelIds);
|
|
25506
25532
|
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
25507
|
-
|
|
25508
|
-
|
|
25509
|
-
|
|
25510
|
-
|
|
25533
|
+
let payload;
|
|
25534
|
+
try {
|
|
25535
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
25536
|
+
const response = await client.http.get(`/api/v3/channels/list`, {
|
|
25537
|
+
params: { channelIds: encodedChannelIds },
|
|
25538
|
+
});
|
|
25539
|
+
payload = response.data;
|
|
25540
|
+
}
|
|
25541
|
+
catch (error) {
|
|
25542
|
+
channelIds.forEach(channelId => {
|
|
25543
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
25544
|
+
pushToTombstone('channel', channelId);
|
|
25545
|
+
}
|
|
25546
|
+
});
|
|
25547
|
+
throw error;
|
|
25548
|
+
}
|
|
25511
25549
|
const data = prepareChannelPayload(payload);
|
|
25512
25550
|
const cachedAt = client.cache && Date.now();
|
|
25513
25551
|
if (client.cache)
|
|
@@ -26897,13 +26935,14 @@ const liveChannels = (params, callback, config) => {
|
|
|
26897
26935
|
}
|
|
26898
26936
|
pushToCache(cacheKey, data);
|
|
26899
26937
|
responder(data);
|
|
26900
|
-
}, queryOptions(policy));
|
|
26938
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
26901
26939
|
};
|
|
26902
26940
|
disposers.push(onChannelCreated(realtimeRouter()), onChannelDeleted(realtimeRouter()), onChannelUpdated(realtimeRouter()), onChannelMuted(realtimeRouter()), onChannelJoined(realtimeRouter()), onChannelLeft(realtimeRouter()), onChannelMemberAdded(realtimeRouter()), onChannelMemberRemoved(realtimeRouter()), onMessageCreated(() => null));
|
|
26903
26941
|
onFetch();
|
|
26904
26942
|
return () => {
|
|
26905
26943
|
log(`liveChannels(tmpid: ${timestamp}) > dispose`);
|
|
26906
26944
|
disposers.forEach(fn => fn());
|
|
26945
|
+
dropFromCache(cacheKey);
|
|
26907
26946
|
};
|
|
26908
26947
|
};
|
|
26909
26948
|
|
|
@@ -27547,7 +27586,7 @@ const liveSubChannels = (params, callback, config) => {
|
|
|
27547
27586
|
data: result ? merge(subChannels, result) : subChannels,
|
|
27548
27587
|
};
|
|
27549
27588
|
responder(snapshot);
|
|
27550
|
-
}, queryOptions(policy));
|
|
27589
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
27551
27590
|
};
|
|
27552
27591
|
disposers.push(onSubChannelCreated(realtimeRouter('onCreate')), onSubChannelDeleted(realtimeRouter('onDelete')), onSubChannelFetched(realtimeRouter('onFetch')), onSubChannelUpdated(realtimeRouter('onUpdate')));
|
|
27553
27592
|
onFetch();
|
|
@@ -27693,7 +27732,7 @@ const liveMessages = (params, callback, config) => {
|
|
|
27693
27732
|
}
|
|
27694
27733
|
pushToCache(cacheKey, data);
|
|
27695
27734
|
responder(data);
|
|
27696
|
-
}, queryOptions(policy));
|
|
27735
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
27697
27736
|
};
|
|
27698
27737
|
disposers.push(onMessageFetched(realtimeRouter()), onMessageCreated(realtimeRouter()), onMessageUpdated(realtimeRouter()), onMessageDeleted(realtimeRouter()), onMessageFlagged(realtimeRouter()), onMessageUnflagged(realtimeRouter()), onMessageFlagCleared(realtimeRouter()), onMessageReactionAdded(realtimeRouter()), onMessageReactionRemoved(realtimeRouter()));
|
|
27699
27738
|
onFetch();
|
|
@@ -28248,13 +28287,14 @@ const liveCommunities = (params, callback, config) => {
|
|
|
28248
28287
|
}
|
|
28249
28288
|
pushToCache(cacheKey, data);
|
|
28250
28289
|
responder(data);
|
|
28251
|
-
}, queryOptions(policy));
|
|
28290
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
28252
28291
|
};
|
|
28253
28292
|
disposers.push(onCommunityCreated(realtimeRouter()), onCommunityDeleted(realtimeRouter()), onCommunityUpdated(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityLeft(realtimeRouter()), onCommunityUserChanged(realtimeRouter()));
|
|
28254
28293
|
onFetch();
|
|
28255
28294
|
return () => {
|
|
28256
28295
|
log(`liveCommunities(tmpid: ${timestamp}) > dispose`);
|
|
28257
28296
|
disposers.forEach(fn => fn());
|
|
28297
|
+
dropFromCache(cacheKey);
|
|
28258
28298
|
};
|
|
28259
28299
|
};
|
|
28260
28300
|
|
|
@@ -29731,13 +29771,14 @@ const livePosts = (params, callback, config) => {
|
|
|
29731
29771
|
}
|
|
29732
29772
|
pushToCache(cacheKey, data);
|
|
29733
29773
|
responder(data);
|
|
29734
|
-
}, queryOptions(policy));
|
|
29774
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
29735
29775
|
};
|
|
29736
29776
|
disposers.push(onPostCreated(realtimeRouter('onCreate')), onPostApproved(realtimeRouter('onApproved')), onPostDeclined(realtimeRouter('onDeclined')), onPostDeleted(realtimeRouter('onDelete')), onPostUpdated(realtimeRouter('onUpdate')), onPostFlagged(realtimeRouter('onFlagged')), onPostUnflagged(realtimeRouter('onUnflagged')), onPostReactionAdded(realtimeRouter('onReactionAdded')), onPostReactionRemoved(realtimeRouter('onReactionRemoved')));
|
|
29737
29777
|
onFetch();
|
|
29738
29778
|
return () => {
|
|
29739
29779
|
log(`livePosts(tmpid: ${timestamp}) > dispose`);
|
|
29740
29780
|
disposers.forEach(fn => fn());
|
|
29781
|
+
dropFromCache(cacheKey);
|
|
29741
29782
|
};
|
|
29742
29783
|
};
|
|
29743
29784
|
|
|
@@ -29944,13 +29985,14 @@ const liveComments = (params, callback, config) => {
|
|
|
29944
29985
|
}
|
|
29945
29986
|
pushToCache(cacheKey, data);
|
|
29946
29987
|
responder(data);
|
|
29947
|
-
}, queryOptions(policy));
|
|
29988
|
+
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
29948
29989
|
};
|
|
29949
29990
|
disposers.push(onCommentCreated(realtimeRouter('onCreate')), onCommentUpdated(realtimeRouter('onUpdate')), onCommentDeleted(realtimeRouter('onDelete')), onCommentFlagged(realtimeRouter('onFlagged')), onCommentUnflagged(realtimeRouter('onUnflagged')), onCommentReactionAdded(realtimeRouter('onReactionAdded')), onCommentReactionRemoved(realtimeRouter('onReactionRemoved')));
|
|
29950
29991
|
onFetch();
|
|
29951
29992
|
return () => {
|
|
29952
29993
|
log(`liveComments(tmpid: ${timestamp}) > dispose`);
|
|
29953
29994
|
disposers.forEach(fn => fn());
|
|
29995
|
+
dropFromCache(cacheKey);
|
|
29954
29996
|
};
|
|
29955
29997
|
};
|
|
29956
29998
|
|