@amityco/ts-sdk 7.12.1-3748bf9.0 → 7.12.1-4d56f961.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 (48) 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/post.d.ts +1 -0
  8. package/dist/@types/domains/post.d.ts.map +1 -1
  9. package/dist/@types/domains/product.d.ts +76 -0
  10. package/dist/@types/domains/product.d.ts.map +1 -0
  11. package/dist/@types/index.d.ts +1 -0
  12. package/dist/@types/index.d.ts.map +1 -1
  13. package/dist/client/api/getProductCatalogueSetting.d.ts +15 -0
  14. package/dist/client/api/getProductCatalogueSetting.d.ts.map +1 -0
  15. package/dist/client/api/index.d.ts +1 -0
  16. package/dist/client/api/index.d.ts.map +1 -1
  17. package/dist/core/model/index.d.ts.map +1 -1
  18. package/dist/index.cjs.js +318 -58
  19. package/dist/index.d.ts +1 -0
  20. package/dist/index.d.ts.map +1 -1
  21. package/dist/index.esm.js +295 -36
  22. package/dist/index.umd.js +2 -2
  23. package/dist/postRepository/api/createPost.d.ts +2 -0
  24. package/dist/postRepository/api/createPost.d.ts.map +1 -1
  25. package/dist/postRepository/api/editPost.d.ts +2 -0
  26. package/dist/postRepository/api/editPost.d.ts.map +1 -1
  27. package/dist/productRepository/index.d.ts +2 -0
  28. package/dist/productRepository/index.d.ts.map +1 -0
  29. package/dist/productRepository/internalApi/getProduct.d.ts +5 -0
  30. package/dist/productRepository/internalApi/getProduct.d.ts.map +1 -0
  31. package/dist/productRepository/internalApi/index.d.ts +2 -0
  32. package/dist/productRepository/internalApi/index.d.ts.map +1 -0
  33. package/dist/productRepository/observers/getProduct.d.ts +21 -0
  34. package/dist/productRepository/observers/getProduct.d.ts.map +1 -0
  35. package/dist/productRepository/observers/index.d.ts +3 -0
  36. package/dist/productRepository/observers/index.d.ts.map +1 -0
  37. package/dist/productRepository/observers/searchProducts/LiveCollectionController.d.ts +15 -0
  38. package/dist/productRepository/observers/searchProducts/LiveCollectionController.d.ts.map +1 -0
  39. package/dist/productRepository/observers/searchProducts/PaginationController.d.ts +5 -0
  40. package/dist/productRepository/observers/searchProducts/PaginationController.d.ts.map +1 -0
  41. package/dist/productRepository/observers/searchProducts/QueryStreamController.d.ts +8 -0
  42. package/dist/productRepository/observers/searchProducts/QueryStreamController.d.ts.map +1 -0
  43. package/dist/productRepository/observers/searchProducts.d.ts +25 -0
  44. package/dist/productRepository/observers/searchProducts.d.ts.map +1 -0
  45. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  46. package/dist/utils/linkedObject/productTagLinkedObject.d.ts +2 -0
  47. package/dist/utils/linkedObject/productTagLinkedObject.d.ts.map +1 -0
  48. package/package.json +1 -1
package/dist/index.cjs.js CHANGED
@@ -748,6 +748,7 @@ const PAYLOAD2MODEL = {
748
748
  events: 'event',
749
749
  viewers: 'viewer',
750
750
  eventResponses: 'eventResponse',
751
+ products: 'product',
751
752
  };
752
753
  /** hidden */
753
754
  const isOutdated = (prevData, nextData) => {
@@ -10063,6 +10064,29 @@ const getShareableLinkConfiguration = async () => {
10063
10064
  return data;
10064
10065
  };
10065
10066
 
10067
+ /* begin_public_function
10068
+ id: client.getProductCatalogueSetting
10069
+ */
10070
+ /**
10071
+ * ```js
10072
+ * import { getProductCatalogueSetting } from '@amityco/ts-sdk'
10073
+ * const productCatalogueSetting = await getProductCatalogueSetting()
10074
+ * ```
10075
+ *
10076
+ * Fetches a {@link Amity.ProductCatalogueSetting} object
10077
+ *
10078
+ * @returns A Promise of {@link Amity.ProductCatalogueSetting} object
10079
+ *
10080
+ * @category Client API
10081
+ * @async
10082
+ */
10083
+ const getProductCatalogueSetting = async () => {
10084
+ const client = getActiveClient();
10085
+ const { data } = await client.http.get(`/api/v3/network-settings/product-catalogue`);
10086
+ return data;
10087
+ };
10088
+ /* end_public_function */
10089
+
10066
10090
  /**
10067
10091
  * Retrieves a pair of {@link Amity.Tokens} necessary for connection
10068
10092
  *
@@ -10555,7 +10579,7 @@ const getUserUnread = (callback) => {
10555
10579
  };
10556
10580
  };
10557
10581
 
10558
- var index$r = /*#__PURE__*/Object.freeze({
10582
+ var index$s = /*#__PURE__*/Object.freeze({
10559
10583
  __proto__: null,
10560
10584
  getActiveClient: getActiveClient,
10561
10585
  getActiveUser: getActiveUser,
@@ -10575,6 +10599,7 @@ var index$r = /*#__PURE__*/Object.freeze({
10575
10599
  getLinkPreviewMetadata: getLinkPreviewMetadata,
10576
10600
  getSocialSettings: getSocialSettings,
10577
10601
  getShareableLinkConfiguration: getShareableLinkConfiguration,
10602
+ getProductCatalogueSetting: getProductCatalogueSetting,
10578
10603
  loginAsVisitor: loginAsVisitor,
10579
10604
  loginAsBot: loginAsBot,
10580
10605
  getCurrentUser: getCurrentUser,
@@ -11775,7 +11800,7 @@ const getMyFollowInfo = (callback) => {
11775
11800
  };
11776
11801
  /* end_public_function */
11777
11802
 
11778
- var index$q = /*#__PURE__*/Object.freeze({
11803
+ var index$r = /*#__PURE__*/Object.freeze({
11779
11804
  __proto__: null,
11780
11805
  blockUser: blockUser,
11781
11806
  unBlockUser: unBlockUser,
@@ -13883,6 +13908,11 @@ const communityLinkedObject = (community) => {
13883
13908
  } });
13884
13909
  };
13885
13910
 
13911
+ const productTagLinkedObject = (productTag) => {
13912
+ var _a;
13913
+ return Object.assign(Object.assign({}, productTag), { product: (_a = pullFromCache(['product', 'get', productTag.productId])) === null || _a === void 0 ? void 0 : _a.data });
13914
+ };
13915
+
13886
13916
  const postLinkedObject = (post) => {
13887
13917
  return shallowClone(post, {
13888
13918
  childrenPosts: post.children
@@ -13895,6 +13925,9 @@ const postLinkedObject = (post) => {
13895
13925
  analyticsEngineInstance.markPostAsViewed(post.postId);
13896
13926
  },
13897
13927
  },
13928
+ get productTags() {
13929
+ return post.productTags.map(productTag => productTagLinkedObject(productTag));
13930
+ },
13898
13931
  get latestComments() {
13899
13932
  if (!post.comments)
13900
13933
  return [];
@@ -15884,9 +15917,9 @@ var AmityUserSearchMatchType;
15884
15917
  AmityUserSearchMatchType["PARTIAL"] = "partial";
15885
15918
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
15886
15919
 
15887
- var index$p = /*#__PURE__*/Object.freeze({
15920
+ var index$q = /*#__PURE__*/Object.freeze({
15888
15921
  __proto__: null,
15889
- Relationship: index$q,
15922
+ Relationship: index$r,
15890
15923
  getUserByIds: getUserByIds,
15891
15924
  updateUser: updateUser,
15892
15925
  flagUser: flagUser,
@@ -16289,7 +16322,7 @@ const uploadAudio = async (formData, onProgress) => {
16289
16322
  };
16290
16323
  /* end_public_function */
16291
16324
 
16292
- var index$o = /*#__PURE__*/Object.freeze({
16325
+ var index$p = /*#__PURE__*/Object.freeze({
16293
16326
  __proto__: null,
16294
16327
  getFile: getFile,
16295
16328
  uploadFile: uploadFile,
@@ -18101,7 +18134,7 @@ const getReactions$1 = (params, callback, config) => {
18101
18134
  };
18102
18135
  /* end_public_function */
18103
18136
 
18104
- var index$n = /*#__PURE__*/Object.freeze({
18137
+ var index$o = /*#__PURE__*/Object.freeze({
18105
18138
  __proto__: null,
18106
18139
  addReaction: addReaction,
18107
18140
  removeReaction: removeReaction,
@@ -19873,7 +19906,7 @@ const getMessages = (params, callback, config) => {
19873
19906
  };
19874
19907
  /* end_public_function */
19875
19908
 
19876
- var index$m = /*#__PURE__*/Object.freeze({
19909
+ var index$n = /*#__PURE__*/Object.freeze({
19877
19910
  __proto__: null,
19878
19911
  createMessage: createMessage,
19879
19912
  updateMessage: updateMessage,
@@ -20399,7 +20432,7 @@ const stopMessageReceiptSync = (subChannelId) => {
20399
20432
  };
20400
20433
  /* end_public_function */
20401
20434
 
20402
- var index$l = /*#__PURE__*/Object.freeze({
20435
+ var index$m = /*#__PURE__*/Object.freeze({
20403
20436
  __proto__: null,
20404
20437
  getSubChannelByIds: getSubChannels$1,
20405
20438
  createSubChannel: createSubChannel,
@@ -21726,7 +21759,7 @@ const searchMembers$1 = (params, callback, config) => {
21726
21759
  };
21727
21760
  /* end_public_function */
21728
21761
 
21729
- var index$k = /*#__PURE__*/Object.freeze({
21762
+ var index$l = /*#__PURE__*/Object.freeze({
21730
21763
  __proto__: null,
21731
21764
  addMembers: addMembers$1,
21732
21765
  removeMembers: removeMembers$1,
@@ -21929,7 +21962,7 @@ const unmuteMembers = async (channelId, userIds) => {
21929
21962
  };
21930
21963
  /* end_public_function */
21931
21964
 
21932
- var index$j = /*#__PURE__*/Object.freeze({
21965
+ var index$k = /*#__PURE__*/Object.freeze({
21933
21966
  __proto__: null,
21934
21967
  addRole: addRole,
21935
21968
  removeRole: removeRole,
@@ -21939,10 +21972,10 @@ var index$j = /*#__PURE__*/Object.freeze({
21939
21972
  unmuteMembers: unmuteMembers
21940
21973
  });
21941
21974
 
21942
- var index$i = /*#__PURE__*/Object.freeze({
21975
+ var index$j = /*#__PURE__*/Object.freeze({
21943
21976
  __proto__: null,
21944
- Membership: index$k,
21945
- Moderation: index$j,
21977
+ Membership: index$l,
21978
+ Moderation: index$k,
21946
21979
  getChannelByIds: getChannelByIds$1,
21947
21980
  createChannel: createChannel,
21948
21981
  updateChannel: updateChannel,
@@ -23345,7 +23378,7 @@ const searchMembers = (params, callback, config) => {
23345
23378
  };
23346
23379
  /* end_public_function */
23347
23380
 
23348
- var index$h = /*#__PURE__*/Object.freeze({
23381
+ var index$i = /*#__PURE__*/Object.freeze({
23349
23382
  __proto__: null,
23350
23383
  addMembers: addMembers,
23351
23384
  removeMembers: removeMembers,
@@ -24596,7 +24629,7 @@ const unbanMembers = async (communityId, userIds) => {
24596
24629
  };
24597
24630
  /* end_public_function */
24598
24631
 
24599
- var index$g = /*#__PURE__*/Object.freeze({
24632
+ var index$h = /*#__PURE__*/Object.freeze({
24600
24633
  __proto__: null,
24601
24634
  addRoles: addRoles,
24602
24635
  removeRoles: removeRoles,
@@ -24604,10 +24637,10 @@ var index$g = /*#__PURE__*/Object.freeze({
24604
24637
  unbanMembers: unbanMembers
24605
24638
  });
24606
24639
 
24607
- var index$f = /*#__PURE__*/Object.freeze({
24640
+ var index$g = /*#__PURE__*/Object.freeze({
24608
24641
  __proto__: null,
24609
- Moderation: index$g,
24610
- Membership: index$h,
24642
+ Moderation: index$h,
24643
+ Membership: index$i,
24611
24644
  getCommunityByIds: getCommunities$1,
24612
24645
  createCommunity: createCommunity,
24613
24646
  updateCommunity: updateCommunity,
@@ -24841,7 +24874,7 @@ const getCategories = (params, callback, config) => {
24841
24874
  };
24842
24875
  /* end_public_function */
24843
24876
 
24844
- var index$e = /*#__PURE__*/Object.freeze({
24877
+ var index$f = /*#__PURE__*/Object.freeze({
24845
24878
  __proto__: null,
24846
24879
  getCategory: getCategory,
24847
24880
  getCategories: getCategories
@@ -25900,7 +25933,7 @@ const getComments = (params, callback, config) => {
25900
25933
  };
25901
25934
  /* end_public_function */
25902
25935
 
25903
- var index$d = /*#__PURE__*/Object.freeze({
25936
+ var index$e = /*#__PURE__*/Object.freeze({
25904
25937
  __proto__: null,
25905
25938
  getCommentByIds: getCommentByIds,
25906
25939
  createComment: createComment,
@@ -26571,7 +26604,7 @@ const getUserFeed = (params, callback, config) => {
26571
26604
  };
26572
26605
  /* end_public_function */
26573
26606
 
26574
- var index$c = /*#__PURE__*/Object.freeze({
26607
+ var index$d = /*#__PURE__*/Object.freeze({
26575
26608
  __proto__: null,
26576
26609
  queryGlobalFeed: queryGlobalFeed,
26577
26610
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
@@ -26686,7 +26719,15 @@ const createPost = async (bundle) => {
26686
26719
  // eslint-disable-next-line no-param-reassign
26687
26720
  delete bundle.dataType;
26688
26721
  }
26689
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
26722
+ const { attachments } = bundle;
26723
+ const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
26724
+ ? attachments.map(attachment => {
26725
+ if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
26726
+ return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
26727
+ return attachment;
26728
+ })
26729
+ : attachments;
26730
+ const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, bundle), { attachments: processedAttachments }));
26690
26731
  fireEvent('post.created', payload);
26691
26732
  const data = preparePostPayload(payload);
26692
26733
  const cachedAt = client.cache && Date.now();
@@ -26723,7 +26764,15 @@ const createPost = async (bundle) => {
26723
26764
  const editPost = async (postId, patch) => {
26724
26765
  const client = getActiveClient();
26725
26766
  client.log('user/editPost', patch);
26726
- const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
26767
+ const { attachments } = patch;
26768
+ const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
26769
+ ? attachments.map(attachment => {
26770
+ if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
26771
+ return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
26772
+ return attachment;
26773
+ })
26774
+ : attachments;
26775
+ const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, Object.assign(Object.assign({}, patch), { attachments: processedAttachments }));
26727
26776
  const data = prepareMembershipPayload(payload, 'communityUsers');
26728
26777
  const cachedAt = client.cache && Date.now();
26729
26778
  if (client.cache)
@@ -29367,7 +29416,7 @@ const getRooms = (params, callback, config) => {
29367
29416
  };
29368
29417
  /* end_public_function */
29369
29418
 
29370
- var index$b = /*#__PURE__*/Object.freeze({
29419
+ var index$c = /*#__PURE__*/Object.freeze({
29371
29420
  __proto__: null,
29372
29421
  createRoom: createRoom,
29373
29422
  updateRoom: updateRoom,
@@ -29663,7 +29712,7 @@ const getCommunityLiveRoomPosts = (params, callback, config) => {
29663
29712
  };
29664
29713
  /* end_public_function */
29665
29714
 
29666
- var index$a = /*#__PURE__*/Object.freeze({
29715
+ var index$b = /*#__PURE__*/Object.freeze({
29667
29716
  __proto__: null,
29668
29717
  getPostByIds: getPostByIds,
29669
29718
  createPost: createPost,
@@ -30273,7 +30322,7 @@ const getStreams = (params, callback, config) => {
30273
30322
  };
30274
30323
  };
30275
30324
 
30276
- var index$9 = /*#__PURE__*/Object.freeze({
30325
+ var index$a = /*#__PURE__*/Object.freeze({
30277
30326
  __proto__: null,
30278
30327
  createStream: createStream,
30279
30328
  updateStream: updateStream,
@@ -30576,7 +30625,7 @@ const stopHeartbeat = (roomId) => {
30576
30625
  };
30577
30626
  /* end_public_function */
30578
30627
 
30579
- var index$8 = /*#__PURE__*/Object.freeze({
30628
+ var index$9 = /*#__PURE__*/Object.freeze({
30580
30629
  __proto__: null,
30581
30630
  getRoomOnlineUsers: getRoomOnlineUsers,
30582
30631
  getRoomUserCount: getRoomUserCount,
@@ -30884,7 +30933,7 @@ const getPoll = (pollId, callback) => {
30884
30933
  };
30885
30934
  /* end_public_function */
30886
30935
 
30887
- var index$7 = /*#__PURE__*/Object.freeze({
30936
+ var index$8 = /*#__PURE__*/Object.freeze({
30888
30937
  __proto__: null,
30889
30938
  createPoll: createPoll,
30890
30939
  closePoll: closePoll,
@@ -31188,7 +31237,7 @@ const getPlayer = async (parameters) => {
31188
31237
  return video;
31189
31238
  };
31190
31239
 
31191
- var index$6 = /*#__PURE__*/Object.freeze({
31240
+ var index$7 = /*#__PURE__*/Object.freeze({
31192
31241
  __proto__: null,
31193
31242
  getPlayer: getPlayer
31194
31243
  });
@@ -32361,7 +32410,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
32361
32410
  };
32362
32411
  };
32363
32412
 
32364
- var index$5 = /*#__PURE__*/Object.freeze({
32413
+ var index$6 = /*#__PURE__*/Object.freeze({
32365
32414
  __proto__: null,
32366
32415
  createImageStory: createImageStory,
32367
32416
  createVideoStory: createVideoStory,
@@ -32398,7 +32447,7 @@ const getNetworkAds = async () => {
32398
32447
  };
32399
32448
  };
32400
32449
 
32401
- var index$4 = /*#__PURE__*/Object.freeze({
32450
+ var index$5 = /*#__PURE__*/Object.freeze({
32402
32451
  __proto__: null,
32403
32452
  getNetworkAds: getNetworkAds
32404
32453
  });
@@ -32789,7 +32838,7 @@ const markTraySeen = async (lastSeenAt) => {
32789
32838
  };
32790
32839
  /* end_public_function */
32791
32840
 
32792
- var index$3 = /*#__PURE__*/Object.freeze({
32841
+ var index$4 = /*#__PURE__*/Object.freeze({
32793
32842
  __proto__: null,
32794
32843
  getNotificationTraySeen: getNotificationTraySeen,
32795
32844
  getNotificationTrayItems: getNotificationTrayItems,
@@ -33087,7 +33136,7 @@ const getInvitations = (params, callback) => {
33087
33136
  };
33088
33137
  };
33089
33138
 
33090
- var index$2 = /*#__PURE__*/Object.freeze({
33139
+ var index$3 = /*#__PURE__*/Object.freeze({
33091
33140
  __proto__: null,
33092
33141
  cancelInvitation: cancelInvitation,
33093
33142
  onLocalInvitationCreated: onLocalInvitationCreated,
@@ -33236,7 +33285,7 @@ const getReactions = (postId, callback) => {
33236
33285
  };
33237
33286
  };
33238
33287
 
33239
- var index$1 = /*#__PURE__*/Object.freeze({
33288
+ var index$2 = /*#__PURE__*/Object.freeze({
33240
33289
  __proto__: null,
33241
33290
  createReaction: createReaction,
33242
33291
  onLiveReactionCreated: onLiveReactionCreated,
@@ -33719,7 +33768,7 @@ const getMyEvents = (params, callback, config) => {
33719
33768
  };
33720
33769
  };
33721
33770
 
33722
- var index = /*#__PURE__*/Object.freeze({
33771
+ var index$1 = /*#__PURE__*/Object.freeze({
33723
33772
  __proto__: null,
33724
33773
  createEvent: createEvent,
33725
33774
  updateEvent: updateEvent,
@@ -33740,38 +33789,249 @@ var index = /*#__PURE__*/Object.freeze({
33740
33789
  getRSVPs: getRSVPs
33741
33790
  });
33742
33791
 
33792
+ const getProduct$1 = async (productId) => {
33793
+ const client = getActiveClient();
33794
+ client.log('product/getProduct', productId);
33795
+ isInTombstone('product', productId);
33796
+ let payload;
33797
+ try {
33798
+ const response = await client.http.get(`/api/v1/products/${encodeURIComponent(productId)}`);
33799
+ payload = response.data;
33800
+ }
33801
+ catch (error) {
33802
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
33803
+ pushToTombstone('product', productId);
33804
+ }
33805
+ throw error;
33806
+ }
33807
+ const cachedAt = client.cache && Date.now();
33808
+ if (client.cache)
33809
+ ingestInCache(payload, { cachedAt });
33810
+ const { products } = payload;
33811
+ const result = products.find(product => product.productId === productId);
33812
+ return {
33813
+ data: result,
33814
+ cachedAt,
33815
+ };
33816
+ };
33817
+ getProduct$1.locally = (productId) => {
33818
+ const client = getActiveClient();
33819
+ client.log('product/getProduct.locally', productId);
33820
+ if (!client.cache)
33821
+ return;
33822
+ const cached = pullFromCache(['product', 'get', productId]);
33823
+ if (!cached)
33824
+ return;
33825
+ return {
33826
+ data: cached.data,
33827
+ cachedAt: cached.cachedAt,
33828
+ };
33829
+ };
33830
+
33831
+ /* begin_public_function
33832
+ id: product.get
33833
+ */
33834
+ /**
33835
+ * ```js
33836
+ * import { ProductRepository } from '@amityco/ts-sdk';
33837
+ *
33838
+ * let product;
33839
+ *
33840
+ * const unsub = ProductRepository.getProduct(productId, response => {
33841
+ * product = response.data;
33842
+ * });
33843
+ * ```
33844
+ *
33845
+ * Observe all mutation on a given {@link Amity.Product}
33846
+ *
33847
+ * @param productId the ID of the product to observe
33848
+ * @param callback the function to call when new data are available
33849
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the product
33850
+ *
33851
+ * @category Product Live Object
33852
+ */
33853
+ const getProduct = (productId, callback) => {
33854
+ const responder = (snapshot) => {
33855
+ callback(snapshot);
33856
+ };
33857
+ return liveObject(productId, responder, 'productId', getProduct$1, []);
33858
+ };
33859
+ /* end_public_function */
33860
+
33861
+ class SearchProductPaginationController extends PaginationController {
33862
+ async getRequest(queryParams, token) {
33863
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
33864
+ const options = token ? { token } : { limit };
33865
+ const { data: queryResponse } = await this.http.get(`/api/v1/products/search`, {
33866
+ params: Object.assign(Object.assign({}, params), { options }),
33867
+ });
33868
+ return queryResponse;
33869
+ }
33870
+ }
33871
+
33872
+ class SearchProductQueryStreamController extends QueryStreamController {
33873
+ constructor(query, cacheKey, notifyChange) {
33874
+ super(query, cacheKey);
33875
+ this.notifyChange = notifyChange;
33876
+ }
33877
+ // eslint-disable-next-line class-methods-use-this
33878
+ saveToMainDB(response) {
33879
+ const client = getActiveClient();
33880
+ const cachedAt = client.cache && Date.now();
33881
+ if (client.cache) {
33882
+ ingestInCache(response, { cachedAt });
33883
+ }
33884
+ }
33885
+ appendToQueryStream(response, direction, refresh = false) {
33886
+ var _a, _b;
33887
+ if (refresh) {
33888
+ pushToCache(this.cacheKey, {
33889
+ data: response.products.map(getResolver('product')),
33890
+ });
33891
+ }
33892
+ else {
33893
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
33894
+ const products = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
33895
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...products, ...response.products.map(getResolver('product'))])] }));
33896
+ }
33897
+ }
33898
+ }
33899
+
33900
+ class SearchProductLiveCollectionController extends LiveCollectionController {
33901
+ constructor(query, callback) {
33902
+ const queryStreamId = hash__default["default"](query);
33903
+ const cacheKey = ['products', 'collection', queryStreamId];
33904
+ const paginationController = new SearchProductPaginationController(query);
33905
+ super(paginationController, queryStreamId, cacheKey, callback);
33906
+ this.query = query;
33907
+ this.queryStreamController = new SearchProductQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this));
33908
+ this.callback = callback.bind(this);
33909
+ this.loadPage({ initial: true });
33910
+ }
33911
+ setup() {
33912
+ var _a;
33913
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
33914
+ if (!collection) {
33915
+ pushToCache(this.cacheKey, {
33916
+ data: [],
33917
+ params: {},
33918
+ });
33919
+ }
33920
+ }
33921
+ async persistModel(queryPayload) {
33922
+ await this.queryStreamController.saveToMainDB(queryPayload);
33923
+ }
33924
+ persistQueryStream({ response, direction, refresh, }) {
33925
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
33926
+ }
33927
+ // eslint-disable-next-line class-methods-use-this
33928
+ startSubscription() {
33929
+ return [];
33930
+ }
33931
+ notifyChange({ origin, loading, error }) {
33932
+ var _a, _b;
33933
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
33934
+ if (!collection)
33935
+ return;
33936
+ const data = (_b = collection.data
33937
+ .map(id => pullFromCache(['product', 'get', id]))
33938
+ .filter(isNonNullable)
33939
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
33940
+ if (!this.shouldNotify(data) && origin === 'event')
33941
+ return;
33942
+ this.callback({
33943
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
33944
+ data,
33945
+ hasNextPage: !!this.paginationController.getNextToken(),
33946
+ loading,
33947
+ error,
33948
+ });
33949
+ }
33950
+ }
33951
+
33952
+ /* begin_public_function
33953
+ id: product.search
33954
+ */
33955
+ /**
33956
+ * ```js
33957
+ * import { ProductRepository } from '@amityco/ts-sdk'
33958
+ *
33959
+ * let products = []
33960
+ * const unsub = ProductRepository.searchProducts({
33961
+ * keyword: string,
33962
+ * }, response => merge(products, response.data))
33963
+ * ```
33964
+ *
33965
+ * Observe all mutations on a list of {@link Amity.Product}
33966
+ *
33967
+ * @param params.keyword the search keyword
33968
+ * @param params.isActive filter by active status
33969
+ * @param params.isDeleted filter by deleted status
33970
+ * @param params.sortBy sort option
33971
+ * @param params.sortOrder order option
33972
+ * @param callback the function to call when new data are available
33973
+ * @param config
33974
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the products
33975
+ *
33976
+ * @category Products Live Collection
33977
+ */
33978
+ const searchProducts = (params, callback, config) => {
33979
+ const { log, cache } = getActiveClient();
33980
+ if (!cache) {
33981
+ console.log(ENABLE_CACHE_MESSAGE);
33982
+ }
33983
+ const timestamp = Date.now();
33984
+ log(`searchProducts(tmpid: ${timestamp}) > listen`);
33985
+ const productsLiveCollection = new SearchProductLiveCollectionController(params, callback);
33986
+ const disposers = productsLiveCollection.startSubscription();
33987
+ const cacheKey = productsLiveCollection.getCacheKey();
33988
+ disposers.push(() => dropFromCache(cacheKey));
33989
+ return () => {
33990
+ log(`searchProducts(tmpid: ${timestamp}) > dispose`);
33991
+ disposers.forEach(fn => fn());
33992
+ };
33993
+ };
33994
+ /* end_public_function */
33995
+
33996
+ var index = /*#__PURE__*/Object.freeze({
33997
+ __proto__: null,
33998
+ getProduct: getProduct,
33999
+ searchProducts: searchProducts
34000
+ });
34001
+
33743
34002
  exports.API_REGIONS = API_REGIONS;
33744
- exports.AdRepository = index$4;
33745
- exports.CategoryRepository = index$e;
33746
- exports.ChannelRepository = index$i;
33747
- exports.Client = index$r;
33748
- exports.CommentRepository = index$d;
34003
+ exports.AdRepository = index$5;
34004
+ exports.CategoryRepository = index$f;
34005
+ exports.ChannelRepository = index$j;
34006
+ exports.Client = index$s;
34007
+ exports.CommentRepository = index$e;
33749
34008
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
33750
34009
  exports.CommunityPostSettings = CommunityPostSettings;
33751
- exports.CommunityRepository = index$f;
34010
+ exports.CommunityRepository = index$g;
33752
34011
  exports.ContentFeedType = ContentFeedType;
33753
34012
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
33754
- exports.EventRepository = index;
33755
- exports.FeedRepository = index$c;
33756
- exports.FileRepository = index$o;
34013
+ exports.EventRepository = index$1;
34014
+ exports.FeedRepository = index$d;
34015
+ exports.FileRepository = index$p;
33757
34016
  exports.FileType = FileType;
33758
34017
  exports.GET_WATCHER_URLS = GET_WATCHER_URLS;
33759
- exports.InvitationRepository = index$2;
33760
- exports.LiveReactionRepository = index$1;
33761
- exports.LiveStreamPlayer = index$6;
34018
+ exports.InvitationRepository = index$3;
34019
+ exports.LiveReactionRepository = index$2;
34020
+ exports.LiveStreamPlayer = index$7;
33762
34021
  exports.MessageContentType = MessageContentType;
33763
- exports.MessageRepository = index$m;
33764
- exports.PollRepository = index$7;
34022
+ exports.MessageRepository = index$n;
34023
+ exports.PollRepository = index$8;
33765
34024
  exports.PostContentType = PostContentType;
33766
- exports.PostRepository = index$a;
34025
+ exports.PostRepository = index$b;
33767
34026
  exports.PostStructureType = PostStructureType;
33768
- exports.ReactionRepository = index$n;
33769
- exports.RoomPresenceRepository = index$8;
33770
- exports.RoomRepository = index$b;
33771
- exports.StoryRepository = index$5;
33772
- exports.StreamRepository = index$9;
33773
- exports.SubChannelRepository = index$l;
33774
- exports.UserRepository = index$p;
34027
+ exports.ProductRepository = index;
34028
+ exports.ReactionRepository = index$o;
34029
+ exports.RoomPresenceRepository = index$9;
34030
+ exports.RoomRepository = index$c;
34031
+ exports.StoryRepository = index$6;
34032
+ exports.StreamRepository = index$a;
34033
+ exports.SubChannelRepository = index$m;
34034
+ exports.UserRepository = index$q;
33775
34035
  exports.VERSION = VERSION;
33776
34036
  exports.VideoResolution = VideoResolution;
33777
34037
  exports.VideoSize = VideoSize;
@@ -33827,7 +34087,7 @@ exports.isPaged = isPaged;
33827
34087
  exports.isReportedByMe = isReportedByMe;
33828
34088
  exports.isSkip = isSkip;
33829
34089
  exports.mergeInCache = mergeInCache;
33830
- exports.notificationTray = index$3;
34090
+ exports.notificationTray = index$4;
33831
34091
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
33832
34092
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
33833
34093
  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,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,cAAc,YAAY,CAAC;AAG3B,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAE3D,cAAc,cAAc,CAAC;AAG7B,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAE/D,cAAc,iBAAiB,CAAC;AAGhC,OAAO,KAAK,mBAAmB,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,sBAAsB,MAAM,0BAA0B,CAAC;AAEnE,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,eAAe,MAAM,mBAAmB,CAAC;AAGrD,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAG/C,cAAc,gBAAgB,CAAC;AAE/B,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAE/D,OAAO,KAAK,sBAAsB,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAE3E,OAAO,KAAK,eAAe,MAAM,mBAAmB,CAAC"}
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,EAAE,MAAM,0BAA0B,CAAC;AAGvD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,cAAc,YAAY,CAAC;AAG3B,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAE3D,cAAc,cAAc,CAAC;AAG7B,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAE/D,cAAc,iBAAiB,CAAC;AAGhC,OAAO,KAAK,mBAAmB,MAAM,uBAAuB,CAAC;AAC7D,OAAO,KAAK,kBAAkB,MAAM,sBAAsB,CAAC;AAC3D,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC;AACzD,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AACvD,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AACnD,OAAO,KAAK,sBAAsB,MAAM,0BAA0B,CAAC;AAEnE,OAAO,KAAK,cAAc,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,eAAe,MAAM,mBAAmB,CAAC;AAGrD,OAAO,KAAK,YAAY,MAAM,gBAAgB,CAAC;AAG/C,cAAc,gBAAgB,CAAC;AAE/B,OAAO,KAAK,gBAAgB,MAAM,oBAAoB,CAAC;AAEvD,OAAO,KAAK,oBAAoB,MAAM,wBAAwB,CAAC;AAE/D,OAAO,KAAK,sBAAsB,MAAM,0BAA0B,CAAC;AAEnE,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAE3E,OAAO,KAAK,eAAe,MAAM,mBAAmB,CAAC;AAErD,OAAO,KAAK,iBAAiB,MAAM,qBAAqB,CAAC"}