@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.esm.js
CHANGED
|
@@ -674,6 +674,7 @@ const idResolvers = {
|
|
|
674
674
|
viewer: ({ userId }) => userId,
|
|
675
675
|
event: ({ eventId }) => eventId,
|
|
676
676
|
eventResponse: ({ userId }) => userId,
|
|
677
|
+
product: ({ _id }) => _id,
|
|
677
678
|
};
|
|
678
679
|
/**
|
|
679
680
|
* Retrieve the id resolver matching a domain name
|
|
@@ -733,6 +734,7 @@ const PAYLOAD2MODEL = {
|
|
|
733
734
|
events: 'event',
|
|
734
735
|
viewers: 'viewer',
|
|
735
736
|
eventResponses: 'eventResponse',
|
|
737
|
+
products: 'product',
|
|
736
738
|
};
|
|
737
739
|
/** hidden */
|
|
738
740
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -26155,6 +26157,29 @@ const getShareableLinkConfiguration = async () => {
|
|
|
26155
26157
|
return data;
|
|
26156
26158
|
};
|
|
26157
26159
|
|
|
26160
|
+
/* begin_public_function
|
|
26161
|
+
id: client.getProductCatalogueSetting
|
|
26162
|
+
*/
|
|
26163
|
+
/**
|
|
26164
|
+
* ```js
|
|
26165
|
+
* import { getProductCatalogueSetting } from '@amityco/ts-sdk'
|
|
26166
|
+
* const productCatalogueSetting = await getProductCatalogueSetting()
|
|
26167
|
+
* ```
|
|
26168
|
+
*
|
|
26169
|
+
* Fetches a {@link Amity.ProductCatalogueSetting} object
|
|
26170
|
+
*
|
|
26171
|
+
* @returns A Promise of {@link Amity.ProductCatalogueSetting} object
|
|
26172
|
+
*
|
|
26173
|
+
* @category Client API
|
|
26174
|
+
* @async
|
|
26175
|
+
*/
|
|
26176
|
+
const getProductCatalogueSetting = async () => {
|
|
26177
|
+
const client = getActiveClient();
|
|
26178
|
+
const { data } = await client.http.get(`/api/v3/network-settings/product-catalogue`);
|
|
26179
|
+
return data;
|
|
26180
|
+
};
|
|
26181
|
+
/* end_public_function */
|
|
26182
|
+
|
|
26158
26183
|
/**
|
|
26159
26184
|
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
26160
26185
|
*
|
|
@@ -26647,7 +26672,7 @@ const getUserUnread = (callback) => {
|
|
|
26647
26672
|
};
|
|
26648
26673
|
};
|
|
26649
26674
|
|
|
26650
|
-
var index$
|
|
26675
|
+
var index$s = /*#__PURE__*/Object.freeze({
|
|
26651
26676
|
__proto__: null,
|
|
26652
26677
|
getActiveClient: getActiveClient,
|
|
26653
26678
|
getActiveUser: getActiveUser,
|
|
@@ -26667,6 +26692,7 @@ var index$r = /*#__PURE__*/Object.freeze({
|
|
|
26667
26692
|
getLinkPreviewMetadata: getLinkPreviewMetadata,
|
|
26668
26693
|
getSocialSettings: getSocialSettings,
|
|
26669
26694
|
getShareableLinkConfiguration: getShareableLinkConfiguration,
|
|
26695
|
+
getProductCatalogueSetting: getProductCatalogueSetting,
|
|
26670
26696
|
loginAsVisitor: loginAsVisitor,
|
|
26671
26697
|
loginAsBot: loginAsBot,
|
|
26672
26698
|
getCurrentUser: getCurrentUser,
|
|
@@ -26729,7 +26755,7 @@ const blockUser = async (userId) => {
|
|
|
26729
26755
|
ingestInCache(blockedFollowStatus, { cachedAt });
|
|
26730
26756
|
upsertInCache(['followInfo', 'get', userId], followCounts[0], { cachedAt });
|
|
26731
26757
|
}
|
|
26732
|
-
//
|
|
26758
|
+
// need to swap {from} and {to} to get the correct id for unfollow event to filter from follower live collection
|
|
26733
26759
|
const blockedUnfollowStatus = {
|
|
26734
26760
|
follows: follows.map(follow => {
|
|
26735
26761
|
const unfollowStatus = Object.assign(Object.assign({}, follow), { to: follow.from, from: follow.to, status: 'none' });
|
|
@@ -27874,7 +27900,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
27874
27900
|
};
|
|
27875
27901
|
/* end_public_function */
|
|
27876
27902
|
|
|
27877
|
-
var index$
|
|
27903
|
+
var index$r = /*#__PURE__*/Object.freeze({
|
|
27878
27904
|
__proto__: null,
|
|
27879
27905
|
blockUser: blockUser,
|
|
27880
27906
|
unBlockUser: unBlockUser,
|
|
@@ -29982,6 +30008,11 @@ const communityLinkedObject = (community) => {
|
|
|
29982
30008
|
} });
|
|
29983
30009
|
};
|
|
29984
30010
|
|
|
30011
|
+
const productTagLinkedObject = (productTag) => {
|
|
30012
|
+
var _a;
|
|
30013
|
+
return Object.assign(Object.assign({}, productTag), { product: (_a = pullFromCache(['product', 'get', productTag.productId])) === null || _a === void 0 ? void 0 : _a.data });
|
|
30014
|
+
};
|
|
30015
|
+
|
|
29985
30016
|
const postLinkedObject = (post) => {
|
|
29986
30017
|
return shallowClone(post, {
|
|
29987
30018
|
childrenPosts: post.children
|
|
@@ -29994,6 +30025,10 @@ const postLinkedObject = (post) => {
|
|
|
29994
30025
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
29995
30026
|
},
|
|
29996
30027
|
},
|
|
30028
|
+
get productTags() {
|
|
30029
|
+
var _a, _b;
|
|
30030
|
+
return (_b = (_a = post.productTags) === null || _a === void 0 ? void 0 : _a.map(productTag => productTagLinkedObject(productTag))) !== null && _b !== void 0 ? _b : [];
|
|
30031
|
+
},
|
|
29997
30032
|
get latestComments() {
|
|
29998
30033
|
if (!post.comments)
|
|
29999
30034
|
return [];
|
|
@@ -31983,9 +32018,9 @@ var AmityUserSearchMatchType;
|
|
|
31983
32018
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
31984
32019
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
31985
32020
|
|
|
31986
|
-
var index$
|
|
32021
|
+
var index$q = /*#__PURE__*/Object.freeze({
|
|
31987
32022
|
__proto__: null,
|
|
31988
|
-
Relationship: index$
|
|
32023
|
+
Relationship: index$r,
|
|
31989
32024
|
getUserByIds: getUserByIds,
|
|
31990
32025
|
updateUser: updateUser,
|
|
31991
32026
|
flagUser: flagUser,
|
|
@@ -32388,7 +32423,7 @@ const uploadAudio = async (formData, onProgress) => {
|
|
|
32388
32423
|
};
|
|
32389
32424
|
/* end_public_function */
|
|
32390
32425
|
|
|
32391
|
-
var index$
|
|
32426
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
32392
32427
|
__proto__: null,
|
|
32393
32428
|
getFile: getFile,
|
|
32394
32429
|
uploadFile: uploadFile,
|
|
@@ -34200,7 +34235,7 @@ const getReactions$1 = (params, callback, config) => {
|
|
|
34200
34235
|
};
|
|
34201
34236
|
/* end_public_function */
|
|
34202
34237
|
|
|
34203
|
-
var index$
|
|
34238
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
34204
34239
|
__proto__: null,
|
|
34205
34240
|
addReaction: addReaction,
|
|
34206
34241
|
removeReaction: removeReaction,
|
|
@@ -35972,7 +36007,7 @@ const getMessages = (params, callback, config) => {
|
|
|
35972
36007
|
};
|
|
35973
36008
|
/* end_public_function */
|
|
35974
36009
|
|
|
35975
|
-
var index$
|
|
36010
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
35976
36011
|
__proto__: null,
|
|
35977
36012
|
createMessage: createMessage,
|
|
35978
36013
|
updateMessage: updateMessage,
|
|
@@ -36498,7 +36533,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
36498
36533
|
};
|
|
36499
36534
|
/* end_public_function */
|
|
36500
36535
|
|
|
36501
|
-
var index$
|
|
36536
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
36502
36537
|
__proto__: null,
|
|
36503
36538
|
getSubChannelByIds: getSubChannels$1,
|
|
36504
36539
|
createSubChannel: createSubChannel,
|
|
@@ -37825,7 +37860,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
37825
37860
|
};
|
|
37826
37861
|
/* end_public_function */
|
|
37827
37862
|
|
|
37828
|
-
var index$
|
|
37863
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
37829
37864
|
__proto__: null,
|
|
37830
37865
|
addMembers: addMembers$1,
|
|
37831
37866
|
removeMembers: removeMembers$1,
|
|
@@ -38028,7 +38063,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
38028
38063
|
};
|
|
38029
38064
|
/* end_public_function */
|
|
38030
38065
|
|
|
38031
|
-
var index$
|
|
38066
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
38032
38067
|
__proto__: null,
|
|
38033
38068
|
addRole: addRole,
|
|
38034
38069
|
removeRole: removeRole,
|
|
@@ -38038,10 +38073,10 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
38038
38073
|
unmuteMembers: unmuteMembers
|
|
38039
38074
|
});
|
|
38040
38075
|
|
|
38041
|
-
var index$
|
|
38076
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
38042
38077
|
__proto__: null,
|
|
38043
|
-
Membership: index$
|
|
38044
|
-
Moderation: index$
|
|
38078
|
+
Membership: index$l,
|
|
38079
|
+
Moderation: index$k,
|
|
38045
38080
|
getChannelByIds: getChannelByIds$1,
|
|
38046
38081
|
createChannel: createChannel,
|
|
38047
38082
|
updateChannel: updateChannel,
|
|
@@ -39444,7 +39479,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
39444
39479
|
};
|
|
39445
39480
|
/* end_public_function */
|
|
39446
39481
|
|
|
39447
|
-
var index$
|
|
39482
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
39448
39483
|
__proto__: null,
|
|
39449
39484
|
addMembers: addMembers,
|
|
39450
39485
|
removeMembers: removeMembers,
|
|
@@ -40695,7 +40730,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
40695
40730
|
};
|
|
40696
40731
|
/* end_public_function */
|
|
40697
40732
|
|
|
40698
|
-
var index$
|
|
40733
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
40699
40734
|
__proto__: null,
|
|
40700
40735
|
addRoles: addRoles,
|
|
40701
40736
|
removeRoles: removeRoles,
|
|
@@ -40703,10 +40738,10 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
40703
40738
|
unbanMembers: unbanMembers
|
|
40704
40739
|
});
|
|
40705
40740
|
|
|
40706
|
-
var index$
|
|
40741
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
40707
40742
|
__proto__: null,
|
|
40708
|
-
Moderation: index$
|
|
40709
|
-
Membership: index$
|
|
40743
|
+
Moderation: index$h,
|
|
40744
|
+
Membership: index$i,
|
|
40710
40745
|
getCommunityByIds: getCommunities$1,
|
|
40711
40746
|
createCommunity: createCommunity,
|
|
40712
40747
|
updateCommunity: updateCommunity,
|
|
@@ -40940,7 +40975,7 @@ const getCategories = (params, callback, config) => {
|
|
|
40940
40975
|
};
|
|
40941
40976
|
/* end_public_function */
|
|
40942
40977
|
|
|
40943
|
-
var index$
|
|
40978
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
40944
40979
|
__proto__: null,
|
|
40945
40980
|
getCategory: getCategory,
|
|
40946
40981
|
getCategories: getCategories
|
|
@@ -41059,6 +41094,9 @@ var EnumPostActions;
|
|
|
41059
41094
|
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
41060
41095
|
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
41061
41096
|
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
41097
|
+
EnumPostActions["OnPostPinProduct"] = "onPostPinProduct";
|
|
41098
|
+
EnumPostActions["OnPostUnpinProduct"] = "onPostUnpinProduct";
|
|
41099
|
+
EnumPostActions["OnPostUpdateProductTags"] = "onPostUpdateProductTags";
|
|
41062
41100
|
})(EnumPostActions || (EnumPostActions = {}));
|
|
41063
41101
|
|
|
41064
41102
|
class CustomRankingGlobalFeedQueryStreamController extends QueryStreamController {
|
|
@@ -41999,7 +42037,7 @@ const getComments = (params, callback, config) => {
|
|
|
41999
42037
|
};
|
|
42000
42038
|
/* end_public_function */
|
|
42001
42039
|
|
|
42002
|
-
var index$
|
|
42040
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
42003
42041
|
__proto__: null,
|
|
42004
42042
|
getCommentByIds: getCommentByIds,
|
|
42005
42043
|
createComment: createComment,
|
|
@@ -42670,7 +42708,7 @@ const getUserFeed = (params, callback, config) => {
|
|
|
42670
42708
|
};
|
|
42671
42709
|
/* end_public_function */
|
|
42672
42710
|
|
|
42673
|
-
var index$
|
|
42711
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
42674
42712
|
__proto__: null,
|
|
42675
42713
|
queryGlobalFeed: queryGlobalFeed,
|
|
42676
42714
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
@@ -42785,7 +42823,15 @@ const createPost = async (bundle) => {
|
|
|
42785
42823
|
// eslint-disable-next-line no-param-reassign
|
|
42786
42824
|
delete bundle.dataType;
|
|
42787
42825
|
}
|
|
42788
|
-
const {
|
|
42826
|
+
const { attachments } = bundle;
|
|
42827
|
+
const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
|
|
42828
|
+
? attachments.map(attachment => {
|
|
42829
|
+
if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
|
|
42830
|
+
return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
|
|
42831
|
+
return attachment;
|
|
42832
|
+
})
|
|
42833
|
+
: attachments;
|
|
42834
|
+
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, bundle), { attachments: processedAttachments }));
|
|
42789
42835
|
fireEvent('post.created', payload);
|
|
42790
42836
|
const data = preparePostPayload(payload);
|
|
42791
42837
|
const cachedAt = client.cache && Date.now();
|
|
@@ -42822,7 +42868,15 @@ const createPost = async (bundle) => {
|
|
|
42822
42868
|
const editPost = async (postId, patch) => {
|
|
42823
42869
|
const client = getActiveClient();
|
|
42824
42870
|
client.log('user/editPost', patch);
|
|
42825
|
-
const {
|
|
42871
|
+
const { attachments } = patch;
|
|
42872
|
+
const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
|
|
42873
|
+
? attachments.map(attachment => {
|
|
42874
|
+
if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
|
|
42875
|
+
return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
|
|
42876
|
+
return attachment;
|
|
42877
|
+
})
|
|
42878
|
+
: attachments;
|
|
42879
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, Object.assign(Object.assign({}, patch), { attachments: processedAttachments }));
|
|
42826
42880
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
42827
42881
|
const cachedAt = client.cache && Date.now();
|
|
42828
42882
|
if (client.cache)
|
|
@@ -43245,6 +43299,143 @@ const createMixedMediaPost = async (bundle) => {
|
|
|
43245
43299
|
};
|
|
43246
43300
|
/* end_public_function */
|
|
43247
43301
|
|
|
43302
|
+
/* begin_public_function
|
|
43303
|
+
id: post.create_room_post
|
|
43304
|
+
*/
|
|
43305
|
+
/**
|
|
43306
|
+
* ```js
|
|
43307
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
43308
|
+
* const created = await PostRepository.createRoomPost({
|
|
43309
|
+
* targetType: 'user',
|
|
43310
|
+
* targetId: 'foobar',
|
|
43311
|
+
* data: { text: 'hello world', title: 'Room Title', roomId: 'roomId123' }
|
|
43312
|
+
* }))
|
|
43313
|
+
* ```
|
|
43314
|
+
*
|
|
43315
|
+
* Creates an {@link Amity.Post}
|
|
43316
|
+
*
|
|
43317
|
+
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
43318
|
+
* @returns The newly created {@link Amity.Post}
|
|
43319
|
+
*
|
|
43320
|
+
* @category Post API
|
|
43321
|
+
* @async
|
|
43322
|
+
*/
|
|
43323
|
+
const createRoomPost = async (bundle) => {
|
|
43324
|
+
const client = getActiveClient();
|
|
43325
|
+
client.log('post/createRoomPost', bundle);
|
|
43326
|
+
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, bundle), { dataType: 'room' }));
|
|
43327
|
+
fireEvent('post.created', payload);
|
|
43328
|
+
const data = preparePostPayload(payload);
|
|
43329
|
+
const cachedAt = client.cache && Date.now();
|
|
43330
|
+
if (client.cache)
|
|
43331
|
+
ingestInCache(data, { cachedAt });
|
|
43332
|
+
const { posts } = data;
|
|
43333
|
+
return {
|
|
43334
|
+
data: LinkedObject.post(posts[0]),
|
|
43335
|
+
cachedAt,
|
|
43336
|
+
};
|
|
43337
|
+
};
|
|
43338
|
+
/* end_public_function */
|
|
43339
|
+
|
|
43340
|
+
/* begin_public_function
|
|
43341
|
+
id: post.pin_product
|
|
43342
|
+
*/
|
|
43343
|
+
/**
|
|
43344
|
+
* ```js
|
|
43345
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
43346
|
+
* const pinProduct = await PostRepository.pinProduct(postId, productId)
|
|
43347
|
+
* ```
|
|
43348
|
+
*
|
|
43349
|
+
* @param postId The ID of the post to unpin the product from
|
|
43350
|
+
* @param productId the ID of the product to pin
|
|
43351
|
+
* @returns Amity.Post
|
|
43352
|
+
*
|
|
43353
|
+
* @category Post API
|
|
43354
|
+
* @async
|
|
43355
|
+
* */
|
|
43356
|
+
const pinProduct = async (postId, productId) => {
|
|
43357
|
+
const client = getActiveClient();
|
|
43358
|
+
client.log('post/pinProduct', postId);
|
|
43359
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
43360
|
+
productId,
|
|
43361
|
+
});
|
|
43362
|
+
const data = preparePostPayload(payload);
|
|
43363
|
+
const cachedAt = client.cache && Date.now();
|
|
43364
|
+
if (client.cache)
|
|
43365
|
+
ingestInCache(payload, { cachedAt });
|
|
43366
|
+
fireEvent('local.post.updated', payload);
|
|
43367
|
+
return {
|
|
43368
|
+
data: postLinkedObject(data === null || data === void 0 ? void 0 : data.posts[0]),
|
|
43369
|
+
cachedAt,
|
|
43370
|
+
};
|
|
43371
|
+
};
|
|
43372
|
+
/* end_public_function */
|
|
43373
|
+
|
|
43374
|
+
/* begin_public_function
|
|
43375
|
+
id: post.unpin_product
|
|
43376
|
+
*/
|
|
43377
|
+
/**
|
|
43378
|
+
* ```js
|
|
43379
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
43380
|
+
* const unpinProduct = await PostRepository.unpinProduct(postId)
|
|
43381
|
+
* ```
|
|
43382
|
+
*
|
|
43383
|
+
* @param postId The ID of the post to unpin the product from
|
|
43384
|
+
* @returns Amity.Post
|
|
43385
|
+
*
|
|
43386
|
+
* @category Post API
|
|
43387
|
+
* @async
|
|
43388
|
+
* */
|
|
43389
|
+
const unpinProduct = async (postId) => {
|
|
43390
|
+
const client = getActiveClient();
|
|
43391
|
+
client.log('post/unpinProduct', postId);
|
|
43392
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, { pinnedProductId: null });
|
|
43393
|
+
const data = preparePostPayload(payload);
|
|
43394
|
+
const cachedAt = client.cache && Date.now();
|
|
43395
|
+
if (client.cache)
|
|
43396
|
+
ingestInCache(payload, { cachedAt });
|
|
43397
|
+
fireEvent('local.post.updated', payload);
|
|
43398
|
+
return {
|
|
43399
|
+
data: postLinkedObject(data === null || data === void 0 ? void 0 : data.posts[0]),
|
|
43400
|
+
cachedAt,
|
|
43401
|
+
};
|
|
43402
|
+
};
|
|
43403
|
+
/* end_public_function */
|
|
43404
|
+
|
|
43405
|
+
/* begin_public_function
|
|
43406
|
+
id: post.update_product_tags
|
|
43407
|
+
*/
|
|
43408
|
+
/**
|
|
43409
|
+
* ```js
|
|
43410
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
43411
|
+
* const updateProductTags = await PostRepository.updateProductTags(postId, productTags)
|
|
43412
|
+
* ```
|
|
43413
|
+
*
|
|
43414
|
+
* @param postId of child room
|
|
43415
|
+
* @param productTags the array of product tags to set on the post
|
|
43416
|
+
* @returns Amity.Post
|
|
43417
|
+
*
|
|
43418
|
+
* @category Post API
|
|
43419
|
+
* @async
|
|
43420
|
+
* */
|
|
43421
|
+
const updateProductTags = async (postId, productTags) => {
|
|
43422
|
+
const client = getActiveClient();
|
|
43423
|
+
client.log('post/updateProductTags', postId);
|
|
43424
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
43425
|
+
productTags,
|
|
43426
|
+
});
|
|
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
|
+
|
|
43248
43439
|
/* begin_public_function
|
|
43249
43440
|
id: post.get
|
|
43250
43441
|
*/
|
|
@@ -45026,6 +45217,30 @@ const onRoomTerminated = (callback) => {
|
|
|
45026
45217
|
return createEventSubscriber(client, 'room/onRoomTerminated', 'room.terminated', filter);
|
|
45027
45218
|
};
|
|
45028
45219
|
|
|
45220
|
+
/**
|
|
45221
|
+
* ```js
|
|
45222
|
+
* import { onRoomDidUpdate } from '@amityco/ts-sdk'
|
|
45223
|
+
* const dispose = onRoomDidUpdate(room => {
|
|
45224
|
+
* // ...
|
|
45225
|
+
* })
|
|
45226
|
+
* ```
|
|
45227
|
+
*
|
|
45228
|
+
* Fired when a {@link Amity.Room} has been updated locally
|
|
45229
|
+
*
|
|
45230
|
+
* @param callback The function to call when the event was fired
|
|
45231
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
45232
|
+
*
|
|
45233
|
+
* @category Room Events
|
|
45234
|
+
*/
|
|
45235
|
+
const onRoomDidUpdate = (callback) => {
|
|
45236
|
+
const client = getActiveClient();
|
|
45237
|
+
const filter = (payload) => {
|
|
45238
|
+
ingestInCache(payload);
|
|
45239
|
+
callback(payload.rooms[0]);
|
|
45240
|
+
};
|
|
45241
|
+
return createEventSubscriber(client, 'room/onRoomDidUpdate', 'local.room.didUpdate', filter);
|
|
45242
|
+
};
|
|
45243
|
+
|
|
45029
45244
|
/**
|
|
45030
45245
|
* ```js
|
|
45031
45246
|
* import { onRoomCreated } from '@amityco/ts-sdk'
|
|
@@ -45174,6 +45389,30 @@ const onRoomLeft = (callback) => {
|
|
|
45174
45389
|
return createEventSubscriber(client, 'room/onRoomLeft', 'local.room.left', filter);
|
|
45175
45390
|
};
|
|
45176
45391
|
|
|
45392
|
+
/**
|
|
45393
|
+
* ```js
|
|
45394
|
+
* import { onLocalRoomDidUpdate } from '@amityco/ts-sdk'
|
|
45395
|
+
* const dispose = onLocalRoomDidUpdate(room => {
|
|
45396
|
+
* // ...
|
|
45397
|
+
* })
|
|
45398
|
+
* ```
|
|
45399
|
+
*
|
|
45400
|
+
* Fired when a {@link Amity.Room} has been updated locally
|
|
45401
|
+
*
|
|
45402
|
+
* @param callback The function to call when the event was fired
|
|
45403
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
45404
|
+
*
|
|
45405
|
+
* @category Room Events
|
|
45406
|
+
*/
|
|
45407
|
+
const onLocalRoomDidUpdate = (callback) => {
|
|
45408
|
+
const client = getActiveClient();
|
|
45409
|
+
const filter = (payload) => {
|
|
45410
|
+
ingestInCache(payload);
|
|
45411
|
+
callback(payload.rooms[0]);
|
|
45412
|
+
};
|
|
45413
|
+
return createEventSubscriber(client, 'room/onLocalRoomDidUpdate', 'room.didUpdate', filter);
|
|
45414
|
+
};
|
|
45415
|
+
|
|
45177
45416
|
/**
|
|
45178
45417
|
* ```js
|
|
45179
45418
|
* import { onRoomParticipantRemoved } from '@amityco/ts-sdk'
|
|
@@ -45207,6 +45446,7 @@ var EnumRoomActions;
|
|
|
45207
45446
|
EnumRoomActions["OnRoomEndBroadcasting"] = "OnRoomEndBroadcasting";
|
|
45208
45447
|
EnumRoomActions["OnRoomParticipantJoined"] = "OnRoomParticipantJoined";
|
|
45209
45448
|
EnumRoomActions["OnRoomParticipantLeft"] = "OnRoomParticipantLeft";
|
|
45449
|
+
EnumRoomActions["OnRoomDidUpdate"] = "OnRoomDidUpdate";
|
|
45210
45450
|
})(EnumRoomActions || (EnumRoomActions = {}));
|
|
45211
45451
|
|
|
45212
45452
|
const convertToRoomEventPayload = (eventHandler) => (callback) => eventHandler((payload) => {
|
|
@@ -45258,6 +45498,14 @@ const getRoomSubscription = () => [
|
|
|
45258
45498
|
fn: convertEventPayload(onRoomCoHostInviteAccepted, 'targetId', 'room'),
|
|
45259
45499
|
action: EnumRoomActions.OnRoomUpdated,
|
|
45260
45500
|
},
|
|
45501
|
+
{
|
|
45502
|
+
fn: onRoomDidUpdate,
|
|
45503
|
+
action: EnumRoomActions.OnRoomDidUpdate,
|
|
45504
|
+
},
|
|
45505
|
+
{
|
|
45506
|
+
fn: onLocalRoomDidUpdate,
|
|
45507
|
+
action: EnumRoomActions.OnRoomDidUpdate,
|
|
45508
|
+
},
|
|
45261
45509
|
];
|
|
45262
45510
|
|
|
45263
45511
|
const getRoom = (roomId, callback) => {
|
|
@@ -45466,7 +45714,7 @@ const getRooms = (params, callback, config) => {
|
|
|
45466
45714
|
};
|
|
45467
45715
|
/* end_public_function */
|
|
45468
45716
|
|
|
45469
|
-
var index$
|
|
45717
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
45470
45718
|
__proto__: null,
|
|
45471
45719
|
createRoom: createRoom,
|
|
45472
45720
|
updateRoom: updateRoom,
|
|
@@ -45493,12 +45741,14 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
45493
45741
|
onRoomParticipantStageLeft: onRoomParticipantStageLeft,
|
|
45494
45742
|
onRoomParticipantStageJoined: onRoomParticipantStageJoined,
|
|
45495
45743
|
onRoomTerminated: onRoomTerminated,
|
|
45744
|
+
onRoomDidUpdate: onRoomDidUpdate,
|
|
45496
45745
|
onRoomCreated: onRoomCreated,
|
|
45497
45746
|
onRoomUpdated: onRoomUpdated,
|
|
45498
45747
|
onRoomDeleted: onRoomDeleted,
|
|
45499
45748
|
onRoomStopped: onRoomStopped,
|
|
45500
45749
|
onRoomParticipantRemoved: onRoomParticipantRemoved,
|
|
45501
45750
|
onRoomLeft: onRoomLeft,
|
|
45751
|
+
onLocalRoomDidUpdate: onLocalRoomDidUpdate,
|
|
45502
45752
|
getRoom: getRoom,
|
|
45503
45753
|
getRooms: getRooms
|
|
45504
45754
|
});
|
|
@@ -45762,7 +46012,7 @@ const getCommunityLiveRoomPosts = (params, callback, config) => {
|
|
|
45762
46012
|
};
|
|
45763
46013
|
/* end_public_function */
|
|
45764
46014
|
|
|
45765
|
-
var index$
|
|
46015
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
45766
46016
|
__proto__: null,
|
|
45767
46017
|
getPostByIds: getPostByIds,
|
|
45768
46018
|
createPost: createPost,
|
|
@@ -45778,6 +46028,10 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
45778
46028
|
createClipPost: createClipPost,
|
|
45779
46029
|
createAudioPost: createAudioPost,
|
|
45780
46030
|
createMixedMediaPost: createMixedMediaPost,
|
|
46031
|
+
createRoomPost: createRoomPost,
|
|
46032
|
+
pinProduct: pinProduct,
|
|
46033
|
+
unpinProduct: unpinProduct,
|
|
46034
|
+
updateProductTags: updateProductTags,
|
|
45781
46035
|
onPostCreated: onPostCreated,
|
|
45782
46036
|
onPostUpdated: onPostUpdated,
|
|
45783
46037
|
onPostDeleted: onPostDeleted,
|
|
@@ -46372,7 +46626,7 @@ const getStreams = (params, callback, config) => {
|
|
|
46372
46626
|
};
|
|
46373
46627
|
};
|
|
46374
46628
|
|
|
46375
|
-
var index$
|
|
46629
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
46376
46630
|
__proto__: null,
|
|
46377
46631
|
createStream: createStream,
|
|
46378
46632
|
updateStream: updateStream,
|
|
@@ -46675,7 +46929,7 @@ const stopHeartbeat = (roomId) => {
|
|
|
46675
46929
|
};
|
|
46676
46930
|
/* end_public_function */
|
|
46677
46931
|
|
|
46678
|
-
var index$
|
|
46932
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
46679
46933
|
__proto__: null,
|
|
46680
46934
|
getRoomOnlineUsers: getRoomOnlineUsers,
|
|
46681
46935
|
getRoomUserCount: getRoomUserCount,
|
|
@@ -46983,7 +47237,7 @@ const getPoll = (pollId, callback) => {
|
|
|
46983
47237
|
};
|
|
46984
47238
|
/* end_public_function */
|
|
46985
47239
|
|
|
46986
|
-
var index$
|
|
47240
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
46987
47241
|
__proto__: null,
|
|
46988
47242
|
createPoll: createPoll,
|
|
46989
47243
|
closePoll: closePoll,
|
|
@@ -47287,7 +47541,7 @@ const getPlayer = async (parameters) => {
|
|
|
47287
47541
|
return video;
|
|
47288
47542
|
};
|
|
47289
47543
|
|
|
47290
|
-
var index$
|
|
47544
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
47291
47545
|
__proto__: null,
|
|
47292
47546
|
getPlayer: getPlayer
|
|
47293
47547
|
});
|
|
@@ -48460,7 +48714,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
48460
48714
|
};
|
|
48461
48715
|
};
|
|
48462
48716
|
|
|
48463
|
-
var index$
|
|
48717
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
48464
48718
|
__proto__: null,
|
|
48465
48719
|
createImageStory: createImageStory,
|
|
48466
48720
|
createVideoStory: createVideoStory,
|
|
@@ -48497,7 +48751,7 @@ const getNetworkAds = async () => {
|
|
|
48497
48751
|
};
|
|
48498
48752
|
};
|
|
48499
48753
|
|
|
48500
|
-
var index$
|
|
48754
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
48501
48755
|
__proto__: null,
|
|
48502
48756
|
getNetworkAds: getNetworkAds
|
|
48503
48757
|
});
|
|
@@ -48888,7 +49142,7 @@ const markTraySeen = async (lastSeenAt) => {
|
|
|
48888
49142
|
};
|
|
48889
49143
|
/* end_public_function */
|
|
48890
49144
|
|
|
48891
|
-
var index$
|
|
49145
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
48892
49146
|
__proto__: null,
|
|
48893
49147
|
getNotificationTraySeen: getNotificationTraySeen,
|
|
48894
49148
|
getNotificationTrayItems: getNotificationTrayItems,
|
|
@@ -49186,7 +49440,7 @@ const getInvitations = (params, callback) => {
|
|
|
49186
49440
|
};
|
|
49187
49441
|
};
|
|
49188
49442
|
|
|
49189
|
-
var index$
|
|
49443
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
49190
49444
|
__proto__: null,
|
|
49191
49445
|
cancelInvitation: cancelInvitation,
|
|
49192
49446
|
onLocalInvitationCreated: onLocalInvitationCreated,
|
|
@@ -49335,7 +49589,7 @@ const getReactions = (postId, callback) => {
|
|
|
49335
49589
|
};
|
|
49336
49590
|
};
|
|
49337
49591
|
|
|
49338
|
-
var index$
|
|
49592
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
49339
49593
|
__proto__: null,
|
|
49340
49594
|
createReaction: createReaction,
|
|
49341
49595
|
onLiveReactionCreated: onLiveReactionCreated,
|
|
@@ -49818,7 +50072,7 @@ const getMyEvents = (params, callback, config) => {
|
|
|
49818
50072
|
};
|
|
49819
50073
|
};
|
|
49820
50074
|
|
|
49821
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
50075
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
49822
50076
|
__proto__: null,
|
|
49823
50077
|
createEvent: createEvent,
|
|
49824
50078
|
updateEvent: updateEvent,
|
|
@@ -49839,4 +50093,214 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
49839
50093
|
getRSVPs: getRSVPs
|
|
49840
50094
|
});
|
|
49841
50095
|
|
|
49842
|
-
|
|
50096
|
+
const getProduct$1 = async (productId) => {
|
|
50097
|
+
const client = getActiveClient();
|
|
50098
|
+
client.log('product/getProduct', productId);
|
|
50099
|
+
isInTombstone('product', productId);
|
|
50100
|
+
let payload;
|
|
50101
|
+
try {
|
|
50102
|
+
const response = await client.http.get(`/api/v1/products/${encodeURIComponent(productId)}`);
|
|
50103
|
+
payload = response.data;
|
|
50104
|
+
}
|
|
50105
|
+
catch (error) {
|
|
50106
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
50107
|
+
pushToTombstone('product', productId);
|
|
50108
|
+
}
|
|
50109
|
+
throw error;
|
|
50110
|
+
}
|
|
50111
|
+
const cachedAt = client.cache && Date.now();
|
|
50112
|
+
if (client.cache)
|
|
50113
|
+
ingestInCache(payload, { cachedAt });
|
|
50114
|
+
const { products } = payload;
|
|
50115
|
+
const result = products.find(product => product.productId === productId);
|
|
50116
|
+
return {
|
|
50117
|
+
data: result,
|
|
50118
|
+
cachedAt,
|
|
50119
|
+
};
|
|
50120
|
+
};
|
|
50121
|
+
getProduct$1.locally = (productId) => {
|
|
50122
|
+
const client = getActiveClient();
|
|
50123
|
+
client.log('product/getProduct.locally', productId);
|
|
50124
|
+
if (!client.cache)
|
|
50125
|
+
return;
|
|
50126
|
+
const cached = pullFromCache(['product', 'get', productId]);
|
|
50127
|
+
if (!cached)
|
|
50128
|
+
return;
|
|
50129
|
+
return {
|
|
50130
|
+
data: cached.data,
|
|
50131
|
+
cachedAt: cached.cachedAt,
|
|
50132
|
+
};
|
|
50133
|
+
};
|
|
50134
|
+
|
|
50135
|
+
/* begin_public_function
|
|
50136
|
+
id: product.get
|
|
50137
|
+
*/
|
|
50138
|
+
/**
|
|
50139
|
+
* ```js
|
|
50140
|
+
* import { ProductRepository } from '@amityco/ts-sdk';
|
|
50141
|
+
*
|
|
50142
|
+
* let product;
|
|
50143
|
+
*
|
|
50144
|
+
* const unsub = ProductRepository.getProduct(productId, response => {
|
|
50145
|
+
* product = response.data;
|
|
50146
|
+
* });
|
|
50147
|
+
* ```
|
|
50148
|
+
*
|
|
50149
|
+
* Observe all mutation on a given {@link Amity.Product}
|
|
50150
|
+
*
|
|
50151
|
+
* @param productId the ID of the product to observe
|
|
50152
|
+
* @param callback the function to call when new data are available
|
|
50153
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the product
|
|
50154
|
+
*
|
|
50155
|
+
* @category Product Live Object
|
|
50156
|
+
*/
|
|
50157
|
+
const getProduct = (productId, callback) => {
|
|
50158
|
+
const responder = (snapshot) => {
|
|
50159
|
+
callback(snapshot);
|
|
50160
|
+
};
|
|
50161
|
+
return liveObject(productId, responder, 'productId', getProduct$1, []);
|
|
50162
|
+
};
|
|
50163
|
+
/* end_public_function */
|
|
50164
|
+
|
|
50165
|
+
class SearchProductPaginationController extends PaginationController {
|
|
50166
|
+
async getRequest(queryParams, token) {
|
|
50167
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
50168
|
+
const options = token ? { token } : { limit };
|
|
50169
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/products/search`, {
|
|
50170
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
50171
|
+
});
|
|
50172
|
+
return queryResponse;
|
|
50173
|
+
}
|
|
50174
|
+
}
|
|
50175
|
+
|
|
50176
|
+
class SearchProductQueryStreamController extends QueryStreamController {
|
|
50177
|
+
constructor(query, cacheKey, notifyChange) {
|
|
50178
|
+
super(query, cacheKey);
|
|
50179
|
+
this.notifyChange = notifyChange;
|
|
50180
|
+
}
|
|
50181
|
+
// eslint-disable-next-line class-methods-use-this
|
|
50182
|
+
saveToMainDB(response) {
|
|
50183
|
+
const client = getActiveClient();
|
|
50184
|
+
const cachedAt = client.cache && Date.now();
|
|
50185
|
+
if (client.cache) {
|
|
50186
|
+
ingestInCache(response, { cachedAt });
|
|
50187
|
+
}
|
|
50188
|
+
}
|
|
50189
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
50190
|
+
var _a, _b;
|
|
50191
|
+
if (refresh) {
|
|
50192
|
+
pushToCache(this.cacheKey, {
|
|
50193
|
+
data: response.products.map(getResolver('product')),
|
|
50194
|
+
});
|
|
50195
|
+
}
|
|
50196
|
+
else {
|
|
50197
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
50198
|
+
const products = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
50199
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...products, ...response.products.map(getResolver('product'))])] }));
|
|
50200
|
+
}
|
|
50201
|
+
}
|
|
50202
|
+
}
|
|
50203
|
+
|
|
50204
|
+
class SearchProductLiveCollectionController extends LiveCollectionController {
|
|
50205
|
+
constructor(query, callback) {
|
|
50206
|
+
const queryStreamId = hash(query);
|
|
50207
|
+
const cacheKey = ['products', 'collection', queryStreamId];
|
|
50208
|
+
const paginationController = new SearchProductPaginationController(query);
|
|
50209
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
50210
|
+
this.query = query;
|
|
50211
|
+
this.queryStreamController = new SearchProductQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this));
|
|
50212
|
+
this.callback = callback.bind(this);
|
|
50213
|
+
this.loadPage({ initial: true });
|
|
50214
|
+
}
|
|
50215
|
+
setup() {
|
|
50216
|
+
var _a;
|
|
50217
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
50218
|
+
if (!collection) {
|
|
50219
|
+
pushToCache(this.cacheKey, {
|
|
50220
|
+
data: [],
|
|
50221
|
+
params: {},
|
|
50222
|
+
});
|
|
50223
|
+
}
|
|
50224
|
+
}
|
|
50225
|
+
async persistModel(queryPayload) {
|
|
50226
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
50227
|
+
}
|
|
50228
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
50229
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
50230
|
+
}
|
|
50231
|
+
// eslint-disable-next-line class-methods-use-this
|
|
50232
|
+
startSubscription() {
|
|
50233
|
+
return [];
|
|
50234
|
+
}
|
|
50235
|
+
notifyChange({ origin, loading, error }) {
|
|
50236
|
+
var _a, _b;
|
|
50237
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
50238
|
+
if (!collection)
|
|
50239
|
+
return;
|
|
50240
|
+
const data = (_b = collection.data
|
|
50241
|
+
.map(id => pullFromCache(['product', 'get', id]))
|
|
50242
|
+
.filter(isNonNullable)
|
|
50243
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
50244
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
50245
|
+
return;
|
|
50246
|
+
this.callback({
|
|
50247
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
50248
|
+
data,
|
|
50249
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
50250
|
+
loading,
|
|
50251
|
+
error,
|
|
50252
|
+
});
|
|
50253
|
+
}
|
|
50254
|
+
}
|
|
50255
|
+
|
|
50256
|
+
/* begin_public_function
|
|
50257
|
+
id: product.search
|
|
50258
|
+
*/
|
|
50259
|
+
/**
|
|
50260
|
+
* ```js
|
|
50261
|
+
* import { ProductRepository } from '@amityco/ts-sdk'
|
|
50262
|
+
*
|
|
50263
|
+
* let products = []
|
|
50264
|
+
* const unsub = ProductRepository.searchProducts({
|
|
50265
|
+
* keyword: string,
|
|
50266
|
+
* }, response => merge(products, response.data))
|
|
50267
|
+
* ```
|
|
50268
|
+
*
|
|
50269
|
+
* Observe all mutations on a list of {@link Amity.Product}
|
|
50270
|
+
*
|
|
50271
|
+
* @param params.keyword the search keyword
|
|
50272
|
+
* @param params.isActive filter by active status
|
|
50273
|
+
* @param params.isDeleted filter by deleted status
|
|
50274
|
+
* @param params.sortBy sort option
|
|
50275
|
+
* @param params.sortOrder order option
|
|
50276
|
+
* @param callback the function to call when new data are available
|
|
50277
|
+
* @param config
|
|
50278
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the products
|
|
50279
|
+
*
|
|
50280
|
+
* @category Products Live Collection
|
|
50281
|
+
*/
|
|
50282
|
+
const searchProducts = (params, callback, config) => {
|
|
50283
|
+
const { log, cache } = getActiveClient();
|
|
50284
|
+
if (!cache) {
|
|
50285
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
50286
|
+
}
|
|
50287
|
+
const timestamp = Date.now();
|
|
50288
|
+
log(`searchProducts(tmpid: ${timestamp}) > listen`);
|
|
50289
|
+
const productsLiveCollection = new SearchProductLiveCollectionController(params, callback);
|
|
50290
|
+
const disposers = productsLiveCollection.startSubscription();
|
|
50291
|
+
const cacheKey = productsLiveCollection.getCacheKey();
|
|
50292
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
50293
|
+
return () => {
|
|
50294
|
+
log(`searchProducts(tmpid: ${timestamp}) > dispose`);
|
|
50295
|
+
disposers.forEach(fn => fn());
|
|
50296
|
+
};
|
|
50297
|
+
};
|
|
50298
|
+
/* end_public_function */
|
|
50299
|
+
|
|
50300
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
50301
|
+
__proto__: null,
|
|
50302
|
+
getProduct: getProduct,
|
|
50303
|
+
searchProducts: searchProducts
|
|
50304
|
+
});
|
|
50305
|
+
|
|
50306
|
+
export { API_REGIONS, index$5 as AdRepository, 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 };
|