@amityco/ts-sdk 7.13.1-e0a963d.0 → 7.14.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/core/events.d.ts +0 -2
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +0 -2
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +0 -5
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +10 -7
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +17 -1
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +1 -1
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +5 -2
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/room.d.ts +0 -1
- package/dist/@types/domains/room.d.ts.map +1 -1
- package/dist/@types/index.d.ts +0 -1
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/client/api/accessTokenExpiryWatcher.d.ts +1 -1
- package/dist/client/api/accessTokenExpiryWatcher.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +2 -1
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/isSameUserId.d.ts +2 -0
- package/dist/client/api/isSameUserId.d.ts.map +1 -0
- package/dist/client/api/login.d.ts.map +1 -1
- package/dist/client/api/loginAsBot.d.ts.map +1 -1
- package/dist/client/api/loginAsVisitor.d.ts.map +1 -1
- package/dist/client/api/loginWithAccessToken.d.ts +28 -0
- package/dist/client/api/loginWithAccessToken.d.ts.map +1 -0
- package/dist/client/api/logout.d.ts.map +1 -1
- package/dist/client/api/renewTokenWithHandler.d.ts +11 -0
- package/dist/client/api/renewTokenWithHandler.d.ts.map +1 -0
- package/dist/client/api/renewWithAccessToken.d.ts +2 -0
- package/dist/client/api/renewWithAccessToken.d.ts.map +1 -0
- package/dist/client/api/resumeSession.d.ts.map +1 -1
- package/dist/client/api/setAccessTokenHandler.d.ts +31 -0
- package/dist/client/api/setAccessTokenHandler.d.ts.map +1 -0
- package/dist/client/api/setupLoginSubscriptions.d.ts +11 -0
- package/dist/client/api/setupLoginSubscriptions.d.ts.map +1 -0
- package/dist/client/api/tests/loginWithAccessToken.test.d.ts +2 -0
- package/dist/client/api/tests/loginWithAccessToken.test.d.ts.map +1 -0
- package/dist/client/api/validateAccessToken.d.ts +11 -0
- package/dist/client/api/validateAccessToken.d.ts.map +1 -0
- package/dist/commentRepository/api/createComment.d.ts.map +1 -1
- package/dist/commentRepository/api/deleteComment.d.ts.map +1 -1
- package/dist/commentRepository/events/utils.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/subscription.d.ts +2 -2
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/feedRepository/index.d.ts +1 -1
- package/dist/feedRepository/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/getCommunityFeed/LiveCollectionController.d.ts +13 -0
- package/dist/feedRepository/observers/getCommunityFeed/LiveCollectionController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getCommunityFeed/PaginationController.d.ts +5 -0
- package/dist/feedRepository/observers/getCommunityFeed/PaginationController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getCommunityFeed/QueryStreamController.d.ts +15 -0
- package/dist/feedRepository/observers/getCommunityFeed/QueryStreamController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getCommunityFeed.d.ts +34 -0
- package/dist/feedRepository/observers/getCommunityFeed.d.ts.map +1 -0
- package/dist/feedRepository/observers/index.d.ts +1 -0
- package/dist/feedRepository/observers/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/utils.d.ts.map +1 -1
- package/dist/index.cjs.js +1040 -1013
- package/dist/index.d.ts +0 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +1018 -989
- package/dist/index.umd.js +3 -3
- package/dist/postRepository/api/createAudioPost.d.ts +0 -2
- package/dist/postRepository/api/createAudioPost.d.ts.map +1 -1
- package/dist/postRepository/api/createClipPost.d.ts +0 -2
- package/dist/postRepository/api/createClipPost.d.ts.map +1 -1
- package/dist/postRepository/api/createMixedMediaPost.d.ts +0 -2
- package/dist/postRepository/api/createMixedMediaPost.d.ts.map +1 -1
- package/dist/postRepository/api/createPost.d.ts +0 -3
- package/dist/postRepository/api/createPost.d.ts.map +1 -1
- package/dist/postRepository/api/editPost.d.ts +0 -3
- package/dist/postRepository/api/editPost.d.ts.map +1 -1
- package/dist/postRepository/api/index.d.ts +0 -4
- package/dist/postRepository/api/index.d.ts.map +1 -1
- package/dist/postRepository/events/utils.d.ts.map +1 -1
- package/dist/postRepository/observers/enums.d.ts +1 -4
- package/dist/postRepository/observers/enums.d.ts.map +1 -1
- package/dist/postRepository/observers/utils.d.ts.map +1 -1
- package/dist/postRepository/utils/PostCommentCountEngine/CommentChange.d.ts +11 -0
- package/dist/postRepository/utils/PostCommentCountEngine/CommentChange.d.ts.map +1 -0
- package/dist/postRepository/utils/PostCommentCountEngine/CreateTask.d.ts +8 -0
- package/dist/postRepository/utils/PostCommentCountEngine/CreateTask.d.ts.map +1 -0
- package/dist/postRepository/utils/PostCommentCountEngine/DeleteTask.d.ts +7 -0
- package/dist/postRepository/utils/PostCommentCountEngine/DeleteTask.d.ts.map +1 -0
- package/dist/postRepository/utils/PostCommentCountEngine/PostCommentCountEngine.d.ts +19 -0
- package/dist/postRepository/utils/PostCommentCountEngine/PostCommentCountEngine.d.ts.map +1 -0
- package/dist/postRepository/utils/PostCommentCountEngine/ResetTask.d.ts +8 -0
- package/dist/postRepository/utils/PostCommentCountEngine/ResetTask.d.ts.map +1 -0
- package/dist/postRepository/utils/payload.d.ts.map +1 -1
- package/dist/roomRepository/api/index.d.ts +0 -1
- package/dist/roomRepository/api/index.d.ts.map +1 -1
- package/dist/roomRepository/events/index.d.ts +0 -2
- package/dist/roomRepository/events/index.d.ts.map +1 -1
- package/dist/roomRepository/observers/enums.d.ts +1 -2
- package/dist/roomRepository/observers/enums.d.ts.map +1 -1
- package/dist/roomRepository/observers/utils.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/package.json +3 -1
- package/dist/@types/domains/product.d.ts +0 -75
- package/dist/@types/domains/product.d.ts.map +0 -1
- package/dist/client/api/getProductCatalogueSetting.d.ts +0 -15
- package/dist/client/api/getProductCatalogueSetting.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/createComment.d.ts +0 -2
- package/dist/commentRepository/internalApi/createComment.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/deleteComment.d.ts +0 -2
- package/dist/commentRepository/internalApi/deleteComment.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/flagComment.d.ts +0 -2
- package/dist/commentRepository/internalApi/flagComment.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/hardDeleteComment.d.ts +0 -2
- package/dist/commentRepository/internalApi/hardDeleteComment.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/isCommentFlaggedByMe.d.ts +0 -2
- package/dist/commentRepository/internalApi/isCommentFlaggedByMe.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/queryComments.d.ts +0 -2
- package/dist/commentRepository/internalApi/queryComments.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/softDeleteComment.d.ts +0 -2
- package/dist/commentRepository/internalApi/softDeleteComment.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/tests/createComment.test.d.ts +0 -2
- package/dist/commentRepository/internalApi/tests/createComment.test.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/tests/deleteComment.test.d.ts +0 -2
- package/dist/commentRepository/internalApi/tests/deleteComment.test.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/tests/getCommentByIds.test.d.ts +0 -2
- package/dist/commentRepository/internalApi/tests/getCommentByIds.test.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/tests/getComments.test.d.ts +0 -2
- package/dist/commentRepository/internalApi/tests/getComments.test.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/tests/hardDeleteComment.test.d.ts +0 -2
- package/dist/commentRepository/internalApi/tests/hardDeleteComment.test.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/tests/queryComments.test.d.ts +0 -2
- package/dist/commentRepository/internalApi/tests/queryComments.test.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/tests/softDeleteComment.test.d.ts +0 -2
- package/dist/commentRepository/internalApi/tests/softDeleteComment.test.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/tests/updateComment.test.d.ts +0 -2
- package/dist/commentRepository/internalApi/tests/updateComment.test.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/unflagComment.d.ts +0 -2
- package/dist/commentRepository/internalApi/unflagComment.d.ts.map +0 -1
- package/dist/commentRepository/internalApi/updateComment.d.ts +0 -2
- package/dist/commentRepository/internalApi/updateComment.d.ts.map +0 -1
- package/dist/postRepository/api/createRoomPost.d.ts +0 -29
- package/dist/postRepository/api/createRoomPost.d.ts.map +0 -1
- package/dist/postRepository/api/pinProduct.d.ts +0 -15
- package/dist/postRepository/api/pinProduct.d.ts.map +0 -1
- package/dist/postRepository/api/unpinProduct.d.ts +0 -14
- package/dist/postRepository/api/unpinProduct.d.ts.map +0 -1
- package/dist/postRepository/api/updateProductTags.d.ts +0 -15
- package/dist/postRepository/api/updateProductTags.d.ts.map +0 -1
- package/dist/productRepository/helpers/AttachmentProductTags.d.ts +0 -41
- package/dist/productRepository/helpers/AttachmentProductTags.d.ts.map +0 -1
- package/dist/productRepository/helpers/index.d.ts +0 -2
- package/dist/productRepository/helpers/index.d.ts.map +0 -1
- package/dist/productRepository/index.d.ts +0 -2
- package/dist/productRepository/index.d.ts.map +0 -1
- package/dist/productRepository/internalApi/getProduct.d.ts +0 -5
- package/dist/productRepository/internalApi/getProduct.d.ts.map +0 -1
- package/dist/productRepository/internalApi/index.d.ts +0 -2
- package/dist/productRepository/internalApi/index.d.ts.map +0 -1
- package/dist/productRepository/observers/getProduct.d.ts +0 -21
- package/dist/productRepository/observers/getProduct.d.ts.map +0 -1
- package/dist/productRepository/observers/index.d.ts +0 -3
- package/dist/productRepository/observers/index.d.ts.map +0 -1
- package/dist/productRepository/observers/searchProducts/LiveCollectionController.d.ts +0 -15
- package/dist/productRepository/observers/searchProducts/LiveCollectionController.d.ts.map +0 -1
- package/dist/productRepository/observers/searchProducts/PaginationController.d.ts +0 -5
- package/dist/productRepository/observers/searchProducts/PaginationController.d.ts.map +0 -1
- package/dist/productRepository/observers/searchProducts/QueryStreamController.d.ts +0 -8
- package/dist/productRepository/observers/searchProducts/QueryStreamController.d.ts.map +0 -1
- package/dist/productRepository/observers/searchProducts.d.ts +0 -25
- package/dist/productRepository/observers/searchProducts.d.ts.map +0 -1
- package/dist/roomRepository/api/updateCohostPermission.d.ts +0 -18
- package/dist/roomRepository/api/updateCohostPermission.d.ts.map +0 -1
- package/dist/roomRepository/events/onLocalRoomDidUpdate.d.ts +0 -17
- package/dist/roomRepository/events/onLocalRoomDidUpdate.d.ts.map +0 -1
- package/dist/roomRepository/events/onRoomDidUpdate.d.ts +0 -17
- package/dist/roomRepository/events/onRoomDidUpdate.d.ts.map +0 -1
- package/dist/utils/linkedObject/productTagLinkedObject.d.ts +0 -2
- package/dist/utils/linkedObject/productTagLinkedObject.d.ts.map +0 -1
package/dist/index.esm.js
CHANGED
|
@@ -188,6 +188,12 @@ var FeedSourceEnum;
|
|
|
188
188
|
FeedSourceEnum["Community"] = "community";
|
|
189
189
|
FeedSourceEnum["User"] = "user";
|
|
190
190
|
})(FeedSourceEnum || (FeedSourceEnum = {}));
|
|
191
|
+
var FeedTypeEnum;
|
|
192
|
+
(function (FeedTypeEnum) {
|
|
193
|
+
FeedTypeEnum["Reviewing"] = "reviewing";
|
|
194
|
+
FeedTypeEnum["Published"] = "published";
|
|
195
|
+
FeedTypeEnum["Declined"] = "declined";
|
|
196
|
+
})(FeedTypeEnum || (FeedTypeEnum = {}));
|
|
191
197
|
|
|
192
198
|
var AmityEventType;
|
|
193
199
|
(function (AmityEventType) {
|
|
@@ -224,8 +230,8 @@ var AmityEventOrderOption;
|
|
|
224
230
|
|
|
225
231
|
function getVersion() {
|
|
226
232
|
try {
|
|
227
|
-
// the string ''v7.
|
|
228
|
-
return 'v7.
|
|
233
|
+
// the string ''v7.14.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
234
|
+
return 'v7.14.0-esm';
|
|
229
235
|
}
|
|
230
236
|
catch (error) {
|
|
231
237
|
return '__dev__';
|
|
@@ -674,7 +680,6 @@ const idResolvers = {
|
|
|
674
680
|
viewer: ({ userId }) => userId,
|
|
675
681
|
event: ({ eventId }) => eventId,
|
|
676
682
|
eventResponse: ({ userId }) => userId,
|
|
677
|
-
product: ({ productId }) => productId,
|
|
678
683
|
};
|
|
679
684
|
/**
|
|
680
685
|
* Retrieve the id resolver matching a domain name
|
|
@@ -734,7 +739,6 @@ const PAYLOAD2MODEL = {
|
|
|
734
739
|
events: 'event',
|
|
735
740
|
viewers: 'viewer',
|
|
736
741
|
eventResponses: 'eventResponse',
|
|
737
|
-
products: 'product',
|
|
738
742
|
};
|
|
739
743
|
/** hidden */
|
|
740
744
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -1669,10 +1673,14 @@ const getLiveReactionTopic = (post) => {
|
|
|
1669
1673
|
};
|
|
1670
1674
|
const getRoomWatcherTopic = (room) => {
|
|
1671
1675
|
const user = getCurrentUser();
|
|
1676
|
+
if (!user)
|
|
1677
|
+
return;
|
|
1672
1678
|
return `${getNetworkId(user)}/room/${room._id}`;
|
|
1673
1679
|
};
|
|
1674
1680
|
const getRoomStreamerTopic = (room) => {
|
|
1675
1681
|
const user = getCurrentUser();
|
|
1682
|
+
if (!user)
|
|
1683
|
+
return;
|
|
1676
1684
|
return `${getNetworkId(user)}/room/${room.roomId}/streamer`;
|
|
1677
1685
|
};
|
|
1678
1686
|
function subscribeTopic(topic, callback) {
|
|
@@ -1767,13 +1775,13 @@ class NetworkActivitiesWatcher {
|
|
|
1767
1775
|
this._listener.clear();
|
|
1768
1776
|
}
|
|
1769
1777
|
}
|
|
1770
|
-
let instance$
|
|
1778
|
+
let instance$8;
|
|
1771
1779
|
var NetworkActivitiesWatcher$1 = {
|
|
1772
1780
|
getInstance: () => {
|
|
1773
|
-
if (!instance$
|
|
1774
|
-
instance$
|
|
1781
|
+
if (!instance$8) {
|
|
1782
|
+
instance$8 = new NetworkActivitiesWatcher();
|
|
1775
1783
|
}
|
|
1776
|
-
return instance$
|
|
1784
|
+
return instance$8;
|
|
1777
1785
|
},
|
|
1778
1786
|
};
|
|
1779
1787
|
|
|
@@ -22932,13 +22940,13 @@ class SessionWatcher {
|
|
|
22932
22940
|
this._listener.clear();
|
|
22933
22941
|
}
|
|
22934
22942
|
}
|
|
22935
|
-
let instance$
|
|
22943
|
+
let instance$7;
|
|
22936
22944
|
var SessionWatcher$1 = {
|
|
22937
22945
|
getInstance: () => {
|
|
22938
|
-
if (!instance$
|
|
22939
|
-
instance$
|
|
22946
|
+
if (!instance$7) {
|
|
22947
|
+
instance$7 = new SessionWatcher();
|
|
22940
22948
|
}
|
|
22941
|
-
return instance$
|
|
22949
|
+
return instance$7;
|
|
22942
22950
|
},
|
|
22943
22951
|
};
|
|
22944
22952
|
|
|
@@ -23220,29 +23228,6 @@ const getSocialSettings = async () => {
|
|
|
23220
23228
|
return data.socialNetworkSetting;
|
|
23221
23229
|
};
|
|
23222
23230
|
|
|
23223
|
-
/* begin_public_function
|
|
23224
|
-
id: client.getProductCatalogueSetting
|
|
23225
|
-
*/
|
|
23226
|
-
/**
|
|
23227
|
-
* ```js
|
|
23228
|
-
* import { getProductCatalogueSetting } from '@amityco/ts-sdk'
|
|
23229
|
-
* const productCatalogueSetting = await getProductCatalogueSetting()
|
|
23230
|
-
* ```
|
|
23231
|
-
*
|
|
23232
|
-
* Fetches a {@link Amity.ProductCatalogueSetting} object
|
|
23233
|
-
*
|
|
23234
|
-
* @returns A Promise of {@link Amity.ProductCatalogueSetting} object
|
|
23235
|
-
*
|
|
23236
|
-
* @category Client API
|
|
23237
|
-
* @async
|
|
23238
|
-
*/
|
|
23239
|
-
const getProductCatalogueSetting = async () => {
|
|
23240
|
-
const client = getActiveClient();
|
|
23241
|
-
const { data } = await client.http.get(`/api/v3/network-settings/product`);
|
|
23242
|
-
return data;
|
|
23243
|
-
};
|
|
23244
|
-
/* end_public_function */
|
|
23245
|
-
|
|
23246
23231
|
const checkUserPermission = (userId, permission) => {
|
|
23247
23232
|
var _a;
|
|
23248
23233
|
const user = (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
@@ -23538,6 +23523,108 @@ const setVisitorClientToken = async (params) => {
|
|
|
23538
23523
|
return { accessToken, users, userType };
|
|
23539
23524
|
};
|
|
23540
23525
|
|
|
23526
|
+
/* begin_public_function
|
|
23527
|
+
id: client.logout
|
|
23528
|
+
*/
|
|
23529
|
+
/**
|
|
23530
|
+
* ```js
|
|
23531
|
+
* import { Client } from '@amityco/ts-sdk';
|
|
23532
|
+
* const success = await Client.logout()
|
|
23533
|
+
* ```
|
|
23534
|
+
*
|
|
23535
|
+
* Disconnects an {@link Amity.Client} instance from ASC servers
|
|
23536
|
+
*
|
|
23537
|
+
* @returns a success boolean if disconnected
|
|
23538
|
+
*
|
|
23539
|
+
* @category Client API
|
|
23540
|
+
* @async
|
|
23541
|
+
*/
|
|
23542
|
+
const logout = async () => {
|
|
23543
|
+
var _a;
|
|
23544
|
+
const client = getActiveClient();
|
|
23545
|
+
client.log('client/api/disconnectClient');
|
|
23546
|
+
if (client.mqtt && client.mqtt.connected) {
|
|
23547
|
+
client.mqtt.disconnect();
|
|
23548
|
+
}
|
|
23549
|
+
/*
|
|
23550
|
+
* for cases when session state is terminated (example on ban) or token expired,
|
|
23551
|
+
* the terminating block will set session state to terminated or for the or
|
|
23552
|
+
* in the case of expired token the same happens
|
|
23553
|
+
*
|
|
23554
|
+
* establishing state also ignored in cases where accessTokenExpiryWatcher
|
|
23555
|
+
* calls renewal. There is a possibility that renewal will be called before
|
|
23556
|
+
* disconnectClient finishes execution
|
|
23557
|
+
*
|
|
23558
|
+
* IMPORTANT: call this before `emitter.all.clear()`, otherwise the session
|
|
23559
|
+
* event will never be triggered
|
|
23560
|
+
*/
|
|
23561
|
+
if (client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */)
|
|
23562
|
+
setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
23563
|
+
client.emitter.all.clear();
|
|
23564
|
+
(_a = client.mqtt) === null || _a === void 0 ? void 0 : _a.removeAllListeners();
|
|
23565
|
+
client.userId = undefined;
|
|
23566
|
+
client.token = undefined;
|
|
23567
|
+
client.loginType = undefined;
|
|
23568
|
+
client.http.defaults.headers.common.Authorization = '';
|
|
23569
|
+
client.http.defaults.metadata = {
|
|
23570
|
+
tokenExpiry: '',
|
|
23571
|
+
isGlobalBanned: false,
|
|
23572
|
+
isUserDeleted: false,
|
|
23573
|
+
};
|
|
23574
|
+
if (typeof document !== 'undefined') {
|
|
23575
|
+
document.cookie = '_ascSession=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
|
|
23576
|
+
}
|
|
23577
|
+
/*
|
|
23578
|
+
* Cache should be usable if tokenExpired
|
|
23579
|
+
* https://ekoapp.atlassian.net/wiki/spaces/UP/pages/2082537485/ASC+Core+-+Session+Management+3.0#SDK-usability-based-on-Session-State
|
|
23580
|
+
*/
|
|
23581
|
+
if (client.sessionState !== "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ && client.cache) {
|
|
23582
|
+
client.cache = { data: {} };
|
|
23583
|
+
}
|
|
23584
|
+
return true;
|
|
23585
|
+
};
|
|
23586
|
+
/* end_public_function */
|
|
23587
|
+
|
|
23588
|
+
/**
|
|
23589
|
+
* Terminates {@link Amity.Client} instance
|
|
23590
|
+
*
|
|
23591
|
+
*
|
|
23592
|
+
*
|
|
23593
|
+
* @category private
|
|
23594
|
+
*/
|
|
23595
|
+
const terminateClient = (terminationReason) => {
|
|
23596
|
+
const client = getActiveClient();
|
|
23597
|
+
setSessionState("terminated" /* Amity.SessionStates.TERMINATED */, terminationReason);
|
|
23598
|
+
if (client.http.defaults.metadata) {
|
|
23599
|
+
if (terminationReason === "globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */)
|
|
23600
|
+
client.http.defaults.metadata.isGlobalBanned = true;
|
|
23601
|
+
if (terminationReason === "userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */)
|
|
23602
|
+
client.http.defaults.metadata.isUserDeleted = true;
|
|
23603
|
+
}
|
|
23604
|
+
client.sessionHandler = undefined;
|
|
23605
|
+
logout();
|
|
23606
|
+
};
|
|
23607
|
+
|
|
23608
|
+
let currentUserType = null;
|
|
23609
|
+
/* begin_public_function
|
|
23610
|
+
id: client.get_current_user_type
|
|
23611
|
+
*/
|
|
23612
|
+
const getCurrentUserType = () => {
|
|
23613
|
+
if (!currentUserType) {
|
|
23614
|
+
throw new ASCError('Connect client first', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
23615
|
+
}
|
|
23616
|
+
return currentUserType;
|
|
23617
|
+
};
|
|
23618
|
+
/* end_public_function */
|
|
23619
|
+
const setCurrentUserType = (userType) => {
|
|
23620
|
+
currentUserType = userType;
|
|
23621
|
+
};
|
|
23622
|
+
|
|
23623
|
+
const setCurrentUser = ({ user, userType, }) => {
|
|
23624
|
+
setActiveUser(user);
|
|
23625
|
+
setCurrentUserType(userType);
|
|
23626
|
+
};
|
|
23627
|
+
|
|
23541
23628
|
const createUserEventSubscriber = (event, callback) => {
|
|
23542
23629
|
const client = getActiveClient();
|
|
23543
23630
|
const filter = (data) => {
|
|
@@ -23856,13 +23943,13 @@ class AnalyticsEngine {
|
|
|
23856
23943
|
this._eventCapturer.resetAllBuckets();
|
|
23857
23944
|
}
|
|
23858
23945
|
}
|
|
23859
|
-
let instance$
|
|
23946
|
+
let instance$6;
|
|
23860
23947
|
var AnalyticsEngine$1 = {
|
|
23861
23948
|
getInstance: () => {
|
|
23862
|
-
if (!instance$
|
|
23863
|
-
instance$
|
|
23949
|
+
if (!instance$6) {
|
|
23950
|
+
instance$6 = new AnalyticsEngine();
|
|
23864
23951
|
}
|
|
23865
|
-
return instance$
|
|
23952
|
+
return instance$6;
|
|
23866
23953
|
},
|
|
23867
23954
|
};
|
|
23868
23955
|
|
|
@@ -24090,12 +24177,12 @@ class MessageReadReceiptSyncEngine {
|
|
|
24090
24177
|
}
|
|
24091
24178
|
}
|
|
24092
24179
|
}
|
|
24093
|
-
let instance$
|
|
24180
|
+
let instance$5 = null;
|
|
24094
24181
|
var ReadReceiptSyncEngine = {
|
|
24095
24182
|
getInstance: () => {
|
|
24096
|
-
if (!instance$
|
|
24097
|
-
instance$
|
|
24098
|
-
return instance$
|
|
24183
|
+
if (!instance$5)
|
|
24184
|
+
instance$5 = new MessageReadReceiptSyncEngine();
|
|
24185
|
+
return instance$5;
|
|
24099
24186
|
},
|
|
24100
24187
|
};
|
|
24101
24188
|
|
|
@@ -24349,12 +24436,12 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
24349
24436
|
}
|
|
24350
24437
|
}
|
|
24351
24438
|
}
|
|
24352
|
-
let instance$
|
|
24439
|
+
let instance$4 = null;
|
|
24353
24440
|
var LegacyReadReceiptSyncEngine = {
|
|
24354
24441
|
getInstance: () => {
|
|
24355
|
-
if (!instance$
|
|
24356
|
-
instance$
|
|
24357
|
-
return instance$
|
|
24442
|
+
if (!instance$4)
|
|
24443
|
+
instance$4 = new LegacyMessageReadReceiptSyncEngine();
|
|
24444
|
+
return instance$4;
|
|
24358
24445
|
},
|
|
24359
24446
|
};
|
|
24360
24447
|
|
|
@@ -24600,12 +24687,12 @@ class ObjectResolverEngine {
|
|
|
24600
24687
|
this.stopResolver();
|
|
24601
24688
|
}
|
|
24602
24689
|
}
|
|
24603
|
-
let instance$
|
|
24690
|
+
let instance$3 = null;
|
|
24604
24691
|
var ObjectResolverEngine$1 = {
|
|
24605
24692
|
getInstance: () => {
|
|
24606
|
-
if (!instance$
|
|
24607
|
-
instance$
|
|
24608
|
-
return instance$
|
|
24693
|
+
if (!instance$3)
|
|
24694
|
+
instance$3 = new ObjectResolverEngine();
|
|
24695
|
+
return instance$3;
|
|
24609
24696
|
},
|
|
24610
24697
|
};
|
|
24611
24698
|
|
|
@@ -24755,13 +24842,13 @@ class LiveReactionSyncEngine {
|
|
|
24755
24842
|
this.stopReactionsSync();
|
|
24756
24843
|
}
|
|
24757
24844
|
}
|
|
24758
|
-
let instance$
|
|
24845
|
+
let instance$2;
|
|
24759
24846
|
var ReactionSyncEngine = {
|
|
24760
24847
|
getInstance: () => {
|
|
24761
|
-
if (!instance$
|
|
24762
|
-
instance$
|
|
24848
|
+
if (!instance$2) {
|
|
24849
|
+
instance$2 = new LiveReactionSyncEngine();
|
|
24763
24850
|
}
|
|
24764
|
-
return instance$
|
|
24851
|
+
return instance$2;
|
|
24765
24852
|
},
|
|
24766
24853
|
};
|
|
24767
24854
|
|
|
@@ -24783,87 +24870,6 @@ var reactionSyncEngineOnLoginHandler = () => {
|
|
|
24783
24870
|
};
|
|
24784
24871
|
};
|
|
24785
24872
|
|
|
24786
|
-
/* begin_public_function
|
|
24787
|
-
id: client.logout
|
|
24788
|
-
*/
|
|
24789
|
-
/**
|
|
24790
|
-
* ```js
|
|
24791
|
-
* import { Client } from '@amityco/ts-sdk';
|
|
24792
|
-
* const success = await Client.logout()
|
|
24793
|
-
* ```
|
|
24794
|
-
*
|
|
24795
|
-
* Disconnects an {@link Amity.Client} instance from ASC servers
|
|
24796
|
-
*
|
|
24797
|
-
* @returns a success boolean if disconnected
|
|
24798
|
-
*
|
|
24799
|
-
* @category Client API
|
|
24800
|
-
* @async
|
|
24801
|
-
*/
|
|
24802
|
-
const logout = async () => {
|
|
24803
|
-
var _a;
|
|
24804
|
-
const client = getActiveClient();
|
|
24805
|
-
client.log('client/api/disconnectClient');
|
|
24806
|
-
if (client.mqtt && client.mqtt.connected) {
|
|
24807
|
-
client.mqtt.disconnect();
|
|
24808
|
-
}
|
|
24809
|
-
/*
|
|
24810
|
-
* for cases when session state is terminated (example on ban) or token expired,
|
|
24811
|
-
* the terminating block will set session state to terminated or for the or
|
|
24812
|
-
* in the case of expired token the same happens
|
|
24813
|
-
*
|
|
24814
|
-
* establishing state also ignored in cases where accessTokenExpiryWatcher
|
|
24815
|
-
* calls renewal. There is a possibility that renewal will be called before
|
|
24816
|
-
* disconnectClient finishes execution
|
|
24817
|
-
*
|
|
24818
|
-
* IMPORTANT: call this before `emitter.all.clear()`, otherwise the session
|
|
24819
|
-
* event will never be triggered
|
|
24820
|
-
*/
|
|
24821
|
-
if (client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */)
|
|
24822
|
-
setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
24823
|
-
client.emitter.all.clear();
|
|
24824
|
-
(_a = client.mqtt) === null || _a === void 0 ? void 0 : _a.removeAllListeners();
|
|
24825
|
-
client.userId = undefined;
|
|
24826
|
-
client.token = undefined;
|
|
24827
|
-
client.http.defaults.headers.common.Authorization = '';
|
|
24828
|
-
client.http.defaults.metadata = {
|
|
24829
|
-
tokenExpiry: '',
|
|
24830
|
-
isGlobalBanned: false,
|
|
24831
|
-
isUserDeleted: false,
|
|
24832
|
-
};
|
|
24833
|
-
if (typeof document !== 'undefined') {
|
|
24834
|
-
document.cookie = '_ascSession=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
|
|
24835
|
-
}
|
|
24836
|
-
/*
|
|
24837
|
-
* Cache should be usable if tokenExpired
|
|
24838
|
-
* https://ekoapp.atlassian.net/wiki/spaces/UP/pages/2082537485/ASC+Core+-+Session+Management+3.0#SDK-usability-based-on-Session-State
|
|
24839
|
-
*/
|
|
24840
|
-
if (client.sessionState !== "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ && client.cache) {
|
|
24841
|
-
client.cache = { data: {} };
|
|
24842
|
-
}
|
|
24843
|
-
return true;
|
|
24844
|
-
};
|
|
24845
|
-
/* end_public_function */
|
|
24846
|
-
|
|
24847
|
-
/**
|
|
24848
|
-
* Terminates {@link Amity.Client} instance
|
|
24849
|
-
*
|
|
24850
|
-
*
|
|
24851
|
-
*
|
|
24852
|
-
* @category private
|
|
24853
|
-
*/
|
|
24854
|
-
const terminateClient = (terminationReason) => {
|
|
24855
|
-
const client = getActiveClient();
|
|
24856
|
-
setSessionState("terminated" /* Amity.SessionStates.TERMINATED */, terminationReason);
|
|
24857
|
-
if (client.http.defaults.metadata) {
|
|
24858
|
-
if (terminationReason === "globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */)
|
|
24859
|
-
client.http.defaults.metadata.isGlobalBanned = true;
|
|
24860
|
-
if (terminationReason === "userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */)
|
|
24861
|
-
client.http.defaults.metadata.isUserDeleted = true;
|
|
24862
|
-
}
|
|
24863
|
-
client.sessionHandler = undefined;
|
|
24864
|
-
logout();
|
|
24865
|
-
};
|
|
24866
|
-
|
|
24867
24873
|
const EVENTS = [
|
|
24868
24874
|
'disconnected',
|
|
24869
24875
|
'error',
|
|
@@ -24993,24 +24999,50 @@ const removeChannelMarkerCache = (channel) => {
|
|
|
24993
24999
|
dropFromCache(['channelMarker', 'get', id], true);
|
|
24994
25000
|
};
|
|
24995
25001
|
|
|
24996
|
-
|
|
24997
|
-
|
|
24998
|
-
|
|
24999
|
-
|
|
25000
|
-
|
|
25001
|
-
|
|
25002
|
-
|
|
25002
|
+
/**
|
|
25003
|
+
* Sets up all login-related event subscriptions
|
|
25004
|
+
* This includes handlers for user bans, deletions, token events, and various engine initializations
|
|
25005
|
+
*
|
|
25006
|
+
* @param unsubWatcher - The unsubscriber function for the access token expiry watcher
|
|
25007
|
+
* @returns Array of unsubscriber functions for all registered subscriptions
|
|
25008
|
+
*
|
|
25009
|
+
* @category private
|
|
25010
|
+
*/
|
|
25011
|
+
const setupLoginSubscriptions = (unsubWatcher) => {
|
|
25012
|
+
const client = getActiveClient();
|
|
25013
|
+
const subscriptions = [];
|
|
25014
|
+
subscriptions.push(
|
|
25015
|
+
// GLOBAL_BAN
|
|
25016
|
+
onClientBanned((_) => {
|
|
25017
|
+
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
25018
|
+
subscriptions.forEach(fn => fn());
|
|
25019
|
+
unsubWatcher();
|
|
25020
|
+
}), onTokenTerminated(_ => {
|
|
25021
|
+
terminateClient();
|
|
25022
|
+
subscriptions.forEach(fn => fn());
|
|
25023
|
+
unsubWatcher();
|
|
25024
|
+
}), onUserDeleted$2((user) => {
|
|
25025
|
+
if (user.userId === client.userId) {
|
|
25026
|
+
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
25027
|
+
subscriptions.forEach(fn => fn());
|
|
25028
|
+
unsubWatcher();
|
|
25029
|
+
}
|
|
25030
|
+
}), onTokenExpired(state => {
|
|
25031
|
+
SessionWatcher$1.getInstance().setSessionState(state);
|
|
25032
|
+
logout();
|
|
25033
|
+
subscriptions.forEach(fn => fn());
|
|
25034
|
+
}),
|
|
25035
|
+
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
25036
|
+
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
25037
|
+
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
25038
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler());
|
|
25039
|
+
if (client.useLegacyUnreadCount) {
|
|
25040
|
+
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
25003
25041
|
}
|
|
25004
|
-
|
|
25005
|
-
|
|
25006
|
-
|
|
25007
|
-
|
|
25008
|
-
currentUserType = userType;
|
|
25009
|
-
};
|
|
25010
|
-
|
|
25011
|
-
const setCurrentUser = ({ user, userType, }) => {
|
|
25012
|
-
setActiveUser(user);
|
|
25013
|
-
setCurrentUserType(userType);
|
|
25042
|
+
else {
|
|
25043
|
+
subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
25044
|
+
}
|
|
25045
|
+
return subscriptions;
|
|
25014
25046
|
};
|
|
25015
25047
|
|
|
25016
25048
|
/* eslint-disable no-param-reassign */
|
|
@@ -25019,8 +25051,8 @@ const setCurrentUser = ({ user, userType, }) => {
|
|
|
25019
25051
|
* than the one already connected, in which case the existing subscriptions need
|
|
25020
25052
|
* to be cleared
|
|
25021
25053
|
*/
|
|
25022
|
-
let subscriptions$
|
|
25023
|
-
async function runMqtt$
|
|
25054
|
+
let subscriptions$4 = [];
|
|
25055
|
+
async function runMqtt$2() {
|
|
25024
25056
|
await modifyMqttConnection();
|
|
25025
25057
|
}
|
|
25026
25058
|
/* begin_public_function
|
|
@@ -25054,8 +25086,8 @@ const login = async (params, sessionHandler, config) => {
|
|
|
25054
25086
|
if (client.userId && client.userId !== params.userId) {
|
|
25055
25087
|
await logout();
|
|
25056
25088
|
// Remove subscription to ban and delete
|
|
25057
|
-
subscriptions$
|
|
25058
|
-
subscriptions$
|
|
25089
|
+
subscriptions$4.forEach(fn => fn());
|
|
25090
|
+
subscriptions$4 = [];
|
|
25059
25091
|
}
|
|
25060
25092
|
// default values
|
|
25061
25093
|
const defaultDeviceId = await getDeviceId();
|
|
@@ -25080,11 +25112,12 @@ const login = async (params, sessionHandler, config) => {
|
|
|
25080
25112
|
}
|
|
25081
25113
|
client.userId = user.userId;
|
|
25082
25114
|
client.sessionHandler = sessionHandler;
|
|
25115
|
+
client.loginType = 'userId';
|
|
25083
25116
|
/*
|
|
25084
25117
|
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
25085
25118
|
* token expires
|
|
25086
25119
|
*/
|
|
25087
|
-
unsubWatcher = client.accessTokenExpiryWatcher(
|
|
25120
|
+
unsubWatcher = client.accessTokenExpiryWatcher();
|
|
25088
25121
|
setCurrentUser({ user, userType });
|
|
25089
25122
|
}
|
|
25090
25123
|
catch (error) {
|
|
@@ -25097,40 +25130,11 @@ const login = async (params, sessionHandler, config) => {
|
|
|
25097
25130
|
throw error;
|
|
25098
25131
|
}
|
|
25099
25132
|
if ((config === null || config === void 0 ? void 0 : config.disableRTE) !== true) {
|
|
25100
|
-
runMqtt$
|
|
25133
|
+
runMqtt$2();
|
|
25101
25134
|
}
|
|
25102
25135
|
await initializeMessagePreviewSetting();
|
|
25103
|
-
if (subscriptions$
|
|
25104
|
-
subscriptions$
|
|
25105
|
-
// GLOBAL_BAN
|
|
25106
|
-
onClientBanned((_) => {
|
|
25107
|
-
terminateClient("globalBan" /* Amity.TokenTerminationReason.GLOBAL_BAN */);
|
|
25108
|
-
subscriptions$3.forEach(fn => fn());
|
|
25109
|
-
unsubWatcher();
|
|
25110
|
-
}), onTokenTerminated(_ => {
|
|
25111
|
-
terminateClient();
|
|
25112
|
-
subscriptions$3.forEach(fn => fn());
|
|
25113
|
-
unsubWatcher();
|
|
25114
|
-
}), onUserDeleted$2((user) => {
|
|
25115
|
-
if (user.userId === client.userId) {
|
|
25116
|
-
terminateClient("userDeleted" /* Amity.TokenTerminationReason.USER_DELETED */);
|
|
25117
|
-
subscriptions$3.forEach(fn => fn());
|
|
25118
|
-
unsubWatcher();
|
|
25119
|
-
}
|
|
25120
|
-
}), onTokenExpired(state => {
|
|
25121
|
-
SessionWatcher$1.getInstance().setSessionState(state);
|
|
25122
|
-
logout();
|
|
25123
|
-
subscriptions$3.forEach(fn => fn());
|
|
25124
|
-
}),
|
|
25125
|
-
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
25126
|
-
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
25127
|
-
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
25128
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler());
|
|
25129
|
-
if (client.useLegacyUnreadCount) {
|
|
25130
|
-
subscriptions$3.push(readReceiptSyncEngineOnLoginHandler());
|
|
25131
|
-
}
|
|
25132
|
-
else
|
|
25133
|
-
subscriptions$3.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
25136
|
+
if (subscriptions$4.length === 0) {
|
|
25137
|
+
subscriptions$4 = setupLoginSubscriptions(unsubWatcher);
|
|
25134
25138
|
}
|
|
25135
25139
|
return true;
|
|
25136
25140
|
};
|
|
@@ -25142,7 +25146,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
25142
25146
|
* than the one already connected, in which case the existing subscriptions need
|
|
25143
25147
|
* to be cleared
|
|
25144
25148
|
*/
|
|
25145
|
-
const subscriptions$
|
|
25149
|
+
const subscriptions$3 = [];
|
|
25146
25150
|
/* begin_public_function
|
|
25147
25151
|
id: client.loginAsVisitor
|
|
25148
25152
|
*/
|
|
@@ -25185,11 +25189,12 @@ const loginAsVisitor = async (params) => {
|
|
|
25185
25189
|
[user] = users;
|
|
25186
25190
|
client.userId = user.userId;
|
|
25187
25191
|
client.sessionHandler = params.sessionHandler;
|
|
25192
|
+
client.loginType = 'userId';
|
|
25188
25193
|
/*
|
|
25189
25194
|
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
25190
25195
|
* token expires
|
|
25191
25196
|
*/
|
|
25192
|
-
unsubWatcher = client.accessTokenExpiryWatcher(
|
|
25197
|
+
unsubWatcher = client.accessTokenExpiryWatcher();
|
|
25193
25198
|
setCurrentUser({ user, userType });
|
|
25194
25199
|
}
|
|
25195
25200
|
catch (error) {
|
|
@@ -25202,16 +25207,16 @@ const loginAsVisitor = async (params) => {
|
|
|
25202
25207
|
throw error;
|
|
25203
25208
|
}
|
|
25204
25209
|
await initializeMessagePreviewSetting();
|
|
25205
|
-
if (subscriptions$
|
|
25210
|
+
if (subscriptions$3.length === 0) {
|
|
25206
25211
|
// handling internal SDK events
|
|
25207
|
-
subscriptions$
|
|
25212
|
+
subscriptions$3.push(onTokenTerminated(_ => {
|
|
25208
25213
|
terminateClient();
|
|
25209
|
-
subscriptions$
|
|
25214
|
+
subscriptions$3.forEach(fn => fn());
|
|
25210
25215
|
unsubWatcher();
|
|
25211
25216
|
}), onTokenExpired(state => {
|
|
25212
25217
|
SessionWatcher$1.getInstance().setSessionState(state);
|
|
25213
25218
|
logout();
|
|
25214
|
-
subscriptions$
|
|
25219
|
+
subscriptions$3.forEach(fn => fn());
|
|
25215
25220
|
}));
|
|
25216
25221
|
}
|
|
25217
25222
|
return true;
|
|
@@ -25240,7 +25245,7 @@ const renewal = () => {
|
|
|
25240
25245
|
* Per instance of Renewal, only one renewal is allowed
|
|
25241
25246
|
*/
|
|
25242
25247
|
const renewToken = async (authToken) => {
|
|
25243
|
-
const { userId, displayName } =
|
|
25248
|
+
const { userId, displayName } = getActiveUser();
|
|
25244
25249
|
const deviceId = await getDeviceId();
|
|
25245
25250
|
const params = { userId, displayName, authToken, deviceId };
|
|
25246
25251
|
if (client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ && client.sessionHandler) {
|
|
@@ -25315,6 +25320,242 @@ const renewal = () => {
|
|
|
25315
25320
|
};
|
|
25316
25321
|
/* end_public_function */
|
|
25317
25322
|
|
|
25323
|
+
const validateAccessToken = async ({ token, userId }) => {
|
|
25324
|
+
const client = getActiveClient();
|
|
25325
|
+
// Validate token using sessions API
|
|
25326
|
+
await client.http.get('/api/v3/sessions', {
|
|
25327
|
+
headers: {
|
|
25328
|
+
Authorization: `Bearer ${token.accessToken}`,
|
|
25329
|
+
},
|
|
25330
|
+
});
|
|
25331
|
+
// Get user details
|
|
25332
|
+
const { data: { users }, } = await client.http.get(`/api/v3/users/${userId}`, {
|
|
25333
|
+
headers: {
|
|
25334
|
+
Authorization: `Bearer ${token.accessToken}`,
|
|
25335
|
+
},
|
|
25336
|
+
});
|
|
25337
|
+
const user = users.find((u) => u.userId === userId);
|
|
25338
|
+
client.http.defaults.headers.common.Authorization = `Bearer ${token.accessToken}`;
|
|
25339
|
+
client.http.defaults.metadata = {
|
|
25340
|
+
tokenExpiry: token.expiresAt,
|
|
25341
|
+
isGlobalBanned: false,
|
|
25342
|
+
isUserDeleted: false,
|
|
25343
|
+
};
|
|
25344
|
+
client.upload.defaults.headers.common.Authorization = `Bearer ${token.accessToken}`;
|
|
25345
|
+
client.upload.defaults.metadata = {
|
|
25346
|
+
tokenExpiry: token.expiresAt,
|
|
25347
|
+
isGlobalBanned: false,
|
|
25348
|
+
isUserDeleted: false,
|
|
25349
|
+
};
|
|
25350
|
+
client.token = token;
|
|
25351
|
+
return user;
|
|
25352
|
+
};
|
|
25353
|
+
|
|
25354
|
+
const isSameUserId = (token) => {
|
|
25355
|
+
var _a;
|
|
25356
|
+
const client = getActiveClient();
|
|
25357
|
+
const decoded = jwtDecode(token);
|
|
25358
|
+
return ((_a = decoded === null || decoded === void 0 ? void 0 : decoded.user) === null || _a === void 0 ? void 0 : _a.publicUserId) === client.userId;
|
|
25359
|
+
};
|
|
25360
|
+
|
|
25361
|
+
let subscriptions$2 = [];
|
|
25362
|
+
async function runMqtt$1() {
|
|
25363
|
+
await modifyMqttConnection();
|
|
25364
|
+
}
|
|
25365
|
+
/* begin_public_function
|
|
25366
|
+
id: client.loginWithAccessToken
|
|
25367
|
+
*/
|
|
25368
|
+
/**
|
|
25369
|
+
* ```js
|
|
25370
|
+
* import { loginWithAccessToken } from '@amityco/ts-sdk'
|
|
25371
|
+
* const success = await loginWithAccessToken('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...')
|
|
25372
|
+
* ```
|
|
25373
|
+
*
|
|
25374
|
+
* Authenticates a user using a pre-existing access token, allowing direct login without user credentials.
|
|
25375
|
+
* Designed for customers who manage access tokens on their own backend.
|
|
25376
|
+
*
|
|
25377
|
+
* @param accessToken JWT access token signed by customer's backend containing user identity
|
|
25378
|
+
* @returns true if authentication is successful
|
|
25379
|
+
*
|
|
25380
|
+
* @category Client API
|
|
25381
|
+
* @async
|
|
25382
|
+
*/
|
|
25383
|
+
const loginWithAccessToken = async (accessToken) => {
|
|
25384
|
+
var _a, _b;
|
|
25385
|
+
const client = getActiveClient();
|
|
25386
|
+
let unsubWatcher;
|
|
25387
|
+
client.log('client/api/loginWithAccessToken', {
|
|
25388
|
+
apiKey: client.apiKey,
|
|
25389
|
+
sessionState: client.sessionState,
|
|
25390
|
+
});
|
|
25391
|
+
// Validate input
|
|
25392
|
+
if (!accessToken || typeof accessToken !== 'string' || accessToken.trim() === '') {
|
|
25393
|
+
throw new ASCError('Access token must be a non-empty string', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25394
|
+
}
|
|
25395
|
+
let decoded;
|
|
25396
|
+
try {
|
|
25397
|
+
decoded = jwtDecode(accessToken);
|
|
25398
|
+
}
|
|
25399
|
+
catch (error) {
|
|
25400
|
+
throw new ASCError('Invalid access token format', 400100 /* Amity.ServerError.UNAUTHORIZED */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25401
|
+
}
|
|
25402
|
+
// Extract userId from token
|
|
25403
|
+
const userId = ((_a = decoded === null || decoded === void 0 ? void 0 : decoded.user) === null || _a === void 0 ? void 0 : _a.publicUserId) || ((_b = decoded === null || decoded === void 0 ? void 0 : decoded.user) === null || _b === void 0 ? void 0 : _b.userId);
|
|
25404
|
+
if (!userId) {
|
|
25405
|
+
throw new ASCError('Access token does not contain userId', 400100 /* Amity.ServerError.UNAUTHORIZED */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25406
|
+
}
|
|
25407
|
+
// Handle existing connected user
|
|
25408
|
+
if (client.userId) {
|
|
25409
|
+
const sameUser = isSameUserId(accessToken);
|
|
25410
|
+
if (!sameUser) {
|
|
25411
|
+
// Different user - do full logout
|
|
25412
|
+
await logout();
|
|
25413
|
+
}
|
|
25414
|
+
}
|
|
25415
|
+
try {
|
|
25416
|
+
// Set state to establishing
|
|
25417
|
+
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
25418
|
+
// Prepare token object for validation
|
|
25419
|
+
const tokenObject = {
|
|
25420
|
+
accessToken,
|
|
25421
|
+
issuedAt: decoded.iat ? new Date(decoded.iat * 1000).toISOString() : new Date().toISOString(),
|
|
25422
|
+
expiresAt: new Date(decoded.exp * 1000).toISOString(),
|
|
25423
|
+
};
|
|
25424
|
+
// Validate token and get user
|
|
25425
|
+
const user = await validateAccessToken({
|
|
25426
|
+
token: tokenObject,
|
|
25427
|
+
userId,
|
|
25428
|
+
});
|
|
25429
|
+
if (user == null) {
|
|
25430
|
+
setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
25431
|
+
throw new ASCError(`User ${userId} has not been found`, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25432
|
+
}
|
|
25433
|
+
if (user.isDeleted) {
|
|
25434
|
+
setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
25435
|
+
throw new ASCError(`User ${userId} has been deleted`, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25436
|
+
}
|
|
25437
|
+
if (user.isGlobalBanned) {
|
|
25438
|
+
setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
25439
|
+
throw new ASCError(`User ${userId} is globally banned`, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25440
|
+
}
|
|
25441
|
+
// Set userId and login method flag
|
|
25442
|
+
client.userId = user.userId;
|
|
25443
|
+
// Set login method flag to 'accessToken' in platform-specific login session
|
|
25444
|
+
client.loginType = 'accessToken';
|
|
25445
|
+
// This will be used by the access token handler to determine if token renewal should be invoked
|
|
25446
|
+
// Set active user
|
|
25447
|
+
setActiveUser(user);
|
|
25448
|
+
unsubWatcher = client.accessTokenExpiryWatcher();
|
|
25449
|
+
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
25450
|
+
}
|
|
25451
|
+
catch (error) {
|
|
25452
|
+
// If error occurs, revert session state to not logged in
|
|
25453
|
+
setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
25454
|
+
// Re-throw if it's already an ASCError
|
|
25455
|
+
if (error instanceof ASCError) {
|
|
25456
|
+
throw error;
|
|
25457
|
+
}
|
|
25458
|
+
// Wrap other errors
|
|
25459
|
+
throw new ASCError((error instanceof Error ? error.message : undefined) || 'Login with access token failed', 400100 /* Amity.ServerError.UNAUTHORIZED */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25460
|
+
}
|
|
25461
|
+
runMqtt$1();
|
|
25462
|
+
await initializeMessagePreviewSetting();
|
|
25463
|
+
if (subscriptions$2.length === 0) {
|
|
25464
|
+
subscriptions$2 = setupLoginSubscriptions(unsubWatcher);
|
|
25465
|
+
}
|
|
25466
|
+
return true;
|
|
25467
|
+
};
|
|
25468
|
+
/* end_public_function */
|
|
25469
|
+
|
|
25470
|
+
/* begin_public_function
|
|
25471
|
+
id: client.renew_with_accessToken
|
|
25472
|
+
*/
|
|
25473
|
+
/*
|
|
25474
|
+
* Renewal defintion accepted by SessionHandler interface
|
|
25475
|
+
*
|
|
25476
|
+
* Tech Spec:
|
|
25477
|
+
* https://ekoapp.atlassian.net/wiki/spaces/UP/pages/2082537485/ASC+Core+-+Session+Management+3.0#Session-Handler
|
|
25478
|
+
*
|
|
25479
|
+
* @category private
|
|
25480
|
+
*/
|
|
25481
|
+
const renewWithAccessToken = async (accessToken) => {
|
|
25482
|
+
var _a, _b;
|
|
25483
|
+
const client = getActiveClient();
|
|
25484
|
+
client.log('initiating access token renewal');
|
|
25485
|
+
/*
|
|
25486
|
+
* Renews a token if it is hasn't been renewed before. Also marks token as
|
|
25487
|
+
* renewed once done
|
|
25488
|
+
* Per instance of Renewal, only one renewal is allowed
|
|
25489
|
+
*/
|
|
25490
|
+
// Validate input
|
|
25491
|
+
if (!accessToken || typeof accessToken !== 'string' || accessToken.trim() === '') {
|
|
25492
|
+
throw new ASCError('Access token must be a non-empty string', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25493
|
+
}
|
|
25494
|
+
let decoded;
|
|
25495
|
+
try {
|
|
25496
|
+
decoded = jwtDecode(accessToken);
|
|
25497
|
+
}
|
|
25498
|
+
catch (error) {
|
|
25499
|
+
throw new ASCError('Invalid access token format', 400100 /* Amity.ServerError.UNAUTHORIZED */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25500
|
+
}
|
|
25501
|
+
// Extract userId from token
|
|
25502
|
+
const userId = ((_a = decoded === null || decoded === void 0 ? void 0 : decoded.user) === null || _a === void 0 ? void 0 : _a.publicUserId) || ((_b = decoded === null || decoded === void 0 ? void 0 : decoded.user) === null || _b === void 0 ? void 0 : _b.userId);
|
|
25503
|
+
if (!userId) {
|
|
25504
|
+
throw new ASCError('Access token does not contain userId', 400100 /* Amity.ServerError.UNAUTHORIZED */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
25505
|
+
}
|
|
25506
|
+
// Handle existing connected user
|
|
25507
|
+
if (client.userId) {
|
|
25508
|
+
const sameUser = isSameUserId(accessToken);
|
|
25509
|
+
if (!sameUser) {
|
|
25510
|
+
// Different user - do full logout
|
|
25511
|
+
await logout();
|
|
25512
|
+
}
|
|
25513
|
+
}
|
|
25514
|
+
const tokenObject = {
|
|
25515
|
+
accessToken,
|
|
25516
|
+
issuedAt: decoded.iat ? new Date(decoded.iat * 1000).toISOString() : new Date().toISOString(),
|
|
25517
|
+
expiresAt: new Date(decoded.exp * 1000).toISOString(),
|
|
25518
|
+
};
|
|
25519
|
+
if (client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ && client.sessionHandler) {
|
|
25520
|
+
await loginWithAccessToken(accessToken);
|
|
25521
|
+
}
|
|
25522
|
+
else {
|
|
25523
|
+
// about to expire
|
|
25524
|
+
await validateAccessToken({
|
|
25525
|
+
token: tokenObject,
|
|
25526
|
+
userId,
|
|
25527
|
+
});
|
|
25528
|
+
}
|
|
25529
|
+
};
|
|
25530
|
+
/* end_public_function */
|
|
25531
|
+
|
|
25532
|
+
/**
|
|
25533
|
+
* Helper function to renew access token using the accessTokenHandler
|
|
25534
|
+
* Handles error catching and logging
|
|
25535
|
+
*
|
|
25536
|
+
* @param useScheduledTask - Whether to wrap renewal in scheduleTask (for token expired case)
|
|
25537
|
+
* @category private
|
|
25538
|
+
*/
|
|
25539
|
+
const renewTokenWithHandler = async ({ useScheduledTask = false, }) => {
|
|
25540
|
+
const client = getActiveClient();
|
|
25541
|
+
if (!client.userId || !client.accessTokenHandler) {
|
|
25542
|
+
return;
|
|
25543
|
+
}
|
|
25544
|
+
try {
|
|
25545
|
+
const newToken = await client.accessTokenHandler.onTokenRenew(client.userId);
|
|
25546
|
+
if (useScheduledTask) {
|
|
25547
|
+
scheduleTask(() => renewWithAccessToken(newToken));
|
|
25548
|
+
}
|
|
25549
|
+
else {
|
|
25550
|
+
renewWithAccessToken(newToken);
|
|
25551
|
+
}
|
|
25552
|
+
}
|
|
25553
|
+
catch (error) {
|
|
25554
|
+
client.log('Proactive token renewal failed, will retry when token expires', error);
|
|
25555
|
+
// Will fallback to expired token flow
|
|
25556
|
+
}
|
|
25557
|
+
};
|
|
25558
|
+
|
|
25318
25559
|
const ABOUT_TO_EXPIRE_THRESHOLD = 80 / 100;
|
|
25319
25560
|
const COMPENSATED_DELAY = 5 * MINUTE;
|
|
25320
25561
|
/*
|
|
@@ -25350,10 +25591,11 @@ const isAboutToExpire = (params) => {
|
|
|
25350
25591
|
*
|
|
25351
25592
|
* @category private
|
|
25352
25593
|
*/
|
|
25353
|
-
const accessTokenExpiryWatcher = (
|
|
25354
|
-
const interval = setInterval(() => {
|
|
25594
|
+
const accessTokenExpiryWatcher = () => {
|
|
25595
|
+
const interval = setInterval(async () => {
|
|
25355
25596
|
const client = getActiveClient();
|
|
25356
|
-
|
|
25597
|
+
const { sessionHandler, accessTokenHandler, loginType } = client;
|
|
25598
|
+
if (!client.token || !client.userId)
|
|
25357
25599
|
return;
|
|
25358
25600
|
const { issuedAt, expiresAt } = client.token;
|
|
25359
25601
|
if (isExpired(expiresAt)) {
|
|
@@ -25364,18 +25606,38 @@ const accessTokenExpiryWatcher = (sessionHandler) => {
|
|
|
25364
25606
|
*/
|
|
25365
25607
|
fireEvent('tokenExpired', "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */);
|
|
25366
25608
|
/*
|
|
25367
|
-
*
|
|
25368
|
-
*
|
|
25369
|
-
*
|
|
25370
|
-
* Since fireEvent is scheduled, it will be called
|
|
25371
|
-
* after sessionHandler leading to an invalid state change from
|
|
25372
|
-
* establishing to tokenExpired
|
|
25609
|
+
* Check loginType to determine which handler to use:
|
|
25610
|
+
* - 'accessToken' = use accessTokenHandler
|
|
25611
|
+
* - 'userId' = use sessionHandler
|
|
25373
25612
|
*/
|
|
25374
|
-
|
|
25613
|
+
if (loginType === 'accessToken' && accessTokenHandler) {
|
|
25614
|
+
await renewTokenWithHandler({ useScheduledTask: false });
|
|
25615
|
+
}
|
|
25616
|
+
else if (loginType === 'userId' && sessionHandler) {
|
|
25617
|
+
/*
|
|
25618
|
+
* https://ekoapp.atlassian.net/wiki/spaces/UP/pages/2082537485/ASC+Core+-+Session+Management+3.0#Automatically-initiate-renewal-flow
|
|
25619
|
+
*
|
|
25620
|
+
* Why scheduled task?
|
|
25621
|
+
* Since fireEvent is scheduled, it will be called
|
|
25622
|
+
* after sessionHandler leading to an invalid state change from
|
|
25623
|
+
* establishing to tokenExpired
|
|
25624
|
+
*/
|
|
25625
|
+
scheduleTask(() => sessionHandler.sessionWillRenewAccessToken(renewal()));
|
|
25626
|
+
}
|
|
25375
25627
|
return;
|
|
25376
25628
|
}
|
|
25377
25629
|
if (isAboutToExpire({ expiresAt, issuedAt })) {
|
|
25378
|
-
|
|
25630
|
+
/*
|
|
25631
|
+
* Check loginType to determine which handler to use for proactive renewal:
|
|
25632
|
+
* - 'accessToken' = use accessTokenHandler
|
|
25633
|
+
* - 'userId' = use sessionHandler
|
|
25634
|
+
*/
|
|
25635
|
+
if (loginType === 'accessToken' && accessTokenHandler) {
|
|
25636
|
+
await renewTokenWithHandler({ useScheduledTask: false });
|
|
25637
|
+
}
|
|
25638
|
+
else if (loginType === 'userId' && sessionHandler) {
|
|
25639
|
+
sessionHandler.sessionWillRenewAccessToken(renewal());
|
|
25640
|
+
}
|
|
25379
25641
|
}
|
|
25380
25642
|
}, ACCESS_TOKEN_WATCHER_INTERVAL);
|
|
25381
25643
|
return () => clearInterval(interval);
|
|
@@ -25863,7 +26125,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25863
26125
|
isUnreadCountEnabled,
|
|
25864
26126
|
useLegacyUnreadCount,
|
|
25865
26127
|
getMarkerSyncConsistentMode,
|
|
25866
|
-
getProductCatalogueSetting,
|
|
25867
26128
|
/**
|
|
25868
26129
|
* Prefix for the deviceId key in the local storage or async storage.
|
|
25869
26130
|
* This is allow user to have multiple SDK client and Mqtt client within the same app.
|
|
@@ -25909,6 +26170,7 @@ const secureLogout = async () => {
|
|
|
25909
26170
|
};
|
|
25910
26171
|
/* end_public_function */
|
|
25911
26172
|
|
|
26173
|
+
/* eslint-disable no-param-reassign */
|
|
25912
26174
|
/*
|
|
25913
26175
|
* declared earlier to accomodate case when logging in with a different user
|
|
25914
26176
|
* than the one already connected, in which case the existing subscriptions need
|
|
@@ -25918,38 +26180,6 @@ let subscriptions$1 = [];
|
|
|
25918
26180
|
async function runMqtt() {
|
|
25919
26181
|
await modifyMqttConnection();
|
|
25920
26182
|
}
|
|
25921
|
-
const isSameUserId = (token) => {
|
|
25922
|
-
var _a;
|
|
25923
|
-
const client = getActiveClient();
|
|
25924
|
-
const decoded = jwtDecode(token);
|
|
25925
|
-
return ((_a = decoded === null || decoded === void 0 ? void 0 : decoded.user) === null || _a === void 0 ? void 0 : _a.publicUserId) === client.userId;
|
|
25926
|
-
};
|
|
25927
|
-
const validateAccessToken = async ({ token, userId }) => {
|
|
25928
|
-
const client = getActiveClient();
|
|
25929
|
-
// begin establishing session
|
|
25930
|
-
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
25931
|
-
const { data: { users }, } = await client.http.get(`/api/v3/users/${userId}`, {
|
|
25932
|
-
headers: {
|
|
25933
|
-
Authorization: `Bearer ${token.accessToken}`,
|
|
25934
|
-
},
|
|
25935
|
-
});
|
|
25936
|
-
const user = users.find((u) => u.userId === userId);
|
|
25937
|
-
client.http.defaults.headers.common.Authorization = `Bearer ${token.accessToken}`;
|
|
25938
|
-
client.http.defaults.metadata = {
|
|
25939
|
-
tokenExpiry: token.expiresAt,
|
|
25940
|
-
isGlobalBanned: false,
|
|
25941
|
-
isUserDeleted: false,
|
|
25942
|
-
};
|
|
25943
|
-
client.upload.defaults.headers.common.Authorization = `Bearer ${token.accessToken}`;
|
|
25944
|
-
client.upload.defaults.metadata = {
|
|
25945
|
-
tokenExpiry: token.expiresAt,
|
|
25946
|
-
isGlobalBanned: false,
|
|
25947
|
-
isUserDeleted: false,
|
|
25948
|
-
};
|
|
25949
|
-
client.token = token;
|
|
25950
|
-
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
25951
|
-
return user;
|
|
25952
|
-
};
|
|
25953
26183
|
/* begin_public_function
|
|
25954
26184
|
id: client.resumeSession
|
|
25955
26185
|
*/
|
|
@@ -25998,6 +26228,7 @@ const resumeSession = async (params, sessionHandler, config) => {
|
|
|
25998
26228
|
}
|
|
25999
26229
|
}
|
|
26000
26230
|
try {
|
|
26231
|
+
setSessionState("establishing" /* Amity.SessionStates.ESTABLISHING */);
|
|
26001
26232
|
const user = await validateAccessToken(params);
|
|
26002
26233
|
if (user == null) {
|
|
26003
26234
|
throw new ASCError(`${params.userId} has not been found`, 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
@@ -26104,13 +26335,13 @@ class GlobalFileAccessType {
|
|
|
26104
26335
|
}
|
|
26105
26336
|
}
|
|
26106
26337
|
_GlobalFileAccessType_fileAccessType = new WeakMap();
|
|
26107
|
-
let instance;
|
|
26338
|
+
let instance$1;
|
|
26108
26339
|
var GlobalFileAccessType$1 = {
|
|
26109
26340
|
getInstance: () => {
|
|
26110
|
-
if (!instance) {
|
|
26111
|
-
instance = new GlobalFileAccessType();
|
|
26341
|
+
if (!instance$1) {
|
|
26342
|
+
instance$1 = new GlobalFileAccessType();
|
|
26112
26343
|
}
|
|
26113
|
-
return instance;
|
|
26344
|
+
return instance$1;
|
|
26114
26345
|
},
|
|
26115
26346
|
};
|
|
26116
26347
|
|
|
@@ -26288,11 +26519,12 @@ const loginAsBot = async (params) => {
|
|
|
26288
26519
|
[user] = users;
|
|
26289
26520
|
client.userId = user.userId;
|
|
26290
26521
|
client.sessionHandler = params.sessionHandler;
|
|
26522
|
+
client.loginType = 'userId';
|
|
26291
26523
|
/*
|
|
26292
26524
|
* Cannot push to subscriptions as watcher needs to continue working even if
|
|
26293
26525
|
* token expires
|
|
26294
26526
|
*/
|
|
26295
|
-
unsubWatcher = client.accessTokenExpiryWatcher(
|
|
26527
|
+
unsubWatcher = client.accessTokenExpiryWatcher();
|
|
26296
26528
|
setCurrentUser({ user, userType });
|
|
26297
26529
|
}
|
|
26298
26530
|
catch (error) {
|
|
@@ -26321,6 +26553,53 @@ const loginAsBot = async (params) => {
|
|
|
26321
26553
|
};
|
|
26322
26554
|
/* end_public_function */
|
|
26323
26555
|
|
|
26556
|
+
/* begin_public_function
|
|
26557
|
+
id: client.setAccessTokenHandler
|
|
26558
|
+
*/
|
|
26559
|
+
/**
|
|
26560
|
+
* ```js
|
|
26561
|
+
* import { setAccessTokenHandler } from '@amityco/ts-sdk'
|
|
26562
|
+
*
|
|
26563
|
+
* const tokenHandler = {
|
|
26564
|
+
* async onTokenRenew() {
|
|
26565
|
+
* const response = await fetch('https://your-backend.com/api/refresh-token', {
|
|
26566
|
+
* method: 'POST',
|
|
26567
|
+
* credentials: 'include',
|
|
26568
|
+
* });
|
|
26569
|
+
* const data = await response.json();
|
|
26570
|
+
* return data.accessToken;
|
|
26571
|
+
* }
|
|
26572
|
+
* };
|
|
26573
|
+
*
|
|
26574
|
+
* setAccessTokenHandler(tokenHandler);
|
|
26575
|
+
* ```
|
|
26576
|
+
*
|
|
26577
|
+
* Registers a custom handler for managing access token renewal and expiration events.
|
|
26578
|
+
* This enables automatic token refresh and graceful handling of expired tokens.
|
|
26579
|
+
*
|
|
26580
|
+
* Must be called before loginWithAccessToken() to ensure the handler is available
|
|
26581
|
+
* when token expiry is detected.
|
|
26582
|
+
*
|
|
26583
|
+
* @param accessTokenHandler Handler object implementing token renewal callbacks
|
|
26584
|
+
* @returns void
|
|
26585
|
+
*
|
|
26586
|
+
* @category Client API
|
|
26587
|
+
*/
|
|
26588
|
+
const setAccessTokenHandler = (accessTokenHandler) => {
|
|
26589
|
+
const client = getActiveClient();
|
|
26590
|
+
client.log('client/api/setAccessTokenHandler', {
|
|
26591
|
+
apiKey: client.apiKey,
|
|
26592
|
+
sessionState: client.sessionState,
|
|
26593
|
+
hasOnTokenRenew: typeof (accessTokenHandler === null || accessTokenHandler === void 0 ? void 0 : accessTokenHandler.onTokenRenew) === 'function',
|
|
26594
|
+
});
|
|
26595
|
+
// Validate handler has required method
|
|
26596
|
+
if (!accessTokenHandler || typeof accessTokenHandler.onTokenRenew !== 'function') {
|
|
26597
|
+
throw new Error('AccessTokenHandler must implement onTokenRenew() method');
|
|
26598
|
+
}
|
|
26599
|
+
// Register the handler
|
|
26600
|
+
client.accessTokenHandler = accessTokenHandler;
|
|
26601
|
+
};
|
|
26602
|
+
|
|
26324
26603
|
/**
|
|
26325
26604
|
* ```js
|
|
26326
26605
|
* import { onChannelMarkerFetched } from '@amityco/ts-sdk'
|
|
@@ -26673,13 +26952,14 @@ const getUserUnread = (callback) => {
|
|
|
26673
26952
|
};
|
|
26674
26953
|
};
|
|
26675
26954
|
|
|
26676
|
-
var index$
|
|
26955
|
+
var index$r = /*#__PURE__*/Object.freeze({
|
|
26677
26956
|
__proto__: null,
|
|
26678
26957
|
getActiveClient: getActiveClient,
|
|
26679
26958
|
getActiveUser: getActiveUser,
|
|
26680
26959
|
setActiveUser: setActiveUser,
|
|
26681
26960
|
createClient: createClient,
|
|
26682
26961
|
login: login,
|
|
26962
|
+
loginWithAccessToken: loginWithAccessToken,
|
|
26683
26963
|
logout: logout,
|
|
26684
26964
|
secureLogout: secureLogout,
|
|
26685
26965
|
resumeSession: resumeSession,
|
|
@@ -26693,12 +26973,12 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
26693
26973
|
getLinkPreviewMetadata: getLinkPreviewMetadata,
|
|
26694
26974
|
getSocialSettings: getSocialSettings,
|
|
26695
26975
|
getShareableLinkConfiguration: getShareableLinkConfiguration,
|
|
26696
|
-
getProductCatalogueSetting: getProductCatalogueSetting,
|
|
26697
26976
|
loginAsVisitor: loginAsVisitor,
|
|
26698
26977
|
loginAsBot: loginAsBot,
|
|
26699
26978
|
getCurrentUser: getCurrentUser,
|
|
26700
26979
|
getCurrentUserType: getCurrentUserType,
|
|
26701
26980
|
setCurrentUserType: setCurrentUserType,
|
|
26981
|
+
setAccessTokenHandler: setAccessTokenHandler,
|
|
26702
26982
|
onConnectionError: onConnectionError,
|
|
26703
26983
|
onClientDisconnected: onClientDisconnected,
|
|
26704
26984
|
onClientBanned: onClientBanned,
|
|
@@ -27901,7 +28181,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
27901
28181
|
};
|
|
27902
28182
|
/* end_public_function */
|
|
27903
28183
|
|
|
27904
|
-
var index$
|
|
28184
|
+
var index$q = /*#__PURE__*/Object.freeze({
|
|
27905
28185
|
__proto__: null,
|
|
27906
28186
|
blockUser: blockUser,
|
|
27907
28187
|
unBlockUser: unBlockUser,
|
|
@@ -28731,7 +29011,7 @@ const getWatchSessionStorage = () => {
|
|
|
28731
29011
|
return storageInstance;
|
|
28732
29012
|
};
|
|
28733
29013
|
|
|
28734
|
-
const privateKey = "
|
|
29014
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
|
|
28735
29015
|
/*
|
|
28736
29016
|
* The crypto algorithm used for importing key and signing string
|
|
28737
29017
|
*/
|
|
@@ -30009,11 +30289,6 @@ const communityLinkedObject = (community) => {
|
|
|
30009
30289
|
} });
|
|
30010
30290
|
};
|
|
30011
30291
|
|
|
30012
|
-
const productTagLinkedObject = (productTag) => {
|
|
30013
|
-
var _a;
|
|
30014
|
-
return Object.assign(Object.assign({}, productTag), { product: (_a = pullFromCache(['product', 'get', productTag.productId])) === null || _a === void 0 ? void 0 : _a.data });
|
|
30015
|
-
};
|
|
30016
|
-
|
|
30017
30292
|
const postLinkedObject = (post) => {
|
|
30018
30293
|
return shallowClone(post, {
|
|
30019
30294
|
childrenPosts: post.children
|
|
@@ -30026,10 +30301,6 @@ const postLinkedObject = (post) => {
|
|
|
30026
30301
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
30027
30302
|
},
|
|
30028
30303
|
},
|
|
30029
|
-
get productTags() {
|
|
30030
|
-
var _a, _b;
|
|
30031
|
-
return (_b = (_a = post.productTags) === null || _a === void 0 ? void 0 : _a.map(productTag => productTagLinkedObject(productTag))) !== null && _b !== void 0 ? _b : [];
|
|
30032
|
-
},
|
|
30033
30304
|
get latestComments() {
|
|
30034
30305
|
if (!post.comments)
|
|
30035
30306
|
return [];
|
|
@@ -32019,9 +32290,9 @@ var AmityUserSearchMatchType;
|
|
|
32019
32290
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
32020
32291
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
32021
32292
|
|
|
32022
|
-
var index$
|
|
32293
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
32023
32294
|
__proto__: null,
|
|
32024
|
-
Relationship: index$
|
|
32295
|
+
Relationship: index$q,
|
|
32025
32296
|
getUserByIds: getUserByIds,
|
|
32026
32297
|
updateUser: updateUser,
|
|
32027
32298
|
flagUser: flagUser,
|
|
@@ -32424,7 +32695,7 @@ const uploadAudio = async (formData, onProgress) => {
|
|
|
32424
32695
|
};
|
|
32425
32696
|
/* end_public_function */
|
|
32426
32697
|
|
|
32427
|
-
var index$
|
|
32698
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
32428
32699
|
__proto__: null,
|
|
32429
32700
|
getFile: getFile,
|
|
32430
32701
|
uploadFile: uploadFile,
|
|
@@ -33065,6 +33336,147 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
33065
33336
|
return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
|
|
33066
33337
|
};
|
|
33067
33338
|
|
|
33339
|
+
class ResetTask {
|
|
33340
|
+
constructor(postId, latestCreatedAt, serverCommentCount) {
|
|
33341
|
+
this.postId = postId;
|
|
33342
|
+
this.latestCreatedAt = latestCreatedAt;
|
|
33343
|
+
this.serverCommentCount = serverCommentCount;
|
|
33344
|
+
}
|
|
33345
|
+
}
|
|
33346
|
+
|
|
33347
|
+
// Task to track comment creation
|
|
33348
|
+
class CreateTask {
|
|
33349
|
+
constructor(postId, commentId, createdAt) {
|
|
33350
|
+
this.postId = postId;
|
|
33351
|
+
this.commentId = commentId;
|
|
33352
|
+
this.createdAt = createdAt;
|
|
33353
|
+
}
|
|
33354
|
+
}
|
|
33355
|
+
|
|
33356
|
+
// Task to track comment deletion
|
|
33357
|
+
class DeleteTask {
|
|
33358
|
+
constructor(postId, commentId) {
|
|
33359
|
+
this.postId = postId;
|
|
33360
|
+
this.commentId = commentId;
|
|
33361
|
+
}
|
|
33362
|
+
}
|
|
33363
|
+
|
|
33364
|
+
class CommentChange {
|
|
33365
|
+
constructor(latestCreatedAt, serverCommentCount) {
|
|
33366
|
+
this.latestCommentCreatedAt = latestCreatedAt;
|
|
33367
|
+
this.serverCommentCount = serverCommentCount;
|
|
33368
|
+
this.createdCommentIds = new Set();
|
|
33369
|
+
this.deletedCommentIds = new Set();
|
|
33370
|
+
}
|
|
33371
|
+
}
|
|
33372
|
+
|
|
33373
|
+
class PostCommentCountEngine {
|
|
33374
|
+
constructor() {
|
|
33375
|
+
this.isProcessing = false;
|
|
33376
|
+
this.tasks = [];
|
|
33377
|
+
this.commentChangeTracker = new Map();
|
|
33378
|
+
}
|
|
33379
|
+
queueCommentChangeTask(task) {
|
|
33380
|
+
this.tasks.push(task);
|
|
33381
|
+
if (!this.isProcessing) {
|
|
33382
|
+
this.processCommentChangeTask();
|
|
33383
|
+
}
|
|
33384
|
+
}
|
|
33385
|
+
processCommentChangeTask() {
|
|
33386
|
+
if (this.isProcessing) {
|
|
33387
|
+
return;
|
|
33388
|
+
}
|
|
33389
|
+
this.isProcessing = true;
|
|
33390
|
+
if (this.tasks.length === 0) {
|
|
33391
|
+
this.isProcessing = false;
|
|
33392
|
+
return;
|
|
33393
|
+
}
|
|
33394
|
+
// Process in capped batches, coalescing updates
|
|
33395
|
+
const batch = this.tasks.splice(0, PostCommentCountEngine.BATCH_SIZE);
|
|
33396
|
+
const modifiedPostIds = new Set();
|
|
33397
|
+
batch.forEach(task => {
|
|
33398
|
+
let modified = false;
|
|
33399
|
+
if (task instanceof ResetTask) {
|
|
33400
|
+
modified = this.processResetTaskInternal(task);
|
|
33401
|
+
}
|
|
33402
|
+
else if (task instanceof CreateTask) {
|
|
33403
|
+
modified = this.processCreateTaskInternal(task);
|
|
33404
|
+
}
|
|
33405
|
+
else if (task instanceof DeleteTask) {
|
|
33406
|
+
modified = this.processDeleteTaskInternal(task);
|
|
33407
|
+
}
|
|
33408
|
+
if (modified) {
|
|
33409
|
+
modifiedPostIds.add(task.postId);
|
|
33410
|
+
}
|
|
33411
|
+
});
|
|
33412
|
+
// Publish one update per modified post
|
|
33413
|
+
modifiedPostIds.forEach(postId => {
|
|
33414
|
+
const count = this.computeCommentCount(postId);
|
|
33415
|
+
PostCommentCountEngine.publishUpdate(postId, count);
|
|
33416
|
+
});
|
|
33417
|
+
this.isProcessing = false;
|
|
33418
|
+
// Recurse if more tasks remain
|
|
33419
|
+
if (this.tasks.length > 0) {
|
|
33420
|
+
this.processCommentChangeTask();
|
|
33421
|
+
}
|
|
33422
|
+
}
|
|
33423
|
+
processResetTaskInternal(task) {
|
|
33424
|
+
// Always creates/overwrites tracker
|
|
33425
|
+
this.commentChangeTracker.set(task.postId, new CommentChange(task.latestCreatedAt, task.serverCommentCount));
|
|
33426
|
+
return true;
|
|
33427
|
+
}
|
|
33428
|
+
processCreateTaskInternal(task) {
|
|
33429
|
+
const tracker = this.commentChangeTracker.get(task.postId);
|
|
33430
|
+
if (!tracker)
|
|
33431
|
+
return false; // No tracker, skip
|
|
33432
|
+
if (tracker.createdCommentIds.has(task.commentId))
|
|
33433
|
+
return false; // Deduplication
|
|
33434
|
+
if (task.createdAt <= tracker.latestCommentCreatedAt)
|
|
33435
|
+
return false; // Timestamp filtering
|
|
33436
|
+
tracker.createdCommentIds.add(task.commentId);
|
|
33437
|
+
return true;
|
|
33438
|
+
}
|
|
33439
|
+
processDeleteTaskInternal(task) {
|
|
33440
|
+
const tracker = this.commentChangeTracker.get(task.postId);
|
|
33441
|
+
if (!tracker)
|
|
33442
|
+
return false; // No tracker, skip
|
|
33443
|
+
if (tracker.deletedCommentIds.has(task.commentId))
|
|
33444
|
+
return false; // Deduplication
|
|
33445
|
+
tracker.deletedCommentIds.add(task.commentId);
|
|
33446
|
+
return true;
|
|
33447
|
+
}
|
|
33448
|
+
computeCommentCount(postId) {
|
|
33449
|
+
const tracker = this.commentChangeTracker.get(postId);
|
|
33450
|
+
if (!tracker)
|
|
33451
|
+
return 0;
|
|
33452
|
+
const count = tracker.serverCommentCount + tracker.createdCommentIds.size - tracker.deletedCommentIds.size;
|
|
33453
|
+
return Math.max(0, count);
|
|
33454
|
+
}
|
|
33455
|
+
static publishUpdate(postId, newCount) {
|
|
33456
|
+
var _a;
|
|
33457
|
+
const queryKey = ['post', 'get', postId];
|
|
33458
|
+
mergeInCache(queryKey, {
|
|
33459
|
+
localCommentCount: newCount,
|
|
33460
|
+
});
|
|
33461
|
+
const postPayload = (_a = pullFromCache(queryKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33462
|
+
if (!postPayload)
|
|
33463
|
+
return;
|
|
33464
|
+
fireEvent('local.post.updated', {
|
|
33465
|
+
posts: [postPayload],
|
|
33466
|
+
});
|
|
33467
|
+
}
|
|
33468
|
+
}
|
|
33469
|
+
PostCommentCountEngine.BATCH_SIZE = 50;
|
|
33470
|
+
let instance;
|
|
33471
|
+
var PostCommentCountEngine$1 = {
|
|
33472
|
+
getInstance: () => {
|
|
33473
|
+
if (!instance) {
|
|
33474
|
+
instance = new PostCommentCountEngine();
|
|
33475
|
+
}
|
|
33476
|
+
return instance;
|
|
33477
|
+
},
|
|
33478
|
+
};
|
|
33479
|
+
|
|
33068
33480
|
const updateStreamReferences = (streams, streamId, postId) => {
|
|
33069
33481
|
if (!streamId)
|
|
33070
33482
|
return streams;
|
|
@@ -33084,14 +33496,26 @@ const preparePostPayload = (payload) => {
|
|
|
33084
33496
|
let mappedNewStream = [];
|
|
33085
33497
|
// feed type
|
|
33086
33498
|
const posts = postsData.map(post => {
|
|
33087
|
-
var _a, _b;
|
|
33499
|
+
var _a, _b, _c, _d;
|
|
33088
33500
|
const feedType = (_a = postPayload.feeds.find(feed => feed.feedId === post.feedId)) === null || _a === void 0 ? void 0 : _a.feedType;
|
|
33089
33501
|
const childPosts = payload.postChildren.filter(children => children.parentPostId === post.postId);
|
|
33090
33502
|
if (childPosts.length > 0 && isAmityLivestreamPost(childPosts[0])) {
|
|
33091
33503
|
mappedNewStream = updateStreamReferences(videoStreamings, (_b = childPosts[0].data) === null || _b === void 0 ? void 0 : _b.streamId, post.postId);
|
|
33092
33504
|
}
|
|
33505
|
+
// --- Computed Comment Count: ResetTask integration ---
|
|
33506
|
+
// Find all comments for this post (referenceType === 'post' && referenceId === postId)
|
|
33507
|
+
const allComments = (payload.comments || []).filter((c) => c.referenceType === 'post' && c.referenceId === post.postId);
|
|
33508
|
+
// Compute latestCreatedAt
|
|
33509
|
+
const latestCreatedAt = allComments.length === 0
|
|
33510
|
+
? new Date().toISOString()
|
|
33511
|
+
: allComments
|
|
33512
|
+
.map(c => c.createdAt)
|
|
33513
|
+
.sort()
|
|
33514
|
+
.at(-1);
|
|
33515
|
+
// Queue ResetTask for this post
|
|
33516
|
+
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new ResetTask(post.postId, latestCreatedAt, (_c = post.commentsCount) !== null && _c !== void 0 ? _c : 0));
|
|
33093
33517
|
return Object.assign(Object.assign({}, post), { childPosts,
|
|
33094
|
-
feedType });
|
|
33518
|
+
feedType, localCommentCount: (_d = post.localCommentCount) !== null && _d !== void 0 ? _d : post.commentsCount });
|
|
33095
33519
|
});
|
|
33096
33520
|
return Object.assign(Object.assign({}, postPayload), { postChildren, videoStreamings: mappedNewStream, posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
33097
33521
|
};
|
|
@@ -33193,14 +33617,12 @@ const createLocalPostEventSubscriber = (event, callback) => {
|
|
|
33193
33617
|
callback(payload.posts[0]);
|
|
33194
33618
|
}
|
|
33195
33619
|
else {
|
|
33196
|
-
const
|
|
33197
|
-
const { communities } = data;
|
|
33198
|
-
ingestInCache(data);
|
|
33620
|
+
const { communities } = payload;
|
|
33199
33621
|
if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['local.post.updated'].includes(event)) {
|
|
33200
33622
|
fireEvent('community.updated', {
|
|
33201
33623
|
communities,
|
|
33202
33624
|
categories: [],
|
|
33203
|
-
communityUsers:
|
|
33625
|
+
communityUsers: payload.communityUsers,
|
|
33204
33626
|
feeds: [],
|
|
33205
33627
|
files: [],
|
|
33206
33628
|
users: [],
|
|
@@ -33471,7 +33893,7 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
33471
33893
|
const createLocalCommentEventSubscriber = (event, callback) => {
|
|
33472
33894
|
const client = getActiveClient();
|
|
33473
33895
|
const filter = (payload) => {
|
|
33474
|
-
var _a, _b;
|
|
33896
|
+
var _a, _b, _c, _d, _e;
|
|
33475
33897
|
if (!client.cache) {
|
|
33476
33898
|
// TODO: here we are missing specific properties here!
|
|
33477
33899
|
callback(LinkedObject.comment(payload.comments[0]));
|
|
@@ -33511,7 +33933,13 @@ const createLocalCommentEventSubscriber = (event, callback) => {
|
|
|
33511
33933
|
}
|
|
33512
33934
|
}
|
|
33513
33935
|
}
|
|
33514
|
-
|
|
33936
|
+
else {
|
|
33937
|
+
const postCacheKey = ['post', 'get', comments[0].referenceId];
|
|
33938
|
+
const postCache = (_a = pullFromCache(postCacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33939
|
+
postCache === null || postCache === void 0 ? void 0 : postCache.comments.push((_b = comments[0]) === null || _b === void 0 ? void 0 : _b.commentId);
|
|
33940
|
+
pushToCache(postCacheKey, postCache);
|
|
33941
|
+
}
|
|
33942
|
+
const queries = (_c = queryCache(['comment', 'query'])) === null || _c === void 0 ? void 0 : _c.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
33515
33943
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
33516
33944
|
}
|
|
33517
33945
|
if (['local.comment.deleted'].includes(event)) {
|
|
@@ -33543,7 +33971,13 @@ const createLocalCommentEventSubscriber = (event, callback) => {
|
|
|
33543
33971
|
}
|
|
33544
33972
|
}
|
|
33545
33973
|
}
|
|
33546
|
-
|
|
33974
|
+
else {
|
|
33975
|
+
const postCacheKey = ['post', 'get', comments[0].referenceId];
|
|
33976
|
+
const postCache = (_d = pullFromCache(postCacheKey)) === null || _d === void 0 ? void 0 : _d.data;
|
|
33977
|
+
const updatedPost = Object.assign(Object.assign({}, postCache), { comments: postCache === null || postCache === void 0 ? void 0 : postCache.comments.filter(commentId => { var _a; return commentId !== ((_a = comments[0]) === null || _a === void 0 ? void 0 : _a.commentId); }) });
|
|
33978
|
+
pushToCache(postCacheKey, updatedPost);
|
|
33979
|
+
}
|
|
33980
|
+
const queries = (_e = queryCache(['comment', 'query'])) === null || _e === void 0 ? void 0 : _e.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
33547
33981
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
33548
33982
|
}
|
|
33549
33983
|
callback(LinkedObject.comment(comment.data));
|
|
@@ -34236,7 +34670,7 @@ const getReactions$1 = (params, callback, config) => {
|
|
|
34236
34670
|
};
|
|
34237
34671
|
/* end_public_function */
|
|
34238
34672
|
|
|
34239
|
-
var index$
|
|
34673
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
34240
34674
|
__proto__: null,
|
|
34241
34675
|
addReaction: addReaction,
|
|
34242
34676
|
removeReaction: removeReaction,
|
|
@@ -36008,7 +36442,7 @@ const getMessages = (params, callback, config) => {
|
|
|
36008
36442
|
};
|
|
36009
36443
|
/* end_public_function */
|
|
36010
36444
|
|
|
36011
|
-
var index$
|
|
36445
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
36012
36446
|
__proto__: null,
|
|
36013
36447
|
createMessage: createMessage,
|
|
36014
36448
|
updateMessage: updateMessage,
|
|
@@ -36534,7 +36968,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
36534
36968
|
};
|
|
36535
36969
|
/* end_public_function */
|
|
36536
36970
|
|
|
36537
|
-
var index$
|
|
36971
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
36538
36972
|
__proto__: null,
|
|
36539
36973
|
getSubChannelByIds: getSubChannels$1,
|
|
36540
36974
|
createSubChannel: createSubChannel,
|
|
@@ -37861,7 +38295,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
37861
38295
|
};
|
|
37862
38296
|
/* end_public_function */
|
|
37863
38297
|
|
|
37864
|
-
var index$
|
|
38298
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
37865
38299
|
__proto__: null,
|
|
37866
38300
|
addMembers: addMembers$1,
|
|
37867
38301
|
removeMembers: removeMembers$1,
|
|
@@ -38064,7 +38498,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
38064
38498
|
};
|
|
38065
38499
|
/* end_public_function */
|
|
38066
38500
|
|
|
38067
|
-
var index$
|
|
38501
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
38068
38502
|
__proto__: null,
|
|
38069
38503
|
addRole: addRole,
|
|
38070
38504
|
removeRole: removeRole,
|
|
@@ -38074,10 +38508,10 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
38074
38508
|
unmuteMembers: unmuteMembers
|
|
38075
38509
|
});
|
|
38076
38510
|
|
|
38077
|
-
var index$
|
|
38511
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
38078
38512
|
__proto__: null,
|
|
38079
|
-
Membership: index$
|
|
38080
|
-
Moderation: index$
|
|
38513
|
+
Membership: index$k,
|
|
38514
|
+
Moderation: index$j,
|
|
38081
38515
|
getChannelByIds: getChannelByIds$1,
|
|
38082
38516
|
createChannel: createChannel,
|
|
38083
38517
|
updateChannel: updateChannel,
|
|
@@ -39480,7 +39914,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
39480
39914
|
};
|
|
39481
39915
|
/* end_public_function */
|
|
39482
39916
|
|
|
39483
|
-
var index$
|
|
39917
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
39484
39918
|
__proto__: null,
|
|
39485
39919
|
addMembers: addMembers,
|
|
39486
39920
|
removeMembers: removeMembers,
|
|
@@ -40731,7 +41165,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
40731
41165
|
};
|
|
40732
41166
|
/* end_public_function */
|
|
40733
41167
|
|
|
40734
|
-
var index$
|
|
41168
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
40735
41169
|
__proto__: null,
|
|
40736
41170
|
addRoles: addRoles,
|
|
40737
41171
|
removeRoles: removeRoles,
|
|
@@ -40739,10 +41173,10 @@ var index$h = /*#__PURE__*/Object.freeze({
|
|
|
40739
41173
|
unbanMembers: unbanMembers
|
|
40740
41174
|
});
|
|
40741
41175
|
|
|
40742
|
-
var index$
|
|
41176
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
40743
41177
|
__proto__: null,
|
|
40744
|
-
Moderation: index$
|
|
40745
|
-
Membership: index$
|
|
41178
|
+
Moderation: index$g,
|
|
41179
|
+
Membership: index$h,
|
|
40746
41180
|
getCommunityByIds: getCommunities$1,
|
|
40747
41181
|
createCommunity: createCommunity,
|
|
40748
41182
|
updateCommunity: updateCommunity,
|
|
@@ -40976,7 +41410,7 @@ const getCategories = (params, callback, config) => {
|
|
|
40976
41410
|
};
|
|
40977
41411
|
/* end_public_function */
|
|
40978
41412
|
|
|
40979
|
-
var index$
|
|
41413
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
40980
41414
|
__proto__: null,
|
|
40981
41415
|
getCategory: getCategory,
|
|
40982
41416
|
getCategories: getCategories
|
|
@@ -41095,9 +41529,6 @@ var EnumPostActions;
|
|
|
41095
41529
|
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
41096
41530
|
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
41097
41531
|
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
41098
|
-
EnumPostActions["OnPostPinProduct"] = "onPostPinProduct";
|
|
41099
|
-
EnumPostActions["OnPostUnpinProduct"] = "onPostUnpinProduct";
|
|
41100
|
-
EnumPostActions["OnPostUpdateProductTags"] = "onPostUpdateProductTags";
|
|
41101
41532
|
})(EnumPostActions || (EnumPostActions = {}));
|
|
41102
41533
|
|
|
41103
41534
|
class CustomRankingGlobalFeedQueryStreamController extends QueryStreamController {
|
|
@@ -41256,7 +41687,6 @@ getCommentByIds.locally = (commentIds) => {
|
|
|
41256
41687
|
* @async
|
|
41257
41688
|
*/
|
|
41258
41689
|
const createComment = async (bundle) => {
|
|
41259
|
-
var _a;
|
|
41260
41690
|
const client = getActiveClient();
|
|
41261
41691
|
client.log('comment/createComment', bundle);
|
|
41262
41692
|
const { data } = await client.http.post('/api/v3/comments', bundle);
|
|
@@ -41268,22 +41698,7 @@ const createComment = async (bundle) => {
|
|
|
41268
41698
|
if (client.cache)
|
|
41269
41699
|
ingestInCache(data, { cachedAt });
|
|
41270
41700
|
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
41271
|
-
|
|
41272
|
-
if (post) {
|
|
41273
|
-
post.commentsCount += 1;
|
|
41274
|
-
fireEvent('local.post.updated', {
|
|
41275
|
-
posts: [post],
|
|
41276
|
-
categories: [],
|
|
41277
|
-
comments: [],
|
|
41278
|
-
communities: [],
|
|
41279
|
-
communityUsers: data.communityUsers,
|
|
41280
|
-
feeds: [],
|
|
41281
|
-
files: data.files,
|
|
41282
|
-
postChildren: [],
|
|
41283
|
-
users: data.users,
|
|
41284
|
-
videoStreamings: [],
|
|
41285
|
-
});
|
|
41286
|
-
}
|
|
41701
|
+
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new CreateTask(bundle.referenceId, comments[0].commentId, data.comments[0].createdAt));
|
|
41287
41702
|
}
|
|
41288
41703
|
else if (bundle.referenceType === 'story') {
|
|
41289
41704
|
const storyIndex = pullFromCache([
|
|
@@ -41442,7 +41857,7 @@ getStoryByStoryId$1.locally = (storyId) => {
|
|
|
41442
41857
|
* @async
|
|
41443
41858
|
*/
|
|
41444
41859
|
const deleteComment = async (commentId, permanent = false) => {
|
|
41445
|
-
var _a;
|
|
41860
|
+
var _a, _b;
|
|
41446
41861
|
const client = getActiveClient();
|
|
41447
41862
|
const comment = await getComment$2(commentId);
|
|
41448
41863
|
// API-FIX: This endpoint has not been implemented yet.
|
|
@@ -41475,26 +41890,14 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
41475
41890
|
else {
|
|
41476
41891
|
const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
41477
41892
|
if (post) {
|
|
41478
|
-
|
|
41479
|
-
|
|
41480
|
-
|
|
41481
|
-
|
|
41893
|
+
const engine = PostCommentCountEngine$1.getInstance();
|
|
41894
|
+
engine.queueCommentChangeTask(new DeleteTask(post.postId, commentId));
|
|
41895
|
+
if (!deleted.parentId && ((_b = deleted.children) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
41896
|
+
// NOTE: delete the parent comment will also remove all children comments
|
|
41897
|
+
deleted.children.forEach((childCommentId) => {
|
|
41898
|
+
engine.queueCommentChangeTask(new DeleteTask(post.postId, childCommentId));
|
|
41899
|
+
});
|
|
41482
41900
|
}
|
|
41483
|
-
else
|
|
41484
|
-
removeCount = 1;
|
|
41485
|
-
post.commentsCount -= removeCount;
|
|
41486
|
-
fireEvent('local.post.updated', {
|
|
41487
|
-
posts: [post],
|
|
41488
|
-
categories: [],
|
|
41489
|
-
comments: [],
|
|
41490
|
-
communities: [],
|
|
41491
|
-
communityUsers: [],
|
|
41492
|
-
feeds: [],
|
|
41493
|
-
files: [],
|
|
41494
|
-
postChildren: [],
|
|
41495
|
-
users: [],
|
|
41496
|
-
videoStreamings: [],
|
|
41497
|
-
});
|
|
41498
41901
|
}
|
|
41499
41902
|
}
|
|
41500
41903
|
fireEvent('local.comment.deleted', {
|
|
@@ -42038,7 +42441,7 @@ const getComments = (params, callback, config) => {
|
|
|
42038
42441
|
};
|
|
42039
42442
|
/* end_public_function */
|
|
42040
42443
|
|
|
42041
|
-
var index$
|
|
42444
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
42042
42445
|
__proto__: null,
|
|
42043
42446
|
getCommentByIds: getCommentByIds,
|
|
42044
42447
|
createComment: createComment,
|
|
@@ -42060,47 +42463,6 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
42060
42463
|
getComments: getComments
|
|
42061
42464
|
});
|
|
42062
42465
|
|
|
42063
|
-
const getPost$1 = async (postId) => {
|
|
42064
|
-
const client = getActiveClient();
|
|
42065
|
-
client.log('post/getPost', postId);
|
|
42066
|
-
isInTombstone('post', postId);
|
|
42067
|
-
let payload;
|
|
42068
|
-
try {
|
|
42069
|
-
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
42070
|
-
const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
|
|
42071
|
-
payload = response.data;
|
|
42072
|
-
}
|
|
42073
|
-
catch (error) {
|
|
42074
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
42075
|
-
pushToTombstone('post', postId);
|
|
42076
|
-
}
|
|
42077
|
-
throw error;
|
|
42078
|
-
}
|
|
42079
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
42080
|
-
const cachedAt = client.cache && Date.now();
|
|
42081
|
-
if (client.cache)
|
|
42082
|
-
ingestInCache(data, { cachedAt });
|
|
42083
|
-
const { posts } = data;
|
|
42084
|
-
const result = posts.find(post => post.postId === postId);
|
|
42085
|
-
return {
|
|
42086
|
-
data: result,
|
|
42087
|
-
cachedAt,
|
|
42088
|
-
};
|
|
42089
|
-
};
|
|
42090
|
-
getPost$1.locally = (postId) => {
|
|
42091
|
-
const client = getActiveClient();
|
|
42092
|
-
client.log('post/getPost.locally', postId);
|
|
42093
|
-
if (!client.cache)
|
|
42094
|
-
return;
|
|
42095
|
-
const cached = pullFromCache(['post', 'get', postId]);
|
|
42096
|
-
if (!cached)
|
|
42097
|
-
return;
|
|
42098
|
-
return {
|
|
42099
|
-
data: cached.data,
|
|
42100
|
-
cachedAt: cached.cachedAt,
|
|
42101
|
-
};
|
|
42102
|
-
};
|
|
42103
|
-
|
|
42104
42466
|
/**
|
|
42105
42467
|
* ```js
|
|
42106
42468
|
* import { onLocalPostDeleted } from '@amityco/ts-sdk'
|
|
@@ -42199,7 +42561,6 @@ const commentEventHandler$1 = (callback, eventHandler, cacheKey) => {
|
|
|
42199
42561
|
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
42200
42562
|
if (!currentCollection || !currentCollection.data.includes(comment.referenceId))
|
|
42201
42563
|
return;
|
|
42202
|
-
await getPost$1(comment.referenceId);
|
|
42203
42564
|
callback(comment);
|
|
42204
42565
|
});
|
|
42205
42566
|
};
|
|
@@ -42207,12 +42568,8 @@ const generateCommentSubscriptions$1 = (cacheKey) => {
|
|
|
42207
42568
|
const eventHandlers = [
|
|
42208
42569
|
onCommentCreated,
|
|
42209
42570
|
onCommentDeleted,
|
|
42210
|
-
onCommentReactionAdded,
|
|
42211
|
-
onCommentReactionRemoved,
|
|
42212
42571
|
onCommentCreatedLocal,
|
|
42213
42572
|
onCommentDeleteLocal,
|
|
42214
|
-
onLocalCommentReactionAdded,
|
|
42215
|
-
onLocalCommentReactionRemoved,
|
|
42216
42573
|
];
|
|
42217
42574
|
return eventHandlers.map(handler => ({
|
|
42218
42575
|
fn: convertEventPayload((callback) => commentEventHandler$1(callback, handler, cacheKey), 'referenceId', 'post'),
|
|
@@ -42576,6 +42933,47 @@ class UserFeedQueryStreamController extends QueryStreamController {
|
|
|
42576
42933
|
}
|
|
42577
42934
|
}
|
|
42578
42935
|
|
|
42936
|
+
const getPost$1 = async (postId) => {
|
|
42937
|
+
const client = getActiveClient();
|
|
42938
|
+
client.log('post/getPost', postId);
|
|
42939
|
+
isInTombstone('post', postId);
|
|
42940
|
+
let payload;
|
|
42941
|
+
try {
|
|
42942
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
42943
|
+
const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
|
|
42944
|
+
payload = response.data;
|
|
42945
|
+
}
|
|
42946
|
+
catch (error) {
|
|
42947
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
42948
|
+
pushToTombstone('post', postId);
|
|
42949
|
+
}
|
|
42950
|
+
throw error;
|
|
42951
|
+
}
|
|
42952
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
42953
|
+
const cachedAt = client.cache && Date.now();
|
|
42954
|
+
if (client.cache)
|
|
42955
|
+
ingestInCache(data, { cachedAt });
|
|
42956
|
+
const { posts } = data;
|
|
42957
|
+
const result = posts.find(post => post.postId === postId);
|
|
42958
|
+
return {
|
|
42959
|
+
data: result,
|
|
42960
|
+
cachedAt,
|
|
42961
|
+
};
|
|
42962
|
+
};
|
|
42963
|
+
getPost$1.locally = (postId) => {
|
|
42964
|
+
const client = getActiveClient();
|
|
42965
|
+
client.log('post/getPost.locally', postId);
|
|
42966
|
+
if (!client.cache)
|
|
42967
|
+
return;
|
|
42968
|
+
const cached = pullFromCache(['post', 'get', postId]);
|
|
42969
|
+
if (!cached)
|
|
42970
|
+
return;
|
|
42971
|
+
return {
|
|
42972
|
+
data: cached.data,
|
|
42973
|
+
cachedAt: cached.cachedAt,
|
|
42974
|
+
};
|
|
42975
|
+
};
|
|
42976
|
+
|
|
42579
42977
|
class UserFeedLiveCollectionController extends LiveCollectionController {
|
|
42580
42978
|
constructor(query, callback) {
|
|
42581
42979
|
const queryStreamId = hash(query);
|
|
@@ -42709,12 +43107,240 @@ const getUserFeed = (params, callback, config) => {
|
|
|
42709
43107
|
};
|
|
42710
43108
|
/* end_public_function */
|
|
42711
43109
|
|
|
42712
|
-
|
|
43110
|
+
class CommunityFeedPaginationController extends PaginationController {
|
|
43111
|
+
async getRequest(queryParams, token) {
|
|
43112
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted, communityId } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted", "communityId"]);
|
|
43113
|
+
const options = token ? { token } : { limit };
|
|
43114
|
+
const { data: queryResponse } = await this.http.get(`/api/v5/posts`, {
|
|
43115
|
+
params: Object.assign(Object.assign({}, params), { targetId: communityId, targetType: 'community', isDeleted: inferIsDeleted(includeDeleted), matchingOnlyParentPost: true, options }),
|
|
43116
|
+
});
|
|
43117
|
+
return queryResponse;
|
|
43118
|
+
}
|
|
43119
|
+
}
|
|
43120
|
+
|
|
43121
|
+
class CommunityFeedQueryStreamController extends QueryStreamController {
|
|
43122
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
43123
|
+
super(query, cacheKey);
|
|
43124
|
+
this.notifyChange = notifyChange;
|
|
43125
|
+
this.preparePayload = preparePayload;
|
|
43126
|
+
}
|
|
43127
|
+
async saveToMainDB(response) {
|
|
43128
|
+
const processedPayload = await this.preparePayload(response);
|
|
43129
|
+
const client = getActiveClient();
|
|
43130
|
+
const cachedAt = client.cache && Date.now();
|
|
43131
|
+
if (client.cache) {
|
|
43132
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
43133
|
+
}
|
|
43134
|
+
}
|
|
43135
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
43136
|
+
var _a, _b;
|
|
43137
|
+
if (refresh) {
|
|
43138
|
+
pushToCache(this.cacheKey, {
|
|
43139
|
+
data: response.posts.map(getResolver('post')),
|
|
43140
|
+
});
|
|
43141
|
+
}
|
|
43142
|
+
else {
|
|
43143
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43144
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
43145
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
43146
|
+
}
|
|
43147
|
+
}
|
|
43148
|
+
reactor(action) {
|
|
43149
|
+
return (post) => {
|
|
43150
|
+
var _a, _b;
|
|
43151
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43152
|
+
if (!collection)
|
|
43153
|
+
return;
|
|
43154
|
+
if (action === EnumPostActions.OnPostDeleted) {
|
|
43155
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
43156
|
+
}
|
|
43157
|
+
if (post.parentPostId && post.isDeleted) {
|
|
43158
|
+
const parentPost = (_b = pullFromCache([
|
|
43159
|
+
'post',
|
|
43160
|
+
'get',
|
|
43161
|
+
post.parentPostId,
|
|
43162
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
43163
|
+
if (!parentPost)
|
|
43164
|
+
return;
|
|
43165
|
+
parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
|
|
43166
|
+
pushToCache(['post', 'get', parentPost.postId], parentPost);
|
|
43167
|
+
}
|
|
43168
|
+
if (action === EnumPostActions.OnPostDeclined) {
|
|
43169
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
43170
|
+
}
|
|
43171
|
+
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
43172
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
43173
|
+
}
|
|
43174
|
+
pushToCache(this.cacheKey, collection);
|
|
43175
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
43176
|
+
};
|
|
43177
|
+
}
|
|
43178
|
+
subscribeRTE(createSubscriber) {
|
|
43179
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
43180
|
+
}
|
|
43181
|
+
}
|
|
43182
|
+
|
|
43183
|
+
const commentEventHandler = (callback, eventHandler, cacheKey, resolveId) => {
|
|
43184
|
+
return eventHandler(async (comment) => {
|
|
43185
|
+
var _a;
|
|
43186
|
+
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43187
|
+
if (!currentCollection ||
|
|
43188
|
+
!currentCollection.data.includes(resolveId ? resolveId(comment.referenceId) : comment.referenceId))
|
|
43189
|
+
return;
|
|
43190
|
+
callback(comment);
|
|
43191
|
+
});
|
|
43192
|
+
};
|
|
43193
|
+
const generateCommentSubscriptions = ({ cacheKey, resolveId, }) => {
|
|
43194
|
+
const eventHandlers = [
|
|
43195
|
+
onCommentCreated,
|
|
43196
|
+
onCommentDeleted,
|
|
43197
|
+
onCommentCreatedLocal,
|
|
43198
|
+
onCommentDeleteLocal,
|
|
43199
|
+
];
|
|
43200
|
+
return eventHandlers.map(handler => ({
|
|
43201
|
+
fn: convertEventPayload((callback) => commentEventHandler(callback, handler, cacheKey, resolveId), 'referenceId', 'post'),
|
|
43202
|
+
action: EnumPostActions.OnPostUpdated,
|
|
43203
|
+
}));
|
|
43204
|
+
};
|
|
43205
|
+
const getPostSubscription = (cacheKey) => {
|
|
43206
|
+
return [
|
|
43207
|
+
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
43208
|
+
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
43209
|
+
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
43210
|
+
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
43211
|
+
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
43212
|
+
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
43213
|
+
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
43214
|
+
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
43215
|
+
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
43216
|
+
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
43217
|
+
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
43218
|
+
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
43219
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
43220
|
+
...generateCommentSubscriptions({ cacheKey }),
|
|
43221
|
+
];
|
|
43222
|
+
};
|
|
43223
|
+
const resolvePostIdsFromRooms = (rooms, posts) => {
|
|
43224
|
+
var _a;
|
|
43225
|
+
return ((_a = rooms
|
|
43226
|
+
.map(room => {
|
|
43227
|
+
const post = posts.find(post => post.postId === room.referenceId);
|
|
43228
|
+
return post ? getResolver('post')({ postId: post === null || post === void 0 ? void 0 : post.postId }) : undefined;
|
|
43229
|
+
})
|
|
43230
|
+
.filter(isNonNullable)) !== null && _a !== void 0 ? _a : []);
|
|
43231
|
+
};
|
|
43232
|
+
|
|
43233
|
+
class CommunityFeedLiveCollectionController extends LiveCollectionController {
|
|
43234
|
+
constructor(query, callback) {
|
|
43235
|
+
const queryStreamId = hash(query);
|
|
43236
|
+
const cacheKey = ['communityFeed', 'collection', queryStreamId];
|
|
43237
|
+
const paginationController = new CommunityFeedPaginationController(query);
|
|
43238
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
43239
|
+
this.query = query;
|
|
43240
|
+
this.queryStreamController = new CommunityFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
43241
|
+
this.callback = callback.bind(this);
|
|
43242
|
+
this.loadPage({ initial: true });
|
|
43243
|
+
}
|
|
43244
|
+
setup() {
|
|
43245
|
+
var _a;
|
|
43246
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43247
|
+
if (!collection) {
|
|
43248
|
+
pushToCache(this.cacheKey, {
|
|
43249
|
+
data: [],
|
|
43250
|
+
params: {},
|
|
43251
|
+
});
|
|
43252
|
+
}
|
|
43253
|
+
}
|
|
43254
|
+
async persistModel(queryPayload) {
|
|
43255
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
43256
|
+
}
|
|
43257
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
43258
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
43259
|
+
}
|
|
43260
|
+
startSubscription() {
|
|
43261
|
+
return this.queryStreamController.subscribeRTE(getPostSubscription(this.cacheKey));
|
|
43262
|
+
}
|
|
43263
|
+
notifyChange({ origin, loading, error }) {
|
|
43264
|
+
var _a, _b;
|
|
43265
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43266
|
+
if (!collection)
|
|
43267
|
+
return;
|
|
43268
|
+
const data = ((_b = collection.data
|
|
43269
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
43270
|
+
.filter(isNonNullable)
|
|
43271
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
43272
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
43273
|
+
return;
|
|
43274
|
+
this.callback({
|
|
43275
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
43276
|
+
data,
|
|
43277
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
43278
|
+
loading,
|
|
43279
|
+
error,
|
|
43280
|
+
});
|
|
43281
|
+
}
|
|
43282
|
+
}
|
|
43283
|
+
|
|
43284
|
+
/* begin_public_function
|
|
43285
|
+
id: feed.query.community_feed
|
|
43286
|
+
*/
|
|
43287
|
+
/**
|
|
43288
|
+
* ```js
|
|
43289
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
43290
|
+
*
|
|
43291
|
+
* let posts = []
|
|
43292
|
+
* const unsubscribe = FeedRepository.getCommunityFeed({
|
|
43293
|
+
* communityId: 'community-id',
|
|
43294
|
+
* sortBy?: 'lastCreated' | 'firstCreated' | 'lastUpdated' | 'firstUpdated',
|
|
43295
|
+
* includeDeleted?: boolean,
|
|
43296
|
+
* feedType?: 'reviewing' | 'published' | 'declined',
|
|
43297
|
+
* tags?: string[],
|
|
43298
|
+
* includeMixedStructure?: boolean,
|
|
43299
|
+
* limit?: number,
|
|
43300
|
+
* }, response => processResponse(response))
|
|
43301
|
+
* ```
|
|
43302
|
+
*
|
|
43303
|
+
* Observe all mutations on a list of {@link Amity.Post} for a given community feed.
|
|
43304
|
+
*
|
|
43305
|
+
* @param params - Parameters for querying the community feed:
|
|
43306
|
+
* @param params.communityId The ID of the community (required)
|
|
43307
|
+
* @param params.sortBy The sorting order of the feed (optional)
|
|
43308
|
+
* @param params.includeDeleted Whether to include deleted posts (optional)
|
|
43309
|
+
* @param params.feedType The type of the feed: 'reviewing', 'published', or 'declined' (optional)
|
|
43310
|
+
* @param params.tags Array of tags to filter posts (optional)
|
|
43311
|
+
* @param params.includeMixedStructure Whether to include mixed structure posts (optional)
|
|
43312
|
+
* @param params.limit The maximum number of posts to retrieve (optional)
|
|
43313
|
+
* @param callback The function to call when new data are available
|
|
43314
|
+
* @param config Additional live collection configuration (optional)
|
|
43315
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the feed
|
|
43316
|
+
*
|
|
43317
|
+
* @category Posts Live Collection
|
|
43318
|
+
*/
|
|
43319
|
+
const getCommunityFeed = (params, callback, config) => {
|
|
43320
|
+
const { log, cache } = getActiveClient();
|
|
43321
|
+
if (!cache) {
|
|
43322
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
43323
|
+
}
|
|
43324
|
+
const timestamp = Date.now();
|
|
43325
|
+
log(`getCommunityFeed(tmpid: ${timestamp}) > listen`);
|
|
43326
|
+
const communityFeedLiveCollection = new CommunityFeedLiveCollectionController(params, callback);
|
|
43327
|
+
const disposers = communityFeedLiveCollection.startSubscription();
|
|
43328
|
+
const cacheKey = communityFeedLiveCollection.getCacheKey();
|
|
43329
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
43330
|
+
return () => {
|
|
43331
|
+
log(`getCommunityFeed(tmpid: ${timestamp}) > dispose`);
|
|
43332
|
+
disposers.forEach(fn => fn());
|
|
43333
|
+
};
|
|
43334
|
+
};
|
|
43335
|
+
/* end_public_function */
|
|
43336
|
+
|
|
43337
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
42713
43338
|
__proto__: null,
|
|
42714
43339
|
queryGlobalFeed: queryGlobalFeed,
|
|
42715
43340
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
42716
43341
|
getGlobalFeed: getGlobalFeed,
|
|
42717
|
-
getUserFeed: getUserFeed
|
|
43342
|
+
getUserFeed: getUserFeed,
|
|
43343
|
+
getCommunityFeed: getCommunityFeed
|
|
42718
43344
|
});
|
|
42719
43345
|
|
|
42720
43346
|
/* begin_public_function
|
|
@@ -42824,17 +43450,7 @@ const createPost = async (bundle) => {
|
|
|
42824
43450
|
// eslint-disable-next-line no-param-reassign
|
|
42825
43451
|
delete bundle.dataType;
|
|
42826
43452
|
}
|
|
42827
|
-
const {
|
|
42828
|
-
const processedAttachments = attachments && attachments.length > 0 && bundle.attachmentProductTags
|
|
42829
|
-
? attachments.map(attachment => {
|
|
42830
|
-
var _a;
|
|
42831
|
-
const productTags = (_a = bundle.attachmentProductTags) === null || _a === void 0 ? void 0 : _a.get(attachment.fileId);
|
|
42832
|
-
if (productTags)
|
|
42833
|
-
return Object.assign(Object.assign({}, attachment), { productTags });
|
|
42834
|
-
return attachment;
|
|
42835
|
-
})
|
|
42836
|
-
: attachments;
|
|
42837
|
-
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
|
|
43453
|
+
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
42838
43454
|
fireEvent('post.created', payload);
|
|
42839
43455
|
const data = preparePostPayload(payload);
|
|
42840
43456
|
const cachedAt = client.cache && Date.now();
|
|
@@ -42871,17 +43487,7 @@ const createPost = async (bundle) => {
|
|
|
42871
43487
|
const editPost = async (postId, patch) => {
|
|
42872
43488
|
const client = getActiveClient();
|
|
42873
43489
|
client.log('user/editPost', patch);
|
|
42874
|
-
const {
|
|
42875
|
-
const processedAttachments = attachments && attachments.length > 0 && patch.attachmentProductTags
|
|
42876
|
-
? attachments.map(attachment => {
|
|
42877
|
-
var _a;
|
|
42878
|
-
const productTags = (_a = patch.attachmentProductTags) === null || _a === void 0 ? void 0 : _a.get(attachment.fileId);
|
|
42879
|
-
if (productTags)
|
|
42880
|
-
return Object.assign(Object.assign({}, attachment), { productTags });
|
|
42881
|
-
return attachment;
|
|
42882
|
-
})
|
|
42883
|
-
: attachments;
|
|
42884
|
-
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, Object.assign(Object.assign({}, patch), { attachments: processedAttachments }));
|
|
43490
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
|
|
42885
43491
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
42886
43492
|
const cachedAt = client.cache && Date.now();
|
|
42887
43493
|
if (client.cache)
|
|
@@ -43208,17 +43814,7 @@ const isPostFlaggedByMe = async (postId) => {
|
|
|
43208
43814
|
const createClipPost = async (bundle) => {
|
|
43209
43815
|
const client = getActiveClient();
|
|
43210
43816
|
client.log('post/createPost', bundle);
|
|
43211
|
-
const {
|
|
43212
|
-
const processedAttachments = attachments && attachments.length > 0 && bundle.attachmentProductTags
|
|
43213
|
-
? attachments.map(attachment => {
|
|
43214
|
-
var _a;
|
|
43215
|
-
const productTags = (_a = bundle.attachmentProductTags) === null || _a === void 0 ? void 0 : _a.get(attachment.fileId);
|
|
43216
|
-
if (productTags)
|
|
43217
|
-
return Object.assign(Object.assign({}, attachment), { productTags });
|
|
43218
|
-
return attachment;
|
|
43219
|
-
})
|
|
43220
|
-
: attachments;
|
|
43221
|
-
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
|
|
43817
|
+
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
43222
43818
|
fireEvent('post.created', payload);
|
|
43223
43819
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
43224
43820
|
const cachedAt = client.cache && Date.now();
|
|
@@ -43257,16 +43853,7 @@ const createClipPost = async (bundle) => {
|
|
|
43257
43853
|
const createAudioPost = async (bundle) => {
|
|
43258
43854
|
const client = getActiveClient();
|
|
43259
43855
|
client.log('post/createAudioPost', bundle);
|
|
43260
|
-
const {
|
|
43261
|
-
const processedAttachments = attachments && attachments.length > 0 && attachmentProductTags
|
|
43262
|
-
? attachments.map(attachment => {
|
|
43263
|
-
const productTags = attachmentProductTags === null || attachmentProductTags === void 0 ? void 0 : attachmentProductTags.get(attachment.fileId);
|
|
43264
|
-
if (productTags)
|
|
43265
|
-
return Object.assign(Object.assign({}, attachment), { productTags });
|
|
43266
|
-
return attachment;
|
|
43267
|
-
})
|
|
43268
|
-
: attachments;
|
|
43269
|
-
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
|
|
43856
|
+
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
43270
43857
|
fireEvent('post.created', payload);
|
|
43271
43858
|
const data = preparePostPayload(payload);
|
|
43272
43859
|
const cachedAt = client.cache && Date.now();
|
|
@@ -43310,17 +43897,7 @@ const createMixedMediaPost = async (bundle) => {
|
|
|
43310
43897
|
var _a;
|
|
43311
43898
|
const client = getActiveClient();
|
|
43312
43899
|
client.log('post/createMixedMediaPost', bundle);
|
|
43313
|
-
const {
|
|
43314
|
-
const processedAttachments = attachments && attachments.length > 0 && bundle.attachmentProductTags
|
|
43315
|
-
? attachments.map(attachment => {
|
|
43316
|
-
var _a;
|
|
43317
|
-
const productTags = (_a = bundle.attachmentProductTags) === null || _a === void 0 ? void 0 : _a.get(attachment.fileId);
|
|
43318
|
-
if (productTags)
|
|
43319
|
-
return Object.assign(Object.assign({}, attachment), { productTags });
|
|
43320
|
-
return attachment;
|
|
43321
|
-
})
|
|
43322
|
-
: attachments;
|
|
43323
|
-
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, rest), { attachments: processedAttachments }));
|
|
43900
|
+
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
43324
43901
|
fireEvent('post.created', payload);
|
|
43325
43902
|
const data = preparePostPayload(payload);
|
|
43326
43903
|
const cachedAt = client.cache && Date.now();
|
|
@@ -43333,143 +43910,6 @@ const createMixedMediaPost = async (bundle) => {
|
|
|
43333
43910
|
};
|
|
43334
43911
|
/* end_public_function */
|
|
43335
43912
|
|
|
43336
|
-
/* begin_public_function
|
|
43337
|
-
id: post.create_room_post
|
|
43338
|
-
*/
|
|
43339
|
-
/**
|
|
43340
|
-
* ```js
|
|
43341
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
43342
|
-
* const created = await PostRepository.createRoomPost({
|
|
43343
|
-
* targetType: 'user',
|
|
43344
|
-
* targetId: 'foobar',
|
|
43345
|
-
* data: { text: 'hello world', title: 'Room Title', roomId: 'roomId123' }
|
|
43346
|
-
* }))
|
|
43347
|
-
* ```
|
|
43348
|
-
*
|
|
43349
|
-
* Creates an {@link Amity.Post}
|
|
43350
|
-
*
|
|
43351
|
-
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
43352
|
-
* @returns The newly created {@link Amity.Post}
|
|
43353
|
-
*
|
|
43354
|
-
* @category Post API
|
|
43355
|
-
* @async
|
|
43356
|
-
*/
|
|
43357
|
-
const createRoomPost = async (bundle) => {
|
|
43358
|
-
const client = getActiveClient();
|
|
43359
|
-
client.log('post/createRoomPost', bundle);
|
|
43360
|
-
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, bundle), { dataType: 'room' }));
|
|
43361
|
-
fireEvent('post.created', payload);
|
|
43362
|
-
const data = preparePostPayload(payload);
|
|
43363
|
-
const cachedAt = client.cache && Date.now();
|
|
43364
|
-
if (client.cache)
|
|
43365
|
-
ingestInCache(data, { cachedAt });
|
|
43366
|
-
const { posts } = data;
|
|
43367
|
-
return {
|
|
43368
|
-
data: LinkedObject.post(posts[0]),
|
|
43369
|
-
cachedAt,
|
|
43370
|
-
};
|
|
43371
|
-
};
|
|
43372
|
-
/* end_public_function */
|
|
43373
|
-
|
|
43374
|
-
/* begin_public_function
|
|
43375
|
-
id: post.pin_product
|
|
43376
|
-
*/
|
|
43377
|
-
/**
|
|
43378
|
-
* ```js
|
|
43379
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
43380
|
-
* const pinProduct = await PostRepository.pinProduct(postId, pinnedProductId)
|
|
43381
|
-
* ```
|
|
43382
|
-
*
|
|
43383
|
-
* @param postId The ID of the post to unpin the product from
|
|
43384
|
-
* @param productId the ID of the product to pin
|
|
43385
|
-
* @returns Amity.Post
|
|
43386
|
-
*
|
|
43387
|
-
* @category Post API
|
|
43388
|
-
* @async
|
|
43389
|
-
* */
|
|
43390
|
-
const pinProduct = async (postId, pinnedProductId) => {
|
|
43391
|
-
const client = getActiveClient();
|
|
43392
|
-
client.log('post/pinProduct', postId);
|
|
43393
|
-
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
43394
|
-
pinnedProductId,
|
|
43395
|
-
});
|
|
43396
|
-
const data = preparePostPayload(payload);
|
|
43397
|
-
const cachedAt = client.cache && Date.now();
|
|
43398
|
-
if (client.cache)
|
|
43399
|
-
ingestInCache(payload, { cachedAt });
|
|
43400
|
-
fireEvent('local.post.updated', payload);
|
|
43401
|
-
return {
|
|
43402
|
-
data: postLinkedObject(data === null || data === void 0 ? void 0 : data.posts[0]),
|
|
43403
|
-
cachedAt,
|
|
43404
|
-
};
|
|
43405
|
-
};
|
|
43406
|
-
/* end_public_function */
|
|
43407
|
-
|
|
43408
|
-
/* begin_public_function
|
|
43409
|
-
id: post.unpin_product
|
|
43410
|
-
*/
|
|
43411
|
-
/**
|
|
43412
|
-
* ```js
|
|
43413
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
43414
|
-
* const unpinProduct = await PostRepository.unpinProduct(postId)
|
|
43415
|
-
* ```
|
|
43416
|
-
*
|
|
43417
|
-
* @param postId The ID of the post to unpin the product from
|
|
43418
|
-
* @returns Amity.Post
|
|
43419
|
-
*
|
|
43420
|
-
* @category Post API
|
|
43421
|
-
* @async
|
|
43422
|
-
* */
|
|
43423
|
-
const unpinProduct = async (postId) => {
|
|
43424
|
-
const client = getActiveClient();
|
|
43425
|
-
client.log('post/unpinProduct', postId);
|
|
43426
|
-
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, { pinnedProductId: null });
|
|
43427
|
-
const data = preparePostPayload(payload);
|
|
43428
|
-
const cachedAt = client.cache && Date.now();
|
|
43429
|
-
if (client.cache)
|
|
43430
|
-
ingestInCache(payload, { cachedAt });
|
|
43431
|
-
fireEvent('local.post.updated', payload);
|
|
43432
|
-
return {
|
|
43433
|
-
data: postLinkedObject(data === null || data === void 0 ? void 0 : data.posts[0]),
|
|
43434
|
-
cachedAt,
|
|
43435
|
-
};
|
|
43436
|
-
};
|
|
43437
|
-
/* end_public_function */
|
|
43438
|
-
|
|
43439
|
-
/* begin_public_function
|
|
43440
|
-
id: post.update_product_tags
|
|
43441
|
-
*/
|
|
43442
|
-
/**
|
|
43443
|
-
* ```js
|
|
43444
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
43445
|
-
* const updateProductTags = await PostRepository.updateProductTags(postId, productTags)
|
|
43446
|
-
* ```
|
|
43447
|
-
*
|
|
43448
|
-
* @param postId of child room
|
|
43449
|
-
* @param productTags the array of product tags to set on the post
|
|
43450
|
-
* @returns Amity.Post
|
|
43451
|
-
*
|
|
43452
|
-
* @category Post API
|
|
43453
|
-
* @async
|
|
43454
|
-
* */
|
|
43455
|
-
const updateProductTags = async (postId, productTags) => {
|
|
43456
|
-
const client = getActiveClient();
|
|
43457
|
-
client.log('post/updateProductTags', postId);
|
|
43458
|
-
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
43459
|
-
productTags,
|
|
43460
|
-
});
|
|
43461
|
-
const data = preparePostPayload(payload);
|
|
43462
|
-
const cachedAt = client.cache && Date.now();
|
|
43463
|
-
if (client.cache)
|
|
43464
|
-
ingestInCache(payload, { cachedAt });
|
|
43465
|
-
fireEvent('local.post.updated', payload);
|
|
43466
|
-
return {
|
|
43467
|
-
data: postLinkedObject(data === null || data === void 0 ? void 0 : data.posts[0]),
|
|
43468
|
-
cachedAt,
|
|
43469
|
-
};
|
|
43470
|
-
};
|
|
43471
|
-
/* end_public_function */
|
|
43472
|
-
|
|
43473
43913
|
/* begin_public_function
|
|
43474
43914
|
id: post.get
|
|
43475
43915
|
*/
|
|
@@ -43646,61 +44086,6 @@ class PostQueryStreamController extends QueryStreamController {
|
|
|
43646
44086
|
}
|
|
43647
44087
|
}
|
|
43648
44088
|
|
|
43649
|
-
const commentEventHandler = (callback, eventHandler, cacheKey, resolveId) => {
|
|
43650
|
-
return eventHandler(async (comment) => {
|
|
43651
|
-
var _a;
|
|
43652
|
-
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
43653
|
-
if (!currentCollection ||
|
|
43654
|
-
!currentCollection.data.includes(resolveId ? resolveId(comment.referenceId) : comment.referenceId))
|
|
43655
|
-
return;
|
|
43656
|
-
await getPost$1(comment.referenceId);
|
|
43657
|
-
callback(comment);
|
|
43658
|
-
});
|
|
43659
|
-
};
|
|
43660
|
-
const generateCommentSubscriptions = ({ cacheKey, resolveId, }) => {
|
|
43661
|
-
const eventHandlers = [
|
|
43662
|
-
onCommentCreated,
|
|
43663
|
-
onCommentDeleted,
|
|
43664
|
-
onCommentReactionAdded,
|
|
43665
|
-
onCommentReactionRemoved,
|
|
43666
|
-
onCommentCreatedLocal,
|
|
43667
|
-
onCommentDeleteLocal,
|
|
43668
|
-
onLocalCommentReactionAdded,
|
|
43669
|
-
onLocalCommentReactionRemoved,
|
|
43670
|
-
];
|
|
43671
|
-
return eventHandlers.map(handler => ({
|
|
43672
|
-
fn: convertEventPayload((callback) => commentEventHandler(callback, handler, cacheKey, resolveId), 'referenceId', 'post'),
|
|
43673
|
-
action: EnumPostActions.OnPostUpdated,
|
|
43674
|
-
}));
|
|
43675
|
-
};
|
|
43676
|
-
const getPostSubscription = (cacheKey) => {
|
|
43677
|
-
return [
|
|
43678
|
-
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
43679
|
-
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
43680
|
-
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
43681
|
-
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
43682
|
-
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
43683
|
-
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
43684
|
-
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
43685
|
-
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
43686
|
-
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
43687
|
-
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
43688
|
-
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
43689
|
-
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
43690
|
-
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
43691
|
-
...generateCommentSubscriptions({ cacheKey }),
|
|
43692
|
-
];
|
|
43693
|
-
};
|
|
43694
|
-
const resolvePostIdsFromRooms = (rooms, posts) => {
|
|
43695
|
-
var _a;
|
|
43696
|
-
return ((_a = rooms
|
|
43697
|
-
.map(room => {
|
|
43698
|
-
const post = posts.find(post => post.postId === room.referenceId);
|
|
43699
|
-
return post ? getResolver('post')({ postId: post === null || post === void 0 ? void 0 : post.postId }) : undefined;
|
|
43700
|
-
})
|
|
43701
|
-
.filter(isNonNullable)) !== null && _a !== void 0 ? _a : []);
|
|
43702
|
-
};
|
|
43703
|
-
|
|
43704
44089
|
class PostLiveCollectionController extends LiveCollectionController {
|
|
43705
44090
|
constructor(query, callback) {
|
|
43706
44091
|
const queryStreamId = hash(query);
|
|
@@ -44877,41 +45262,6 @@ const leaveRoom = async (roomId) => {
|
|
|
44877
45262
|
};
|
|
44878
45263
|
/* end_public_function */
|
|
44879
45264
|
|
|
44880
|
-
/* begin_public_function
|
|
44881
|
-
id: room.update_cohost_permissions
|
|
44882
|
-
*/
|
|
44883
|
-
/**
|
|
44884
|
-
* ```js
|
|
44885
|
-
* import { updateCohostPermission } from '@amityco/ts-sdk'
|
|
44886
|
-
* const updated = await updateCohostPermission('roomId', 'cohostId', true)
|
|
44887
|
-
* ```
|
|
44888
|
-
*
|
|
44889
|
-
* Updates an {@link Amity.InternalRoom}
|
|
44890
|
-
*
|
|
44891
|
-
* @param roomId The ID of the room to update
|
|
44892
|
-
* @param cohostId The ID of the cohost to update
|
|
44893
|
-
* @param canManageProductTags The permission to manage product tags
|
|
44894
|
-
* @returns The updated {@link Amity.InternalRoom}
|
|
44895
|
-
*
|
|
44896
|
-
* @category Room API
|
|
44897
|
-
* @async
|
|
44898
|
-
*/
|
|
44899
|
-
const updateCohostPermission = async (roomId, cohostId, canManageProductTags) => {
|
|
44900
|
-
const client = getActiveClient();
|
|
44901
|
-
client.log('room/updatedCoHostPermission', { roomId, cohostId, canManageProductTags });
|
|
44902
|
-
const { data } = await client.http.put(`/api/v1/rooms/${roomId}/participants/${cohostId}`, { canManageProductTags });
|
|
44903
|
-
fireEvent('local.room.didUpdate', data);
|
|
44904
|
-
const cachedAt = client.cache && Date.now();
|
|
44905
|
-
if (client.cache)
|
|
44906
|
-
ingestInCache(data, { cachedAt });
|
|
44907
|
-
const { rooms } = data;
|
|
44908
|
-
return {
|
|
44909
|
-
data: roomLinkedObject(rooms[0]),
|
|
44910
|
-
cachedAt,
|
|
44911
|
-
};
|
|
44912
|
-
};
|
|
44913
|
-
/* end_public_function */
|
|
44914
|
-
|
|
44915
45265
|
/**
|
|
44916
45266
|
* ```js
|
|
44917
45267
|
* import { onRoomStartBroadcasting } from '@amityco/ts-sdk'
|
|
@@ -45286,30 +45636,6 @@ const onRoomTerminated = (callback) => {
|
|
|
45286
45636
|
return createEventSubscriber(client, 'room/onRoomTerminated', 'room.terminated', filter);
|
|
45287
45637
|
};
|
|
45288
45638
|
|
|
45289
|
-
/**
|
|
45290
|
-
* ```js
|
|
45291
|
-
* import { onRoomDidUpdate } from '@amityco/ts-sdk'
|
|
45292
|
-
* const dispose = onRoomDidUpdate(room => {
|
|
45293
|
-
* // ...
|
|
45294
|
-
* })
|
|
45295
|
-
* ```
|
|
45296
|
-
*
|
|
45297
|
-
* Fired when a {@link Amity.Room} has been updated locally
|
|
45298
|
-
*
|
|
45299
|
-
* @param callback The function to call when the event was fired
|
|
45300
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
45301
|
-
*
|
|
45302
|
-
* @category Room Events
|
|
45303
|
-
*/
|
|
45304
|
-
const onRoomDidUpdate = (callback) => {
|
|
45305
|
-
const client = getActiveClient();
|
|
45306
|
-
const filter = (payload) => {
|
|
45307
|
-
ingestInCache(payload);
|
|
45308
|
-
callback(payload.rooms[0]);
|
|
45309
|
-
};
|
|
45310
|
-
return createEventSubscriber(client, 'room/onRoomDidUpdate', 'local.room.didUpdate', filter);
|
|
45311
|
-
};
|
|
45312
|
-
|
|
45313
45639
|
/**
|
|
45314
45640
|
* ```js
|
|
45315
45641
|
* import { onRoomCreated } from '@amityco/ts-sdk'
|
|
@@ -45458,30 +45784,6 @@ const onRoomLeft = (callback) => {
|
|
|
45458
45784
|
return createEventSubscriber(client, 'room/onRoomLeft', 'local.room.left', filter);
|
|
45459
45785
|
};
|
|
45460
45786
|
|
|
45461
|
-
/**
|
|
45462
|
-
* ```js
|
|
45463
|
-
* import { onLocalRoomDidUpdate } from '@amityco/ts-sdk'
|
|
45464
|
-
* const dispose = onLocalRoomDidUpdate(room => {
|
|
45465
|
-
* // ...
|
|
45466
|
-
* })
|
|
45467
|
-
* ```
|
|
45468
|
-
*
|
|
45469
|
-
* Fired when a {@link Amity.Room} has been updated locally
|
|
45470
|
-
*
|
|
45471
|
-
* @param callback The function to call when the event was fired
|
|
45472
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
45473
|
-
*
|
|
45474
|
-
* @category Room Events
|
|
45475
|
-
*/
|
|
45476
|
-
const onLocalRoomDidUpdate = (callback) => {
|
|
45477
|
-
const client = getActiveClient();
|
|
45478
|
-
const filter = (payload) => {
|
|
45479
|
-
ingestInCache(payload);
|
|
45480
|
-
callback(payload.rooms[0]);
|
|
45481
|
-
};
|
|
45482
|
-
return createEventSubscriber(client, 'room/onLocalRoomDidUpdate', 'room.didUpdate', filter);
|
|
45483
|
-
};
|
|
45484
|
-
|
|
45485
45787
|
/**
|
|
45486
45788
|
* ```js
|
|
45487
45789
|
* import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
|
|
@@ -45515,7 +45817,6 @@ var EnumRoomActions;
|
|
|
45515
45817
|
EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
|
|
45516
45818
|
EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
|
|
45517
45819
|
EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
|
|
45518
|
-
EnumRoomActions["OnRoomDidUpdate"] = "OnRoomDidUpdate";
|
|
45519
45820
|
})(EnumRoomActions || (EnumRoomActions = {}));
|
|
45520
45821
|
|
|
45521
45822
|
const convertToRoomEventPayload = (eventHandler) => (callback) => eventHandler((payload) => {
|
|
@@ -45567,14 +45868,6 @@ const getRoomSubscription = () => [
|
|
|
45567
45868
|
fn: convertEventPayload(onRoomCoHostInviteAccepted, 'targetId', 'room'),
|
|
45568
45869
|
action: EnumRoomActions.OnRoomUpdated,
|
|
45569
45870
|
},
|
|
45570
|
-
{
|
|
45571
|
-
fn: onRoomDidUpdate,
|
|
45572
|
-
action: EnumRoomActions.OnRoomDidUpdate,
|
|
45573
|
-
},
|
|
45574
|
-
{
|
|
45575
|
-
fn: onLocalRoomDidUpdate,
|
|
45576
|
-
action: EnumRoomActions.OnRoomDidUpdate,
|
|
45577
|
-
},
|
|
45578
45871
|
];
|
|
45579
45872
|
|
|
45580
45873
|
const getRoom = (roomId, callback) => {
|
|
@@ -45783,7 +46076,7 @@ const getRooms = (params, callback, config) => {
|
|
|
45783
46076
|
};
|
|
45784
46077
|
/* end_public_function */
|
|
45785
46078
|
|
|
45786
|
-
var index$
|
|
46079
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
45787
46080
|
__proto__: null,
|
|
45788
46081
|
createRoom: createRoom,
|
|
45789
46082
|
updateRoom: updateRoom,
|
|
@@ -45797,7 +46090,6 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
45797
46090
|
WatchSessionStorage: WatchSessionStorage,
|
|
45798
46091
|
getWatchSessionStorage: getWatchSessionStorage,
|
|
45799
46092
|
syncWatchSessions: syncWatchSessions,
|
|
45800
|
-
updateCohostPermission: updateCohostPermission,
|
|
45801
46093
|
onRoomStartBroadcasting: onRoomStartBroadcasting,
|
|
45802
46094
|
onRoomWaitingReconnect: onRoomWaitingReconnect,
|
|
45803
46095
|
onRoomEndBroadcasting: onRoomEndBroadcasting,
|
|
@@ -45811,14 +46103,12 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
45811
46103
|
onRoomParticipantStageLeft: onRoomParticipantStageLeft,
|
|
45812
46104
|
onRoomParticipantStageJoined: onRoomParticipantStageJoined,
|
|
45813
46105
|
onRoomTerminated: onRoomTerminated,
|
|
45814
|
-
onRoomDidUpdate: onRoomDidUpdate,
|
|
45815
46106
|
onRoomCreated: onRoomCreated,
|
|
45816
46107
|
onRoomUpdated: onRoomUpdated,
|
|
45817
46108
|
onRoomDeleted: onRoomDeleted,
|
|
45818
46109
|
onRoomStopped: onRoomStopped,
|
|
45819
46110
|
onRoomParticipantRemoved: onRoomParticipantRemoved,
|
|
45820
46111
|
onRoomLeft: onRoomLeft,
|
|
45821
|
-
onLocalRoomDidUpdate: onLocalRoomDidUpdate,
|
|
45822
46112
|
getRoom: getRoom,
|
|
45823
46113
|
getRooms: getRooms
|
|
45824
46114
|
});
|
|
@@ -46082,7 +46372,7 @@ const getCommunityLiveRoomPosts = (params, callback, config) => {
|
|
|
46082
46372
|
};
|
|
46083
46373
|
/* end_public_function */
|
|
46084
46374
|
|
|
46085
|
-
var index$
|
|
46375
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
46086
46376
|
__proto__: null,
|
|
46087
46377
|
getPostByIds: getPostByIds,
|
|
46088
46378
|
createPost: createPost,
|
|
@@ -46098,10 +46388,6 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
46098
46388
|
createClipPost: createClipPost,
|
|
46099
46389
|
createAudioPost: createAudioPost,
|
|
46100
46390
|
createMixedMediaPost: createMixedMediaPost,
|
|
46101
|
-
createRoomPost: createRoomPost,
|
|
46102
|
-
pinProduct: pinProduct,
|
|
46103
|
-
unpinProduct: unpinProduct,
|
|
46104
|
-
updateProductTags: updateProductTags,
|
|
46105
46391
|
onPostCreated: onPostCreated,
|
|
46106
46392
|
onPostUpdated: onPostUpdated,
|
|
46107
46393
|
onPostDeleted: onPostDeleted,
|
|
@@ -46696,7 +46982,7 @@ const getStreams = (params, callback, config) => {
|
|
|
46696
46982
|
};
|
|
46697
46983
|
};
|
|
46698
46984
|
|
|
46699
|
-
var index$
|
|
46985
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
46700
46986
|
__proto__: null,
|
|
46701
46987
|
createStream: createStream,
|
|
46702
46988
|
updateStream: updateStream,
|
|
@@ -46999,7 +47285,7 @@ const stopHeartbeat = (roomId) => {
|
|
|
46999
47285
|
};
|
|
47000
47286
|
/* end_public_function */
|
|
47001
47287
|
|
|
47002
|
-
var index$
|
|
47288
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
47003
47289
|
__proto__: null,
|
|
47004
47290
|
getRoomOnlineUsers: getRoomOnlineUsers,
|
|
47005
47291
|
getRoomUserCount: getRoomUserCount,
|
|
@@ -47307,7 +47593,7 @@ const getPoll = (pollId, callback) => {
|
|
|
47307
47593
|
};
|
|
47308
47594
|
/* end_public_function */
|
|
47309
47595
|
|
|
47310
|
-
var index$
|
|
47596
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
47311
47597
|
__proto__: null,
|
|
47312
47598
|
createPoll: createPoll,
|
|
47313
47599
|
closePoll: closePoll,
|
|
@@ -47611,7 +47897,7 @@ const getPlayer = async (parameters) => {
|
|
|
47611
47897
|
return video;
|
|
47612
47898
|
};
|
|
47613
47899
|
|
|
47614
|
-
var index$
|
|
47900
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
47615
47901
|
__proto__: null,
|
|
47616
47902
|
getPlayer: getPlayer
|
|
47617
47903
|
});
|
|
@@ -48784,7 +49070,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
48784
49070
|
};
|
|
48785
49071
|
};
|
|
48786
49072
|
|
|
48787
|
-
var index$
|
|
49073
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
48788
49074
|
__proto__: null,
|
|
48789
49075
|
createImageStory: createImageStory,
|
|
48790
49076
|
createVideoStory: createVideoStory,
|
|
@@ -48821,7 +49107,7 @@ const getNetworkAds = async () => {
|
|
|
48821
49107
|
};
|
|
48822
49108
|
};
|
|
48823
49109
|
|
|
48824
|
-
var index$
|
|
49110
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
48825
49111
|
__proto__: null,
|
|
48826
49112
|
getNetworkAds: getNetworkAds
|
|
48827
49113
|
});
|
|
@@ -49212,7 +49498,7 @@ const markTraySeen = async (lastSeenAt) => {
|
|
|
49212
49498
|
};
|
|
49213
49499
|
/* end_public_function */
|
|
49214
49500
|
|
|
49215
|
-
var index$
|
|
49501
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
49216
49502
|
__proto__: null,
|
|
49217
49503
|
getNotificationTraySeen: getNotificationTraySeen,
|
|
49218
49504
|
getNotificationTrayItems: getNotificationTrayItems,
|
|
@@ -49510,7 +49796,7 @@ const getInvitations = (params, callback) => {
|
|
|
49510
49796
|
};
|
|
49511
49797
|
};
|
|
49512
49798
|
|
|
49513
|
-
var index$
|
|
49799
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
49514
49800
|
__proto__: null,
|
|
49515
49801
|
cancelInvitation: cancelInvitation,
|
|
49516
49802
|
onLocalInvitationCreated: onLocalInvitationCreated,
|
|
@@ -49659,7 +49945,7 @@ const getReactions = (postId, callback) => {
|
|
|
49659
49945
|
};
|
|
49660
49946
|
};
|
|
49661
49947
|
|
|
49662
|
-
var index$
|
|
49948
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
49663
49949
|
__proto__: null,
|
|
49664
49950
|
createReaction: createReaction,
|
|
49665
49951
|
onLiveReactionCreated: onLiveReactionCreated,
|
|
@@ -50142,7 +50428,7 @@ const getMyEvents = (params, callback, config) => {
|
|
|
50142
50428
|
};
|
|
50143
50429
|
};
|
|
50144
50430
|
|
|
50145
|
-
var index
|
|
50431
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
50146
50432
|
__proto__: null,
|
|
50147
50433
|
createEvent: createEvent,
|
|
50148
50434
|
updateEvent: updateEvent,
|
|
@@ -50163,261 +50449,4 @@ var index$1 = /*#__PURE__*/Object.freeze({
|
|
|
50163
50449
|
getRSVPs: getRSVPs
|
|
50164
50450
|
});
|
|
50165
50451
|
|
|
50166
|
-
|
|
50167
|
-
const client = getActiveClient();
|
|
50168
|
-
client.log('product/getProduct', productId);
|
|
50169
|
-
isInTombstone('product', productId);
|
|
50170
|
-
let payload;
|
|
50171
|
-
try {
|
|
50172
|
-
const response = await client.http.get(`/api/v1/products/${encodeURIComponent(productId)}`);
|
|
50173
|
-
payload = response.data;
|
|
50174
|
-
}
|
|
50175
|
-
catch (error) {
|
|
50176
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
50177
|
-
pushToTombstone('product', productId);
|
|
50178
|
-
}
|
|
50179
|
-
throw error;
|
|
50180
|
-
}
|
|
50181
|
-
const cachedAt = client.cache && Date.now();
|
|
50182
|
-
if (client.cache)
|
|
50183
|
-
ingestInCache(payload, { cachedAt });
|
|
50184
|
-
const { products } = payload;
|
|
50185
|
-
const result = products.find(product => product.productId === productId);
|
|
50186
|
-
return {
|
|
50187
|
-
data: result,
|
|
50188
|
-
cachedAt,
|
|
50189
|
-
};
|
|
50190
|
-
};
|
|
50191
|
-
getProduct$1.locally = (productId) => {
|
|
50192
|
-
const client = getActiveClient();
|
|
50193
|
-
client.log('product/getProduct.locally', productId);
|
|
50194
|
-
if (!client.cache)
|
|
50195
|
-
return;
|
|
50196
|
-
const cached = pullFromCache(['product', 'get', productId]);
|
|
50197
|
-
if (!cached)
|
|
50198
|
-
return;
|
|
50199
|
-
return {
|
|
50200
|
-
data: cached.data,
|
|
50201
|
-
cachedAt: cached.cachedAt,
|
|
50202
|
-
};
|
|
50203
|
-
};
|
|
50204
|
-
|
|
50205
|
-
/* begin_public_function
|
|
50206
|
-
id: product.get
|
|
50207
|
-
*/
|
|
50208
|
-
/**
|
|
50209
|
-
* ```js
|
|
50210
|
-
* import { ProductRepository } from '@amityco/ts-sdk';
|
|
50211
|
-
*
|
|
50212
|
-
* let product;
|
|
50213
|
-
*
|
|
50214
|
-
* const unsub = ProductRepository.getProduct(productId, response => {
|
|
50215
|
-
* product = response.data;
|
|
50216
|
-
* });
|
|
50217
|
-
* ```
|
|
50218
|
-
*
|
|
50219
|
-
* Observe all mutation on a given {@link Amity.Product}
|
|
50220
|
-
*
|
|
50221
|
-
* @param productId the ID of the product to observe
|
|
50222
|
-
* @param callback the function to call when new data are available
|
|
50223
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the product
|
|
50224
|
-
*
|
|
50225
|
-
* @category Product Live Object
|
|
50226
|
-
*/
|
|
50227
|
-
const getProduct = (productId, callback) => {
|
|
50228
|
-
const responder = (snapshot) => {
|
|
50229
|
-
callback(snapshot);
|
|
50230
|
-
};
|
|
50231
|
-
return liveObject(productId, responder, 'productId', getProduct$1, []);
|
|
50232
|
-
};
|
|
50233
|
-
/* end_public_function */
|
|
50234
|
-
|
|
50235
|
-
class SearchProductPaginationController extends PaginationController {
|
|
50236
|
-
async getRequest(queryParams, token) {
|
|
50237
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
50238
|
-
const options = token ? { token } : { limit };
|
|
50239
|
-
const { data: queryResponse } = await this.http.get(`/api/v1/products/search`, {
|
|
50240
|
-
params: Object.assign(Object.assign({}, params), { options }),
|
|
50241
|
-
});
|
|
50242
|
-
return queryResponse;
|
|
50243
|
-
}
|
|
50244
|
-
}
|
|
50245
|
-
|
|
50246
|
-
class SearchProductQueryStreamController extends QueryStreamController {
|
|
50247
|
-
constructor(query, cacheKey, notifyChange) {
|
|
50248
|
-
super(query, cacheKey);
|
|
50249
|
-
this.notifyChange = notifyChange;
|
|
50250
|
-
}
|
|
50251
|
-
// eslint-disable-next-line class-methods-use-this
|
|
50252
|
-
saveToMainDB(response) {
|
|
50253
|
-
const client = getActiveClient();
|
|
50254
|
-
const cachedAt = client.cache && Date.now();
|
|
50255
|
-
if (client.cache) {
|
|
50256
|
-
ingestInCache(response, { cachedAt });
|
|
50257
|
-
}
|
|
50258
|
-
}
|
|
50259
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
50260
|
-
var _a, _b;
|
|
50261
|
-
if (refresh) {
|
|
50262
|
-
pushToCache(this.cacheKey, {
|
|
50263
|
-
data: response.products.map(getResolver('product')),
|
|
50264
|
-
});
|
|
50265
|
-
}
|
|
50266
|
-
else {
|
|
50267
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
50268
|
-
const products = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
50269
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...products, ...response.products.map(getResolver('product'))])] }));
|
|
50270
|
-
}
|
|
50271
|
-
}
|
|
50272
|
-
}
|
|
50273
|
-
|
|
50274
|
-
class SearchProductLiveCollectionController extends LiveCollectionController {
|
|
50275
|
-
constructor(query, callback) {
|
|
50276
|
-
const queryStreamId = hash(query);
|
|
50277
|
-
const cacheKey = ['products', 'collection', queryStreamId];
|
|
50278
|
-
const paginationController = new SearchProductPaginationController(query);
|
|
50279
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
50280
|
-
this.query = query;
|
|
50281
|
-
this.queryStreamController = new SearchProductQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this));
|
|
50282
|
-
this.callback = callback.bind(this);
|
|
50283
|
-
this.loadPage({ initial: true });
|
|
50284
|
-
}
|
|
50285
|
-
setup() {
|
|
50286
|
-
var _a;
|
|
50287
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
50288
|
-
if (!collection) {
|
|
50289
|
-
pushToCache(this.cacheKey, {
|
|
50290
|
-
data: [],
|
|
50291
|
-
params: {},
|
|
50292
|
-
});
|
|
50293
|
-
}
|
|
50294
|
-
}
|
|
50295
|
-
async persistModel(queryPayload) {
|
|
50296
|
-
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
50297
|
-
}
|
|
50298
|
-
persistQueryStream({ response, direction, refresh, }) {
|
|
50299
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
50300
|
-
}
|
|
50301
|
-
// eslint-disable-next-line class-methods-use-this
|
|
50302
|
-
startSubscription() {
|
|
50303
|
-
return [];
|
|
50304
|
-
}
|
|
50305
|
-
notifyChange({ origin, loading, error }) {
|
|
50306
|
-
var _a, _b;
|
|
50307
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
50308
|
-
if (!collection)
|
|
50309
|
-
return;
|
|
50310
|
-
const data = (_b = collection.data
|
|
50311
|
-
.map(id => pullFromCache(['product', 'get', id]))
|
|
50312
|
-
.filter(isNonNullable)
|
|
50313
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
50314
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
50315
|
-
return;
|
|
50316
|
-
this.callback({
|
|
50317
|
-
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
50318
|
-
data,
|
|
50319
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
50320
|
-
loading,
|
|
50321
|
-
error,
|
|
50322
|
-
});
|
|
50323
|
-
}
|
|
50324
|
-
}
|
|
50325
|
-
|
|
50326
|
-
/* begin_public_function
|
|
50327
|
-
id: product.search
|
|
50328
|
-
*/
|
|
50329
|
-
/**
|
|
50330
|
-
* ```js
|
|
50331
|
-
* import { ProductRepository } from '@amityco/ts-sdk'
|
|
50332
|
-
*
|
|
50333
|
-
* let products = []
|
|
50334
|
-
* const unsub = ProductRepository.searchProducts({
|
|
50335
|
-
* keyword: string,
|
|
50336
|
-
* }, response => merge(products, response.data))
|
|
50337
|
-
* ```
|
|
50338
|
-
*
|
|
50339
|
-
* Observe all mutations on a list of {@link Amity.Product}
|
|
50340
|
-
*
|
|
50341
|
-
* @param params.keyword the search keyword
|
|
50342
|
-
* @param params.isActive filter by active status
|
|
50343
|
-
* @param params.isDeleted filter by deleted status
|
|
50344
|
-
* @param params.sortBy sort option
|
|
50345
|
-
* @param params.sortOrder order option
|
|
50346
|
-
* @param callback the function to call when new data are available
|
|
50347
|
-
* @param config
|
|
50348
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the products
|
|
50349
|
-
*
|
|
50350
|
-
* @category Products Live Collection
|
|
50351
|
-
*/
|
|
50352
|
-
const searchProducts = (params, callback, config) => {
|
|
50353
|
-
const { log, cache } = getActiveClient();
|
|
50354
|
-
if (!cache) {
|
|
50355
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
50356
|
-
}
|
|
50357
|
-
const timestamp = Date.now();
|
|
50358
|
-
log(`searchProducts(tmpid: ${timestamp}) > listen`);
|
|
50359
|
-
const productsLiveCollection = new SearchProductLiveCollectionController(params, callback);
|
|
50360
|
-
const disposers = productsLiveCollection.startSubscription();
|
|
50361
|
-
const cacheKey = productsLiveCollection.getCacheKey();
|
|
50362
|
-
disposers.push(() => dropFromCache(cacheKey));
|
|
50363
|
-
return () => {
|
|
50364
|
-
log(`searchProducts(tmpid: ${timestamp}) > dispose`);
|
|
50365
|
-
disposers.forEach(fn => fn());
|
|
50366
|
-
};
|
|
50367
|
-
};
|
|
50368
|
-
/* end_public_function */
|
|
50369
|
-
|
|
50370
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
50371
|
-
__proto__: null,
|
|
50372
|
-
getProduct: getProduct,
|
|
50373
|
-
searchProducts: searchProducts
|
|
50374
|
-
});
|
|
50375
|
-
|
|
50376
|
-
/**
|
|
50377
|
-
* Helper class for managing product tags per media attachment.
|
|
50378
|
-
*
|
|
50379
|
-
* This class provides a convenient way to organize product tags by file ID,
|
|
50380
|
-
* allowing you to associate multiple products with individual media attachments
|
|
50381
|
-
* (images, videos) in a post.
|
|
50382
|
-
*
|
|
50383
|
-
* @example
|
|
50384
|
-
* ```typescript
|
|
50385
|
-
* const attachmentTags = new AmityAttachmentProductTags();
|
|
50386
|
-
*
|
|
50387
|
-
* // Set tags to specific images
|
|
50388
|
-
*
|
|
50389
|
-
* attachmentTags.set('image-file-2', [
|
|
50390
|
-
* { productId: 'product-3' },
|
|
50391
|
-
* { productId: 'product-4' },
|
|
50392
|
-
* ]);
|
|
50393
|
-
*
|
|
50394
|
-
* // Get tags for a specific file
|
|
50395
|
-
* const tagsOnImage1 = attachmentTags.get('image-file-1');
|
|
50396
|
-
* // Returns: [{ productId: 'product-1' }, { productId: 'product-2' }]
|
|
50397
|
-
* ```
|
|
50398
|
-
*/
|
|
50399
|
-
class AmityAttachmentProductTags {
|
|
50400
|
-
constructor() {
|
|
50401
|
-
this.map = new Map();
|
|
50402
|
-
}
|
|
50403
|
-
/**
|
|
50404
|
-
* Get all product tags associated with a specific file.
|
|
50405
|
-
*
|
|
50406
|
-
* @param fileId - The ID of the file (image/video)
|
|
50407
|
-
* @returns Array of product tags for the file, empty array if none exist
|
|
50408
|
-
*/
|
|
50409
|
-
get(fileId) {
|
|
50410
|
-
return this.map.get(fileId) || [];
|
|
50411
|
-
}
|
|
50412
|
-
/**
|
|
50413
|
-
* Set product tags for a specific file, replacing any existing tags.
|
|
50414
|
-
*
|
|
50415
|
-
* @param fileId - The ID of the file (image/video)
|
|
50416
|
-
* @param tags - Array of product tags to set for the file
|
|
50417
|
-
*/
|
|
50418
|
-
set(fileId, tags) {
|
|
50419
|
-
this.map.set(fileId, tags);
|
|
50420
|
-
}
|
|
50421
|
-
}
|
|
50422
|
-
|
|
50423
|
-
export { API_REGIONS, index$5 as AdRepository, AmityAttachmentProductTags, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, index$f as CategoryRepository, index$j as ChannelRepository, index$s as Client, index$e as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$g as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$1 as EventRepository, FeedDataTypeEnum, index$d as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$p as FileRepository, FileType, GET_WATCHER_URLS, index$3 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$2 as LiveReactionRepository, index$7 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$n as MessageRepository, index$8 as PollRepository, PostContentType, index$b as PostRepository, PostStructureType, index as ProductRepository, index$o as ReactionRepository, index$9 as RoomPresenceRepository, index$c as RoomRepository, index$6 as StoryRepository, index$a as StreamRepository, index$m as SubChannelRepository, SubscriptionLevels, index$q as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$4 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|
|
50452
|
+
export { API_REGIONS, index$4 as AdRepository, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, index$e as CategoryRepository, index$i as ChannelRepository, index$r as Client, index$d as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$f as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$c as FeedRepository, FeedSortByEnum, FeedSourceEnum, FeedTypeEnum, FileAccessTypeEnum, index$o as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$m as MessageRepository, index$7 as PollRepository, PostContentType, index$a as PostRepository, PostStructureType, index$n as ReactionRepository, index$8 as RoomPresenceRepository, index$b as RoomRepository, index$5 as StoryRepository, index$9 as StreamRepository, index$l as SubChannelRepository, SubscriptionLevels, index$p as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$3 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|