@amityco/ts-sdk 0.0.1-beta.13 → 0.0.1-beta.14
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/core/cache.d.ts +2 -2
- package/dist/@types/core/cache.d.ts.map +1 -1
- package/dist/@types/core/paging.d.ts +19 -38
- package/dist/@types/core/paging.d.ts.map +1 -1
- package/dist/@types/core/query.d.ts +12 -4
- package/dist/@types/core/query.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +1 -2
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/mention.d.ts +23 -0
- package/dist/@types/domains/mention.d.ts.map +1 -0
- package/dist/@types/domains/message.d.ts +1 -1
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/partials.d.ts +0 -10
- package/dist/@types/domains/partials.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +1 -2
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/category/api/queryCategories.d.ts +3 -3
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/queryChannels.d.ts +1 -1
- package/dist/community/api/queryCommunities.d.ts +1 -1
- package/dist/core/debug.d.ts.map +1 -1
- package/dist/core/device.d.ts.map +1 -1
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/microtasks.d.ts +13 -0
- package/dist/core/microtasks.d.ts.map +1 -0
- package/dist/core/query/paging.d.ts +2 -13
- package/dist/core/query/paging.d.ts.map +1 -1
- package/dist/core/query/query.d.ts +1 -1
- package/dist/core/query/query.d.ts.map +1 -1
- package/dist/feed/api/queryGlobalFeed.d.ts +22 -4
- package/dist/feed/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/index.cjs.js +78 -51
- package/dist/index.esm.js +79 -51
- package/dist/index.umd.js +5 -5
- package/dist/message/api/createMessage.d.ts +2 -2
- package/dist/message/api/createMessage.d.ts.map +1 -1
- package/dist/message/api/updateMessage.d.ts +2 -2
- package/dist/message/api/updateMessage.d.ts.map +1 -1
- package/dist/post/api/queryPosts.d.ts +3 -3
- package/dist/post/api/queryPosts.d.ts.map +1 -1
- package/dist/role/api/queryRoles.d.ts +1 -1
- package/dist/stream/api/queryStreams.d.ts +1 -1
- package/dist/utils/env.d.ts +5 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/cache.ts +2 -2
- package/src/@types/core/paging.ts +29 -44
- package/src/@types/core/query.ts +7 -3
- package/src/@types/domains/comment.ts +1 -3
- package/src/@types/domains/mention.ts +26 -0
- package/src/@types/domains/message.ts +1 -0
- package/src/@types/domains/partials.ts +0 -8
- package/src/@types/domains/post.ts +1 -3
- package/src/@types/index.ts +2 -0
- package/src/channel/api/queryChannelMembers.ts +2 -1
- package/src/community/api/queryCommunityMembers.ts +1 -1
- package/src/core/debug.ts +3 -1
- package/src/core/device.ts +3 -2
- package/src/core/events.ts +3 -1
- package/src/core/microtasks.ts +27 -0
- package/src/core/query/paging.ts +6 -41
- package/src/core/query/query.ts +5 -5
- package/src/feed/api/queryGlobalFeed.ts +58 -5
- package/src/message/api/createMessage.ts +2 -2
- package/src/message/api/updateMessage.ts +2 -2
- package/src/post/api/queryPosts.ts +5 -5
- package/src/utils/env.ts +7 -0
- package/src/version.ts +3 -1
package/dist/index.cjs.js
CHANGED
|
@@ -19,11 +19,14 @@ var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
|
|
|
19
19
|
var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt);
|
|
20
20
|
var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
|
|
21
21
|
|
|
22
|
-
var _a;
|
|
23
|
-
|
|
24
|
-
const
|
|
22
|
+
var _a$1;
|
|
23
|
+
const theGlobal = globalThis || global || window;
|
|
24
|
+
const { process: safeProcess = {} } = theGlobal;
|
|
25
|
+
const isProduction = ((_a$1 = safeProcess.env) === null || _a$1 === void 0 ? void 0 : _a$1.NODE_ENV) === 'production';
|
|
26
|
+
|
|
27
|
+
var _a, _b;
|
|
28
|
+
const VERSION$1 = (_b = (_a = safeProcess.env) === null || _a === void 0 ? void 0 : _a.VERSION) !== null && _b !== void 0 ? _b : '__dev__';
|
|
25
29
|
|
|
26
|
-
// @ts-ignore
|
|
27
30
|
/**
|
|
28
31
|
* Type guard to find if the a given decoded backend token uses "skip/limit" pagination style
|
|
29
32
|
*
|
|
@@ -41,7 +44,7 @@ const isSkipLimit = (json) => (['skip', 'limit'].some(prop => prop in json));
|
|
|
41
44
|
*
|
|
42
45
|
* @hidden
|
|
43
46
|
*/
|
|
44
|
-
const isAfterBefore = (json) => (['after', 'before', 'first', 'last'].some(prop => prop in json));
|
|
47
|
+
const isAfterBefore = (json) => (['after', 'before', 'first', 'last', 'limit'].some(prop => prop in json));
|
|
45
48
|
/**
|
|
46
49
|
* Type guard to find if the a given decoded backend token uses v4 or newer "after/before" pagination style
|
|
47
50
|
*
|
|
@@ -50,7 +53,7 @@ const isAfterBefore = (json) => (['after', 'before', 'first', 'last'].some(prop
|
|
|
50
53
|
*
|
|
51
54
|
* @hidden
|
|
52
55
|
*/
|
|
53
|
-
const isAfterBeforeRaw = (json) => (
|
|
56
|
+
const isAfterBeforeRaw = (json) => ('limit' in json);
|
|
54
57
|
/**
|
|
55
58
|
* Type guard to find if the a given object is wrapped around Amity.Paged<>
|
|
56
59
|
*
|
|
@@ -85,7 +88,7 @@ const toToken = (paging, style) => {
|
|
|
85
88
|
limit: paging.limit,
|
|
86
89
|
};
|
|
87
90
|
}
|
|
88
|
-
else if (style === 'afterbefore') {
|
|
91
|
+
else if (style === 'afterbefore' && isAfterBefore(paging)) {
|
|
89
92
|
/*
|
|
90
93
|
Caution: this testing style is only valid because
|
|
91
94
|
our backend expects nothing else than a number as
|
|
@@ -171,35 +174,6 @@ const toPageRaw = (token) => {
|
|
|
171
174
|
return json;
|
|
172
175
|
}
|
|
173
176
|
return null;
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* Slices a collection according to its paging
|
|
177
|
-
*
|
|
178
|
-
* @param type the type of collection (for unique id identification with after/before)
|
|
179
|
-
* @param collection the collection to slice
|
|
180
|
-
* @param paging the paging object
|
|
181
|
-
* @returns the sliced collection according to the paging definition
|
|
182
|
-
*
|
|
183
|
-
* @hidden
|
|
184
|
-
*/
|
|
185
|
-
const sliceByPaging = (type, collection, page) => {
|
|
186
|
-
console.log('slice by paging', page);
|
|
187
|
-
if (!page)
|
|
188
|
-
return collection.slice();
|
|
189
|
-
let start = 0;
|
|
190
|
-
let end = undefined;
|
|
191
|
-
// next page behavior
|
|
192
|
-
if (page.after) {
|
|
193
|
-
start = page.after;
|
|
194
|
-
end = start + page.limit;
|
|
195
|
-
// prev page behavior
|
|
196
|
-
}
|
|
197
|
-
else if (page.before) {
|
|
198
|
-
end = page.before + 1;
|
|
199
|
-
start = end > page.limit ? end - page.limit : 0;
|
|
200
|
-
}
|
|
201
|
-
const paged = collection.slice(start, end);
|
|
202
|
-
return paged.length === page.limit ? paged : undefined;
|
|
203
177
|
};
|
|
204
178
|
|
|
205
179
|
/**
|
|
@@ -512,9 +486,8 @@ const setActiveClient = (client) => {
|
|
|
512
486
|
* @hidden
|
|
513
487
|
*/
|
|
514
488
|
const createLogger = (session) => {
|
|
515
|
-
var _a;
|
|
516
489
|
const active = (`${session === null || session === void 0 ? void 0 : session.trim()}`.length > 0
|
|
517
|
-
&&
|
|
490
|
+
&& !isProduction);
|
|
518
491
|
const logger = debug__default['default'](session);
|
|
519
492
|
const print = (topic, ...args) => {
|
|
520
493
|
active && logger(topic, args);
|
|
@@ -14741,6 +14714,22 @@ const createMqttTransport = (endpoint) => {
|
|
|
14741
14714
|
};
|
|
14742
14715
|
};
|
|
14743
14716
|
|
|
14717
|
+
let tasks = [];
|
|
14718
|
+
let timer;
|
|
14719
|
+
/**
|
|
14720
|
+
* Add a function to run just before the next tick
|
|
14721
|
+
*
|
|
14722
|
+
* @param task function to schedule for later execution
|
|
14723
|
+
*/
|
|
14724
|
+
const scheduleTask = (task) => {
|
|
14725
|
+
clearTimeout(timer);
|
|
14726
|
+
tasks.push(task);
|
|
14727
|
+
timer = setTimeout(() => {
|
|
14728
|
+
tasks.forEach(fn => fn());
|
|
14729
|
+
tasks = [];
|
|
14730
|
+
}, 0);
|
|
14731
|
+
};
|
|
14732
|
+
|
|
14744
14733
|
// need to sync up the list
|
|
14745
14734
|
const WS_EVENTS = [
|
|
14746
14735
|
'disconnected',
|
|
@@ -14831,7 +14820,7 @@ const createEventSubscriber = (client, namespace, event, fn) => {
|
|
|
14831
14820
|
*/
|
|
14832
14821
|
const fireEvent = (event, payload) => {
|
|
14833
14822
|
const { emitter } = getActiveClient();
|
|
14834
|
-
|
|
14823
|
+
scheduleTask(() => { emitter.emit(event, payload); });
|
|
14835
14824
|
};
|
|
14836
14825
|
|
|
14837
14826
|
/**
|
|
@@ -14910,7 +14899,6 @@ const disconnectClient = async () => {
|
|
|
14910
14899
|
};
|
|
14911
14900
|
|
|
14912
14901
|
// TODO: find a way to uniquely identify the device
|
|
14913
|
-
// import { getStorage } from './storage'
|
|
14914
14902
|
/** @hidden */
|
|
14915
14903
|
const VERSION = '11.0.0';
|
|
14916
14904
|
/** @hidden */
|
|
@@ -14925,8 +14913,8 @@ const getDeviceId = () => {
|
|
|
14925
14913
|
/** @hidden */
|
|
14926
14914
|
const getDeviceModel = () => {
|
|
14927
14915
|
var _a, _b;
|
|
14928
|
-
if ((_a =
|
|
14929
|
-
return
|
|
14916
|
+
if ((_a = safeProcess.versions) === null || _a === void 0 ? void 0 : _a.node)
|
|
14917
|
+
return safeProcess.versions.node;
|
|
14930
14918
|
if (navigator)
|
|
14931
14919
|
return `${navigator.product.toLowerCase()}#${(_b = navigator.userAgent) !== null && _b !== void 0 ? _b : 'unknown_agent'}`;
|
|
14932
14920
|
return 'unknown_model';
|
|
@@ -16649,11 +16637,11 @@ const queryPosts = async (query) => {
|
|
|
16649
16637
|
const { page = { limit: 10 } } = query, params = __rest(query
|
|
16650
16638
|
// API-FIX: parameters should be querystring. (1)
|
|
16651
16639
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16652
|
-
// const { data } = await client.http.get<Amity.Response<Amity.
|
|
16640
|
+
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16653
16641
|
, ["page"]);
|
|
16654
16642
|
// API-FIX: parameters should be querystring. (1)
|
|
16655
16643
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16656
|
-
// const { data } = await client.http.get<Amity.Response<Amity.
|
|
16644
|
+
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16657
16645
|
const { data } = await client.http.get(`/api/v4/posts`, { params: Object.assign(Object.assign({}, params), { options: {
|
|
16658
16646
|
token: toToken(page, 'afterbeforeraw'),
|
|
16659
16647
|
} }), });
|
|
@@ -17240,7 +17228,7 @@ const queryCommunityMembers = async (query) => {
|
|
|
17240
17228
|
}
|
|
17241
17229
|
const nextPage = toPage(paging.next);
|
|
17242
17230
|
const prevPage = toPage(paging.previous);
|
|
17243
|
-
return { data: communityUsers, nextPage, prevPage };
|
|
17231
|
+
return { data: communityUsers, cachedAt, nextPage, prevPage };
|
|
17244
17232
|
};
|
|
17245
17233
|
/**
|
|
17246
17234
|
* ```js
|
|
@@ -18758,12 +18746,13 @@ const queryChannelMembers = async (query) => {
|
|
|
18758
18746
|
});
|
|
18759
18747
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
18760
18748
|
const { channelUsers } = payload;
|
|
18749
|
+
const cachedAt = client.cache && Date.now();
|
|
18761
18750
|
if (client.cache) {
|
|
18762
18751
|
ingestInCache(payload);
|
|
18763
18752
|
}
|
|
18764
18753
|
const nextPage = toPage(paging.next);
|
|
18765
18754
|
const prevPage = toPage(paging.previous);
|
|
18766
|
-
return { data: channelUsers, nextPage, prevPage };
|
|
18755
|
+
return { data: channelUsers, cachedAt, nextPage, prevPage };
|
|
18767
18756
|
};
|
|
18768
18757
|
/**
|
|
18769
18758
|
* ```js
|
|
@@ -19508,17 +19497,56 @@ const observeCommunity = (communityId, callback) => {
|
|
|
19508
19497
|
const queryGlobalFeed = async (query) => {
|
|
19509
19498
|
const client = getActiveClient();
|
|
19510
19499
|
client.log('feed/queryGlobalFeed', query);
|
|
19511
|
-
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
19512
|
-
const { data } = await client.http.get(`/api/v4/me/global-feeds`, { params: Object.assign(Object.assign({}, params), { options: {
|
|
19500
|
+
const _a = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _a, params = __rest(_a, ["useCustomRanking", "page"]);
|
|
19501
|
+
const { data } = await client.http.get(useCustomRanking ? `/api/v5/me/global-feeds` : `/api/v4/me/global-feeds`, { params: Object.assign(Object.assign({}, params), { options: {
|
|
19513
19502
|
token: toToken(page, 'skiplimit')
|
|
19514
19503
|
} }) });
|
|
19515
19504
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19516
19505
|
const { posts } = payload;
|
|
19517
|
-
|
|
19506
|
+
const cachedAt = client.cache && Date.now();
|
|
19507
|
+
if (client.cache) {
|
|
19518
19508
|
ingestInCache(payload);
|
|
19509
|
+
const cacheKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) })];
|
|
19510
|
+
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
19511
|
+
}
|
|
19519
19512
|
const nextPage = toPage(paging.next);
|
|
19520
19513
|
const prevPage = toPage(paging.previous);
|
|
19521
|
-
return { data: posts, prevPage, nextPage };
|
|
19514
|
+
return { data: posts, cachedAt, prevPage, nextPage };
|
|
19515
|
+
};
|
|
19516
|
+
/**
|
|
19517
|
+
* ```js
|
|
19518
|
+
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
19519
|
+
* const posts = await queryGlobalFeed.locally()
|
|
19520
|
+
* ```
|
|
19521
|
+
*
|
|
19522
|
+
* Queries a paginable list of {@link Amity.Post} objects from cache
|
|
19523
|
+
*
|
|
19524
|
+
* @param query The query parameters
|
|
19525
|
+
* @returns A page of {@link Amity.Post} objects
|
|
19526
|
+
*
|
|
19527
|
+
* @category Feed API
|
|
19528
|
+
* @async
|
|
19529
|
+
**/
|
|
19530
|
+
queryGlobalFeed.locally = (query) => {
|
|
19531
|
+
var _a, _b;
|
|
19532
|
+
const client = getActiveClient();
|
|
19533
|
+
client.log('post/queryGlobalFeed.locally', query);
|
|
19534
|
+
if (!client.cache)
|
|
19535
|
+
return;
|
|
19536
|
+
const _c = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _c, params = __rest(_c, ["useCustomRanking", "page"]);
|
|
19537
|
+
const queryKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) })];
|
|
19538
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19539
|
+
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
19540
|
+
return;
|
|
19541
|
+
const posts = data.posts
|
|
19542
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
19543
|
+
.filter(Boolean)
|
|
19544
|
+
.map(({ data }) => data);
|
|
19545
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19546
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19547
|
+
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
19548
|
+
? { data: posts, cachedAt, prevPage, nextPage }
|
|
19549
|
+
: undefined;
|
|
19522
19550
|
};
|
|
19523
19551
|
|
|
19524
19552
|
/**
|
|
@@ -20126,7 +20154,6 @@ exports.removeCommunityMembersRole = removeCommunityMembersRole;
|
|
|
20126
20154
|
exports.removeReaction = removeReaction;
|
|
20127
20155
|
exports.restoreCache = restoreCache;
|
|
20128
20156
|
exports.runQuery = runQuery;
|
|
20129
|
-
exports.sliceByPaging = sliceByPaging;
|
|
20130
20157
|
exports.sortByChannelSegment = sortByChannelSegment;
|
|
20131
20158
|
exports.sortByDisplayName = sortByDisplayName;
|
|
20132
20159
|
exports.sortByFirstCreated = sortByFirstCreated;
|
package/dist/index.esm.js
CHANGED
|
@@ -6,11 +6,14 @@ import io from 'socket.io-client';
|
|
|
6
6
|
import mitt from 'mitt';
|
|
7
7
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
8
8
|
|
|
9
|
-
var _a;
|
|
10
|
-
|
|
11
|
-
const
|
|
9
|
+
var _a$1;
|
|
10
|
+
const theGlobal = globalThis || global || window;
|
|
11
|
+
const { process: safeProcess = {} } = theGlobal;
|
|
12
|
+
const isProduction = ((_a$1 = safeProcess.env) === null || _a$1 === void 0 ? void 0 : _a$1.NODE_ENV) === 'production';
|
|
13
|
+
|
|
14
|
+
var _a, _b;
|
|
15
|
+
const VERSION$1 = (_b = (_a = safeProcess.env) === null || _a === void 0 ? void 0 : _a.VERSION) !== null && _b !== void 0 ? _b : '__dev__';
|
|
12
16
|
|
|
13
|
-
// @ts-ignore
|
|
14
17
|
/**
|
|
15
18
|
* Type guard to find if the a given decoded backend token uses "skip/limit" pagination style
|
|
16
19
|
*
|
|
@@ -28,7 +31,7 @@ const isSkipLimit = (json) => (['skip', 'limit'].some(prop => prop in json));
|
|
|
28
31
|
*
|
|
29
32
|
* @hidden
|
|
30
33
|
*/
|
|
31
|
-
const isAfterBefore = (json) => (['after', 'before', 'first', 'last'].some(prop => prop in json));
|
|
34
|
+
const isAfterBefore = (json) => (['after', 'before', 'first', 'last', 'limit'].some(prop => prop in json));
|
|
32
35
|
/**
|
|
33
36
|
* Type guard to find if the a given decoded backend token uses v4 or newer "after/before" pagination style
|
|
34
37
|
*
|
|
@@ -37,7 +40,7 @@ const isAfterBefore = (json) => (['after', 'before', 'first', 'last'].some(prop
|
|
|
37
40
|
*
|
|
38
41
|
* @hidden
|
|
39
42
|
*/
|
|
40
|
-
const isAfterBeforeRaw = (json) => (
|
|
43
|
+
const isAfterBeforeRaw = (json) => ('limit' in json);
|
|
41
44
|
/**
|
|
42
45
|
* Type guard to find if the a given object is wrapped around Amity.Paged<>
|
|
43
46
|
*
|
|
@@ -72,7 +75,7 @@ const toToken = (paging, style) => {
|
|
|
72
75
|
limit: paging.limit,
|
|
73
76
|
};
|
|
74
77
|
}
|
|
75
|
-
else if (style === 'afterbefore') {
|
|
78
|
+
else if (style === 'afterbefore' && isAfterBefore(paging)) {
|
|
76
79
|
/*
|
|
77
80
|
Caution: this testing style is only valid because
|
|
78
81
|
our backend expects nothing else than a number as
|
|
@@ -158,35 +161,6 @@ const toPageRaw = (token) => {
|
|
|
158
161
|
return json;
|
|
159
162
|
}
|
|
160
163
|
return null;
|
|
161
|
-
};
|
|
162
|
-
/**
|
|
163
|
-
* Slices a collection according to its paging
|
|
164
|
-
*
|
|
165
|
-
* @param type the type of collection (for unique id identification with after/before)
|
|
166
|
-
* @param collection the collection to slice
|
|
167
|
-
* @param paging the paging object
|
|
168
|
-
* @returns the sliced collection according to the paging definition
|
|
169
|
-
*
|
|
170
|
-
* @hidden
|
|
171
|
-
*/
|
|
172
|
-
const sliceByPaging = (type, collection, page) => {
|
|
173
|
-
console.log('slice by paging', page);
|
|
174
|
-
if (!page)
|
|
175
|
-
return collection.slice();
|
|
176
|
-
let start = 0;
|
|
177
|
-
let end = undefined;
|
|
178
|
-
// next page behavior
|
|
179
|
-
if (page.after) {
|
|
180
|
-
start = page.after;
|
|
181
|
-
end = start + page.limit;
|
|
182
|
-
// prev page behavior
|
|
183
|
-
}
|
|
184
|
-
else if (page.before) {
|
|
185
|
-
end = page.before + 1;
|
|
186
|
-
start = end > page.limit ? end - page.limit : 0;
|
|
187
|
-
}
|
|
188
|
-
const paged = collection.slice(start, end);
|
|
189
|
-
return paged.length === page.limit ? paged : undefined;
|
|
190
164
|
};
|
|
191
165
|
|
|
192
166
|
/**
|
|
@@ -499,9 +473,8 @@ const setActiveClient = (client) => {
|
|
|
499
473
|
* @hidden
|
|
500
474
|
*/
|
|
501
475
|
const createLogger = (session) => {
|
|
502
|
-
var _a;
|
|
503
476
|
const active = (`${session === null || session === void 0 ? void 0 : session.trim()}`.length > 0
|
|
504
|
-
&&
|
|
477
|
+
&& !isProduction);
|
|
505
478
|
const logger = debug(session);
|
|
506
479
|
const print = (topic, ...args) => {
|
|
507
480
|
active && logger(topic, args);
|
|
@@ -14728,6 +14701,22 @@ const createMqttTransport = (endpoint) => {
|
|
|
14728
14701
|
};
|
|
14729
14702
|
};
|
|
14730
14703
|
|
|
14704
|
+
let tasks = [];
|
|
14705
|
+
let timer;
|
|
14706
|
+
/**
|
|
14707
|
+
* Add a function to run just before the next tick
|
|
14708
|
+
*
|
|
14709
|
+
* @param task function to schedule for later execution
|
|
14710
|
+
*/
|
|
14711
|
+
const scheduleTask = (task) => {
|
|
14712
|
+
clearTimeout(timer);
|
|
14713
|
+
tasks.push(task);
|
|
14714
|
+
timer = setTimeout(() => {
|
|
14715
|
+
tasks.forEach(fn => fn());
|
|
14716
|
+
tasks = [];
|
|
14717
|
+
}, 0);
|
|
14718
|
+
};
|
|
14719
|
+
|
|
14731
14720
|
// need to sync up the list
|
|
14732
14721
|
const WS_EVENTS = [
|
|
14733
14722
|
'disconnected',
|
|
@@ -14818,7 +14807,7 @@ const createEventSubscriber = (client, namespace, event, fn) => {
|
|
|
14818
14807
|
*/
|
|
14819
14808
|
const fireEvent = (event, payload) => {
|
|
14820
14809
|
const { emitter } = getActiveClient();
|
|
14821
|
-
|
|
14810
|
+
scheduleTask(() => { emitter.emit(event, payload); });
|
|
14822
14811
|
};
|
|
14823
14812
|
|
|
14824
14813
|
/**
|
|
@@ -14897,7 +14886,6 @@ const disconnectClient = async () => {
|
|
|
14897
14886
|
};
|
|
14898
14887
|
|
|
14899
14888
|
// TODO: find a way to uniquely identify the device
|
|
14900
|
-
// import { getStorage } from './storage'
|
|
14901
14889
|
/** @hidden */
|
|
14902
14890
|
const VERSION = '11.0.0';
|
|
14903
14891
|
/** @hidden */
|
|
@@ -14912,8 +14900,8 @@ const getDeviceId = () => {
|
|
|
14912
14900
|
/** @hidden */
|
|
14913
14901
|
const getDeviceModel = () => {
|
|
14914
14902
|
var _a, _b;
|
|
14915
|
-
if ((_a =
|
|
14916
|
-
return
|
|
14903
|
+
if ((_a = safeProcess.versions) === null || _a === void 0 ? void 0 : _a.node)
|
|
14904
|
+
return safeProcess.versions.node;
|
|
14917
14905
|
if (navigator)
|
|
14918
14906
|
return `${navigator.product.toLowerCase()}#${(_b = navigator.userAgent) !== null && _b !== void 0 ? _b : 'unknown_agent'}`;
|
|
14919
14907
|
return 'unknown_model';
|
|
@@ -16636,11 +16624,11 @@ const queryPosts = async (query) => {
|
|
|
16636
16624
|
const { page = { limit: 10 } } = query, params = __rest(query
|
|
16637
16625
|
// API-FIX: parameters should be querystring. (1)
|
|
16638
16626
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16639
|
-
// const { data } = await client.http.get<Amity.Response<Amity.
|
|
16627
|
+
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16640
16628
|
, ["page"]);
|
|
16641
16629
|
// API-FIX: parameters should be querystring. (1)
|
|
16642
16630
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16643
|
-
// const { data } = await client.http.get<Amity.Response<Amity.
|
|
16631
|
+
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16644
16632
|
const { data } = await client.http.get(`/api/v4/posts`, { params: Object.assign(Object.assign({}, params), { options: {
|
|
16645
16633
|
token: toToken(page, 'afterbeforeraw'),
|
|
16646
16634
|
} }), });
|
|
@@ -17227,7 +17215,7 @@ const queryCommunityMembers = async (query) => {
|
|
|
17227
17215
|
}
|
|
17228
17216
|
const nextPage = toPage(paging.next);
|
|
17229
17217
|
const prevPage = toPage(paging.previous);
|
|
17230
|
-
return { data: communityUsers, nextPage, prevPage };
|
|
17218
|
+
return { data: communityUsers, cachedAt, nextPage, prevPage };
|
|
17231
17219
|
};
|
|
17232
17220
|
/**
|
|
17233
17221
|
* ```js
|
|
@@ -18745,12 +18733,13 @@ const queryChannelMembers = async (query) => {
|
|
|
18745
18733
|
});
|
|
18746
18734
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
18747
18735
|
const { channelUsers } = payload;
|
|
18736
|
+
const cachedAt = client.cache && Date.now();
|
|
18748
18737
|
if (client.cache) {
|
|
18749
18738
|
ingestInCache(payload);
|
|
18750
18739
|
}
|
|
18751
18740
|
const nextPage = toPage(paging.next);
|
|
18752
18741
|
const prevPage = toPage(paging.previous);
|
|
18753
|
-
return { data: channelUsers, nextPage, prevPage };
|
|
18742
|
+
return { data: channelUsers, cachedAt, nextPage, prevPage };
|
|
18754
18743
|
};
|
|
18755
18744
|
/**
|
|
18756
18745
|
* ```js
|
|
@@ -19495,17 +19484,56 @@ const observeCommunity = (communityId, callback) => {
|
|
|
19495
19484
|
const queryGlobalFeed = async (query) => {
|
|
19496
19485
|
const client = getActiveClient();
|
|
19497
19486
|
client.log('feed/queryGlobalFeed', query);
|
|
19498
|
-
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
19499
|
-
const { data } = await client.http.get(`/api/v4/me/global-feeds`, { params: Object.assign(Object.assign({}, params), { options: {
|
|
19487
|
+
const _a = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _a, params = __rest(_a, ["useCustomRanking", "page"]);
|
|
19488
|
+
const { data } = await client.http.get(useCustomRanking ? `/api/v5/me/global-feeds` : `/api/v4/me/global-feeds`, { params: Object.assign(Object.assign({}, params), { options: {
|
|
19500
19489
|
token: toToken(page, 'skiplimit')
|
|
19501
19490
|
} }) });
|
|
19502
19491
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19503
19492
|
const { posts } = payload;
|
|
19504
|
-
|
|
19493
|
+
const cachedAt = client.cache && Date.now();
|
|
19494
|
+
if (client.cache) {
|
|
19505
19495
|
ingestInCache(payload);
|
|
19496
|
+
const cacheKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) })];
|
|
19497
|
+
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
19498
|
+
}
|
|
19506
19499
|
const nextPage = toPage(paging.next);
|
|
19507
19500
|
const prevPage = toPage(paging.previous);
|
|
19508
|
-
return { data: posts, prevPage, nextPage };
|
|
19501
|
+
return { data: posts, cachedAt, prevPage, nextPage };
|
|
19502
|
+
};
|
|
19503
|
+
/**
|
|
19504
|
+
* ```js
|
|
19505
|
+
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
19506
|
+
* const posts = await queryGlobalFeed.locally()
|
|
19507
|
+
* ```
|
|
19508
|
+
*
|
|
19509
|
+
* Queries a paginable list of {@link Amity.Post} objects from cache
|
|
19510
|
+
*
|
|
19511
|
+
* @param query The query parameters
|
|
19512
|
+
* @returns A page of {@link Amity.Post} objects
|
|
19513
|
+
*
|
|
19514
|
+
* @category Feed API
|
|
19515
|
+
* @async
|
|
19516
|
+
**/
|
|
19517
|
+
queryGlobalFeed.locally = (query) => {
|
|
19518
|
+
var _a, _b;
|
|
19519
|
+
const client = getActiveClient();
|
|
19520
|
+
client.log('post/queryGlobalFeed.locally', query);
|
|
19521
|
+
if (!client.cache)
|
|
19522
|
+
return;
|
|
19523
|
+
const _c = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _c, params = __rest(_c, ["useCustomRanking", "page"]);
|
|
19524
|
+
const queryKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) })];
|
|
19525
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19526
|
+
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
19527
|
+
return;
|
|
19528
|
+
const posts = data.posts
|
|
19529
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
19530
|
+
.filter(Boolean)
|
|
19531
|
+
.map(({ data }) => data);
|
|
19532
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19533
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19534
|
+
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
19535
|
+
? { data: posts, cachedAt, prevPage, nextPage }
|
|
19536
|
+
: undefined;
|
|
19509
19537
|
};
|
|
19510
19538
|
|
|
19511
19539
|
/**
|
|
@@ -19966,4 +19994,4 @@ const onStreamRecorded = (callback) => {
|
|
|
19966
19994
|
return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
|
|
19967
19995
|
};
|
|
19968
19996
|
|
|
19969
|
-
export { SubscriptionLevels, VERSION$1 as VERSION, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRole, addReaction, backupCache, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createMessage, createPost, createQuery, createReport, createStream, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, getActiveClient, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getMessage, getMessages, getPost, getPostTopic, getPosts, getRole, getStream, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeMessage, observeMessages, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onMemberAdded, onMemberRemoved, onMessageCreated, onMessageDeleted, onMessageUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserFlagCleared, onUserFlagged, onUserUnflagged, onUserUpdated, pullFromCache, pushToCache, queryCache, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRole, removeReaction, restoreCache, runQuery,
|
|
19997
|
+
export { SubscriptionLevels, VERSION$1 as VERSION, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRole, addReaction, backupCache, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createMessage, createPost, createQuery, createReport, createStream, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, getActiveClient, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getMessage, getMessages, getPost, getPostTopic, getPosts, getRole, getStream, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeMessage, observeMessages, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onMemberAdded, onMemberRemoved, onMessageCreated, onMessageDeleted, onMessageUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserFlagCleared, onUserFlagged, onUserUnflagged, onUserUpdated, pullFromCache, pushToCache, queryCache, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRole, removeReaction, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser, upsertInCache, wipeCache };
|