@amityco/ts-sdk 7.12.1-14007a1.0 → 7.12.1-33aeb646.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/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/post.d.ts +1 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/product.d.ts +76 -0
- package/dist/@types/domains/product.d.ts.map +1 -0
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +295 -59
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +272 -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/editPost.d.ts +2 -0
- package/dist/postRepository/api/editPost.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/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
|
@@ -733,6 +733,7 @@ const PAYLOAD2MODEL = {
|
|
|
733
733
|
events: 'event',
|
|
734
734
|
viewers: 'viewer',
|
|
735
735
|
eventResponses: 'eventResponse',
|
|
736
|
+
products: 'product',
|
|
736
737
|
};
|
|
737
738
|
/** hidden */
|
|
738
739
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -26647,7 +26648,7 @@ const getUserUnread = (callback) => {
|
|
|
26647
26648
|
};
|
|
26648
26649
|
};
|
|
26649
26650
|
|
|
26650
|
-
var index$
|
|
26651
|
+
var index$s = /*#__PURE__*/Object.freeze({
|
|
26651
26652
|
__proto__: null,
|
|
26652
26653
|
getActiveClient: getActiveClient,
|
|
26653
26654
|
getActiveUser: getActiveUser,
|
|
@@ -27867,7 +27868,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
27867
27868
|
};
|
|
27868
27869
|
/* end_public_function */
|
|
27869
27870
|
|
|
27870
|
-
var index$
|
|
27871
|
+
var index$r = /*#__PURE__*/Object.freeze({
|
|
27871
27872
|
__proto__: null,
|
|
27872
27873
|
blockUser: blockUser,
|
|
27873
27874
|
unBlockUser: unBlockUser,
|
|
@@ -28974,7 +28975,7 @@ class AmityRoomAnalytics {
|
|
|
28974
28975
|
throw new ASCApiError('room is not in watchable state', 500000 /* Amity.ServerError.BUSINESS_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
28975
28976
|
}
|
|
28976
28977
|
// Generate session ID with prefix
|
|
28977
|
-
const prefix = this.room.status === 'live' ? 'room_' : '
|
|
28978
|
+
const prefix = this.room.status === 'live' ? 'room_' : 'room_playback_';
|
|
28978
28979
|
const sessionId = prefix + uuid$1.v4();
|
|
28979
28980
|
// Create watch session entity
|
|
28980
28981
|
const session = {
|
|
@@ -29975,6 +29976,11 @@ const communityLinkedObject = (community) => {
|
|
|
29975
29976
|
} });
|
|
29976
29977
|
};
|
|
29977
29978
|
|
|
29979
|
+
const productTagLinkedObject = (productTag) => {
|
|
29980
|
+
var _a;
|
|
29981
|
+
return Object.assign(Object.assign({}, productTag), { product: (_a = pullFromCache(['product', 'get', productTag.productId])) === null || _a === void 0 ? void 0 : _a.data });
|
|
29982
|
+
};
|
|
29983
|
+
|
|
29978
29984
|
const postLinkedObject = (post) => {
|
|
29979
29985
|
return shallowClone(post, {
|
|
29980
29986
|
childrenPosts: post.children
|
|
@@ -29987,6 +29993,9 @@ const postLinkedObject = (post) => {
|
|
|
29987
29993
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
29988
29994
|
},
|
|
29989
29995
|
},
|
|
29996
|
+
get productTags() {
|
|
29997
|
+
return post.productTags.map(productTag => productTagLinkedObject(productTag));
|
|
29998
|
+
},
|
|
29990
29999
|
get latestComments() {
|
|
29991
30000
|
if (!post.comments)
|
|
29992
30001
|
return [];
|
|
@@ -31976,9 +31985,9 @@ var AmityUserSearchMatchType;
|
|
|
31976
31985
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
31977
31986
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
31978
31987
|
|
|
31979
|
-
var index$
|
|
31988
|
+
var index$q = /*#__PURE__*/Object.freeze({
|
|
31980
31989
|
__proto__: null,
|
|
31981
|
-
Relationship: index$
|
|
31990
|
+
Relationship: index$r,
|
|
31982
31991
|
getUserByIds: getUserByIds,
|
|
31983
31992
|
updateUser: updateUser,
|
|
31984
31993
|
flagUser: flagUser,
|
|
@@ -32381,7 +32390,7 @@ const uploadAudio = async (formData, onProgress) => {
|
|
|
32381
32390
|
};
|
|
32382
32391
|
/* end_public_function */
|
|
32383
32392
|
|
|
32384
|
-
var index$
|
|
32393
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
32385
32394
|
__proto__: null,
|
|
32386
32395
|
getFile: getFile,
|
|
32387
32396
|
uploadFile: uploadFile,
|
|
@@ -34193,7 +34202,7 @@ const getReactions$1 = (params, callback, config) => {
|
|
|
34193
34202
|
};
|
|
34194
34203
|
/* end_public_function */
|
|
34195
34204
|
|
|
34196
|
-
var index$
|
|
34205
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
34197
34206
|
__proto__: null,
|
|
34198
34207
|
addReaction: addReaction,
|
|
34199
34208
|
removeReaction: removeReaction,
|
|
@@ -35965,7 +35974,7 @@ const getMessages = (params, callback, config) => {
|
|
|
35965
35974
|
};
|
|
35966
35975
|
/* end_public_function */
|
|
35967
35976
|
|
|
35968
|
-
var index$
|
|
35977
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
35969
35978
|
__proto__: null,
|
|
35970
35979
|
createMessage: createMessage,
|
|
35971
35980
|
updateMessage: updateMessage,
|
|
@@ -36491,7 +36500,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
36491
36500
|
};
|
|
36492
36501
|
/* end_public_function */
|
|
36493
36502
|
|
|
36494
|
-
var index$
|
|
36503
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
36495
36504
|
__proto__: null,
|
|
36496
36505
|
getSubChannelByIds: getSubChannels$1,
|
|
36497
36506
|
createSubChannel: createSubChannel,
|
|
@@ -37818,7 +37827,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
37818
37827
|
};
|
|
37819
37828
|
/* end_public_function */
|
|
37820
37829
|
|
|
37821
|
-
var index$
|
|
37830
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
37822
37831
|
__proto__: null,
|
|
37823
37832
|
addMembers: addMembers$1,
|
|
37824
37833
|
removeMembers: removeMembers$1,
|
|
@@ -38021,7 +38030,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
38021
38030
|
};
|
|
38022
38031
|
/* end_public_function */
|
|
38023
38032
|
|
|
38024
|
-
var index$
|
|
38033
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
38025
38034
|
__proto__: null,
|
|
38026
38035
|
addRole: addRole,
|
|
38027
38036
|
removeRole: removeRole,
|
|
@@ -38031,10 +38040,10 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
38031
38040
|
unmuteMembers: unmuteMembers
|
|
38032
38041
|
});
|
|
38033
38042
|
|
|
38034
|
-
var index$
|
|
38043
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
38035
38044
|
__proto__: null,
|
|
38036
|
-
Membership: index$
|
|
38037
|
-
Moderation: index$
|
|
38045
|
+
Membership: index$l,
|
|
38046
|
+
Moderation: index$k,
|
|
38038
38047
|
getChannelByIds: getChannelByIds$1,
|
|
38039
38048
|
createChannel: createChannel,
|
|
38040
38049
|
updateChannel: updateChannel,
|
|
@@ -39437,7 +39446,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
39437
39446
|
};
|
|
39438
39447
|
/* end_public_function */
|
|
39439
39448
|
|
|
39440
|
-
var index$
|
|
39449
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
39441
39450
|
__proto__: null,
|
|
39442
39451
|
addMembers: addMembers,
|
|
39443
39452
|
removeMembers: removeMembers,
|
|
@@ -40688,7 +40697,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
40688
40697
|
};
|
|
40689
40698
|
/* end_public_function */
|
|
40690
40699
|
|
|
40691
|
-
var index$
|
|
40700
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
40692
40701
|
__proto__: null,
|
|
40693
40702
|
addRoles: addRoles,
|
|
40694
40703
|
removeRoles: removeRoles,
|
|
@@ -40696,10 +40705,10 @@ var index$g = /*#__PURE__*/Object.freeze({
|
|
|
40696
40705
|
unbanMembers: unbanMembers
|
|
40697
40706
|
});
|
|
40698
40707
|
|
|
40699
|
-
var index$
|
|
40708
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
40700
40709
|
__proto__: null,
|
|
40701
|
-
Moderation: index$
|
|
40702
|
-
Membership: index$
|
|
40710
|
+
Moderation: index$h,
|
|
40711
|
+
Membership: index$i,
|
|
40703
40712
|
getCommunityByIds: getCommunities$1,
|
|
40704
40713
|
createCommunity: createCommunity,
|
|
40705
40714
|
updateCommunity: updateCommunity,
|
|
@@ -40933,7 +40942,7 @@ const getCategories = (params, callback, config) => {
|
|
|
40933
40942
|
};
|
|
40934
40943
|
/* end_public_function */
|
|
40935
40944
|
|
|
40936
|
-
var index$
|
|
40945
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
40937
40946
|
__proto__: null,
|
|
40938
40947
|
getCategory: getCategory,
|
|
40939
40948
|
getCategories: getCategories
|
|
@@ -41992,7 +42001,7 @@ const getComments = (params, callback, config) => {
|
|
|
41992
42001
|
};
|
|
41993
42002
|
/* end_public_function */
|
|
41994
42003
|
|
|
41995
|
-
var index$
|
|
42004
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
41996
42005
|
__proto__: null,
|
|
41997
42006
|
getCommentByIds: getCommentByIds,
|
|
41998
42007
|
createComment: createComment,
|
|
@@ -42663,7 +42672,7 @@ const getUserFeed = (params, callback, config) => {
|
|
|
42663
42672
|
};
|
|
42664
42673
|
/* end_public_function */
|
|
42665
42674
|
|
|
42666
|
-
var index$
|
|
42675
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
42667
42676
|
__proto__: null,
|
|
42668
42677
|
queryGlobalFeed: queryGlobalFeed,
|
|
42669
42678
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
@@ -42778,7 +42787,15 @@ const createPost = async (bundle) => {
|
|
|
42778
42787
|
// eslint-disable-next-line no-param-reassign
|
|
42779
42788
|
delete bundle.dataType;
|
|
42780
42789
|
}
|
|
42781
|
-
const {
|
|
42790
|
+
const { attachments } = bundle;
|
|
42791
|
+
const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
|
|
42792
|
+
? attachments.map(attachment => {
|
|
42793
|
+
if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
|
|
42794
|
+
return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
|
|
42795
|
+
return attachment;
|
|
42796
|
+
})
|
|
42797
|
+
: attachments;
|
|
42798
|
+
const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, bundle), { attachments: processedAttachments }));
|
|
42782
42799
|
fireEvent('post.created', payload);
|
|
42783
42800
|
const data = preparePostPayload(payload);
|
|
42784
42801
|
const cachedAt = client.cache && Date.now();
|
|
@@ -42815,7 +42832,15 @@ const createPost = async (bundle) => {
|
|
|
42815
42832
|
const editPost = async (postId, patch) => {
|
|
42816
42833
|
const client = getActiveClient();
|
|
42817
42834
|
client.log('user/editPost', patch);
|
|
42818
|
-
const {
|
|
42835
|
+
const { attachments } = patch;
|
|
42836
|
+
const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
|
|
42837
|
+
? attachments.map(attachment => {
|
|
42838
|
+
if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
|
|
42839
|
+
return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
|
|
42840
|
+
return attachment;
|
|
42841
|
+
})
|
|
42842
|
+
: attachments;
|
|
42843
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, Object.assign(Object.assign({}, patch), { attachments: processedAttachments }));
|
|
42819
42844
|
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
42820
42845
|
const cachedAt = client.cache && Date.now();
|
|
42821
42846
|
if (client.cache)
|
|
@@ -45459,7 +45484,7 @@ const getRooms = (params, callback, config) => {
|
|
|
45459
45484
|
};
|
|
45460
45485
|
/* end_public_function */
|
|
45461
45486
|
|
|
45462
|
-
var index$
|
|
45487
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
45463
45488
|
__proto__: null,
|
|
45464
45489
|
createRoom: createRoom,
|
|
45465
45490
|
updateRoom: updateRoom,
|
|
@@ -45755,7 +45780,7 @@ const getCommunityLiveRoomPosts = (params, callback, config) => {
|
|
|
45755
45780
|
};
|
|
45756
45781
|
/* end_public_function */
|
|
45757
45782
|
|
|
45758
|
-
var index$
|
|
45783
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
45759
45784
|
__proto__: null,
|
|
45760
45785
|
getPostByIds: getPostByIds,
|
|
45761
45786
|
createPost: createPost,
|
|
@@ -46365,7 +46390,7 @@ const getStreams = (params, callback, config) => {
|
|
|
46365
46390
|
};
|
|
46366
46391
|
};
|
|
46367
46392
|
|
|
46368
|
-
var index$
|
|
46393
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
46369
46394
|
__proto__: null,
|
|
46370
46395
|
createStream: createStream,
|
|
46371
46396
|
updateStream: updateStream,
|
|
@@ -46668,7 +46693,7 @@ const stopHeartbeat = (roomId) => {
|
|
|
46668
46693
|
};
|
|
46669
46694
|
/* end_public_function */
|
|
46670
46695
|
|
|
46671
|
-
var index$
|
|
46696
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
46672
46697
|
__proto__: null,
|
|
46673
46698
|
getRoomOnlineUsers: getRoomOnlineUsers,
|
|
46674
46699
|
getRoomUserCount: getRoomUserCount,
|
|
@@ -46976,7 +47001,7 @@ const getPoll = (pollId, callback) => {
|
|
|
46976
47001
|
};
|
|
46977
47002
|
/* end_public_function */
|
|
46978
47003
|
|
|
46979
|
-
var index$
|
|
47004
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
46980
47005
|
__proto__: null,
|
|
46981
47006
|
createPoll: createPoll,
|
|
46982
47007
|
closePoll: closePoll,
|
|
@@ -47280,7 +47305,7 @@ const getPlayer = async (parameters) => {
|
|
|
47280
47305
|
return video;
|
|
47281
47306
|
};
|
|
47282
47307
|
|
|
47283
|
-
var index$
|
|
47308
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
47284
47309
|
__proto__: null,
|
|
47285
47310
|
getPlayer: getPlayer
|
|
47286
47311
|
});
|
|
@@ -48453,7 +48478,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
48453
48478
|
};
|
|
48454
48479
|
};
|
|
48455
48480
|
|
|
48456
|
-
var index$
|
|
48481
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
48457
48482
|
__proto__: null,
|
|
48458
48483
|
createImageStory: createImageStory,
|
|
48459
48484
|
createVideoStory: createVideoStory,
|
|
@@ -48490,7 +48515,7 @@ const getNetworkAds = async () => {
|
|
|
48490
48515
|
};
|
|
48491
48516
|
};
|
|
48492
48517
|
|
|
48493
|
-
var index$
|
|
48518
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
48494
48519
|
__proto__: null,
|
|
48495
48520
|
getNetworkAds: getNetworkAds
|
|
48496
48521
|
});
|
|
@@ -48881,7 +48906,7 @@ const markTraySeen = async (lastSeenAt) => {
|
|
|
48881
48906
|
};
|
|
48882
48907
|
/* end_public_function */
|
|
48883
48908
|
|
|
48884
|
-
var index$
|
|
48909
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
48885
48910
|
__proto__: null,
|
|
48886
48911
|
getNotificationTraySeen: getNotificationTraySeen,
|
|
48887
48912
|
getNotificationTrayItems: getNotificationTrayItems,
|
|
@@ -49179,7 +49204,7 @@ const getInvitations = (params, callback) => {
|
|
|
49179
49204
|
};
|
|
49180
49205
|
};
|
|
49181
49206
|
|
|
49182
|
-
var index$
|
|
49207
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
49183
49208
|
__proto__: null,
|
|
49184
49209
|
cancelInvitation: cancelInvitation,
|
|
49185
49210
|
onLocalInvitationCreated: onLocalInvitationCreated,
|
|
@@ -49328,7 +49353,7 @@ const getReactions = (postId, callback) => {
|
|
|
49328
49353
|
};
|
|
49329
49354
|
};
|
|
49330
49355
|
|
|
49331
|
-
var index$
|
|
49356
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
49332
49357
|
__proto__: null,
|
|
49333
49358
|
createReaction: createReaction,
|
|
49334
49359
|
onLiveReactionCreated: onLiveReactionCreated,
|
|
@@ -49811,7 +49836,7 @@ const getMyEvents = (params, callback, config) => {
|
|
|
49811
49836
|
};
|
|
49812
49837
|
};
|
|
49813
49838
|
|
|
49814
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
49839
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
49815
49840
|
__proto__: null,
|
|
49816
49841
|
createEvent: createEvent,
|
|
49817
49842
|
updateEvent: updateEvent,
|
|
@@ -49832,4 +49857,214 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
49832
49857
|
getRSVPs: getRSVPs
|
|
49833
49858
|
});
|
|
49834
49859
|
|
|
49835
|
-
|
|
49860
|
+
const getProduct$1 = async (productId) => {
|
|
49861
|
+
const client = getActiveClient();
|
|
49862
|
+
client.log('product/getProduct', productId);
|
|
49863
|
+
isInTombstone('product', productId);
|
|
49864
|
+
let payload;
|
|
49865
|
+
try {
|
|
49866
|
+
const response = await client.http.get(`/api/v1/products/${encodeURIComponent(productId)}`);
|
|
49867
|
+
payload = response.data;
|
|
49868
|
+
}
|
|
49869
|
+
catch (error) {
|
|
49870
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
49871
|
+
pushToTombstone('product', productId);
|
|
49872
|
+
}
|
|
49873
|
+
throw error;
|
|
49874
|
+
}
|
|
49875
|
+
const cachedAt = client.cache && Date.now();
|
|
49876
|
+
if (client.cache)
|
|
49877
|
+
ingestInCache(payload, { cachedAt });
|
|
49878
|
+
const { products } = payload;
|
|
49879
|
+
const result = products.find(product => product.productId === productId);
|
|
49880
|
+
return {
|
|
49881
|
+
data: result,
|
|
49882
|
+
cachedAt,
|
|
49883
|
+
};
|
|
49884
|
+
};
|
|
49885
|
+
getProduct$1.locally = (productId) => {
|
|
49886
|
+
const client = getActiveClient();
|
|
49887
|
+
client.log('product/getProduct.locally', productId);
|
|
49888
|
+
if (!client.cache)
|
|
49889
|
+
return;
|
|
49890
|
+
const cached = pullFromCache(['product', 'get', productId]);
|
|
49891
|
+
if (!cached)
|
|
49892
|
+
return;
|
|
49893
|
+
return {
|
|
49894
|
+
data: cached.data,
|
|
49895
|
+
cachedAt: cached.cachedAt,
|
|
49896
|
+
};
|
|
49897
|
+
};
|
|
49898
|
+
|
|
49899
|
+
/* begin_public_function
|
|
49900
|
+
id: product.get
|
|
49901
|
+
*/
|
|
49902
|
+
/**
|
|
49903
|
+
* ```js
|
|
49904
|
+
* import { ProductRepository } from '@amityco/ts-sdk';
|
|
49905
|
+
*
|
|
49906
|
+
* let product;
|
|
49907
|
+
*
|
|
49908
|
+
* const unsub = ProductRepository.getProduct(productId, response => {
|
|
49909
|
+
* product = response.data;
|
|
49910
|
+
* });
|
|
49911
|
+
* ```
|
|
49912
|
+
*
|
|
49913
|
+
* Observe all mutation on a given {@link Amity.Product}
|
|
49914
|
+
*
|
|
49915
|
+
* @param productId the ID of the product to observe
|
|
49916
|
+
* @param callback the function to call when new data are available
|
|
49917
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the product
|
|
49918
|
+
*
|
|
49919
|
+
* @category Product Live Object
|
|
49920
|
+
*/
|
|
49921
|
+
const getProduct = (productId, callback) => {
|
|
49922
|
+
const responder = (snapshot) => {
|
|
49923
|
+
callback(snapshot);
|
|
49924
|
+
};
|
|
49925
|
+
return liveObject(productId, responder, 'productId', getProduct$1, []);
|
|
49926
|
+
};
|
|
49927
|
+
/* end_public_function */
|
|
49928
|
+
|
|
49929
|
+
class SearchProductPaginationController extends PaginationController {
|
|
49930
|
+
async getRequest(queryParams, token) {
|
|
49931
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
49932
|
+
const options = token ? { token } : { limit };
|
|
49933
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/products/search`, {
|
|
49934
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
49935
|
+
});
|
|
49936
|
+
return queryResponse;
|
|
49937
|
+
}
|
|
49938
|
+
}
|
|
49939
|
+
|
|
49940
|
+
class SearchProductQueryStreamController extends QueryStreamController {
|
|
49941
|
+
constructor(query, cacheKey, notifyChange) {
|
|
49942
|
+
super(query, cacheKey);
|
|
49943
|
+
this.notifyChange = notifyChange;
|
|
49944
|
+
}
|
|
49945
|
+
// eslint-disable-next-line class-methods-use-this
|
|
49946
|
+
saveToMainDB(response) {
|
|
49947
|
+
const client = getActiveClient();
|
|
49948
|
+
const cachedAt = client.cache && Date.now();
|
|
49949
|
+
if (client.cache) {
|
|
49950
|
+
ingestInCache(response, { cachedAt });
|
|
49951
|
+
}
|
|
49952
|
+
}
|
|
49953
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
49954
|
+
var _a, _b;
|
|
49955
|
+
if (refresh) {
|
|
49956
|
+
pushToCache(this.cacheKey, {
|
|
49957
|
+
data: response.products.map(getResolver('product')),
|
|
49958
|
+
});
|
|
49959
|
+
}
|
|
49960
|
+
else {
|
|
49961
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
49962
|
+
const products = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
49963
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...products, ...response.products.map(getResolver('product'))])] }));
|
|
49964
|
+
}
|
|
49965
|
+
}
|
|
49966
|
+
}
|
|
49967
|
+
|
|
49968
|
+
class SearchProductLiveCollectionController extends LiveCollectionController {
|
|
49969
|
+
constructor(query, callback) {
|
|
49970
|
+
const queryStreamId = hash(query);
|
|
49971
|
+
const cacheKey = ['products', 'collection', queryStreamId];
|
|
49972
|
+
const paginationController = new SearchProductPaginationController(query);
|
|
49973
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
49974
|
+
this.query = query;
|
|
49975
|
+
this.queryStreamController = new SearchProductQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this));
|
|
49976
|
+
this.callback = callback.bind(this);
|
|
49977
|
+
this.loadPage({ initial: true });
|
|
49978
|
+
}
|
|
49979
|
+
setup() {
|
|
49980
|
+
var _a;
|
|
49981
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
49982
|
+
if (!collection) {
|
|
49983
|
+
pushToCache(this.cacheKey, {
|
|
49984
|
+
data: [],
|
|
49985
|
+
params: {},
|
|
49986
|
+
});
|
|
49987
|
+
}
|
|
49988
|
+
}
|
|
49989
|
+
async persistModel(queryPayload) {
|
|
49990
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
49991
|
+
}
|
|
49992
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
49993
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
49994
|
+
}
|
|
49995
|
+
// eslint-disable-next-line class-methods-use-this
|
|
49996
|
+
startSubscription() {
|
|
49997
|
+
return [];
|
|
49998
|
+
}
|
|
49999
|
+
notifyChange({ origin, loading, error }) {
|
|
50000
|
+
var _a, _b;
|
|
50001
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
50002
|
+
if (!collection)
|
|
50003
|
+
return;
|
|
50004
|
+
const data = (_b = collection.data
|
|
50005
|
+
.map(id => pullFromCache(['product', 'get', id]))
|
|
50006
|
+
.filter(isNonNullable)
|
|
50007
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
50008
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
50009
|
+
return;
|
|
50010
|
+
this.callback({
|
|
50011
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
50012
|
+
data,
|
|
50013
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
50014
|
+
loading,
|
|
50015
|
+
error,
|
|
50016
|
+
});
|
|
50017
|
+
}
|
|
50018
|
+
}
|
|
50019
|
+
|
|
50020
|
+
/* begin_public_function
|
|
50021
|
+
id: product.search
|
|
50022
|
+
*/
|
|
50023
|
+
/**
|
|
50024
|
+
* ```js
|
|
50025
|
+
* import { ProductRepository } from '@amityco/ts-sdk'
|
|
50026
|
+
*
|
|
50027
|
+
* let products = []
|
|
50028
|
+
* const unsub = ProductRepository.searchProducts({
|
|
50029
|
+
* keyword: string,
|
|
50030
|
+
* }, response => merge(products, response.data))
|
|
50031
|
+
* ```
|
|
50032
|
+
*
|
|
50033
|
+
* Observe all mutations on a list of {@link Amity.Product}
|
|
50034
|
+
*
|
|
50035
|
+
* @param params.keyword the search keyword
|
|
50036
|
+
* @param params.isActive filter by active status
|
|
50037
|
+
* @param params.isDeleted filter by deleted status
|
|
50038
|
+
* @param params.sortBy sort option
|
|
50039
|
+
* @param params.sortOrder order option
|
|
50040
|
+
* @param callback the function to call when new data are available
|
|
50041
|
+
* @param config
|
|
50042
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the products
|
|
50043
|
+
*
|
|
50044
|
+
* @category Products Live Collection
|
|
50045
|
+
*/
|
|
50046
|
+
const searchProducts = (params, callback, config) => {
|
|
50047
|
+
const { log, cache } = getActiveClient();
|
|
50048
|
+
if (!cache) {
|
|
50049
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
50050
|
+
}
|
|
50051
|
+
const timestamp = Date.now();
|
|
50052
|
+
log(`searchProducts(tmpid: ${timestamp}) > listen`);
|
|
50053
|
+
const productsLiveCollection = new SearchProductLiveCollectionController(params, callback);
|
|
50054
|
+
const disposers = productsLiveCollection.startSubscription();
|
|
50055
|
+
const cacheKey = productsLiveCollection.getCacheKey();
|
|
50056
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
50057
|
+
return () => {
|
|
50058
|
+
log(`searchProducts(tmpid: ${timestamp}) > dispose`);
|
|
50059
|
+
disposers.forEach(fn => fn());
|
|
50060
|
+
};
|
|
50061
|
+
};
|
|
50062
|
+
/* end_public_function */
|
|
50063
|
+
|
|
50064
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
50065
|
+
__proto__: null,
|
|
50066
|
+
getProduct: getProduct,
|
|
50067
|
+
searchProducts: searchProducts
|
|
50068
|
+
});
|
|
50069
|
+
|
|
50070
|
+
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 };
|