@amityco/ts-sdk 7.12.1-777202f6.0 → 7.12.1-df30e76f.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.
Files changed (57) hide show
  1. package/dist/@types/core/model.d.ts +2 -0
  2. package/dist/@types/core/model.d.ts.map +1 -1
  3. package/dist/@types/core/payload.d.ts +4 -0
  4. package/dist/@types/core/payload.d.ts.map +1 -1
  5. package/dist/@types/domains/client.d.ts +3 -0
  6. package/dist/@types/domains/client.d.ts.map +1 -1
  7. package/dist/@types/domains/comment.d.ts +0 -1
  8. package/dist/@types/domains/comment.d.ts.map +1 -1
  9. package/dist/@types/domains/post.d.ts +1 -0
  10. package/dist/@types/domains/post.d.ts.map +1 -1
  11. package/dist/@types/domains/product.d.ts +77 -0
  12. package/dist/@types/domains/product.d.ts.map +1 -0
  13. package/dist/@types/index.d.ts +1 -0
  14. package/dist/@types/index.d.ts.map +1 -1
  15. package/dist/client/api/getProductCatalogueSetting.d.ts +15 -0
  16. package/dist/client/api/getProductCatalogueSetting.d.ts.map +1 -0
  17. package/dist/client/api/index.d.ts +1 -0
  18. package/dist/client/api/index.d.ts.map +1 -1
  19. package/dist/commentRepository/api/createComment.d.ts +1 -1
  20. package/dist/commentRepository/api/createComment.d.ts.map +1 -1
  21. package/dist/commentRepository/api/updateComment.d.ts +1 -1
  22. package/dist/commentRepository/api/updateComment.d.ts.map +1 -1
  23. package/dist/core/model/idResolvers.d.ts.map +1 -1
  24. package/dist/core/model/index.d.ts.map +1 -1
  25. package/dist/index.cjs.js +320 -60
  26. package/dist/index.d.ts +1 -0
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.esm.js +297 -38
  29. package/dist/index.umd.js +2 -2
  30. package/dist/postRepository/api/createPost.d.ts +2 -0
  31. package/dist/postRepository/api/createPost.d.ts.map +1 -1
  32. package/dist/postRepository/api/editPost.d.ts +2 -0
  33. package/dist/postRepository/api/editPost.d.ts.map +1 -1
  34. package/dist/productRepository/index.d.ts +2 -0
  35. package/dist/productRepository/index.d.ts.map +1 -0
  36. package/dist/productRepository/internalApi/getProduct.d.ts +5 -0
  37. package/dist/productRepository/internalApi/getProduct.d.ts.map +1 -0
  38. package/dist/productRepository/internalApi/index.d.ts +2 -0
  39. package/dist/productRepository/internalApi/index.d.ts.map +1 -0
  40. package/dist/productRepository/observers/getProduct.d.ts +21 -0
  41. package/dist/productRepository/observers/getProduct.d.ts.map +1 -0
  42. package/dist/productRepository/observers/index.d.ts +3 -0
  43. package/dist/productRepository/observers/index.d.ts.map +1 -0
  44. package/dist/productRepository/observers/searchProducts/LiveCollectionController.d.ts +15 -0
  45. package/dist/productRepository/observers/searchProducts/LiveCollectionController.d.ts.map +1 -0
  46. package/dist/productRepository/observers/searchProducts/PaginationController.d.ts +5 -0
  47. package/dist/productRepository/observers/searchProducts/PaginationController.d.ts.map +1 -0
  48. package/dist/productRepository/observers/searchProducts/QueryStreamController.d.ts +8 -0
  49. package/dist/productRepository/observers/searchProducts/QueryStreamController.d.ts.map +1 -0
  50. package/dist/productRepository/observers/searchProducts.d.ts +25 -0
  51. package/dist/productRepository/observers/searchProducts.d.ts.map +1 -0
  52. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  53. package/dist/utils/linkedObject/productTagLinkedObject.d.ts +2 -0
  54. package/dist/utils/linkedObject/productTagLinkedObject.d.ts.map +1 -0
  55. package/dist/utils/tests/dummy/comment.d.ts +0 -1
  56. package/dist/utils/tests/dummy/comment.d.ts.map +1 -1
  57. 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$r = /*#__PURE__*/Object.freeze({
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,
@@ -11775,7 +11801,7 @@ const getMyFollowInfo = (callback) => {
11775
11801
  };
11776
11802
  /* end_public_function */
11777
11803
 
11778
- var index$q = /*#__PURE__*/Object.freeze({
11804
+ var index$r = /*#__PURE__*/Object.freeze({
11779
11805
  __proto__: null,
11780
11806
  blockUser: blockUser,
11781
11807
  unBlockUser: unBlockUser,
@@ -13883,6 +13909,11 @@ const communityLinkedObject = (community) => {
13883
13909
  } });
13884
13910
  };
13885
13911
 
13912
+ const productTagLinkedObject = (productTag) => {
13913
+ var _a;
13914
+ return Object.assign(Object.assign({}, productTag), { product: (_a = pullFromCache(['product', 'get', productTag.productId])) === null || _a === void 0 ? void 0 : _a.data });
13915
+ };
13916
+
13886
13917
  const postLinkedObject = (post) => {
13887
13918
  return shallowClone(post, {
13888
13919
  childrenPosts: post.children
@@ -13895,6 +13926,10 @@ const postLinkedObject = (post) => {
13895
13926
  analyticsEngineInstance.markPostAsViewed(post.postId);
13896
13927
  },
13897
13928
  },
13929
+ get productTags() {
13930
+ var _a, _b;
13931
+ return (_b = (_a = post.productTags) === null || _a === void 0 ? void 0 : _a.map(productTag => productTagLinkedObject(productTag))) !== null && _b !== void 0 ? _b : [];
13932
+ },
13898
13933
  get latestComments() {
13899
13934
  if (!post.comments)
13900
13935
  return [];
@@ -15884,9 +15919,9 @@ var AmityUserSearchMatchType;
15884
15919
  AmityUserSearchMatchType["PARTIAL"] = "partial";
15885
15920
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
15886
15921
 
15887
- var index$p = /*#__PURE__*/Object.freeze({
15922
+ var index$q = /*#__PURE__*/Object.freeze({
15888
15923
  __proto__: null,
15889
- Relationship: index$q,
15924
+ Relationship: index$r,
15890
15925
  getUserByIds: getUserByIds,
15891
15926
  updateUser: updateUser,
15892
15927
  flagUser: flagUser,
@@ -16289,7 +16324,7 @@ const uploadAudio = async (formData, onProgress) => {
16289
16324
  };
16290
16325
  /* end_public_function */
16291
16326
 
16292
- var index$o = /*#__PURE__*/Object.freeze({
16327
+ var index$p = /*#__PURE__*/Object.freeze({
16293
16328
  __proto__: null,
16294
16329
  getFile: getFile,
16295
16330
  uploadFile: uploadFile,
@@ -18101,7 +18136,7 @@ const getReactions$1 = (params, callback, config) => {
18101
18136
  };
18102
18137
  /* end_public_function */
18103
18138
 
18104
- var index$n = /*#__PURE__*/Object.freeze({
18139
+ var index$o = /*#__PURE__*/Object.freeze({
18105
18140
  __proto__: null,
18106
18141
  addReaction: addReaction,
18107
18142
  removeReaction: removeReaction,
@@ -19873,7 +19908,7 @@ const getMessages = (params, callback, config) => {
19873
19908
  };
19874
19909
  /* end_public_function */
19875
19910
 
19876
- var index$m = /*#__PURE__*/Object.freeze({
19911
+ var index$n = /*#__PURE__*/Object.freeze({
19877
19912
  __proto__: null,
19878
19913
  createMessage: createMessage,
19879
19914
  updateMessage: updateMessage,
@@ -20399,7 +20434,7 @@ const stopMessageReceiptSync = (subChannelId) => {
20399
20434
  };
20400
20435
  /* end_public_function */
20401
20436
 
20402
- var index$l = /*#__PURE__*/Object.freeze({
20437
+ var index$m = /*#__PURE__*/Object.freeze({
20403
20438
  __proto__: null,
20404
20439
  getSubChannelByIds: getSubChannels$1,
20405
20440
  createSubChannel: createSubChannel,
@@ -21726,7 +21761,7 @@ const searchMembers$1 = (params, callback, config) => {
21726
21761
  };
21727
21762
  /* end_public_function */
21728
21763
 
21729
- var index$k = /*#__PURE__*/Object.freeze({
21764
+ var index$l = /*#__PURE__*/Object.freeze({
21730
21765
  __proto__: null,
21731
21766
  addMembers: addMembers$1,
21732
21767
  removeMembers: removeMembers$1,
@@ -21929,7 +21964,7 @@ const unmuteMembers = async (channelId, userIds) => {
21929
21964
  };
21930
21965
  /* end_public_function */
21931
21966
 
21932
- var index$j = /*#__PURE__*/Object.freeze({
21967
+ var index$k = /*#__PURE__*/Object.freeze({
21933
21968
  __proto__: null,
21934
21969
  addRole: addRole,
21935
21970
  removeRole: removeRole,
@@ -21939,10 +21974,10 @@ var index$j = /*#__PURE__*/Object.freeze({
21939
21974
  unmuteMembers: unmuteMembers
21940
21975
  });
21941
21976
 
21942
- var index$i = /*#__PURE__*/Object.freeze({
21977
+ var index$j = /*#__PURE__*/Object.freeze({
21943
21978
  __proto__: null,
21944
- Membership: index$k,
21945
- Moderation: index$j,
21979
+ Membership: index$l,
21980
+ Moderation: index$k,
21946
21981
  getChannelByIds: getChannelByIds$1,
21947
21982
  createChannel: createChannel,
21948
21983
  updateChannel: updateChannel,
@@ -23345,7 +23380,7 @@ const searchMembers = (params, callback, config) => {
23345
23380
  };
23346
23381
  /* end_public_function */
23347
23382
 
23348
- var index$h = /*#__PURE__*/Object.freeze({
23383
+ var index$i = /*#__PURE__*/Object.freeze({
23349
23384
  __proto__: null,
23350
23385
  addMembers: addMembers,
23351
23386
  removeMembers: removeMembers,
@@ -24596,7 +24631,7 @@ const unbanMembers = async (communityId, userIds) => {
24596
24631
  };
24597
24632
  /* end_public_function */
24598
24633
 
24599
- var index$g = /*#__PURE__*/Object.freeze({
24634
+ var index$h = /*#__PURE__*/Object.freeze({
24600
24635
  __proto__: null,
24601
24636
  addRoles: addRoles,
24602
24637
  removeRoles: removeRoles,
@@ -24604,10 +24639,10 @@ var index$g = /*#__PURE__*/Object.freeze({
24604
24639
  unbanMembers: unbanMembers
24605
24640
  });
24606
24641
 
24607
- var index$f = /*#__PURE__*/Object.freeze({
24642
+ var index$g = /*#__PURE__*/Object.freeze({
24608
24643
  __proto__: null,
24609
- Moderation: index$g,
24610
- Membership: index$h,
24644
+ Moderation: index$h,
24645
+ Membership: index$i,
24611
24646
  getCommunityByIds: getCommunities$1,
24612
24647
  createCommunity: createCommunity,
24613
24648
  updateCommunity: updateCommunity,
@@ -24841,7 +24876,7 @@ const getCategories = (params, callback, config) => {
24841
24876
  };
24842
24877
  /* end_public_function */
24843
24878
 
24844
- var index$e = /*#__PURE__*/Object.freeze({
24879
+ var index$f = /*#__PURE__*/Object.freeze({
24845
24880
  __proto__: null,
24846
24881
  getCategory: getCategory,
24847
24882
  getCategories: getCategories
@@ -25144,8 +25179,6 @@ const createComment = async (bundle) => {
25144
25179
  postChildren: [],
25145
25180
  users: data.users,
25146
25181
  videoStreamings: [],
25147
- videoStreamingChildren: [],
25148
- rooms: [],
25149
25182
  });
25150
25183
  }
25151
25184
  }
@@ -25902,7 +25935,7 @@ const getComments = (params, callback, config) => {
25902
25935
  };
25903
25936
  /* end_public_function */
25904
25937
 
25905
- var index$d = /*#__PURE__*/Object.freeze({
25938
+ var index$e = /*#__PURE__*/Object.freeze({
25906
25939
  __proto__: null,
25907
25940
  getCommentByIds: getCommentByIds,
25908
25941
  createComment: createComment,
@@ -26573,7 +26606,7 @@ const getUserFeed = (params, callback, config) => {
26573
26606
  };
26574
26607
  /* end_public_function */
26575
26608
 
26576
- var index$c = /*#__PURE__*/Object.freeze({
26609
+ var index$d = /*#__PURE__*/Object.freeze({
26577
26610
  __proto__: null,
26578
26611
  queryGlobalFeed: queryGlobalFeed,
26579
26612
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
@@ -26688,7 +26721,15 @@ const createPost = async (bundle) => {
26688
26721
  // eslint-disable-next-line no-param-reassign
26689
26722
  delete bundle.dataType;
26690
26723
  }
26691
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
26724
+ const { attachments } = bundle;
26725
+ const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
26726
+ ? attachments.map(attachment => {
26727
+ if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
26728
+ return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
26729
+ return attachment;
26730
+ })
26731
+ : attachments;
26732
+ const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, bundle), { attachments: processedAttachments }));
26692
26733
  fireEvent('post.created', payload);
26693
26734
  const data = preparePostPayload(payload);
26694
26735
  const cachedAt = client.cache && Date.now();
@@ -26725,7 +26766,15 @@ const createPost = async (bundle) => {
26725
26766
  const editPost = async (postId, patch) => {
26726
26767
  const client = getActiveClient();
26727
26768
  client.log('user/editPost', patch);
26728
- const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
26769
+ const { attachments } = patch;
26770
+ const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
26771
+ ? attachments.map(attachment => {
26772
+ if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
26773
+ return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
26774
+ return attachment;
26775
+ })
26776
+ : attachments;
26777
+ const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, Object.assign(Object.assign({}, patch), { attachments: processedAttachments }));
26729
26778
  const data = prepareMembershipPayload(payload, 'communityUsers');
26730
26779
  const cachedAt = client.cache && Date.now();
26731
26780
  if (client.cache)
@@ -29369,7 +29418,7 @@ const getRooms = (params, callback, config) => {
29369
29418
  };
29370
29419
  /* end_public_function */
29371
29420
 
29372
- var index$b = /*#__PURE__*/Object.freeze({
29421
+ var index$c = /*#__PURE__*/Object.freeze({
29373
29422
  __proto__: null,
29374
29423
  createRoom: createRoom,
29375
29424
  updateRoom: updateRoom,
@@ -29665,7 +29714,7 @@ const getCommunityLiveRoomPosts = (params, callback, config) => {
29665
29714
  };
29666
29715
  /* end_public_function */
29667
29716
 
29668
- var index$a = /*#__PURE__*/Object.freeze({
29717
+ var index$b = /*#__PURE__*/Object.freeze({
29669
29718
  __proto__: null,
29670
29719
  getPostByIds: getPostByIds,
29671
29720
  createPost: createPost,
@@ -30275,7 +30324,7 @@ const getStreams = (params, callback, config) => {
30275
30324
  };
30276
30325
  };
30277
30326
 
30278
- var index$9 = /*#__PURE__*/Object.freeze({
30327
+ var index$a = /*#__PURE__*/Object.freeze({
30279
30328
  __proto__: null,
30280
30329
  createStream: createStream,
30281
30330
  updateStream: updateStream,
@@ -30578,7 +30627,7 @@ const stopHeartbeat = (roomId) => {
30578
30627
  };
30579
30628
  /* end_public_function */
30580
30629
 
30581
- var index$8 = /*#__PURE__*/Object.freeze({
30630
+ var index$9 = /*#__PURE__*/Object.freeze({
30582
30631
  __proto__: null,
30583
30632
  getRoomOnlineUsers: getRoomOnlineUsers,
30584
30633
  getRoomUserCount: getRoomUserCount,
@@ -30886,7 +30935,7 @@ const getPoll = (pollId, callback) => {
30886
30935
  };
30887
30936
  /* end_public_function */
30888
30937
 
30889
- var index$7 = /*#__PURE__*/Object.freeze({
30938
+ var index$8 = /*#__PURE__*/Object.freeze({
30890
30939
  __proto__: null,
30891
30940
  createPoll: createPoll,
30892
30941
  closePoll: closePoll,
@@ -31190,7 +31239,7 @@ const getPlayer = async (parameters) => {
31190
31239
  return video;
31191
31240
  };
31192
31241
 
31193
- var index$6 = /*#__PURE__*/Object.freeze({
31242
+ var index$7 = /*#__PURE__*/Object.freeze({
31194
31243
  __proto__: null,
31195
31244
  getPlayer: getPlayer
31196
31245
  });
@@ -32363,7 +32412,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
32363
32412
  };
32364
32413
  };
32365
32414
 
32366
- var index$5 = /*#__PURE__*/Object.freeze({
32415
+ var index$6 = /*#__PURE__*/Object.freeze({
32367
32416
  __proto__: null,
32368
32417
  createImageStory: createImageStory,
32369
32418
  createVideoStory: createVideoStory,
@@ -32400,7 +32449,7 @@ const getNetworkAds = async () => {
32400
32449
  };
32401
32450
  };
32402
32451
 
32403
- var index$4 = /*#__PURE__*/Object.freeze({
32452
+ var index$5 = /*#__PURE__*/Object.freeze({
32404
32453
  __proto__: null,
32405
32454
  getNetworkAds: getNetworkAds
32406
32455
  });
@@ -32791,7 +32840,7 @@ const markTraySeen = async (lastSeenAt) => {
32791
32840
  };
32792
32841
  /* end_public_function */
32793
32842
 
32794
- var index$3 = /*#__PURE__*/Object.freeze({
32843
+ var index$4 = /*#__PURE__*/Object.freeze({
32795
32844
  __proto__: null,
32796
32845
  getNotificationTraySeen: getNotificationTraySeen,
32797
32846
  getNotificationTrayItems: getNotificationTrayItems,
@@ -33089,7 +33138,7 @@ const getInvitations = (params, callback) => {
33089
33138
  };
33090
33139
  };
33091
33140
 
33092
- var index$2 = /*#__PURE__*/Object.freeze({
33141
+ var index$3 = /*#__PURE__*/Object.freeze({
33093
33142
  __proto__: null,
33094
33143
  cancelInvitation: cancelInvitation,
33095
33144
  onLocalInvitationCreated: onLocalInvitationCreated,
@@ -33238,7 +33287,7 @@ const getReactions = (postId, callback) => {
33238
33287
  };
33239
33288
  };
33240
33289
 
33241
- var index$1 = /*#__PURE__*/Object.freeze({
33290
+ var index$2 = /*#__PURE__*/Object.freeze({
33242
33291
  __proto__: null,
33243
33292
  createReaction: createReaction,
33244
33293
  onLiveReactionCreated: onLiveReactionCreated,
@@ -33721,7 +33770,7 @@ const getMyEvents = (params, callback, config) => {
33721
33770
  };
33722
33771
  };
33723
33772
 
33724
- var index = /*#__PURE__*/Object.freeze({
33773
+ var index$1 = /*#__PURE__*/Object.freeze({
33725
33774
  __proto__: null,
33726
33775
  createEvent: createEvent,
33727
33776
  updateEvent: updateEvent,
@@ -33742,38 +33791,249 @@ var index = /*#__PURE__*/Object.freeze({
33742
33791
  getRSVPs: getRSVPs
33743
33792
  });
33744
33793
 
33794
+ const getProduct$1 = async (productId) => {
33795
+ const client = getActiveClient();
33796
+ client.log('product/getProduct', productId);
33797
+ isInTombstone('product', productId);
33798
+ let payload;
33799
+ try {
33800
+ const response = await client.http.get(`/api/v1/products/${encodeURIComponent(productId)}`);
33801
+ payload = response.data;
33802
+ }
33803
+ catch (error) {
33804
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
33805
+ pushToTombstone('product', productId);
33806
+ }
33807
+ throw error;
33808
+ }
33809
+ const cachedAt = client.cache && Date.now();
33810
+ if (client.cache)
33811
+ ingestInCache(payload, { cachedAt });
33812
+ const { products } = payload;
33813
+ const result = products.find(product => product.productId === productId);
33814
+ return {
33815
+ data: result,
33816
+ cachedAt,
33817
+ };
33818
+ };
33819
+ getProduct$1.locally = (productId) => {
33820
+ const client = getActiveClient();
33821
+ client.log('product/getProduct.locally', productId);
33822
+ if (!client.cache)
33823
+ return;
33824
+ const cached = pullFromCache(['product', 'get', productId]);
33825
+ if (!cached)
33826
+ return;
33827
+ return {
33828
+ data: cached.data,
33829
+ cachedAt: cached.cachedAt,
33830
+ };
33831
+ };
33832
+
33833
+ /* begin_public_function
33834
+ id: product.get
33835
+ */
33836
+ /**
33837
+ * ```js
33838
+ * import { ProductRepository } from '@amityco/ts-sdk';
33839
+ *
33840
+ * let product;
33841
+ *
33842
+ * const unsub = ProductRepository.getProduct(productId, response => {
33843
+ * product = response.data;
33844
+ * });
33845
+ * ```
33846
+ *
33847
+ * Observe all mutation on a given {@link Amity.Product}
33848
+ *
33849
+ * @param productId the ID of the product to observe
33850
+ * @param callback the function to call when new data are available
33851
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the product
33852
+ *
33853
+ * @category Product Live Object
33854
+ */
33855
+ const getProduct = (productId, callback) => {
33856
+ const responder = (snapshot) => {
33857
+ callback(snapshot);
33858
+ };
33859
+ return liveObject(productId, responder, 'productId', getProduct$1, []);
33860
+ };
33861
+ /* end_public_function */
33862
+
33863
+ class SearchProductPaginationController extends PaginationController {
33864
+ async getRequest(queryParams, token) {
33865
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
33866
+ const options = token ? { token } : { limit };
33867
+ const { data: queryResponse } = await this.http.get(`/api/v1/products/search`, {
33868
+ params: Object.assign(Object.assign({}, params), { options }),
33869
+ });
33870
+ return queryResponse;
33871
+ }
33872
+ }
33873
+
33874
+ class SearchProductQueryStreamController extends QueryStreamController {
33875
+ constructor(query, cacheKey, notifyChange) {
33876
+ super(query, cacheKey);
33877
+ this.notifyChange = notifyChange;
33878
+ }
33879
+ // eslint-disable-next-line class-methods-use-this
33880
+ saveToMainDB(response) {
33881
+ const client = getActiveClient();
33882
+ const cachedAt = client.cache && Date.now();
33883
+ if (client.cache) {
33884
+ ingestInCache(response, { cachedAt });
33885
+ }
33886
+ }
33887
+ appendToQueryStream(response, direction, refresh = false) {
33888
+ var _a, _b;
33889
+ if (refresh) {
33890
+ pushToCache(this.cacheKey, {
33891
+ data: response.products.map(getResolver('product')),
33892
+ });
33893
+ }
33894
+ else {
33895
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
33896
+ const products = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
33897
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...products, ...response.products.map(getResolver('product'))])] }));
33898
+ }
33899
+ }
33900
+ }
33901
+
33902
+ class SearchProductLiveCollectionController extends LiveCollectionController {
33903
+ constructor(query, callback) {
33904
+ const queryStreamId = hash__default["default"](query);
33905
+ const cacheKey = ['products', 'collection', queryStreamId];
33906
+ const paginationController = new SearchProductPaginationController(query);
33907
+ super(paginationController, queryStreamId, cacheKey, callback);
33908
+ this.query = query;
33909
+ this.queryStreamController = new SearchProductQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this));
33910
+ this.callback = callback.bind(this);
33911
+ this.loadPage({ initial: true });
33912
+ }
33913
+ setup() {
33914
+ var _a;
33915
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
33916
+ if (!collection) {
33917
+ pushToCache(this.cacheKey, {
33918
+ data: [],
33919
+ params: {},
33920
+ });
33921
+ }
33922
+ }
33923
+ async persistModel(queryPayload) {
33924
+ await this.queryStreamController.saveToMainDB(queryPayload);
33925
+ }
33926
+ persistQueryStream({ response, direction, refresh, }) {
33927
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
33928
+ }
33929
+ // eslint-disable-next-line class-methods-use-this
33930
+ startSubscription() {
33931
+ return [];
33932
+ }
33933
+ notifyChange({ origin, loading, error }) {
33934
+ var _a, _b;
33935
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
33936
+ if (!collection)
33937
+ return;
33938
+ const data = (_b = collection.data
33939
+ .map(id => pullFromCache(['product', 'get', id]))
33940
+ .filter(isNonNullable)
33941
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
33942
+ if (!this.shouldNotify(data) && origin === 'event')
33943
+ return;
33944
+ this.callback({
33945
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
33946
+ data,
33947
+ hasNextPage: !!this.paginationController.getNextToken(),
33948
+ loading,
33949
+ error,
33950
+ });
33951
+ }
33952
+ }
33953
+
33954
+ /* begin_public_function
33955
+ id: product.search
33956
+ */
33957
+ /**
33958
+ * ```js
33959
+ * import { ProductRepository } from '@amityco/ts-sdk'
33960
+ *
33961
+ * let products = []
33962
+ * const unsub = ProductRepository.searchProducts({
33963
+ * keyword: string,
33964
+ * }, response => merge(products, response.data))
33965
+ * ```
33966
+ *
33967
+ * Observe all mutations on a list of {@link Amity.Product}
33968
+ *
33969
+ * @param params.keyword the search keyword
33970
+ * @param params.isActive filter by active status
33971
+ * @param params.isDeleted filter by deleted status
33972
+ * @param params.sortBy sort option
33973
+ * @param params.sortOrder order option
33974
+ * @param callback the function to call when new data are available
33975
+ * @param config
33976
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the products
33977
+ *
33978
+ * @category Products Live Collection
33979
+ */
33980
+ const searchProducts = (params, callback, config) => {
33981
+ const { log, cache } = getActiveClient();
33982
+ if (!cache) {
33983
+ console.log(ENABLE_CACHE_MESSAGE);
33984
+ }
33985
+ const timestamp = Date.now();
33986
+ log(`searchProducts(tmpid: ${timestamp}) > listen`);
33987
+ const productsLiveCollection = new SearchProductLiveCollectionController(params, callback);
33988
+ const disposers = productsLiveCollection.startSubscription();
33989
+ const cacheKey = productsLiveCollection.getCacheKey();
33990
+ disposers.push(() => dropFromCache(cacheKey));
33991
+ return () => {
33992
+ log(`searchProducts(tmpid: ${timestamp}) > dispose`);
33993
+ disposers.forEach(fn => fn());
33994
+ };
33995
+ };
33996
+ /* end_public_function */
33997
+
33998
+ var index = /*#__PURE__*/Object.freeze({
33999
+ __proto__: null,
34000
+ getProduct: getProduct,
34001
+ searchProducts: searchProducts
34002
+ });
34003
+
33745
34004
  exports.API_REGIONS = API_REGIONS;
33746
- exports.AdRepository = index$4;
33747
- exports.CategoryRepository = index$e;
33748
- exports.ChannelRepository = index$i;
33749
- exports.Client = index$r;
33750
- exports.CommentRepository = index$d;
34005
+ exports.AdRepository = index$5;
34006
+ exports.CategoryRepository = index$f;
34007
+ exports.ChannelRepository = index$j;
34008
+ exports.Client = index$s;
34009
+ exports.CommentRepository = index$e;
33751
34010
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
33752
34011
  exports.CommunityPostSettings = CommunityPostSettings;
33753
- exports.CommunityRepository = index$f;
34012
+ exports.CommunityRepository = index$g;
33754
34013
  exports.ContentFeedType = ContentFeedType;
33755
34014
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
33756
- exports.EventRepository = index;
33757
- exports.FeedRepository = index$c;
33758
- exports.FileRepository = index$o;
34015
+ exports.EventRepository = index$1;
34016
+ exports.FeedRepository = index$d;
34017
+ exports.FileRepository = index$p;
33759
34018
  exports.FileType = FileType;
33760
34019
  exports.GET_WATCHER_URLS = GET_WATCHER_URLS;
33761
- exports.InvitationRepository = index$2;
33762
- exports.LiveReactionRepository = index$1;
33763
- exports.LiveStreamPlayer = index$6;
34020
+ exports.InvitationRepository = index$3;
34021
+ exports.LiveReactionRepository = index$2;
34022
+ exports.LiveStreamPlayer = index$7;
33764
34023
  exports.MessageContentType = MessageContentType;
33765
- exports.MessageRepository = index$m;
33766
- exports.PollRepository = index$7;
34024
+ exports.MessageRepository = index$n;
34025
+ exports.PollRepository = index$8;
33767
34026
  exports.PostContentType = PostContentType;
33768
- exports.PostRepository = index$a;
34027
+ exports.PostRepository = index$b;
33769
34028
  exports.PostStructureType = PostStructureType;
33770
- exports.ReactionRepository = index$n;
33771
- exports.RoomPresenceRepository = index$8;
33772
- exports.RoomRepository = index$b;
33773
- exports.StoryRepository = index$5;
33774
- exports.StreamRepository = index$9;
33775
- exports.SubChannelRepository = index$l;
33776
- exports.UserRepository = index$p;
34029
+ exports.ProductRepository = index;
34030
+ exports.ReactionRepository = index$o;
34031
+ exports.RoomPresenceRepository = index$9;
34032
+ exports.RoomRepository = index$c;
34033
+ exports.StoryRepository = index$6;
34034
+ exports.StreamRepository = index$a;
34035
+ exports.SubChannelRepository = index$m;
34036
+ exports.UserRepository = index$q;
33777
34037
  exports.VERSION = VERSION;
33778
34038
  exports.VideoResolution = VideoResolution;
33779
34039
  exports.VideoSize = VideoSize;
@@ -33829,7 +34089,7 @@ exports.isPaged = isPaged;
33829
34089
  exports.isReportedByMe = isReportedByMe;
33830
34090
  exports.isSkip = isSkip;
33831
34091
  exports.mergeInCache = mergeInCache;
33832
- exports.notificationTray = index$3;
34092
+ exports.notificationTray = index$4;
33833
34093
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
33834
34094
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
33835
34095
  exports.onFeedMarkerUpdated = onFeedMarkerUpdated;
package/dist/index.d.ts CHANGED
@@ -32,4 +32,5 @@ export * as InvitationRepository from './invitationRepository';
32
32
  export * as LiveReactionRepository from './liveReactionRepository';
33
33
  export { GET_WATCHER_URLS } from './utils/linkedObject/streamLinkedObject';
34
34
  export * as EventRepository from './eventRepository';
35
+ export * as ProductRepository from './productRepository';
35
36
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,cAAc,UAAU,CAAC;AAEzB,cAAc,WAAW,CAAC;AAG1B,cAAc,cAAc,CAAC;AAC7B,cAAc,qBAAqB,CAAC;AACpC,cAAc,aAAa,CAAC;AAE5B,OAAO,KAAK,MAAM,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,WAAW,EAA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