@amityco/ts-sdk 7.12.1-bcda02ea.0 → 7.12.1-ca67d41b.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 +2 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +2 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +4 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +3 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +2 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/product.d.ts +78 -0
- package/dist/@types/domains/product.d.ts.map +1 -0
- package/dist/@types/domains/room.d.ts +1 -0
- package/dist/@types/domains/room.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/client/api/getProductCatalogueSetting.d.ts +15 -0
- package/dist/client/api/getProductCatalogueSetting.d.ts.map +1 -0
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.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/index.cjs.js +524 -59
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +501 -37
- package/dist/index.umd.js +2 -2
- package/dist/postRepository/api/createPost.d.ts +2 -0
- package/dist/postRepository/api/createPost.d.ts.map +1 -1
- package/dist/postRepository/api/createRoomPost.d.ts +29 -0
- package/dist/postRepository/api/createRoomPost.d.ts.map +1 -0
- package/dist/postRepository/api/editPost.d.ts +2 -0
- package/dist/postRepository/api/editPost.d.ts.map +1 -1
- package/dist/postRepository/api/index.d.ts +4 -0
- package/dist/postRepository/api/index.d.ts.map +1 -1
- package/dist/postRepository/api/pinProduct.d.ts +15 -0
- package/dist/postRepository/api/pinProduct.d.ts.map +1 -0
- package/dist/postRepository/api/unpinProduct.d.ts +14 -0
- package/dist/postRepository/api/unpinProduct.d.ts.map +1 -0
- package/dist/postRepository/api/updateProductTags.d.ts +15 -0
- package/dist/postRepository/api/updateProductTags.d.ts.map +1 -0
- package/dist/postRepository/observers/enums.d.ts +4 -1
- package/dist/postRepository/observers/enums.d.ts.map +1 -1
- package/dist/productRepository/index.d.ts +2 -0
- package/dist/productRepository/index.d.ts.map +1 -0
- package/dist/productRepository/internalApi/getProduct.d.ts +5 -0
- package/dist/productRepository/internalApi/getProduct.d.ts.map +1 -0
- package/dist/productRepository/internalApi/index.d.ts +2 -0
- package/dist/productRepository/internalApi/index.d.ts.map +1 -0
- package/dist/productRepository/observers/getProduct.d.ts +21 -0
- package/dist/productRepository/observers/getProduct.d.ts.map +1 -0
- package/dist/productRepository/observers/index.d.ts +3 -0
- package/dist/productRepository/observers/index.d.ts.map +1 -0
- package/dist/productRepository/observers/searchProducts/LiveCollectionController.d.ts +15 -0
- package/dist/productRepository/observers/searchProducts/LiveCollectionController.d.ts.map +1 -0
- package/dist/productRepository/observers/searchProducts/PaginationController.d.ts +5 -0
- package/dist/productRepository/observers/searchProducts/PaginationController.d.ts.map +1 -0
- package/dist/productRepository/observers/searchProducts/QueryStreamController.d.ts +8 -0
- package/dist/productRepository/observers/searchProducts/QueryStreamController.d.ts.map +1 -0
- package/dist/productRepository/observers/searchProducts.d.ts +25 -0
- package/dist/productRepository/observers/searchProducts.d.ts.map +1 -0
- package/dist/roomRepository/api/updateCohostPermission.d.ts +18 -0
- package/dist/roomRepository/api/updateCohostPermission.d.ts.map +1 -0
- package/dist/roomRepository/events/index.d.ts +2 -0
- package/dist/roomRepository/events/index.d.ts.map +1 -1
- package/dist/roomRepository/events/onLocalRoomDidUpdate.d.ts +17 -0
- package/dist/roomRepository/events/onLocalRoomDidUpdate.d.ts.map +1 -0
- package/dist/roomRepository/events/onRoomDidUpdate.d.ts +17 -0
- package/dist/roomRepository/events/onRoomDidUpdate.d.ts.map +1 -0
- package/dist/roomRepository/observers/enums.d.ts +2 -1
- 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/dist/utils/linkedObject/productTagLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/productTagLinkedObject.d.ts.map +1 -0
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -689,6 +689,7 @@ const idResolvers = {
|
|
|
689
689
|
viewer: ({ userId }) => userId,
|
|
690
690
|
event: ({ eventId }) => eventId,
|
|
691
691
|
eventResponse: ({ userId }) => userId,
|
|
692
|
+
product: ({ _id }) => _id,
|
|
692
693
|
};
|
|
693
694
|
/**
|
|
694
695
|
* Retrieve the id resolver matching a domain name
|
|
@@ -748,6 +749,7 @@ const PAYLOAD2MODEL = {
|
|
|
748
749
|
events: 'event',
|
|
749
750
|
viewers: 'viewer',
|
|
750
751
|
eventResponses: 'eventResponse',
|
|
752
|
+
products: 'product',
|
|
751
753
|
};
|
|
752
754
|
/** hidden */
|
|
753
755
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -10063,6 +10065,29 @@ const getShareableLinkConfiguration = async () => {
|
|
|
10063
10065
|
return data;
|
|
10064
10066
|
};
|
|
10065
10067
|
|
|
10068
|
+
/* begin_public_function
|
|
10069
|
+
id: client.getProductCatalogueSetting
|
|
10070
|
+
*/
|
|
10071
|
+
/**
|
|
10072
|
+
* ```js
|
|
10073
|
+
* import { getProductCatalogueSetting } from '@amityco/ts-sdk'
|
|
10074
|
+
* const productCatalogueSetting = await getProductCatalogueSetting()
|
|
10075
|
+
* ```
|
|
10076
|
+
*
|
|
10077
|
+
* Fetches a {@link Amity.ProductCatalogueSetting} object
|
|
10078
|
+
*
|
|
10079
|
+
* @returns A Promise of {@link Amity.ProductCatalogueSetting} object
|
|
10080
|
+
*
|
|
10081
|
+
* @category Client API
|
|
10082
|
+
* @async
|
|
10083
|
+
*/
|
|
10084
|
+
const getProductCatalogueSetting = async () => {
|
|
10085
|
+
const client = getActiveClient();
|
|
10086
|
+
const { data } = await client.http.get(`/api/v3/network-settings/product-catalogue`);
|
|
10087
|
+
return data;
|
|
10088
|
+
};
|
|
10089
|
+
/* end_public_function */
|
|
10090
|
+
|
|
10066
10091
|
/**
|
|
10067
10092
|
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
10068
10093
|
*
|
|
@@ -10555,7 +10580,7 @@ const getUserUnread = (callback) => {
|
|
|
10555
10580
|
};
|
|
10556
10581
|
};
|
|
10557
10582
|
|
|
10558
|
-
var index$
|
|
10583
|
+
var index$s = /*#__PURE__*/Object.freeze({
|
|
10559
10584
|
__proto__: null,
|
|
10560
10585
|
getActiveClient: getActiveClient,
|
|
10561
10586
|
getActiveUser: getActiveUser,
|
|
@@ -10575,6 +10600,7 @@ var index$r = /*#__PURE__*/Object.freeze({
|
|
|
10575
10600
|
getLinkPreviewMetadata: getLinkPreviewMetadata,
|
|
10576
10601
|
getSocialSettings: getSocialSettings,
|
|
10577
10602
|
getShareableLinkConfiguration: getShareableLinkConfiguration,
|
|
10603
|
+
getProductCatalogueSetting: getProductCatalogueSetting,
|
|
10578
10604
|
loginAsVisitor: loginAsVisitor,
|
|
10579
10605
|
loginAsBot: loginAsBot,
|
|
10580
10606
|
getCurrentUser: getCurrentUser,
|
|
@@ -10637,7 +10663,7 @@ const blockUser = async (userId) => {
|
|
|
10637
10663
|
ingestInCache(blockedFollowStatus, { cachedAt });
|
|
10638
10664
|
upsertInCache(['followInfo', 'get', userId], followCounts[0], { cachedAt });
|
|
10639
10665
|
}
|
|
10640
|
-
//
|
|
10666
|
+
// need to swap {from} and {to} to get the correct id for unfollow event to filter from follower live collection
|
|
10641
10667
|
const blockedUnfollowStatus = {
|
|
10642
10668
|
follows: follows.map(follow => {
|
|
10643
10669
|
const unfollowStatus = Object.assign(Object.assign({}, follow), { to: follow.from, from: follow.to, status: 'none' });
|
|
@@ -11782,7 +11808,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
11782
11808
|
};
|
|
11783
11809
|
/* end_public_function */
|
|
11784
11810
|
|
|
11785
|
-
var index$
|
|
11811
|
+
var index$r = /*#__PURE__*/Object.freeze({
|
|
11786
11812
|
__proto__: null,
|
|
11787
11813
|
blockUser: blockUser,
|
|
11788
11814
|
unBlockUser: unBlockUser,
|
|
@@ -13890,6 +13916,11 @@ const communityLinkedObject = (community) => {
|
|
|
13890
13916
|
} });
|
|
13891
13917
|
};
|
|
13892
13918
|
|
|
13919
|
+
const productTagLinkedObject = (productTag) => {
|
|
13920
|
+
var _a;
|
|
13921
|
+
return Object.assign(Object.assign({}, productTag), { product: (_a = pullFromCache(['product', 'get', productTag.productId])) === null || _a === void 0 ? void 0 : _a.data });
|
|
13922
|
+
};
|
|
13923
|
+
|
|
13893
13924
|
const postLinkedObject = (post) => {
|
|
13894
13925
|
return shallowClone(post, {
|
|
13895
13926
|
childrenPosts: post.children
|
|
@@ -13902,6 +13933,10 @@ const postLinkedObject = (post) => {
|
|
|
13902
13933
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
13903
13934
|
},
|
|
13904
13935
|
},
|
|
13936
|
+
get productTags() {
|
|
13937
|
+
var _a, _b;
|
|
13938
|
+
return (_b = (_a = post.productTags) === null || _a === void 0 ? void 0 : _a.map(productTag => productTagLinkedObject(productTag))) !== null && _b !== void 0 ? _b : [];
|
|
13939
|
+
},
|
|
13905
13940
|
get latestComments() {
|
|
13906
13941
|
if (!post.comments)
|
|
13907
13942
|
return [];
|
|
@@ -15891,9 +15926,9 @@ var AmityUserSearchMatchType;
|
|
|
15891
15926
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
15892
15927
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
15893
15928
|
|
|
15894
|
-
var index$
|
|
15929
|
+
var index$q = /*#__PURE__*/Object.freeze({
|
|
15895
15930
|
__proto__: null,
|
|
15896
|
-
Relationship: index$
|
|
15931
|
+
Relationship: index$r,
|
|
15897
15932
|
getUserByIds: getUserByIds,
|
|
15898
15933
|
updateUser: updateUser,
|
|
15899
15934
|
flagUser: flagUser,
|
|
@@ -16296,7 +16331,7 @@ const uploadAudio = async (formData, onProgress) => {
|
|
|
16296
16331
|
};
|
|
16297
16332
|
/* end_public_function */
|
|
16298
16333
|
|
|
16299
|
-
var index$
|
|
16334
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
16300
16335
|
__proto__: null,
|
|
16301
16336
|
getFile: getFile,
|
|
16302
16337
|
uploadFile: uploadFile,
|
|
@@ -18108,7 +18143,7 @@ const getReactions$1 = (params, callback, config) => {
|
|
|
18108
18143
|
};
|
|
18109
18144
|
/* end_public_function */
|
|
18110
18145
|
|
|
18111
|
-
var index$
|
|
18146
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
18112
18147
|
__proto__: null,
|
|
18113
18148
|
addReaction: addReaction,
|
|
18114
18149
|
removeReaction: removeReaction,
|
|
@@ -19880,7 +19915,7 @@ const getMessages = (params, callback, config) => {
|
|
|
19880
19915
|
};
|
|
19881
19916
|
/* end_public_function */
|
|
19882
19917
|
|
|
19883
|
-
var index$
|
|
19918
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
19884
19919
|
__proto__: null,
|
|
19885
19920
|
createMessage: createMessage,
|
|
19886
19921
|
updateMessage: updateMessage,
|
|
@@ -20406,7 +20441,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
20406
20441
|
};
|
|
20407
20442
|
/* end_public_function */
|
|
20408
20443
|
|
|
20409
|
-
var index$
|
|
20444
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
20410
20445
|
__proto__: null,
|
|
20411
20446
|
getSubChannelByIds: getSubChannels$1,
|
|
20412
20447
|
createSubChannel: createSubChannel,
|
|
@@ -21733,7 +21768,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
21733
21768
|
};
|
|
21734
21769
|
/* end_public_function */
|
|
21735
21770
|
|
|
21736
|
-
var index$
|
|
21771
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
21737
21772
|
__proto__: null,
|
|
21738
21773
|
addMembers: addMembers$1,
|
|
21739
21774
|
removeMembers: removeMembers$1,
|
|
@@ -21936,7 +21971,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
21936
21971
|
};
|
|
21937
21972
|
/* end_public_function */
|
|
21938
21973
|
|
|
21939
|
-
var index$
|
|
21974
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
21940
21975
|
__proto__: null,
|
|
21941
21976
|
addRole: addRole,
|
|
21942
21977
|
removeRole: removeRole,
|
|
@@ -21946,10 +21981,10 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
21946
21981
|
unmuteMembers: unmuteMembers
|
|
21947
21982
|
});
|
|
21948
21983
|
|
|
21949
|
-
var index$
|
|
21984
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
21950
21985
|
__proto__: null,
|
|
21951
|
-
Membership: index$
|
|
21952
|
-
Moderation: index$
|
|
21986
|
+
Membership: index$l,
|
|
21987
|
+
Moderation: index$k,
|
|
21953
21988
|
getChannelByIds: getChannelByIds$1,
|
|
21954
21989
|
createChannel: createChannel,
|
|
21955
21990
|
updateChannel: updateChannel,
|
|
@@ -23352,7 +23387,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
23352
23387
|
};
|
|
23353
23388
|
/* end_public_function */
|
|
23354
23389
|
|
|
23355
|
-
var index$
|
|
23390
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
23356
23391
|
__proto__: null,
|
|
23357
23392
|
addMembers: addMembers,
|
|
23358
23393
|
removeMembers: removeMembers,
|
|
@@ -24603,7 +24638,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
24603
24638
|
};
|
|
24604
24639
|
/* end_public_function */
|
|
24605
24640
|
|
|
24606
|
-
var index$
|
|
24641
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
24607
24642
|
__proto__: null,
|
|
24608
24643
|
addRoles: addRoles,
|
|
24609
24644
|
removeRoles: removeRoles,
|
|
@@ -24611,10 +24646,10 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
24611
24646
|
unbanMembers: unbanMembers
|
|
24612
24647
|
});
|
|
24613
24648
|
|
|
24614
|
-
var index$
|
|
24649
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
24615
24650
|
__proto__: null,
|
|
24616
|
-
Moderation: index$
|
|
24617
|
-
Membership: index$
|
|
24651
|
+
Moderation: index$h,
|
|
24652
|
+
Membership: index$i,
|
|
24618
24653
|
getCommunityByIds: getCommunities$1,
|
|
24619
24654
|
createCommunity: createCommunity,
|
|
24620
24655
|
updateCommunity: updateCommunity,
|
|
@@ -24848,7 +24883,7 @@ const getCategories = (params, callback, config) => {
|
|
|
24848
24883
|
};
|
|
24849
24884
|
/* end_public_function */
|
|
24850
24885
|
|
|
24851
|
-
var index$
|
|
24886
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
24852
24887
|
__proto__: null,
|
|
24853
24888
|
getCategory: getCategory,
|
|
24854
24889
|
getCategories: getCategories
|
|
@@ -24967,6 +25002,9 @@ var EnumPostActions;
|
|
|
24967
25002
|
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
24968
25003
|
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
24969
25004
|
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
25005
|
+
EnumPostActions["OnPostPinProduct"] = "onPostPinProduct";
|
|
25006
|
+
EnumPostActions["OnPostUnpinProduct"] = "onPostUnpinProduct";
|
|
25007
|
+
EnumPostActions["OnPostUpdateProductTags"] = "onPostUpdateProductTags";
|
|
24970
25008
|
})(EnumPostActions || (EnumPostActions = {}));
|
|
24971
25009
|
|
|
24972
25010
|
class CustomRankingGlobalFeedQueryStreamController extends QueryStreamController {
|
|
@@ -25907,7 +25945,7 @@ const getComments = (params, callback, config) => {
|
|
|
25907
25945
|
};
|
|
25908
25946
|
/* end_public_function */
|
|
25909
25947
|
|
|
25910
|
-
var index$
|
|
25948
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
25911
25949
|
__proto__: null,
|
|
25912
25950
|
getCommentByIds: getCommentByIds,
|
|
25913
25951
|
createComment: createComment,
|
|
@@ -26578,7 +26616,7 @@ const getUserFeed = (params, callback, config) => {
|
|
|
26578
26616
|
};
|
|
26579
26617
|
/* end_public_function */
|
|
26580
26618
|
|
|
26581
|
-
var index$
|
|
26619
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
26582
26620
|
__proto__: null,
|
|
26583
26621
|
queryGlobalFeed: queryGlobalFeed,
|
|
26584
26622
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
@@ -26693,7 +26731,15 @@ const createPost = async (bundle) => {
|
|
|
26693
26731
|
// eslint-disable-next-line no-param-reassign
|
|
26694
26732
|
delete bundle.dataType;
|
|
26695
26733
|
}
|
|
26696
|
-
const {
|
|
26734
|
+
const { attachments } = bundle;
|
|
26735
|
+
const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
|
|
26736
|
+
? attachments.map(attachment => {
|
|
26737
|
+
if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
|
|
26738
|
+
return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
|
|
26739
|
+
return attachment;
|
|
26740
|
+
})
|
|
26741
|
+
: attachments;
|
|
26742
|
+
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, bundle), { attachments: processedAttachments }));
|
|
26697
26743
|
fireEvent('post.created', payload);
|
|
26698
26744
|
const data = preparePostPayload(payload);
|
|
26699
26745
|
const cachedAt = client.cache && Date.now();
|
|
@@ -26730,7 +26776,15 @@ const createPost = async (bundle) => {
|
|
|
26730
26776
|
const editPost = async (postId, patch) => {
|
|
26731
26777
|
const client = getActiveClient();
|
|
26732
26778
|
client.log('user/editPost', patch);
|
|
26733
|
-
const {
|
|
26779
|
+
const { attachments } = patch;
|
|
26780
|
+
const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
|
|
26781
|
+
? attachments.map(attachment => {
|
|
26782
|
+
if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
|
|
26783
|
+
return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
|
|
26784
|
+
return attachment;
|
|
26785
|
+
})
|
|
26786
|
+
: attachments;
|
|
26787
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, Object.assign(Object.assign({}, patch), { attachments: processedAttachments }));
|
|
26734
26788
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
26735
26789
|
const cachedAt = client.cache && Date.now();
|
|
26736
26790
|
if (client.cache)
|
|
@@ -27153,6 +27207,143 @@ const createMixedMediaPost = async (bundle) => {
|
|
|
27153
27207
|
};
|
|
27154
27208
|
/* end_public_function */
|
|
27155
27209
|
|
|
27210
|
+
/* begin_public_function
|
|
27211
|
+
id: post.create_room_post
|
|
27212
|
+
*/
|
|
27213
|
+
/**
|
|
27214
|
+
* ```js
|
|
27215
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
27216
|
+
* const created = await PostRepository.createRoomPost({
|
|
27217
|
+
* targetType: 'user',
|
|
27218
|
+
* targetId: 'foobar',
|
|
27219
|
+
* data: { text: 'hello world', title: 'Room Title', roomId: 'roomId123' }
|
|
27220
|
+
* }))
|
|
27221
|
+
* ```
|
|
27222
|
+
*
|
|
27223
|
+
* Creates an {@link Amity.Post}
|
|
27224
|
+
*
|
|
27225
|
+
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
27226
|
+
* @returns The newly created {@link Amity.Post}
|
|
27227
|
+
*
|
|
27228
|
+
* @category Post API
|
|
27229
|
+
* @async
|
|
27230
|
+
*/
|
|
27231
|
+
const createRoomPost = async (bundle) => {
|
|
27232
|
+
const client = getActiveClient();
|
|
27233
|
+
client.log('post/createRoomPost', bundle);
|
|
27234
|
+
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, bundle), { dataType: 'room' }));
|
|
27235
|
+
fireEvent('post.created', payload);
|
|
27236
|
+
const data = preparePostPayload(payload);
|
|
27237
|
+
const cachedAt = client.cache && Date.now();
|
|
27238
|
+
if (client.cache)
|
|
27239
|
+
ingestInCache(data, { cachedAt });
|
|
27240
|
+
const { posts } = data;
|
|
27241
|
+
return {
|
|
27242
|
+
data: LinkedObject.post(posts[0]),
|
|
27243
|
+
cachedAt,
|
|
27244
|
+
};
|
|
27245
|
+
};
|
|
27246
|
+
/* end_public_function */
|
|
27247
|
+
|
|
27248
|
+
/* begin_public_function
|
|
27249
|
+
id: post.pin_product
|
|
27250
|
+
*/
|
|
27251
|
+
/**
|
|
27252
|
+
* ```js
|
|
27253
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
27254
|
+
* const pinProduct = await PostRepository.pinProduct(postId, productId)
|
|
27255
|
+
* ```
|
|
27256
|
+
*
|
|
27257
|
+
* @param postId The ID of the post to unpin the product from
|
|
27258
|
+
* @param productId the ID of the product to pin
|
|
27259
|
+
* @returns Amity.Post
|
|
27260
|
+
*
|
|
27261
|
+
* @category Post API
|
|
27262
|
+
* @async
|
|
27263
|
+
* */
|
|
27264
|
+
const pinProduct = async (postId, productId) => {
|
|
27265
|
+
const client = getActiveClient();
|
|
27266
|
+
client.log('post/pinProduct', postId);
|
|
27267
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
27268
|
+
productId,
|
|
27269
|
+
});
|
|
27270
|
+
const data = preparePostPayload(payload);
|
|
27271
|
+
const cachedAt = client.cache && Date.now();
|
|
27272
|
+
if (client.cache)
|
|
27273
|
+
ingestInCache(payload, { cachedAt });
|
|
27274
|
+
fireEvent('local.post.updated', payload);
|
|
27275
|
+
return {
|
|
27276
|
+
data: postLinkedObject(data === null || data === void 0 ? void 0 : data.posts[0]),
|
|
27277
|
+
cachedAt,
|
|
27278
|
+
};
|
|
27279
|
+
};
|
|
27280
|
+
/* end_public_function */
|
|
27281
|
+
|
|
27282
|
+
/* begin_public_function
|
|
27283
|
+
id: post.unpin_product
|
|
27284
|
+
*/
|
|
27285
|
+
/**
|
|
27286
|
+
* ```js
|
|
27287
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
27288
|
+
* const unpinProduct = await PostRepository.unpinProduct(postId)
|
|
27289
|
+
* ```
|
|
27290
|
+
*
|
|
27291
|
+
* @param postId The ID of the post to unpin the product from
|
|
27292
|
+
* @returns Amity.Post
|
|
27293
|
+
*
|
|
27294
|
+
* @category Post API
|
|
27295
|
+
* @async
|
|
27296
|
+
* */
|
|
27297
|
+
const unpinProduct = async (postId) => {
|
|
27298
|
+
const client = getActiveClient();
|
|
27299
|
+
client.log('post/unpinProduct', postId);
|
|
27300
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, { pinnedProductId: null });
|
|
27301
|
+
const data = preparePostPayload(payload);
|
|
27302
|
+
const cachedAt = client.cache && Date.now();
|
|
27303
|
+
if (client.cache)
|
|
27304
|
+
ingestInCache(payload, { cachedAt });
|
|
27305
|
+
fireEvent('local.post.updated', payload);
|
|
27306
|
+
return {
|
|
27307
|
+
data: postLinkedObject(data === null || data === void 0 ? void 0 : data.posts[0]),
|
|
27308
|
+
cachedAt,
|
|
27309
|
+
};
|
|
27310
|
+
};
|
|
27311
|
+
/* end_public_function */
|
|
27312
|
+
|
|
27313
|
+
/* begin_public_function
|
|
27314
|
+
id: post.update_product_tags
|
|
27315
|
+
*/
|
|
27316
|
+
/**
|
|
27317
|
+
* ```js
|
|
27318
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
27319
|
+
* const updateProductTags = await PostRepository.updateProductTags(postId, productTags)
|
|
27320
|
+
* ```
|
|
27321
|
+
*
|
|
27322
|
+
* @param postId of child room
|
|
27323
|
+
* @param productTags the array of product tags to set on the post
|
|
27324
|
+
* @returns Amity.Post
|
|
27325
|
+
*
|
|
27326
|
+
* @category Post API
|
|
27327
|
+
* @async
|
|
27328
|
+
* */
|
|
27329
|
+
const updateProductTags = async (postId, productTags) => {
|
|
27330
|
+
const client = getActiveClient();
|
|
27331
|
+
client.log('post/updateProductTags', postId);
|
|
27332
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
27333
|
+
productTags,
|
|
27334
|
+
});
|
|
27335
|
+
const data = preparePostPayload(payload);
|
|
27336
|
+
const cachedAt = client.cache && Date.now();
|
|
27337
|
+
if (client.cache)
|
|
27338
|
+
ingestInCache(payload, { cachedAt });
|
|
27339
|
+
fireEvent('local.post.updated', payload);
|
|
27340
|
+
return {
|
|
27341
|
+
data: postLinkedObject(data === null || data === void 0 ? void 0 : data.posts[0]),
|
|
27342
|
+
cachedAt,
|
|
27343
|
+
};
|
|
27344
|
+
};
|
|
27345
|
+
/* end_public_function */
|
|
27346
|
+
|
|
27156
27347
|
/* begin_public_function
|
|
27157
27348
|
id: post.get
|
|
27158
27349
|
*/
|
|
@@ -28934,6 +29125,30 @@ const onRoomTerminated = (callback) => {
|
|
|
28934
29125
|
return createEventSubscriber(client, 'room/onRoomTerminated', 'room.terminated', filter);
|
|
28935
29126
|
};
|
|
28936
29127
|
|
|
29128
|
+
/**
|
|
29129
|
+
* ```js
|
|
29130
|
+
* import { onRoomDidUpdate } from '@amityco/ts-sdk'
|
|
29131
|
+
* const dispose = onRoomDidUpdate(room => {
|
|
29132
|
+
* // ...
|
|
29133
|
+
* })
|
|
29134
|
+
* ```
|
|
29135
|
+
*
|
|
29136
|
+
* Fired when a {@link Amity.Room} has been updated locally
|
|
29137
|
+
*
|
|
29138
|
+
* @param callback The function to call when the event was fired
|
|
29139
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
29140
|
+
*
|
|
29141
|
+
* @category Room Events
|
|
29142
|
+
*/
|
|
29143
|
+
const onRoomDidUpdate = (callback) => {
|
|
29144
|
+
const client = getActiveClient();
|
|
29145
|
+
const filter = (payload) => {
|
|
29146
|
+
ingestInCache(payload);
|
|
29147
|
+
callback(payload.rooms[0]);
|
|
29148
|
+
};
|
|
29149
|
+
return createEventSubscriber(client, 'room/onRoomDidUpdate', 'local.room.didUpdate', filter);
|
|
29150
|
+
};
|
|
29151
|
+
|
|
28937
29152
|
/**
|
|
28938
29153
|
* ```js
|
|
28939
29154
|
* import { onRoomCreated } from '@amityco/ts-sdk'
|
|
@@ -29082,6 +29297,30 @@ const onRoomLeft = (callback) => {
|
|
|
29082
29297
|
return createEventSubscriber(client, 'room/onRoomLeft', 'local.room.left', filter);
|
|
29083
29298
|
};
|
|
29084
29299
|
|
|
29300
|
+
/**
|
|
29301
|
+
* ```js
|
|
29302
|
+
* import { onLocalRoomDidUpdate } from '@amityco/ts-sdk'
|
|
29303
|
+
* const dispose = onLocalRoomDidUpdate(room => {
|
|
29304
|
+
* // ...
|
|
29305
|
+
* })
|
|
29306
|
+
* ```
|
|
29307
|
+
*
|
|
29308
|
+
* Fired when a {@link Amity.Room} has been updated locally
|
|
29309
|
+
*
|
|
29310
|
+
* @param callback The function to call when the event was fired
|
|
29311
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
29312
|
+
*
|
|
29313
|
+
* @category Room Events
|
|
29314
|
+
*/
|
|
29315
|
+
const onLocalRoomDidUpdate = (callback) => {
|
|
29316
|
+
const client = getActiveClient();
|
|
29317
|
+
const filter = (payload) => {
|
|
29318
|
+
ingestInCache(payload);
|
|
29319
|
+
callback(payload.rooms[0]);
|
|
29320
|
+
};
|
|
29321
|
+
return createEventSubscriber(client, 'room/onLocalRoomDidUpdate', 'room.didUpdate', filter);
|
|
29322
|
+
};
|
|
29323
|
+
|
|
29085
29324
|
/**
|
|
29086
29325
|
* ```js
|
|
29087
29326
|
* import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
|
|
@@ -29115,6 +29354,7 @@ var EnumRoomActions;
|
|
|
29115
29354
|
EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
|
|
29116
29355
|
EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
|
|
29117
29356
|
EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
|
|
29357
|
+
EnumRoomActions["OnRoomDidUpdate"] = "OnRoomDidUpdate";
|
|
29118
29358
|
})(EnumRoomActions || (EnumRoomActions = {}));
|
|
29119
29359
|
|
|
29120
29360
|
const convertToRoomEventPayload = (eventHandler) => (callback) => eventHandler((payload) => {
|
|
@@ -29166,6 +29406,14 @@ const getRoomSubscription = () => [
|
|
|
29166
29406
|
fn: convertEventPayload(onRoomCoHostInviteAccepted, 'targetId', 'room'),
|
|
29167
29407
|
action: EnumRoomActions.OnRoomUpdated,
|
|
29168
29408
|
},
|
|
29409
|
+
{
|
|
29410
|
+
fn: onRoomDidUpdate,
|
|
29411
|
+
action: EnumRoomActions.OnRoomDidUpdate,
|
|
29412
|
+
},
|
|
29413
|
+
{
|
|
29414
|
+
fn: onLocalRoomDidUpdate,
|
|
29415
|
+
action: EnumRoomActions.OnRoomDidUpdate,
|
|
29416
|
+
},
|
|
29169
29417
|
];
|
|
29170
29418
|
|
|
29171
29419
|
const getRoom = (roomId, callback) => {
|
|
@@ -29374,7 +29622,7 @@ const getRooms = (params, callback, config) => {
|
|
|
29374
29622
|
};
|
|
29375
29623
|
/* end_public_function */
|
|
29376
29624
|
|
|
29377
|
-
var index$
|
|
29625
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
29378
29626
|
__proto__: null,
|
|
29379
29627
|
createRoom: createRoom,
|
|
29380
29628
|
updateRoom: updateRoom,
|
|
@@ -29401,12 +29649,14 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
29401
29649
|
onRoomParticipantStageLeft: onRoomParticipantStageLeft,
|
|
29402
29650
|
onRoomParticipantStageJoined: onRoomParticipantStageJoined,
|
|
29403
29651
|
onRoomTerminated: onRoomTerminated,
|
|
29652
|
+
onRoomDidUpdate: onRoomDidUpdate,
|
|
29404
29653
|
onRoomCreated: onRoomCreated,
|
|
29405
29654
|
onRoomUpdated: onRoomUpdated,
|
|
29406
29655
|
onRoomDeleted: onRoomDeleted,
|
|
29407
29656
|
onRoomStopped: onRoomStopped,
|
|
29408
29657
|
onRoomParticipantRemoved: onRoomParticipantRemoved,
|
|
29409
29658
|
onRoomLeft: onRoomLeft,
|
|
29659
|
+
onLocalRoomDidUpdate: onLocalRoomDidUpdate,
|
|
29410
29660
|
getRoom: getRoom,
|
|
29411
29661
|
getRooms: getRooms
|
|
29412
29662
|
});
|
|
@@ -29670,7 +29920,7 @@ const getCommunityLiveRoomPosts = (params, callback, config) => {
|
|
|
29670
29920
|
};
|
|
29671
29921
|
/* end_public_function */
|
|
29672
29922
|
|
|
29673
|
-
var index$
|
|
29923
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
29674
29924
|
__proto__: null,
|
|
29675
29925
|
getPostByIds: getPostByIds,
|
|
29676
29926
|
createPost: createPost,
|
|
@@ -29686,6 +29936,10 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
29686
29936
|
createClipPost: createClipPost,
|
|
29687
29937
|
createAudioPost: createAudioPost,
|
|
29688
29938
|
createMixedMediaPost: createMixedMediaPost,
|
|
29939
|
+
createRoomPost: createRoomPost,
|
|
29940
|
+
pinProduct: pinProduct,
|
|
29941
|
+
unpinProduct: unpinProduct,
|
|
29942
|
+
updateProductTags: updateProductTags,
|
|
29689
29943
|
onPostCreated: onPostCreated,
|
|
29690
29944
|
onPostUpdated: onPostUpdated,
|
|
29691
29945
|
onPostDeleted: onPostDeleted,
|
|
@@ -30280,7 +30534,7 @@ const getStreams = (params, callback, config) => {
|
|
|
30280
30534
|
};
|
|
30281
30535
|
};
|
|
30282
30536
|
|
|
30283
|
-
var index$
|
|
30537
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
30284
30538
|
__proto__: null,
|
|
30285
30539
|
createStream: createStream,
|
|
30286
30540
|
updateStream: updateStream,
|
|
@@ -30583,7 +30837,7 @@ const stopHeartbeat = (roomId) => {
|
|
|
30583
30837
|
};
|
|
30584
30838
|
/* end_public_function */
|
|
30585
30839
|
|
|
30586
|
-
var index$
|
|
30840
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
30587
30841
|
__proto__: null,
|
|
30588
30842
|
getRoomOnlineUsers: getRoomOnlineUsers,
|
|
30589
30843
|
getRoomUserCount: getRoomUserCount,
|
|
@@ -30891,7 +31145,7 @@ const getPoll = (pollId, callback) => {
|
|
|
30891
31145
|
};
|
|
30892
31146
|
/* end_public_function */
|
|
30893
31147
|
|
|
30894
|
-
var index$
|
|
31148
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
30895
31149
|
__proto__: null,
|
|
30896
31150
|
createPoll: createPoll,
|
|
30897
31151
|
closePoll: closePoll,
|
|
@@ -31195,7 +31449,7 @@ const getPlayer = async (parameters) => {
|
|
|
31195
31449
|
return video;
|
|
31196
31450
|
};
|
|
31197
31451
|
|
|
31198
|
-
var index$
|
|
31452
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
31199
31453
|
__proto__: null,
|
|
31200
31454
|
getPlayer: getPlayer
|
|
31201
31455
|
});
|
|
@@ -32368,7 +32622,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
32368
32622
|
};
|
|
32369
32623
|
};
|
|
32370
32624
|
|
|
32371
|
-
var index$
|
|
32625
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
32372
32626
|
__proto__: null,
|
|
32373
32627
|
createImageStory: createImageStory,
|
|
32374
32628
|
createVideoStory: createVideoStory,
|
|
@@ -32405,7 +32659,7 @@ const getNetworkAds = async () => {
|
|
|
32405
32659
|
};
|
|
32406
32660
|
};
|
|
32407
32661
|
|
|
32408
|
-
var index$
|
|
32662
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
32409
32663
|
__proto__: null,
|
|
32410
32664
|
getNetworkAds: getNetworkAds
|
|
32411
32665
|
});
|
|
@@ -32796,7 +33050,7 @@ const markTraySeen = async (lastSeenAt) => {
|
|
|
32796
33050
|
};
|
|
32797
33051
|
/* end_public_function */
|
|
32798
33052
|
|
|
32799
|
-
var index$
|
|
33053
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
32800
33054
|
__proto__: null,
|
|
32801
33055
|
getNotificationTraySeen: getNotificationTraySeen,
|
|
32802
33056
|
getNotificationTrayItems: getNotificationTrayItems,
|
|
@@ -33094,7 +33348,7 @@ const getInvitations = (params, callback) => {
|
|
|
33094
33348
|
};
|
|
33095
33349
|
};
|
|
33096
33350
|
|
|
33097
|
-
var index$
|
|
33351
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
33098
33352
|
__proto__: null,
|
|
33099
33353
|
cancelInvitation: cancelInvitation,
|
|
33100
33354
|
onLocalInvitationCreated: onLocalInvitationCreated,
|
|
@@ -33243,7 +33497,7 @@ const getReactions = (postId, callback) => {
|
|
|
33243
33497
|
};
|
|
33244
33498
|
};
|
|
33245
33499
|
|
|
33246
|
-
var index$
|
|
33500
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
33247
33501
|
__proto__: null,
|
|
33248
33502
|
createReaction: createReaction,
|
|
33249
33503
|
onLiveReactionCreated: onLiveReactionCreated,
|
|
@@ -33726,7 +33980,7 @@ const getMyEvents = (params, callback, config) => {
|
|
|
33726
33980
|
};
|
|
33727
33981
|
};
|
|
33728
33982
|
|
|
33729
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
33983
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
33730
33984
|
__proto__: null,
|
|
33731
33985
|
createEvent: createEvent,
|
|
33732
33986
|
updateEvent: updateEvent,
|
|
@@ -33747,38 +34001,249 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
33747
34001
|
getRSVPs: getRSVPs
|
|
33748
34002
|
});
|
|
33749
34003
|
|
|
34004
|
+
const getProduct$1 = async (productId) => {
|
|
34005
|
+
const client = getActiveClient();
|
|
34006
|
+
client.log('product/getProduct', productId);
|
|
34007
|
+
isInTombstone('product', productId);
|
|
34008
|
+
let payload;
|
|
34009
|
+
try {
|
|
34010
|
+
const response = await client.http.get(`/api/v1/products/${encodeURIComponent(productId)}`);
|
|
34011
|
+
payload = response.data;
|
|
34012
|
+
}
|
|
34013
|
+
catch (error) {
|
|
34014
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
34015
|
+
pushToTombstone('product', productId);
|
|
34016
|
+
}
|
|
34017
|
+
throw error;
|
|
34018
|
+
}
|
|
34019
|
+
const cachedAt = client.cache && Date.now();
|
|
34020
|
+
if (client.cache)
|
|
34021
|
+
ingestInCache(payload, { cachedAt });
|
|
34022
|
+
const { products } = payload;
|
|
34023
|
+
const result = products.find(product => product.productId === productId);
|
|
34024
|
+
return {
|
|
34025
|
+
data: result,
|
|
34026
|
+
cachedAt,
|
|
34027
|
+
};
|
|
34028
|
+
};
|
|
34029
|
+
getProduct$1.locally = (productId) => {
|
|
34030
|
+
const client = getActiveClient();
|
|
34031
|
+
client.log('product/getProduct.locally', productId);
|
|
34032
|
+
if (!client.cache)
|
|
34033
|
+
return;
|
|
34034
|
+
const cached = pullFromCache(['product', 'get', productId]);
|
|
34035
|
+
if (!cached)
|
|
34036
|
+
return;
|
|
34037
|
+
return {
|
|
34038
|
+
data: cached.data,
|
|
34039
|
+
cachedAt: cached.cachedAt,
|
|
34040
|
+
};
|
|
34041
|
+
};
|
|
34042
|
+
|
|
34043
|
+
/* begin_public_function
|
|
34044
|
+
id: product.get
|
|
34045
|
+
*/
|
|
34046
|
+
/**
|
|
34047
|
+
* ```js
|
|
34048
|
+
* import { ProductRepository } from '@amityco/ts-sdk';
|
|
34049
|
+
*
|
|
34050
|
+
* let product;
|
|
34051
|
+
*
|
|
34052
|
+
* const unsub = ProductRepository.getProduct(productId, response => {
|
|
34053
|
+
* product = response.data;
|
|
34054
|
+
* });
|
|
34055
|
+
* ```
|
|
34056
|
+
*
|
|
34057
|
+
* Observe all mutation on a given {@link Amity.Product}
|
|
34058
|
+
*
|
|
34059
|
+
* @param productId the ID of the product to observe
|
|
34060
|
+
* @param callback the function to call when new data are available
|
|
34061
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the product
|
|
34062
|
+
*
|
|
34063
|
+
* @category Product Live Object
|
|
34064
|
+
*/
|
|
34065
|
+
const getProduct = (productId, callback) => {
|
|
34066
|
+
const responder = (snapshot) => {
|
|
34067
|
+
callback(snapshot);
|
|
34068
|
+
};
|
|
34069
|
+
return liveObject(productId, responder, 'productId', getProduct$1, []);
|
|
34070
|
+
};
|
|
34071
|
+
/* end_public_function */
|
|
34072
|
+
|
|
34073
|
+
class SearchProductPaginationController extends PaginationController {
|
|
34074
|
+
async getRequest(queryParams, token) {
|
|
34075
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
34076
|
+
const options = token ? { token } : { limit };
|
|
34077
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/products/search`, {
|
|
34078
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
34079
|
+
});
|
|
34080
|
+
return queryResponse;
|
|
34081
|
+
}
|
|
34082
|
+
}
|
|
34083
|
+
|
|
34084
|
+
class SearchProductQueryStreamController extends QueryStreamController {
|
|
34085
|
+
constructor(query, cacheKey, notifyChange) {
|
|
34086
|
+
super(query, cacheKey);
|
|
34087
|
+
this.notifyChange = notifyChange;
|
|
34088
|
+
}
|
|
34089
|
+
// eslint-disable-next-line class-methods-use-this
|
|
34090
|
+
saveToMainDB(response) {
|
|
34091
|
+
const client = getActiveClient();
|
|
34092
|
+
const cachedAt = client.cache && Date.now();
|
|
34093
|
+
if (client.cache) {
|
|
34094
|
+
ingestInCache(response, { cachedAt });
|
|
34095
|
+
}
|
|
34096
|
+
}
|
|
34097
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
34098
|
+
var _a, _b;
|
|
34099
|
+
if (refresh) {
|
|
34100
|
+
pushToCache(this.cacheKey, {
|
|
34101
|
+
data: response.products.map(getResolver('product')),
|
|
34102
|
+
});
|
|
34103
|
+
}
|
|
34104
|
+
else {
|
|
34105
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34106
|
+
const products = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
34107
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...products, ...response.products.map(getResolver('product'))])] }));
|
|
34108
|
+
}
|
|
34109
|
+
}
|
|
34110
|
+
}
|
|
34111
|
+
|
|
34112
|
+
class SearchProductLiveCollectionController extends LiveCollectionController {
|
|
34113
|
+
constructor(query, callback) {
|
|
34114
|
+
const queryStreamId = hash__default["default"](query);
|
|
34115
|
+
const cacheKey = ['products', 'collection', queryStreamId];
|
|
34116
|
+
const paginationController = new SearchProductPaginationController(query);
|
|
34117
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
34118
|
+
this.query = query;
|
|
34119
|
+
this.queryStreamController = new SearchProductQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this));
|
|
34120
|
+
this.callback = callback.bind(this);
|
|
34121
|
+
this.loadPage({ initial: true });
|
|
34122
|
+
}
|
|
34123
|
+
setup() {
|
|
34124
|
+
var _a;
|
|
34125
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34126
|
+
if (!collection) {
|
|
34127
|
+
pushToCache(this.cacheKey, {
|
|
34128
|
+
data: [],
|
|
34129
|
+
params: {},
|
|
34130
|
+
});
|
|
34131
|
+
}
|
|
34132
|
+
}
|
|
34133
|
+
async persistModel(queryPayload) {
|
|
34134
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
34135
|
+
}
|
|
34136
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
34137
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
34138
|
+
}
|
|
34139
|
+
// eslint-disable-next-line class-methods-use-this
|
|
34140
|
+
startSubscription() {
|
|
34141
|
+
return [];
|
|
34142
|
+
}
|
|
34143
|
+
notifyChange({ origin, loading, error }) {
|
|
34144
|
+
var _a, _b;
|
|
34145
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34146
|
+
if (!collection)
|
|
34147
|
+
return;
|
|
34148
|
+
const data = (_b = collection.data
|
|
34149
|
+
.map(id => pullFromCache(['product', 'get', id]))
|
|
34150
|
+
.filter(isNonNullable)
|
|
34151
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
34152
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
34153
|
+
return;
|
|
34154
|
+
this.callback({
|
|
34155
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
34156
|
+
data,
|
|
34157
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
34158
|
+
loading,
|
|
34159
|
+
error,
|
|
34160
|
+
});
|
|
34161
|
+
}
|
|
34162
|
+
}
|
|
34163
|
+
|
|
34164
|
+
/* begin_public_function
|
|
34165
|
+
id: product.search
|
|
34166
|
+
*/
|
|
34167
|
+
/**
|
|
34168
|
+
* ```js
|
|
34169
|
+
* import { ProductRepository } from '@amityco/ts-sdk'
|
|
34170
|
+
*
|
|
34171
|
+
* let products = []
|
|
34172
|
+
* const unsub = ProductRepository.searchProducts({
|
|
34173
|
+
* keyword: string,
|
|
34174
|
+
* }, response => merge(products, response.data))
|
|
34175
|
+
* ```
|
|
34176
|
+
*
|
|
34177
|
+
* Observe all mutations on a list of {@link Amity.Product}
|
|
34178
|
+
*
|
|
34179
|
+
* @param params.keyword the search keyword
|
|
34180
|
+
* @param params.isActive filter by active status
|
|
34181
|
+
* @param params.isDeleted filter by deleted status
|
|
34182
|
+
* @param params.sortBy sort option
|
|
34183
|
+
* @param params.sortOrder order option
|
|
34184
|
+
* @param callback the function to call when new data are available
|
|
34185
|
+
* @param config
|
|
34186
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the products
|
|
34187
|
+
*
|
|
34188
|
+
* @category Products Live Collection
|
|
34189
|
+
*/
|
|
34190
|
+
const searchProducts = (params, callback, config) => {
|
|
34191
|
+
const { log, cache } = getActiveClient();
|
|
34192
|
+
if (!cache) {
|
|
34193
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
34194
|
+
}
|
|
34195
|
+
const timestamp = Date.now();
|
|
34196
|
+
log(`searchProducts(tmpid: ${timestamp}) > listen`);
|
|
34197
|
+
const productsLiveCollection = new SearchProductLiveCollectionController(params, callback);
|
|
34198
|
+
const disposers = productsLiveCollection.startSubscription();
|
|
34199
|
+
const cacheKey = productsLiveCollection.getCacheKey();
|
|
34200
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
34201
|
+
return () => {
|
|
34202
|
+
log(`searchProducts(tmpid: ${timestamp}) > dispose`);
|
|
34203
|
+
disposers.forEach(fn => fn());
|
|
34204
|
+
};
|
|
34205
|
+
};
|
|
34206
|
+
/* end_public_function */
|
|
34207
|
+
|
|
34208
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
34209
|
+
__proto__: null,
|
|
34210
|
+
getProduct: getProduct,
|
|
34211
|
+
searchProducts: searchProducts
|
|
34212
|
+
});
|
|
34213
|
+
|
|
33750
34214
|
exports.API_REGIONS = API_REGIONS;
|
|
33751
|
-
exports.AdRepository = index$
|
|
33752
|
-
exports.CategoryRepository = index$
|
|
33753
|
-
exports.ChannelRepository = index$
|
|
33754
|
-
exports.Client = index$
|
|
33755
|
-
exports.CommentRepository = index$
|
|
34215
|
+
exports.AdRepository = index$5;
|
|
34216
|
+
exports.CategoryRepository = index$f;
|
|
34217
|
+
exports.ChannelRepository = index$j;
|
|
34218
|
+
exports.Client = index$s;
|
|
34219
|
+
exports.CommentRepository = index$e;
|
|
33756
34220
|
exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
|
|
33757
34221
|
exports.CommunityPostSettings = CommunityPostSettings;
|
|
33758
|
-
exports.CommunityRepository = index$
|
|
34222
|
+
exports.CommunityRepository = index$g;
|
|
33759
34223
|
exports.ContentFeedType = ContentFeedType;
|
|
33760
34224
|
exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
|
|
33761
|
-
exports.EventRepository = index;
|
|
33762
|
-
exports.FeedRepository = index$
|
|
33763
|
-
exports.FileRepository = index$
|
|
34225
|
+
exports.EventRepository = index$1;
|
|
34226
|
+
exports.FeedRepository = index$d;
|
|
34227
|
+
exports.FileRepository = index$p;
|
|
33764
34228
|
exports.FileType = FileType;
|
|
33765
34229
|
exports.GET_WATCHER_URLS = GET_WATCHER_URLS;
|
|
33766
|
-
exports.InvitationRepository = index$
|
|
33767
|
-
exports.LiveReactionRepository = index$
|
|
33768
|
-
exports.LiveStreamPlayer = index$
|
|
34230
|
+
exports.InvitationRepository = index$3;
|
|
34231
|
+
exports.LiveReactionRepository = index$2;
|
|
34232
|
+
exports.LiveStreamPlayer = index$7;
|
|
33769
34233
|
exports.MessageContentType = MessageContentType;
|
|
33770
|
-
exports.MessageRepository = index$
|
|
33771
|
-
exports.PollRepository = index$
|
|
34234
|
+
exports.MessageRepository = index$n;
|
|
34235
|
+
exports.PollRepository = index$8;
|
|
33772
34236
|
exports.PostContentType = PostContentType;
|
|
33773
|
-
exports.PostRepository = index$
|
|
34237
|
+
exports.PostRepository = index$b;
|
|
33774
34238
|
exports.PostStructureType = PostStructureType;
|
|
33775
|
-
exports.
|
|
33776
|
-
exports.
|
|
33777
|
-
exports.
|
|
33778
|
-
exports.
|
|
33779
|
-
exports.
|
|
33780
|
-
exports.
|
|
33781
|
-
exports.
|
|
34239
|
+
exports.ProductRepository = index;
|
|
34240
|
+
exports.ReactionRepository = index$o;
|
|
34241
|
+
exports.RoomPresenceRepository = index$9;
|
|
34242
|
+
exports.RoomRepository = index$c;
|
|
34243
|
+
exports.StoryRepository = index$6;
|
|
34244
|
+
exports.StreamRepository = index$a;
|
|
34245
|
+
exports.SubChannelRepository = index$m;
|
|
34246
|
+
exports.UserRepository = index$q;
|
|
33782
34247
|
exports.VERSION = VERSION;
|
|
33783
34248
|
exports.VideoResolution = VideoResolution;
|
|
33784
34249
|
exports.VideoSize = VideoSize;
|
|
@@ -33834,7 +34299,7 @@ exports.isPaged = isPaged;
|
|
|
33834
34299
|
exports.isReportedByMe = isReportedByMe;
|
|
33835
34300
|
exports.isSkip = isSkip;
|
|
33836
34301
|
exports.mergeInCache = mergeInCache;
|
|
33837
|
-
exports.notificationTray = index$
|
|
34302
|
+
exports.notificationTray = index$4;
|
|
33838
34303
|
exports.onChannelMarkerFetched = onChannelMarkerFetched;
|
|
33839
34304
|
exports.onFeedMarkerFetched = onFeedMarkerFetched;
|
|
33840
34305
|
exports.onFeedMarkerUpdated = onFeedMarkerUpdated;
|