@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.
Files changed (42) 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/post.d.ts +1 -0
  6. package/dist/@types/domains/post.d.ts.map +1 -1
  7. package/dist/@types/domains/product.d.ts +76 -0
  8. package/dist/@types/domains/product.d.ts.map +1 -0
  9. package/dist/@types/index.d.ts +1 -0
  10. package/dist/@types/index.d.ts.map +1 -1
  11. package/dist/core/model/index.d.ts.map +1 -1
  12. package/dist/index.cjs.js +295 -59
  13. package/dist/index.d.ts +1 -0
  14. package/dist/index.d.ts.map +1 -1
  15. package/dist/index.esm.js +272 -37
  16. package/dist/index.umd.js +2 -2
  17. package/dist/postRepository/api/createPost.d.ts +2 -0
  18. package/dist/postRepository/api/createPost.d.ts.map +1 -1
  19. package/dist/postRepository/api/editPost.d.ts +2 -0
  20. package/dist/postRepository/api/editPost.d.ts.map +1 -1
  21. package/dist/productRepository/index.d.ts +2 -0
  22. package/dist/productRepository/index.d.ts.map +1 -0
  23. package/dist/productRepository/internalApi/getProduct.d.ts +5 -0
  24. package/dist/productRepository/internalApi/getProduct.d.ts.map +1 -0
  25. package/dist/productRepository/internalApi/index.d.ts +2 -0
  26. package/dist/productRepository/internalApi/index.d.ts.map +1 -0
  27. package/dist/productRepository/observers/getProduct.d.ts +21 -0
  28. package/dist/productRepository/observers/getProduct.d.ts.map +1 -0
  29. package/dist/productRepository/observers/index.d.ts +3 -0
  30. package/dist/productRepository/observers/index.d.ts.map +1 -0
  31. package/dist/productRepository/observers/searchProducts/LiveCollectionController.d.ts +15 -0
  32. package/dist/productRepository/observers/searchProducts/LiveCollectionController.d.ts.map +1 -0
  33. package/dist/productRepository/observers/searchProducts/PaginationController.d.ts +5 -0
  34. package/dist/productRepository/observers/searchProducts/PaginationController.d.ts.map +1 -0
  35. package/dist/productRepository/observers/searchProducts/QueryStreamController.d.ts +8 -0
  36. package/dist/productRepository/observers/searchProducts/QueryStreamController.d.ts.map +1 -0
  37. package/dist/productRepository/observers/searchProducts.d.ts +25 -0
  38. package/dist/productRepository/observers/searchProducts.d.ts.map +1 -0
  39. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  40. package/dist/utils/linkedObject/productTagLinkedObject.d.ts +2 -0
  41. package/dist/utils/linkedObject/productTagLinkedObject.d.ts.map +1 -0
  42. 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) => {
@@ -10555,7 +10556,7 @@ const getUserUnread = (callback) => {
10555
10556
  };
10556
10557
  };
10557
10558
 
10558
- var index$r = /*#__PURE__*/Object.freeze({
10559
+ var index$s = /*#__PURE__*/Object.freeze({
10559
10560
  __proto__: null,
10560
10561
  getActiveClient: getActiveClient,
10561
10562
  getActiveUser: getActiveUser,
@@ -11775,7 +11776,7 @@ const getMyFollowInfo = (callback) => {
11775
11776
  };
11776
11777
  /* end_public_function */
11777
11778
 
11778
- var index$q = /*#__PURE__*/Object.freeze({
11779
+ var index$r = /*#__PURE__*/Object.freeze({
11779
11780
  __proto__: null,
11780
11781
  blockUser: blockUser,
11781
11782
  unBlockUser: unBlockUser,
@@ -12882,7 +12883,7 @@ class AmityRoomAnalytics {
12882
12883
  throw new ASCApiError('room is not in watchable state', 500000 /* Amity.ServerError.BUSINESS_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
12883
12884
  }
12884
12885
  // Generate session ID with prefix
12885
- const prefix = this.room.status === 'live' ? 'room_' : 'room_playback';
12886
+ const prefix = this.room.status === 'live' ? 'room_' : 'room_playback_';
12886
12887
  const sessionId = prefix + uuid__default["default"].v4();
12887
12888
  // Create watch session entity
12888
12889
  const session = {
@@ -13883,6 +13884,11 @@ const communityLinkedObject = (community) => {
13883
13884
  } });
13884
13885
  };
13885
13886
 
13887
+ const productTagLinkedObject = (productTag) => {
13888
+ var _a;
13889
+ return Object.assign(Object.assign({}, productTag), { product: (_a = pullFromCache(['product', 'get', productTag.productId])) === null || _a === void 0 ? void 0 : _a.data });
13890
+ };
13891
+
13886
13892
  const postLinkedObject = (post) => {
13887
13893
  return shallowClone(post, {
13888
13894
  childrenPosts: post.children
@@ -13895,6 +13901,9 @@ const postLinkedObject = (post) => {
13895
13901
  analyticsEngineInstance.markPostAsViewed(post.postId);
13896
13902
  },
13897
13903
  },
13904
+ get productTags() {
13905
+ return post.productTags.map(productTag => productTagLinkedObject(productTag));
13906
+ },
13898
13907
  get latestComments() {
13899
13908
  if (!post.comments)
13900
13909
  return [];
@@ -15884,9 +15893,9 @@ var AmityUserSearchMatchType;
15884
15893
  AmityUserSearchMatchType["PARTIAL"] = "partial";
15885
15894
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
15886
15895
 
15887
- var index$p = /*#__PURE__*/Object.freeze({
15896
+ var index$q = /*#__PURE__*/Object.freeze({
15888
15897
  __proto__: null,
15889
- Relationship: index$q,
15898
+ Relationship: index$r,
15890
15899
  getUserByIds: getUserByIds,
15891
15900
  updateUser: updateUser,
15892
15901
  flagUser: flagUser,
@@ -16289,7 +16298,7 @@ const uploadAudio = async (formData, onProgress) => {
16289
16298
  };
16290
16299
  /* end_public_function */
16291
16300
 
16292
- var index$o = /*#__PURE__*/Object.freeze({
16301
+ var index$p = /*#__PURE__*/Object.freeze({
16293
16302
  __proto__: null,
16294
16303
  getFile: getFile,
16295
16304
  uploadFile: uploadFile,
@@ -18101,7 +18110,7 @@ const getReactions$1 = (params, callback, config) => {
18101
18110
  };
18102
18111
  /* end_public_function */
18103
18112
 
18104
- var index$n = /*#__PURE__*/Object.freeze({
18113
+ var index$o = /*#__PURE__*/Object.freeze({
18105
18114
  __proto__: null,
18106
18115
  addReaction: addReaction,
18107
18116
  removeReaction: removeReaction,
@@ -19873,7 +19882,7 @@ const getMessages = (params, callback, config) => {
19873
19882
  };
19874
19883
  /* end_public_function */
19875
19884
 
19876
- var index$m = /*#__PURE__*/Object.freeze({
19885
+ var index$n = /*#__PURE__*/Object.freeze({
19877
19886
  __proto__: null,
19878
19887
  createMessage: createMessage,
19879
19888
  updateMessage: updateMessage,
@@ -20399,7 +20408,7 @@ const stopMessageReceiptSync = (subChannelId) => {
20399
20408
  };
20400
20409
  /* end_public_function */
20401
20410
 
20402
- var index$l = /*#__PURE__*/Object.freeze({
20411
+ var index$m = /*#__PURE__*/Object.freeze({
20403
20412
  __proto__: null,
20404
20413
  getSubChannelByIds: getSubChannels$1,
20405
20414
  createSubChannel: createSubChannel,
@@ -21726,7 +21735,7 @@ const searchMembers$1 = (params, callback, config) => {
21726
21735
  };
21727
21736
  /* end_public_function */
21728
21737
 
21729
- var index$k = /*#__PURE__*/Object.freeze({
21738
+ var index$l = /*#__PURE__*/Object.freeze({
21730
21739
  __proto__: null,
21731
21740
  addMembers: addMembers$1,
21732
21741
  removeMembers: removeMembers$1,
@@ -21929,7 +21938,7 @@ const unmuteMembers = async (channelId, userIds) => {
21929
21938
  };
21930
21939
  /* end_public_function */
21931
21940
 
21932
- var index$j = /*#__PURE__*/Object.freeze({
21941
+ var index$k = /*#__PURE__*/Object.freeze({
21933
21942
  __proto__: null,
21934
21943
  addRole: addRole,
21935
21944
  removeRole: removeRole,
@@ -21939,10 +21948,10 @@ var index$j = /*#__PURE__*/Object.freeze({
21939
21948
  unmuteMembers: unmuteMembers
21940
21949
  });
21941
21950
 
21942
- var index$i = /*#__PURE__*/Object.freeze({
21951
+ var index$j = /*#__PURE__*/Object.freeze({
21943
21952
  __proto__: null,
21944
- Membership: index$k,
21945
- Moderation: index$j,
21953
+ Membership: index$l,
21954
+ Moderation: index$k,
21946
21955
  getChannelByIds: getChannelByIds$1,
21947
21956
  createChannel: createChannel,
21948
21957
  updateChannel: updateChannel,
@@ -23345,7 +23354,7 @@ const searchMembers = (params, callback, config) => {
23345
23354
  };
23346
23355
  /* end_public_function */
23347
23356
 
23348
- var index$h = /*#__PURE__*/Object.freeze({
23357
+ var index$i = /*#__PURE__*/Object.freeze({
23349
23358
  __proto__: null,
23350
23359
  addMembers: addMembers,
23351
23360
  removeMembers: removeMembers,
@@ -24596,7 +24605,7 @@ const unbanMembers = async (communityId, userIds) => {
24596
24605
  };
24597
24606
  /* end_public_function */
24598
24607
 
24599
- var index$g = /*#__PURE__*/Object.freeze({
24608
+ var index$h = /*#__PURE__*/Object.freeze({
24600
24609
  __proto__: null,
24601
24610
  addRoles: addRoles,
24602
24611
  removeRoles: removeRoles,
@@ -24604,10 +24613,10 @@ var index$g = /*#__PURE__*/Object.freeze({
24604
24613
  unbanMembers: unbanMembers
24605
24614
  });
24606
24615
 
24607
- var index$f = /*#__PURE__*/Object.freeze({
24616
+ var index$g = /*#__PURE__*/Object.freeze({
24608
24617
  __proto__: null,
24609
- Moderation: index$g,
24610
- Membership: index$h,
24618
+ Moderation: index$h,
24619
+ Membership: index$i,
24611
24620
  getCommunityByIds: getCommunities$1,
24612
24621
  createCommunity: createCommunity,
24613
24622
  updateCommunity: updateCommunity,
@@ -24841,7 +24850,7 @@ const getCategories = (params, callback, config) => {
24841
24850
  };
24842
24851
  /* end_public_function */
24843
24852
 
24844
- var index$e = /*#__PURE__*/Object.freeze({
24853
+ var index$f = /*#__PURE__*/Object.freeze({
24845
24854
  __proto__: null,
24846
24855
  getCategory: getCategory,
24847
24856
  getCategories: getCategories
@@ -25900,7 +25909,7 @@ const getComments = (params, callback, config) => {
25900
25909
  };
25901
25910
  /* end_public_function */
25902
25911
 
25903
- var index$d = /*#__PURE__*/Object.freeze({
25912
+ var index$e = /*#__PURE__*/Object.freeze({
25904
25913
  __proto__: null,
25905
25914
  getCommentByIds: getCommentByIds,
25906
25915
  createComment: createComment,
@@ -26571,7 +26580,7 @@ const getUserFeed = (params, callback, config) => {
26571
26580
  };
26572
26581
  /* end_public_function */
26573
26582
 
26574
- var index$c = /*#__PURE__*/Object.freeze({
26583
+ var index$d = /*#__PURE__*/Object.freeze({
26575
26584
  __proto__: null,
26576
26585
  queryGlobalFeed: queryGlobalFeed,
26577
26586
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
@@ -26686,7 +26695,15 @@ const createPost = async (bundle) => {
26686
26695
  // eslint-disable-next-line no-param-reassign
26687
26696
  delete bundle.dataType;
26688
26697
  }
26689
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
26698
+ const { attachments } = bundle;
26699
+ const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
26700
+ ? attachments.map(attachment => {
26701
+ if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
26702
+ return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
26703
+ return attachment;
26704
+ })
26705
+ : attachments;
26706
+ const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, bundle), { attachments: processedAttachments }));
26690
26707
  fireEvent('post.created', payload);
26691
26708
  const data = preparePostPayload(payload);
26692
26709
  const cachedAt = client.cache && Date.now();
@@ -26723,7 +26740,15 @@ const createPost = async (bundle) => {
26723
26740
  const editPost = async (postId, patch) => {
26724
26741
  const client = getActiveClient();
26725
26742
  client.log('user/editPost', patch);
26726
- const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
26743
+ const { attachments } = patch;
26744
+ const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
26745
+ ? attachments.map(attachment => {
26746
+ if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
26747
+ return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
26748
+ return attachment;
26749
+ })
26750
+ : attachments;
26751
+ const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, Object.assign(Object.assign({}, patch), { attachments: processedAttachments }));
26727
26752
  const data = prepareMembershipPayload(payload, 'communityUsers');
26728
26753
  const cachedAt = client.cache && Date.now();
26729
26754
  if (client.cache)
@@ -29367,7 +29392,7 @@ const getRooms = (params, callback, config) => {
29367
29392
  };
29368
29393
  /* end_public_function */
29369
29394
 
29370
- var index$b = /*#__PURE__*/Object.freeze({
29395
+ var index$c = /*#__PURE__*/Object.freeze({
29371
29396
  __proto__: null,
29372
29397
  createRoom: createRoom,
29373
29398
  updateRoom: updateRoom,
@@ -29663,7 +29688,7 @@ const getCommunityLiveRoomPosts = (params, callback, config) => {
29663
29688
  };
29664
29689
  /* end_public_function */
29665
29690
 
29666
- var index$a = /*#__PURE__*/Object.freeze({
29691
+ var index$b = /*#__PURE__*/Object.freeze({
29667
29692
  __proto__: null,
29668
29693
  getPostByIds: getPostByIds,
29669
29694
  createPost: createPost,
@@ -30273,7 +30298,7 @@ const getStreams = (params, callback, config) => {
30273
30298
  };
30274
30299
  };
30275
30300
 
30276
- var index$9 = /*#__PURE__*/Object.freeze({
30301
+ var index$a = /*#__PURE__*/Object.freeze({
30277
30302
  __proto__: null,
30278
30303
  createStream: createStream,
30279
30304
  updateStream: updateStream,
@@ -30576,7 +30601,7 @@ const stopHeartbeat = (roomId) => {
30576
30601
  };
30577
30602
  /* end_public_function */
30578
30603
 
30579
- var index$8 = /*#__PURE__*/Object.freeze({
30604
+ var index$9 = /*#__PURE__*/Object.freeze({
30580
30605
  __proto__: null,
30581
30606
  getRoomOnlineUsers: getRoomOnlineUsers,
30582
30607
  getRoomUserCount: getRoomUserCount,
@@ -30884,7 +30909,7 @@ const getPoll = (pollId, callback) => {
30884
30909
  };
30885
30910
  /* end_public_function */
30886
30911
 
30887
- var index$7 = /*#__PURE__*/Object.freeze({
30912
+ var index$8 = /*#__PURE__*/Object.freeze({
30888
30913
  __proto__: null,
30889
30914
  createPoll: createPoll,
30890
30915
  closePoll: closePoll,
@@ -31188,7 +31213,7 @@ const getPlayer = async (parameters) => {
31188
31213
  return video;
31189
31214
  };
31190
31215
 
31191
- var index$6 = /*#__PURE__*/Object.freeze({
31216
+ var index$7 = /*#__PURE__*/Object.freeze({
31192
31217
  __proto__: null,
31193
31218
  getPlayer: getPlayer
31194
31219
  });
@@ -32361,7 +32386,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
32361
32386
  };
32362
32387
  };
32363
32388
 
32364
- var index$5 = /*#__PURE__*/Object.freeze({
32389
+ var index$6 = /*#__PURE__*/Object.freeze({
32365
32390
  __proto__: null,
32366
32391
  createImageStory: createImageStory,
32367
32392
  createVideoStory: createVideoStory,
@@ -32398,7 +32423,7 @@ const getNetworkAds = async () => {
32398
32423
  };
32399
32424
  };
32400
32425
 
32401
- var index$4 = /*#__PURE__*/Object.freeze({
32426
+ var index$5 = /*#__PURE__*/Object.freeze({
32402
32427
  __proto__: null,
32403
32428
  getNetworkAds: getNetworkAds
32404
32429
  });
@@ -32789,7 +32814,7 @@ const markTraySeen = async (lastSeenAt) => {
32789
32814
  };
32790
32815
  /* end_public_function */
32791
32816
 
32792
- var index$3 = /*#__PURE__*/Object.freeze({
32817
+ var index$4 = /*#__PURE__*/Object.freeze({
32793
32818
  __proto__: null,
32794
32819
  getNotificationTraySeen: getNotificationTraySeen,
32795
32820
  getNotificationTrayItems: getNotificationTrayItems,
@@ -33087,7 +33112,7 @@ const getInvitations = (params, callback) => {
33087
33112
  };
33088
33113
  };
33089
33114
 
33090
- var index$2 = /*#__PURE__*/Object.freeze({
33115
+ var index$3 = /*#__PURE__*/Object.freeze({
33091
33116
  __proto__: null,
33092
33117
  cancelInvitation: cancelInvitation,
33093
33118
  onLocalInvitationCreated: onLocalInvitationCreated,
@@ -33236,7 +33261,7 @@ const getReactions = (postId, callback) => {
33236
33261
  };
33237
33262
  };
33238
33263
 
33239
- var index$1 = /*#__PURE__*/Object.freeze({
33264
+ var index$2 = /*#__PURE__*/Object.freeze({
33240
33265
  __proto__: null,
33241
33266
  createReaction: createReaction,
33242
33267
  onLiveReactionCreated: onLiveReactionCreated,
@@ -33719,7 +33744,7 @@ const getMyEvents = (params, callback, config) => {
33719
33744
  };
33720
33745
  };
33721
33746
 
33722
- var index = /*#__PURE__*/Object.freeze({
33747
+ var index$1 = /*#__PURE__*/Object.freeze({
33723
33748
  __proto__: null,
33724
33749
  createEvent: createEvent,
33725
33750
  updateEvent: updateEvent,
@@ -33740,38 +33765,249 @@ var index = /*#__PURE__*/Object.freeze({
33740
33765
  getRSVPs: getRSVPs
33741
33766
  });
33742
33767
 
33768
+ const getProduct$1 = async (productId) => {
33769
+ const client = getActiveClient();
33770
+ client.log('product/getProduct', productId);
33771
+ isInTombstone('product', productId);
33772
+ let payload;
33773
+ try {
33774
+ const response = await client.http.get(`/api/v1/products/${encodeURIComponent(productId)}`);
33775
+ payload = response.data;
33776
+ }
33777
+ catch (error) {
33778
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
33779
+ pushToTombstone('product', productId);
33780
+ }
33781
+ throw error;
33782
+ }
33783
+ const cachedAt = client.cache && Date.now();
33784
+ if (client.cache)
33785
+ ingestInCache(payload, { cachedAt });
33786
+ const { products } = payload;
33787
+ const result = products.find(product => product.productId === productId);
33788
+ return {
33789
+ data: result,
33790
+ cachedAt,
33791
+ };
33792
+ };
33793
+ getProduct$1.locally = (productId) => {
33794
+ const client = getActiveClient();
33795
+ client.log('product/getProduct.locally', productId);
33796
+ if (!client.cache)
33797
+ return;
33798
+ const cached = pullFromCache(['product', 'get', productId]);
33799
+ if (!cached)
33800
+ return;
33801
+ return {
33802
+ data: cached.data,
33803
+ cachedAt: cached.cachedAt,
33804
+ };
33805
+ };
33806
+
33807
+ /* begin_public_function
33808
+ id: product.get
33809
+ */
33810
+ /**
33811
+ * ```js
33812
+ * import { ProductRepository } from '@amityco/ts-sdk';
33813
+ *
33814
+ * let product;
33815
+ *
33816
+ * const unsub = ProductRepository.getProduct(productId, response => {
33817
+ * product = response.data;
33818
+ * });
33819
+ * ```
33820
+ *
33821
+ * Observe all mutation on a given {@link Amity.Product}
33822
+ *
33823
+ * @param productId the ID of the product to observe
33824
+ * @param callback the function to call when new data are available
33825
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the product
33826
+ *
33827
+ * @category Product Live Object
33828
+ */
33829
+ const getProduct = (productId, callback) => {
33830
+ const responder = (snapshot) => {
33831
+ callback(snapshot);
33832
+ };
33833
+ return liveObject(productId, responder, 'productId', getProduct$1, []);
33834
+ };
33835
+ /* end_public_function */
33836
+
33837
+ class SearchProductPaginationController extends PaginationController {
33838
+ async getRequest(queryParams, token) {
33839
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
33840
+ const options = token ? { token } : { limit };
33841
+ const { data: queryResponse } = await this.http.get(`/api/v1/products/search`, {
33842
+ params: Object.assign(Object.assign({}, params), { options }),
33843
+ });
33844
+ return queryResponse;
33845
+ }
33846
+ }
33847
+
33848
+ class SearchProductQueryStreamController extends QueryStreamController {
33849
+ constructor(query, cacheKey, notifyChange) {
33850
+ super(query, cacheKey);
33851
+ this.notifyChange = notifyChange;
33852
+ }
33853
+ // eslint-disable-next-line class-methods-use-this
33854
+ saveToMainDB(response) {
33855
+ const client = getActiveClient();
33856
+ const cachedAt = client.cache && Date.now();
33857
+ if (client.cache) {
33858
+ ingestInCache(response, { cachedAt });
33859
+ }
33860
+ }
33861
+ appendToQueryStream(response, direction, refresh = false) {
33862
+ var _a, _b;
33863
+ if (refresh) {
33864
+ pushToCache(this.cacheKey, {
33865
+ data: response.products.map(getResolver('product')),
33866
+ });
33867
+ }
33868
+ else {
33869
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
33870
+ const products = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
33871
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...products, ...response.products.map(getResolver('product'))])] }));
33872
+ }
33873
+ }
33874
+ }
33875
+
33876
+ class SearchProductLiveCollectionController extends LiveCollectionController {
33877
+ constructor(query, callback) {
33878
+ const queryStreamId = hash__default["default"](query);
33879
+ const cacheKey = ['products', 'collection', queryStreamId];
33880
+ const paginationController = new SearchProductPaginationController(query);
33881
+ super(paginationController, queryStreamId, cacheKey, callback);
33882
+ this.query = query;
33883
+ this.queryStreamController = new SearchProductQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this));
33884
+ this.callback = callback.bind(this);
33885
+ this.loadPage({ initial: true });
33886
+ }
33887
+ setup() {
33888
+ var _a;
33889
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
33890
+ if (!collection) {
33891
+ pushToCache(this.cacheKey, {
33892
+ data: [],
33893
+ params: {},
33894
+ });
33895
+ }
33896
+ }
33897
+ async persistModel(queryPayload) {
33898
+ await this.queryStreamController.saveToMainDB(queryPayload);
33899
+ }
33900
+ persistQueryStream({ response, direction, refresh, }) {
33901
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
33902
+ }
33903
+ // eslint-disable-next-line class-methods-use-this
33904
+ startSubscription() {
33905
+ return [];
33906
+ }
33907
+ notifyChange({ origin, loading, error }) {
33908
+ var _a, _b;
33909
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
33910
+ if (!collection)
33911
+ return;
33912
+ const data = (_b = collection.data
33913
+ .map(id => pullFromCache(['product', 'get', id]))
33914
+ .filter(isNonNullable)
33915
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
33916
+ if (!this.shouldNotify(data) && origin === 'event')
33917
+ return;
33918
+ this.callback({
33919
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
33920
+ data,
33921
+ hasNextPage: !!this.paginationController.getNextToken(),
33922
+ loading,
33923
+ error,
33924
+ });
33925
+ }
33926
+ }
33927
+
33928
+ /* begin_public_function
33929
+ id: product.search
33930
+ */
33931
+ /**
33932
+ * ```js
33933
+ * import { ProductRepository } from '@amityco/ts-sdk'
33934
+ *
33935
+ * let products = []
33936
+ * const unsub = ProductRepository.searchProducts({
33937
+ * keyword: string,
33938
+ * }, response => merge(products, response.data))
33939
+ * ```
33940
+ *
33941
+ * Observe all mutations on a list of {@link Amity.Product}
33942
+ *
33943
+ * @param params.keyword the search keyword
33944
+ * @param params.isActive filter by active status
33945
+ * @param params.isDeleted filter by deleted status
33946
+ * @param params.sortBy sort option
33947
+ * @param params.sortOrder order option
33948
+ * @param callback the function to call when new data are available
33949
+ * @param config
33950
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the products
33951
+ *
33952
+ * @category Products Live Collection
33953
+ */
33954
+ const searchProducts = (params, callback, config) => {
33955
+ const { log, cache } = getActiveClient();
33956
+ if (!cache) {
33957
+ console.log(ENABLE_CACHE_MESSAGE);
33958
+ }
33959
+ const timestamp = Date.now();
33960
+ log(`searchProducts(tmpid: ${timestamp}) > listen`);
33961
+ const productsLiveCollection = new SearchProductLiveCollectionController(params, callback);
33962
+ const disposers = productsLiveCollection.startSubscription();
33963
+ const cacheKey = productsLiveCollection.getCacheKey();
33964
+ disposers.push(() => dropFromCache(cacheKey));
33965
+ return () => {
33966
+ log(`searchProducts(tmpid: ${timestamp}) > dispose`);
33967
+ disposers.forEach(fn => fn());
33968
+ };
33969
+ };
33970
+ /* end_public_function */
33971
+
33972
+ var index = /*#__PURE__*/Object.freeze({
33973
+ __proto__: null,
33974
+ getProduct: getProduct,
33975
+ searchProducts: searchProducts
33976
+ });
33977
+
33743
33978
  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;
33979
+ exports.AdRepository = index$5;
33980
+ exports.CategoryRepository = index$f;
33981
+ exports.ChannelRepository = index$j;
33982
+ exports.Client = index$s;
33983
+ exports.CommentRepository = index$e;
33749
33984
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
33750
33985
  exports.CommunityPostSettings = CommunityPostSettings;
33751
- exports.CommunityRepository = index$f;
33986
+ exports.CommunityRepository = index$g;
33752
33987
  exports.ContentFeedType = ContentFeedType;
33753
33988
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
33754
- exports.EventRepository = index;
33755
- exports.FeedRepository = index$c;
33756
- exports.FileRepository = index$o;
33989
+ exports.EventRepository = index$1;
33990
+ exports.FeedRepository = index$d;
33991
+ exports.FileRepository = index$p;
33757
33992
  exports.FileType = FileType;
33758
33993
  exports.GET_WATCHER_URLS = GET_WATCHER_URLS;
33759
- exports.InvitationRepository = index$2;
33760
- exports.LiveReactionRepository = index$1;
33761
- exports.LiveStreamPlayer = index$6;
33994
+ exports.InvitationRepository = index$3;
33995
+ exports.LiveReactionRepository = index$2;
33996
+ exports.LiveStreamPlayer = index$7;
33762
33997
  exports.MessageContentType = MessageContentType;
33763
- exports.MessageRepository = index$m;
33764
- exports.PollRepository = index$7;
33998
+ exports.MessageRepository = index$n;
33999
+ exports.PollRepository = index$8;
33765
34000
  exports.PostContentType = PostContentType;
33766
- exports.PostRepository = index$a;
34001
+ exports.PostRepository = index$b;
33767
34002
  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;
34003
+ exports.ProductRepository = index;
34004
+ exports.ReactionRepository = index$o;
34005
+ exports.RoomPresenceRepository = index$9;
34006
+ exports.RoomRepository = index$c;
34007
+ exports.StoryRepository = index$6;
34008
+ exports.StreamRepository = index$a;
34009
+ exports.SubChannelRepository = index$m;
34010
+ exports.UserRepository = index$q;
33775
34011
  exports.VERSION = VERSION;
33776
34012
  exports.VideoResolution = VideoResolution;
33777
34013
  exports.VideoSize = VideoSize;
@@ -33827,7 +34063,7 @@ exports.isPaged = isPaged;
33827
34063
  exports.isReportedByMe = isReportedByMe;
33828
34064
  exports.isSkip = isSkip;
33829
34065
  exports.mergeInCache = mergeInCache;
33830
- exports.notificationTray = index$3;
34066
+ exports.notificationTray = index$4;
33831
34067
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
33832
34068
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
33833
34069
  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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