@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.esm.js CHANGED
@@ -674,6 +674,7 @@ const idResolvers = {
674
674
  viewer: ({ userId }) => userId,
675
675
  event: ({ eventId }) => eventId,
676
676
  eventResponse: ({ userId }) => userId,
677
+ product: ({ _id }) => _id,
677
678
  };
678
679
  /**
679
680
  * Retrieve the id resolver matching a domain name
@@ -733,6 +734,7 @@ const PAYLOAD2MODEL = {
733
734
  events: 'event',
734
735
  viewers: 'viewer',
735
736
  eventResponses: 'eventResponse',
737
+ products: 'product',
736
738
  };
737
739
  /** hidden */
738
740
  const isOutdated = (prevData, nextData) => {
@@ -26155,6 +26157,29 @@ const getShareableLinkConfiguration = async () => {
26155
26157
  return data;
26156
26158
  };
26157
26159
 
26160
+ /* begin_public_function
26161
+ id: client.getProductCatalogueSetting
26162
+ */
26163
+ /**
26164
+ * ```js
26165
+ * import { getProductCatalogueSetting } from '@amityco/ts-sdk'
26166
+ * const productCatalogueSetting = await getProductCatalogueSetting()
26167
+ * ```
26168
+ *
26169
+ * Fetches a {@link Amity.ProductCatalogueSetting} object
26170
+ *
26171
+ * @returns A Promise of {@link Amity.ProductCatalogueSetting} object
26172
+ *
26173
+ * @category Client API
26174
+ * @async
26175
+ */
26176
+ const getProductCatalogueSetting = async () => {
26177
+ const client = getActiveClient();
26178
+ const { data } = await client.http.get(`/api/v3/network-settings/product-catalogue`);
26179
+ return data;
26180
+ };
26181
+ /* end_public_function */
26182
+
26158
26183
  /**
26159
26184
  * Retrieves a pair of {@link Amity.Tokens} necessary for connection
26160
26185
  *
@@ -26647,7 +26672,7 @@ const getUserUnread = (callback) => {
26647
26672
  };
26648
26673
  };
26649
26674
 
26650
- var index$r = /*#__PURE__*/Object.freeze({
26675
+ var index$s = /*#__PURE__*/Object.freeze({
26651
26676
  __proto__: null,
26652
26677
  getActiveClient: getActiveClient,
26653
26678
  getActiveUser: getActiveUser,
@@ -26667,6 +26692,7 @@ var index$r = /*#__PURE__*/Object.freeze({
26667
26692
  getLinkPreviewMetadata: getLinkPreviewMetadata,
26668
26693
  getSocialSettings: getSocialSettings,
26669
26694
  getShareableLinkConfiguration: getShareableLinkConfiguration,
26695
+ getProductCatalogueSetting: getProductCatalogueSetting,
26670
26696
  loginAsVisitor: loginAsVisitor,
26671
26697
  loginAsBot: loginAsBot,
26672
26698
  getCurrentUser: getCurrentUser,
@@ -27867,7 +27893,7 @@ const getMyFollowInfo = (callback) => {
27867
27893
  };
27868
27894
  /* end_public_function */
27869
27895
 
27870
- var index$q = /*#__PURE__*/Object.freeze({
27896
+ var index$r = /*#__PURE__*/Object.freeze({
27871
27897
  __proto__: null,
27872
27898
  blockUser: blockUser,
27873
27899
  unBlockUser: unBlockUser,
@@ -29975,6 +30001,11 @@ const communityLinkedObject = (community) => {
29975
30001
  } });
29976
30002
  };
29977
30003
 
30004
+ const productTagLinkedObject = (productTag) => {
30005
+ var _a;
30006
+ return Object.assign(Object.assign({}, productTag), { product: (_a = pullFromCache(['product', 'get', productTag.productId])) === null || _a === void 0 ? void 0 : _a.data });
30007
+ };
30008
+
29978
30009
  const postLinkedObject = (post) => {
29979
30010
  return shallowClone(post, {
29980
30011
  childrenPosts: post.children
@@ -29987,6 +30018,10 @@ const postLinkedObject = (post) => {
29987
30018
  analyticsEngineInstance.markPostAsViewed(post.postId);
29988
30019
  },
29989
30020
  },
30021
+ get productTags() {
30022
+ var _a, _b;
30023
+ return (_b = (_a = post.productTags) === null || _a === void 0 ? void 0 : _a.map(productTag => productTagLinkedObject(productTag))) !== null && _b !== void 0 ? _b : [];
30024
+ },
29990
30025
  get latestComments() {
29991
30026
  if (!post.comments)
29992
30027
  return [];
@@ -31976,9 +32011,9 @@ var AmityUserSearchMatchType;
31976
32011
  AmityUserSearchMatchType["PARTIAL"] = "partial";
31977
32012
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
31978
32013
 
31979
- var index$p = /*#__PURE__*/Object.freeze({
32014
+ var index$q = /*#__PURE__*/Object.freeze({
31980
32015
  __proto__: null,
31981
- Relationship: index$q,
32016
+ Relationship: index$r,
31982
32017
  getUserByIds: getUserByIds,
31983
32018
  updateUser: updateUser,
31984
32019
  flagUser: flagUser,
@@ -32381,7 +32416,7 @@ const uploadAudio = async (formData, onProgress) => {
32381
32416
  };
32382
32417
  /* end_public_function */
32383
32418
 
32384
- var index$o = /*#__PURE__*/Object.freeze({
32419
+ var index$p = /*#__PURE__*/Object.freeze({
32385
32420
  __proto__: null,
32386
32421
  getFile: getFile,
32387
32422
  uploadFile: uploadFile,
@@ -34193,7 +34228,7 @@ const getReactions$1 = (params, callback, config) => {
34193
34228
  };
34194
34229
  /* end_public_function */
34195
34230
 
34196
- var index$n = /*#__PURE__*/Object.freeze({
34231
+ var index$o = /*#__PURE__*/Object.freeze({
34197
34232
  __proto__: null,
34198
34233
  addReaction: addReaction,
34199
34234
  removeReaction: removeReaction,
@@ -35965,7 +36000,7 @@ const getMessages = (params, callback, config) => {
35965
36000
  };
35966
36001
  /* end_public_function */
35967
36002
 
35968
- var index$m = /*#__PURE__*/Object.freeze({
36003
+ var index$n = /*#__PURE__*/Object.freeze({
35969
36004
  __proto__: null,
35970
36005
  createMessage: createMessage,
35971
36006
  updateMessage: updateMessage,
@@ -36491,7 +36526,7 @@ const stopMessageReceiptSync = (subChannelId) => {
36491
36526
  };
36492
36527
  /* end_public_function */
36493
36528
 
36494
- var index$l = /*#__PURE__*/Object.freeze({
36529
+ var index$m = /*#__PURE__*/Object.freeze({
36495
36530
  __proto__: null,
36496
36531
  getSubChannelByIds: getSubChannels$1,
36497
36532
  createSubChannel: createSubChannel,
@@ -37818,7 +37853,7 @@ const searchMembers$1 = (params, callback, config) => {
37818
37853
  };
37819
37854
  /* end_public_function */
37820
37855
 
37821
- var index$k = /*#__PURE__*/Object.freeze({
37856
+ var index$l = /*#__PURE__*/Object.freeze({
37822
37857
  __proto__: null,
37823
37858
  addMembers: addMembers$1,
37824
37859
  removeMembers: removeMembers$1,
@@ -38021,7 +38056,7 @@ const unmuteMembers = async (channelId, userIds) => {
38021
38056
  };
38022
38057
  /* end_public_function */
38023
38058
 
38024
- var index$j = /*#__PURE__*/Object.freeze({
38059
+ var index$k = /*#__PURE__*/Object.freeze({
38025
38060
  __proto__: null,
38026
38061
  addRole: addRole,
38027
38062
  removeRole: removeRole,
@@ -38031,10 +38066,10 @@ var index$j = /*#__PURE__*/Object.freeze({
38031
38066
  unmuteMembers: unmuteMembers
38032
38067
  });
38033
38068
 
38034
- var index$i = /*#__PURE__*/Object.freeze({
38069
+ var index$j = /*#__PURE__*/Object.freeze({
38035
38070
  __proto__: null,
38036
- Membership: index$k,
38037
- Moderation: index$j,
38071
+ Membership: index$l,
38072
+ Moderation: index$k,
38038
38073
  getChannelByIds: getChannelByIds$1,
38039
38074
  createChannel: createChannel,
38040
38075
  updateChannel: updateChannel,
@@ -39437,7 +39472,7 @@ const searchMembers = (params, callback, config) => {
39437
39472
  };
39438
39473
  /* end_public_function */
39439
39474
 
39440
- var index$h = /*#__PURE__*/Object.freeze({
39475
+ var index$i = /*#__PURE__*/Object.freeze({
39441
39476
  __proto__: null,
39442
39477
  addMembers: addMembers,
39443
39478
  removeMembers: removeMembers,
@@ -40688,7 +40723,7 @@ const unbanMembers = async (communityId, userIds) => {
40688
40723
  };
40689
40724
  /* end_public_function */
40690
40725
 
40691
- var index$g = /*#__PURE__*/Object.freeze({
40726
+ var index$h = /*#__PURE__*/Object.freeze({
40692
40727
  __proto__: null,
40693
40728
  addRoles: addRoles,
40694
40729
  removeRoles: removeRoles,
@@ -40696,10 +40731,10 @@ var index$g = /*#__PURE__*/Object.freeze({
40696
40731
  unbanMembers: unbanMembers
40697
40732
  });
40698
40733
 
40699
- var index$f = /*#__PURE__*/Object.freeze({
40734
+ var index$g = /*#__PURE__*/Object.freeze({
40700
40735
  __proto__: null,
40701
- Moderation: index$g,
40702
- Membership: index$h,
40736
+ Moderation: index$h,
40737
+ Membership: index$i,
40703
40738
  getCommunityByIds: getCommunities$1,
40704
40739
  createCommunity: createCommunity,
40705
40740
  updateCommunity: updateCommunity,
@@ -40933,7 +40968,7 @@ const getCategories = (params, callback, config) => {
40933
40968
  };
40934
40969
  /* end_public_function */
40935
40970
 
40936
- var index$e = /*#__PURE__*/Object.freeze({
40971
+ var index$f = /*#__PURE__*/Object.freeze({
40937
40972
  __proto__: null,
40938
40973
  getCategory: getCategory,
40939
40974
  getCategories: getCategories
@@ -41236,8 +41271,6 @@ const createComment = async (bundle) => {
41236
41271
  postChildren: [],
41237
41272
  users: data.users,
41238
41273
  videoStreamings: [],
41239
- videoStreamingChildren: [],
41240
- rooms: [],
41241
41274
  });
41242
41275
  }
41243
41276
  }
@@ -41994,7 +42027,7 @@ const getComments = (params, callback, config) => {
41994
42027
  };
41995
42028
  /* end_public_function */
41996
42029
 
41997
- var index$d = /*#__PURE__*/Object.freeze({
42030
+ var index$e = /*#__PURE__*/Object.freeze({
41998
42031
  __proto__: null,
41999
42032
  getCommentByIds: getCommentByIds,
42000
42033
  createComment: createComment,
@@ -42665,7 +42698,7 @@ const getUserFeed = (params, callback, config) => {
42665
42698
  };
42666
42699
  /* end_public_function */
42667
42700
 
42668
- var index$c = /*#__PURE__*/Object.freeze({
42701
+ var index$d = /*#__PURE__*/Object.freeze({
42669
42702
  __proto__: null,
42670
42703
  queryGlobalFeed: queryGlobalFeed,
42671
42704
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
@@ -42780,7 +42813,15 @@ const createPost = async (bundle) => {
42780
42813
  // eslint-disable-next-line no-param-reassign
42781
42814
  delete bundle.dataType;
42782
42815
  }
42783
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
42816
+ const { attachments } = bundle;
42817
+ const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
42818
+ ? attachments.map(attachment => {
42819
+ if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
42820
+ return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
42821
+ return attachment;
42822
+ })
42823
+ : attachments;
42824
+ const { data: payload } = await client.http.post('/api/v4/posts', Object.assign(Object.assign({}, bundle), { attachments: processedAttachments }));
42784
42825
  fireEvent('post.created', payload);
42785
42826
  const data = preparePostPayload(payload);
42786
42827
  const cachedAt = client.cache && Date.now();
@@ -42817,7 +42858,15 @@ const createPost = async (bundle) => {
42817
42858
  const editPost = async (postId, patch) => {
42818
42859
  const client = getActiveClient();
42819
42860
  client.log('user/editPost', patch);
42820
- const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
42861
+ const { attachments } = patch;
42862
+ const processedAttachments = attachments && (attachments === null || attachments === void 0 ? void 0 : attachments.length) > 0
42863
+ ? attachments.map(attachment => {
42864
+ if (attachment.productTags && (attachment === null || attachment === void 0 ? void 0 : attachment.productTags.length) > 0)
42865
+ return Object.assign(Object.assign({}, attachment), { productTags: attachment.productTags.map(productId => ({ productId })) });
42866
+ return attachment;
42867
+ })
42868
+ : attachments;
42869
+ const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, Object.assign(Object.assign({}, patch), { attachments: processedAttachments }));
42821
42870
  const data = prepareMembershipPayload(payload, 'communityUsers');
42822
42871
  const cachedAt = client.cache && Date.now();
42823
42872
  if (client.cache)
@@ -45461,7 +45510,7 @@ const getRooms = (params, callback, config) => {
45461
45510
  };
45462
45511
  /* end_public_function */
45463
45512
 
45464
- var index$b = /*#__PURE__*/Object.freeze({
45513
+ var index$c = /*#__PURE__*/Object.freeze({
45465
45514
  __proto__: null,
45466
45515
  createRoom: createRoom,
45467
45516
  updateRoom: updateRoom,
@@ -45757,7 +45806,7 @@ const getCommunityLiveRoomPosts = (params, callback, config) => {
45757
45806
  };
45758
45807
  /* end_public_function */
45759
45808
 
45760
- var index$a = /*#__PURE__*/Object.freeze({
45809
+ var index$b = /*#__PURE__*/Object.freeze({
45761
45810
  __proto__: null,
45762
45811
  getPostByIds: getPostByIds,
45763
45812
  createPost: createPost,
@@ -46367,7 +46416,7 @@ const getStreams = (params, callback, config) => {
46367
46416
  };
46368
46417
  };
46369
46418
 
46370
- var index$9 = /*#__PURE__*/Object.freeze({
46419
+ var index$a = /*#__PURE__*/Object.freeze({
46371
46420
  __proto__: null,
46372
46421
  createStream: createStream,
46373
46422
  updateStream: updateStream,
@@ -46670,7 +46719,7 @@ const stopHeartbeat = (roomId) => {
46670
46719
  };
46671
46720
  /* end_public_function */
46672
46721
 
46673
- var index$8 = /*#__PURE__*/Object.freeze({
46722
+ var index$9 = /*#__PURE__*/Object.freeze({
46674
46723
  __proto__: null,
46675
46724
  getRoomOnlineUsers: getRoomOnlineUsers,
46676
46725
  getRoomUserCount: getRoomUserCount,
@@ -46978,7 +47027,7 @@ const getPoll = (pollId, callback) => {
46978
47027
  };
46979
47028
  /* end_public_function */
46980
47029
 
46981
- var index$7 = /*#__PURE__*/Object.freeze({
47030
+ var index$8 = /*#__PURE__*/Object.freeze({
46982
47031
  __proto__: null,
46983
47032
  createPoll: createPoll,
46984
47033
  closePoll: closePoll,
@@ -47282,7 +47331,7 @@ const getPlayer = async (parameters) => {
47282
47331
  return video;
47283
47332
  };
47284
47333
 
47285
- var index$6 = /*#__PURE__*/Object.freeze({
47334
+ var index$7 = /*#__PURE__*/Object.freeze({
47286
47335
  __proto__: null,
47287
47336
  getPlayer: getPlayer
47288
47337
  });
@@ -48455,7 +48504,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
48455
48504
  };
48456
48505
  };
48457
48506
 
48458
- var index$5 = /*#__PURE__*/Object.freeze({
48507
+ var index$6 = /*#__PURE__*/Object.freeze({
48459
48508
  __proto__: null,
48460
48509
  createImageStory: createImageStory,
48461
48510
  createVideoStory: createVideoStory,
@@ -48492,7 +48541,7 @@ const getNetworkAds = async () => {
48492
48541
  };
48493
48542
  };
48494
48543
 
48495
- var index$4 = /*#__PURE__*/Object.freeze({
48544
+ var index$5 = /*#__PURE__*/Object.freeze({
48496
48545
  __proto__: null,
48497
48546
  getNetworkAds: getNetworkAds
48498
48547
  });
@@ -48883,7 +48932,7 @@ const markTraySeen = async (lastSeenAt) => {
48883
48932
  };
48884
48933
  /* end_public_function */
48885
48934
 
48886
- var index$3 = /*#__PURE__*/Object.freeze({
48935
+ var index$4 = /*#__PURE__*/Object.freeze({
48887
48936
  __proto__: null,
48888
48937
  getNotificationTraySeen: getNotificationTraySeen,
48889
48938
  getNotificationTrayItems: getNotificationTrayItems,
@@ -49181,7 +49230,7 @@ const getInvitations = (params, callback) => {
49181
49230
  };
49182
49231
  };
49183
49232
 
49184
- var index$2 = /*#__PURE__*/Object.freeze({
49233
+ var index$3 = /*#__PURE__*/Object.freeze({
49185
49234
  __proto__: null,
49186
49235
  cancelInvitation: cancelInvitation,
49187
49236
  onLocalInvitationCreated: onLocalInvitationCreated,
@@ -49330,7 +49379,7 @@ const getReactions = (postId, callback) => {
49330
49379
  };
49331
49380
  };
49332
49381
 
49333
- var index$1 = /*#__PURE__*/Object.freeze({
49382
+ var index$2 = /*#__PURE__*/Object.freeze({
49334
49383
  __proto__: null,
49335
49384
  createReaction: createReaction,
49336
49385
  onLiveReactionCreated: onLiveReactionCreated,
@@ -49813,7 +49862,7 @@ const getMyEvents = (params, callback, config) => {
49813
49862
  };
49814
49863
  };
49815
49864
 
49816
- var index = /*#__PURE__*/Object.freeze({
49865
+ var index$1 = /*#__PURE__*/Object.freeze({
49817
49866
  __proto__: null,
49818
49867
  createEvent: createEvent,
49819
49868
  updateEvent: updateEvent,
@@ -49834,4 +49883,214 @@ var index = /*#__PURE__*/Object.freeze({
49834
49883
  getRSVPs: getRSVPs
49835
49884
  });
49836
49885
 
49837
- export { API_REGIONS, index$4 as AdRepository, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, index$e as CategoryRepository, index$i as ChannelRepository, index$r as Client, index$d as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$f as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$c as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$o as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$m as MessageRepository, index$7 as PollRepository, PostContentType, index$a as PostRepository, PostStructureType, index$n as ReactionRepository, index$8 as RoomPresenceRepository, index$b as RoomRepository, index$5 as StoryRepository, index$9 as StreamRepository, index$l as SubChannelRepository, SubscriptionLevels, index$p as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$3 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
49886
+ const getProduct$1 = async (productId) => {
49887
+ const client = getActiveClient();
49888
+ client.log('product/getProduct', productId);
49889
+ isInTombstone('product', productId);
49890
+ let payload;
49891
+ try {
49892
+ const response = await client.http.get(`/api/v1/products/${encodeURIComponent(productId)}`);
49893
+ payload = response.data;
49894
+ }
49895
+ catch (error) {
49896
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
49897
+ pushToTombstone('product', productId);
49898
+ }
49899
+ throw error;
49900
+ }
49901
+ const cachedAt = client.cache && Date.now();
49902
+ if (client.cache)
49903
+ ingestInCache(payload, { cachedAt });
49904
+ const { products } = payload;
49905
+ const result = products.find(product => product.productId === productId);
49906
+ return {
49907
+ data: result,
49908
+ cachedAt,
49909
+ };
49910
+ };
49911
+ getProduct$1.locally = (productId) => {
49912
+ const client = getActiveClient();
49913
+ client.log('product/getProduct.locally', productId);
49914
+ if (!client.cache)
49915
+ return;
49916
+ const cached = pullFromCache(['product', 'get', productId]);
49917
+ if (!cached)
49918
+ return;
49919
+ return {
49920
+ data: cached.data,
49921
+ cachedAt: cached.cachedAt,
49922
+ };
49923
+ };
49924
+
49925
+ /* begin_public_function
49926
+ id: product.get
49927
+ */
49928
+ /**
49929
+ * ```js
49930
+ * import { ProductRepository } from '@amityco/ts-sdk';
49931
+ *
49932
+ * let product;
49933
+ *
49934
+ * const unsub = ProductRepository.getProduct(productId, response => {
49935
+ * product = response.data;
49936
+ * });
49937
+ * ```
49938
+ *
49939
+ * Observe all mutation on a given {@link Amity.Product}
49940
+ *
49941
+ * @param productId the ID of the product to observe
49942
+ * @param callback the function to call when new data are available
49943
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the product
49944
+ *
49945
+ * @category Product Live Object
49946
+ */
49947
+ const getProduct = (productId, callback) => {
49948
+ const responder = (snapshot) => {
49949
+ callback(snapshot);
49950
+ };
49951
+ return liveObject(productId, responder, 'productId', getProduct$1, []);
49952
+ };
49953
+ /* end_public_function */
49954
+
49955
+ class SearchProductPaginationController extends PaginationController {
49956
+ async getRequest(queryParams, token) {
49957
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
49958
+ const options = token ? { token } : { limit };
49959
+ const { data: queryResponse } = await this.http.get(`/api/v1/products/search`, {
49960
+ params: Object.assign(Object.assign({}, params), { options }),
49961
+ });
49962
+ return queryResponse;
49963
+ }
49964
+ }
49965
+
49966
+ class SearchProductQueryStreamController extends QueryStreamController {
49967
+ constructor(query, cacheKey, notifyChange) {
49968
+ super(query, cacheKey);
49969
+ this.notifyChange = notifyChange;
49970
+ }
49971
+ // eslint-disable-next-line class-methods-use-this
49972
+ saveToMainDB(response) {
49973
+ const client = getActiveClient();
49974
+ const cachedAt = client.cache && Date.now();
49975
+ if (client.cache) {
49976
+ ingestInCache(response, { cachedAt });
49977
+ }
49978
+ }
49979
+ appendToQueryStream(response, direction, refresh = false) {
49980
+ var _a, _b;
49981
+ if (refresh) {
49982
+ pushToCache(this.cacheKey, {
49983
+ data: response.products.map(getResolver('product')),
49984
+ });
49985
+ }
49986
+ else {
49987
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
49988
+ const products = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
49989
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...products, ...response.products.map(getResolver('product'))])] }));
49990
+ }
49991
+ }
49992
+ }
49993
+
49994
+ class SearchProductLiveCollectionController extends LiveCollectionController {
49995
+ constructor(query, callback) {
49996
+ const queryStreamId = hash(query);
49997
+ const cacheKey = ['products', 'collection', queryStreamId];
49998
+ const paginationController = new SearchProductPaginationController(query);
49999
+ super(paginationController, queryStreamId, cacheKey, callback);
50000
+ this.query = query;
50001
+ this.queryStreamController = new SearchProductQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this));
50002
+ this.callback = callback.bind(this);
50003
+ this.loadPage({ initial: true });
50004
+ }
50005
+ setup() {
50006
+ var _a;
50007
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
50008
+ if (!collection) {
50009
+ pushToCache(this.cacheKey, {
50010
+ data: [],
50011
+ params: {},
50012
+ });
50013
+ }
50014
+ }
50015
+ async persistModel(queryPayload) {
50016
+ await this.queryStreamController.saveToMainDB(queryPayload);
50017
+ }
50018
+ persistQueryStream({ response, direction, refresh, }) {
50019
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
50020
+ }
50021
+ // eslint-disable-next-line class-methods-use-this
50022
+ startSubscription() {
50023
+ return [];
50024
+ }
50025
+ notifyChange({ origin, loading, error }) {
50026
+ var _a, _b;
50027
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
50028
+ if (!collection)
50029
+ return;
50030
+ const data = (_b = collection.data
50031
+ .map(id => pullFromCache(['product', 'get', id]))
50032
+ .filter(isNonNullable)
50033
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
50034
+ if (!this.shouldNotify(data) && origin === 'event')
50035
+ return;
50036
+ this.callback({
50037
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
50038
+ data,
50039
+ hasNextPage: !!this.paginationController.getNextToken(),
50040
+ loading,
50041
+ error,
50042
+ });
50043
+ }
50044
+ }
50045
+
50046
+ /* begin_public_function
50047
+ id: product.search
50048
+ */
50049
+ /**
50050
+ * ```js
50051
+ * import { ProductRepository } from '@amityco/ts-sdk'
50052
+ *
50053
+ * let products = []
50054
+ * const unsub = ProductRepository.searchProducts({
50055
+ * keyword: string,
50056
+ * }, response => merge(products, response.data))
50057
+ * ```
50058
+ *
50059
+ * Observe all mutations on a list of {@link Amity.Product}
50060
+ *
50061
+ * @param params.keyword the search keyword
50062
+ * @param params.isActive filter by active status
50063
+ * @param params.isDeleted filter by deleted status
50064
+ * @param params.sortBy sort option
50065
+ * @param params.sortOrder order option
50066
+ * @param callback the function to call when new data are available
50067
+ * @param config
50068
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the products
50069
+ *
50070
+ * @category Products Live Collection
50071
+ */
50072
+ const searchProducts = (params, callback, config) => {
50073
+ const { log, cache } = getActiveClient();
50074
+ if (!cache) {
50075
+ console.log(ENABLE_CACHE_MESSAGE);
50076
+ }
50077
+ const timestamp = Date.now();
50078
+ log(`searchProducts(tmpid: ${timestamp}) > listen`);
50079
+ const productsLiveCollection = new SearchProductLiveCollectionController(params, callback);
50080
+ const disposers = productsLiveCollection.startSubscription();
50081
+ const cacheKey = productsLiveCollection.getCacheKey();
50082
+ disposers.push(() => dropFromCache(cacheKey));
50083
+ return () => {
50084
+ log(`searchProducts(tmpid: ${timestamp}) > dispose`);
50085
+ disposers.forEach(fn => fn());
50086
+ };
50087
+ };
50088
+ /* end_public_function */
50089
+
50090
+ var index = /*#__PURE__*/Object.freeze({
50091
+ __proto__: null,
50092
+ getProduct: getProduct,
50093
+ searchProducts: searchProducts
50094
+ });
50095
+
50096
+ export { API_REGIONS, index$5 as AdRepository, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, index$f as CategoryRepository, index$j as ChannelRepository, index$s as Client, index$e as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$g as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$1 as EventRepository, FeedDataTypeEnum, index$d as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$p as FileRepository, FileType, GET_WATCHER_URLS, index$3 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$2 as LiveReactionRepository, index$7 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$n as MessageRepository, index$8 as PollRepository, PostContentType, index$b as PostRepository, PostStructureType, index as ProductRepository, index$o as ReactionRepository, index$9 as RoomPresenceRepository, index$c as RoomRepository, index$6 as StoryRepository, index$a as StreamRepository, index$m as SubChannelRepository, SubscriptionLevels, index$q as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$4 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };