@amityco/ts-sdk 7.2.1-56aa34e.0 → 7.2.1-e149502.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 (76) hide show
  1. package/dist/@types/core/events.d.ts +4 -0
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +4 -0
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +24 -0
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/notification.d.ts +78 -0
  8. package/dist/@types/domains/notification.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/events.d.ts +3 -3
  12. package/dist/core/events.d.ts.map +1 -1
  13. package/dist/core/model/idResolvers.d.ts.map +1 -1
  14. package/dist/core/model/index.d.ts.map +1 -1
  15. package/dist/index.cjs.js +431 -44
  16. package/dist/index.d.ts +1 -0
  17. package/dist/index.d.ts.map +1 -1
  18. package/dist/index.esm.js +414 -28
  19. package/dist/index.umd.js +4 -4
  20. package/dist/notificationTray/api/index.d.ts +3 -0
  21. package/dist/notificationTray/api/index.d.ts.map +1 -0
  22. package/dist/notificationTray/api/markItemsSeen.d.ts +16 -0
  23. package/dist/notificationTray/api/markItemsSeen.d.ts.map +1 -0
  24. package/dist/notificationTray/api/markTraySeen.d.ts +19 -0
  25. package/dist/notificationTray/api/markTraySeen.d.ts.map +1 -0
  26. package/dist/notificationTray/events/index.d.ts +2 -0
  27. package/dist/notificationTray/events/index.d.ts.map +1 -0
  28. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts +17 -0
  29. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts.map +1 -0
  30. package/dist/notificationTray/index.d.ts +4 -0
  31. package/dist/notificationTray/index.d.ts.map +1 -0
  32. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts +30 -0
  33. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts.map +1 -0
  34. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +13 -0
  35. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +1 -0
  36. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +9 -0
  37. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +1 -0
  38. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +9 -0
  39. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +1 -0
  40. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts +12 -0
  41. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts.map +1 -0
  42. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts +20 -0
  43. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts.map +1 -0
  44. package/dist/notificationTray/observers/index.d.ts +3 -0
  45. package/dist/notificationTray/observers/index.d.ts.map +1 -0
  46. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts +2 -0
  47. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts.map +1 -0
  48. package/dist/utils/linkedObject/index.d.ts +1 -0
  49. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  50. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +2 -0
  51. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -0
  52. package/package.json +1 -1
  53. package/src/@types/core/events.ts +5 -0
  54. package/src/@types/core/model.ts +6 -0
  55. package/src/@types/core/payload.ts +29 -0
  56. package/src/@types/domains/notification.ts +94 -0
  57. package/src/@types/index.ts +1 -0
  58. package/src/core/model/idResolvers.ts +3 -0
  59. package/src/core/model/index.ts +2 -0
  60. package/src/index.ts +2 -0
  61. package/src/notificationTray/api/index.ts +2 -0
  62. package/src/notificationTray/api/markItemsSeen.ts +62 -0
  63. package/src/notificationTray/api/markTraySeen.ts +65 -0
  64. package/src/notificationTray/events/index.ts +1 -0
  65. package/src/notificationTray/events/onNotificationTraySeenUpdated.ts +36 -0
  66. package/src/notificationTray/index.ts +3 -0
  67. package/src/notificationTray/internalApi/getNotificationTraySeen.ts +80 -0
  68. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +96 -0
  69. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +31 -0
  70. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +68 -0
  71. package/src/notificationTray/observers/getNotificationTrayItems.ts +44 -0
  72. package/src/notificationTray/observers/getNotificationTraySeen.ts +60 -0
  73. package/src/notificationTray/observers/index.ts +2 -0
  74. package/src/notificationTray/utils/prepareNotificationTrayItemsPayload.ts +12 -0
  75. package/src/utils/linkedObject/index.ts +2 -0
  76. package/src/utils/linkedObject/notificationTrayLinkedObject.ts +19 -0
package/dist/index.cjs.js CHANGED
@@ -121,6 +121,7 @@ const SECOND$1 = 1000;
121
121
  const MINUTE = 60 * SECOND$1;
122
122
  const HOUR = 60 * MINUTE;
123
123
  const DAY = 24 * HOUR;
124
+ const WEEK = 7 * DAY;
124
125
  const YEAR = 365 * DAY;
125
126
  const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
126
127
 
@@ -543,6 +544,8 @@ const idResolvers = {
543
544
  advertiser: ({ advertiserId }) => advertiserId,
544
545
  pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
545
546
  pinTarget: ({ targetId }) => targetId,
547
+ notificationTrayItem: ({ _id }) => _id,
548
+ notificationTraySeen: ({ userId }) => userId,
546
549
  };
547
550
  /**
548
551
  * Retrieve the id resolver matching a domain name
@@ -594,6 +597,7 @@ const PAYLOAD2MODEL = {
594
597
  advertisers: 'advertiser',
595
598
  pinTargets: 'pinTarget',
596
599
  pins: 'pin',
600
+ notificationTrayItems: 'notificationTrayItem',
597
601
  };
598
602
  /** hidden */
599
603
  const isOutdated = (prevData, nextData) => {
@@ -6221,6 +6225,14 @@ const pinnedPostLinkedObject = (pinnedPost) => {
6221
6225
  } });
6222
6226
  };
6223
6227
 
6228
+ const notificationTrayLinkedObject = (noti) => {
6229
+ return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
6230
+ .map(({ _id }) => pullFromCache(['user', 'get', _id]))
6231
+ .filter(isNonNullable)
6232
+ .map(({ data }) => data)
6233
+ .map(user => userLinkedObject(user)) });
6234
+ };
6235
+
6224
6236
  const LinkedObject = {
6225
6237
  ad: adLinkedObject,
6226
6238
  comment: commentLinkedObject,
@@ -6234,6 +6246,7 @@ const LinkedObject = {
6234
6246
  reactor: reactorLinkedObject,
6235
6247
  channel: channelLinkedObject,
6236
6248
  pinnedPost: pinnedPostLinkedObject,
6249
+ notificationTray: notificationTrayLinkedObject,
6237
6250
  };
6238
6251
 
6239
6252
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -10135,7 +10148,7 @@ const getUserUnread = (callback) => {
10135
10148
  };
10136
10149
  };
10137
10150
 
10138
- var index$l = /*#__PURE__*/Object.freeze({
10151
+ var index$m = /*#__PURE__*/Object.freeze({
10139
10152
  __proto__: null,
10140
10153
  getActiveClient: getActiveClient,
10141
10154
  getActiveUser: getActiveUser,
@@ -11342,7 +11355,7 @@ const getMyFollowInfo = (callback) => {
11342
11355
  };
11343
11356
  /* end_public_function */
11344
11357
 
11345
- var index$k = /*#__PURE__*/Object.freeze({
11358
+ var index$l = /*#__PURE__*/Object.freeze({
11346
11359
  __proto__: null,
11347
11360
  blockUser: blockUser,
11348
11361
  unBlockUser: unBlockUser,
@@ -12357,9 +12370,9 @@ var AmityUserSearchMatchType;
12357
12370
  AmityUserSearchMatchType["PARTIAL"] = "partial";
12358
12371
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
12359
12372
 
12360
- var index$j = /*#__PURE__*/Object.freeze({
12373
+ var index$k = /*#__PURE__*/Object.freeze({
12361
12374
  __proto__: null,
12362
- Relationship: index$k,
12375
+ Relationship: index$l,
12363
12376
  getUserByIds: getUserByIds,
12364
12377
  updateUser: updateUser,
12365
12378
  flagUser: flagUser,
@@ -12623,7 +12636,7 @@ const uploadImage = async (formData, onProgress) => {
12623
12636
  };
12624
12637
  /* end_public_function */
12625
12638
 
12626
- var index$i = /*#__PURE__*/Object.freeze({
12639
+ var index$j = /*#__PURE__*/Object.freeze({
12627
12640
  __proto__: null,
12628
12641
  getFile: getFile,
12629
12642
  uploadFile: uploadFile,
@@ -14490,7 +14503,7 @@ const getReactions = (params, callback, config) => {
14490
14503
  };
14491
14504
  /* end_public_function */
14492
14505
 
14493
- var index$h = /*#__PURE__*/Object.freeze({
14506
+ var index$i = /*#__PURE__*/Object.freeze({
14494
14507
  __proto__: null,
14495
14508
  addReaction: addReaction,
14496
14509
  removeReaction: removeReaction,
@@ -16306,7 +16319,7 @@ const getMessages = (params, callback, config) => {
16306
16319
  };
16307
16320
  /* end_public_function */
16308
16321
 
16309
- var index$g = /*#__PURE__*/Object.freeze({
16322
+ var index$h = /*#__PURE__*/Object.freeze({
16310
16323
  __proto__: null,
16311
16324
  createMessage: createMessage,
16312
16325
  updateMessage: updateMessage,
@@ -16832,7 +16845,7 @@ const stopMessageReceiptSync = (subChannelId) => {
16832
16845
  };
16833
16846
  /* end_public_function */
16834
16847
 
16835
- var index$f = /*#__PURE__*/Object.freeze({
16848
+ var index$g = /*#__PURE__*/Object.freeze({
16836
16849
  __proto__: null,
16837
16850
  getSubChannelByIds: getSubChannels$1,
16838
16851
  createSubChannel: createSubChannel,
@@ -18146,7 +18159,7 @@ const searchMembers$1 = (params, callback, config) => {
18146
18159
  };
18147
18160
  /* end_public_function */
18148
18161
 
18149
- var index$e = /*#__PURE__*/Object.freeze({
18162
+ var index$f = /*#__PURE__*/Object.freeze({
18150
18163
  __proto__: null,
18151
18164
  addMembers: addMembers$1,
18152
18165
  removeMembers: removeMembers$1,
@@ -18349,7 +18362,7 @@ const unmuteMembers = async (channelId, userIds) => {
18349
18362
  };
18350
18363
  /* end_public_function */
18351
18364
 
18352
- var index$d = /*#__PURE__*/Object.freeze({
18365
+ var index$e = /*#__PURE__*/Object.freeze({
18353
18366
  __proto__: null,
18354
18367
  addRole: addRole,
18355
18368
  removeRole: removeRole,
@@ -18359,10 +18372,10 @@ var index$d = /*#__PURE__*/Object.freeze({
18359
18372
  unmuteMembers: unmuteMembers
18360
18373
  });
18361
18374
 
18362
- var index$c = /*#__PURE__*/Object.freeze({
18375
+ var index$d = /*#__PURE__*/Object.freeze({
18363
18376
  __proto__: null,
18364
- Membership: index$e,
18365
- Moderation: index$d,
18377
+ Membership: index$f,
18378
+ Moderation: index$e,
18366
18379
  getChannelByIds: getChannelByIds$1,
18367
18380
  createChannel: createChannel,
18368
18381
  updateChannel: updateChannel,
@@ -19742,7 +19755,7 @@ const searchMembers = (params, callback, config) => {
19742
19755
  };
19743
19756
  /* end_public_function */
19744
19757
 
19745
- var index$b = /*#__PURE__*/Object.freeze({
19758
+ var index$c = /*#__PURE__*/Object.freeze({
19746
19759
  __proto__: null,
19747
19760
  addMembers: addMembers,
19748
19761
  removeMembers: removeMembers,
@@ -20767,7 +20780,7 @@ const unbanMembers = async (communityId, userIds) => {
20767
20780
  };
20768
20781
  /* end_public_function */
20769
20782
 
20770
- var index$a = /*#__PURE__*/Object.freeze({
20783
+ var index$b = /*#__PURE__*/Object.freeze({
20771
20784
  __proto__: null,
20772
20785
  addRoles: addRoles,
20773
20786
  removeRoles: removeRoles,
@@ -20775,10 +20788,10 @@ var index$a = /*#__PURE__*/Object.freeze({
20775
20788
  unbanMembers: unbanMembers
20776
20789
  });
20777
20790
 
20778
- var index$9 = /*#__PURE__*/Object.freeze({
20791
+ var index$a = /*#__PURE__*/Object.freeze({
20779
20792
  __proto__: null,
20780
- Moderation: index$a,
20781
- Membership: index$b,
20793
+ Moderation: index$b,
20794
+ Membership: index$c,
20782
20795
  getCommunityByIds: getCommunities$1,
20783
20796
  createCommunity: createCommunity,
20784
20797
  updateCommunity: updateCommunity,
@@ -21011,7 +21024,7 @@ const getCategories = (params, callback, config) => {
21011
21024
  };
21012
21025
  /* end_public_function */
21013
21026
 
21014
- var index$8 = /*#__PURE__*/Object.freeze({
21027
+ var index$9 = /*#__PURE__*/Object.freeze({
21015
21028
  __proto__: null,
21016
21029
  getCategory: getCategory,
21017
21030
  getCategories: getCategories
@@ -21179,7 +21192,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
21179
21192
  : undefined;
21180
21193
  };
21181
21194
 
21182
- var index$7 = /*#__PURE__*/Object.freeze({
21195
+ var index$8 = /*#__PURE__*/Object.freeze({
21183
21196
  __proto__: null,
21184
21197
  queryGlobalFeed: queryGlobalFeed,
21185
21198
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -22494,7 +22507,7 @@ const getComments = (params, callback, config) => {
22494
22507
  };
22495
22508
  /* end_public_function */
22496
22509
 
22497
- var index$6 = /*#__PURE__*/Object.freeze({
22510
+ var index$7 = /*#__PURE__*/Object.freeze({
22498
22511
  __proto__: null,
22499
22512
  getCommentByIds: getCommentByIds,
22500
22513
  createComment: createComment,
@@ -23501,7 +23514,7 @@ const semanticSearchPosts = (params, callback, config) => {
23501
23514
  };
23502
23515
  };
23503
23516
 
23504
- var index$5 = /*#__PURE__*/Object.freeze({
23517
+ var index$6 = /*#__PURE__*/Object.freeze({
23505
23518
  __proto__: null,
23506
23519
  getPostByIds: getPostByIds,
23507
23520
  createPost: createPost,
@@ -24035,7 +24048,7 @@ const getStreams = (params, callback, config) => {
24035
24048
  };
24036
24049
  };
24037
24050
 
24038
- var index$4 = /*#__PURE__*/Object.freeze({
24051
+ var index$5 = /*#__PURE__*/Object.freeze({
24039
24052
  __proto__: null,
24040
24053
  createStream: createStream,
24041
24054
  updateStream: updateStream,
@@ -24322,7 +24335,7 @@ const getPoll = (pollId, callback) => {
24322
24335
  };
24323
24336
  /* end_public_function */
24324
24337
 
24325
- var index$3 = /*#__PURE__*/Object.freeze({
24338
+ var index$4 = /*#__PURE__*/Object.freeze({
24326
24339
  __proto__: null,
24327
24340
  createPoll: createPoll,
24328
24341
  closePoll: closePoll,
@@ -24693,7 +24706,7 @@ const getPlayer = async (parameters) => {
24693
24706
  return video;
24694
24707
  };
24695
24708
 
24696
- var index$2 = /*#__PURE__*/Object.freeze({
24709
+ var index$3 = /*#__PURE__*/Object.freeze({
24697
24710
  __proto__: null,
24698
24711
  getPlayer: getPlayer
24699
24712
  });
@@ -25866,7 +25879,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
25866
25879
  };
25867
25880
  };
25868
25881
 
25869
- var index$1 = /*#__PURE__*/Object.freeze({
25882
+ var index$2 = /*#__PURE__*/Object.freeze({
25870
25883
  __proto__: null,
25871
25884
  createImageStory: createImageStory,
25872
25885
  createVideoStory: createVideoStory,
@@ -25903,7 +25916,7 @@ const getNetworkAds = async () => {
25903
25916
  };
25904
25917
  };
25905
25918
 
25906
- var index = /*#__PURE__*/Object.freeze({
25919
+ var index$1 = /*#__PURE__*/Object.freeze({
25907
25920
  __proto__: null,
25908
25921
  getNetworkAds: getNetworkAds
25909
25922
  });
@@ -25930,31 +25943,404 @@ const createUserToken = async (apiKey, apiRegion, params) => {
25930
25943
  return { accessToken: data.accessToken };
25931
25944
  };
25932
25945
 
25946
+ /* begin_public_function
25947
+ id: notificationTray.getNotificationTraySeen
25948
+ */
25949
+ /**
25950
+ * ```js
25951
+ * import { notificationTray } from '@amityco/ts-sdk'
25952
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen()
25953
+ * ```
25954
+ *
25955
+ *
25956
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
25957
+ *
25958
+ * @category NotificationTray API
25959
+ * @async
25960
+ * */
25961
+ const getNotificationTraySeen$1 = async () => {
25962
+ const client = getActiveClient();
25963
+ client.log('notificationTray/getNotificationTraySeen', {});
25964
+ const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
25965
+ const cachedAt = client.cache && Date.now();
25966
+ if (client.cache) {
25967
+ const cacheKey = ['notificationTraySeen', 'get', client.userId];
25968
+ pushToCache(cacheKey, {
25969
+ userId: client.userId,
25970
+ lastTraySeenAt: payload.lastTraySeenAt,
25971
+ lastTrayOccuredAt: payload.lastTrayOccurredAt,
25972
+ });
25973
+ }
25974
+ return {
25975
+ data: {
25976
+ userId: client.userId,
25977
+ lastTraySeenAt: payload.lastTraySeenAt,
25978
+ lastTrayOccurredAt: payload.lastTrayOccurredAt,
25979
+ isSeen: payload.lastTraySeenAt > payload.lastTrayOccurredAt,
25980
+ },
25981
+ cachedAt,
25982
+ };
25983
+ };
25984
+ /* end_public_function */
25985
+ /**
25986
+ * ```js
25987
+ * import { notificationTray } from '@amityco/ts-sdk'
25988
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen.locally()
25989
+ * ```
25990
+ *
25991
+ * Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
25992
+ *
25993
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
25994
+ *
25995
+ * @category NotificationTray API
25996
+ * @async
25997
+ * */
25998
+ getNotificationTraySeen$1.locally = () => {
25999
+ var _a;
26000
+ const client = getActiveClient();
26001
+ client.log('notificationTray/getNotificationTraySeen.locally', {});
26002
+ if (!client.cache)
26003
+ return;
26004
+ const queryKey = ['notificationTraySeen', 'get'];
26005
+ const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
26006
+ if (!data)
26007
+ return;
26008
+ return { data, cachedAt };
26009
+ };
26010
+
26011
+ /**
26012
+ * ```js
26013
+ * import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
26014
+ * const dispose = onNotificationTraySeenUpdated(data => {
26015
+ * // ...
26016
+ * })
26017
+ * ```
26018
+ *
26019
+ * Fired when an {@link Amity.NotificationTraySeen} has been updated
26020
+ *
26021
+ * @param callback The function to call when the event was fired
26022
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
26023
+ *
26024
+ * @category NotificationTraySeen Events
26025
+ */
26026
+ const onNotificationTraySeenUpdated = (callback) => {
26027
+ const client = getActiveClient();
26028
+ const disposers = [
26029
+ createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
26030
+ ];
26031
+ return () => {
26032
+ disposers.forEach(fn => fn());
26033
+ };
26034
+ };
26035
+
26036
+ /* begin_public_function
26037
+ id: notificationTray.getNotificationTraySeen
26038
+ */
26039
+ /**
26040
+ * ```js
26041
+ * import { notificationTray } from '@amityco/ts-sdk';
26042
+ *
26043
+ * let notificationTraySeen;
26044
+ *
26045
+ * const unsubscribe = getNotificationTraySeen(response => {
26046
+ * notificationTraySeen = response.data;
26047
+ * });
26048
+ * ```
26049
+ *
26050
+ * Observe all mutation on a given {@link Amity.NotificationTraySeen}
26051
+ *
26052
+ * @param callback the function to call when new data are available
26053
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
26054
+ *
26055
+ * @category NotificationTraySeen Live Object
26056
+ */
26057
+ const getNotificationTraySeen = (callback) => {
26058
+ const { userId } = getActiveUser();
26059
+ return liveObject(userId, callback, 'userId', getNotificationTraySeen$1, [onNotificationTraySeenUpdated], {
26060
+ callbackDataSelector: (data) => {
26061
+ let isSeen = true;
26062
+ if (data === null || data === void 0 ? void 0 : data.lastTrayOccurredAt) {
26063
+ if (!data.lastTraySeenAt) {
26064
+ isSeen = false;
26065
+ }
26066
+ else {
26067
+ isSeen =
26068
+ convertDateStringToTimestamp(data.lastTraySeenAt) >
26069
+ convertDateStringToTimestamp(data.lastTrayOccurredAt);
26070
+ }
26071
+ }
26072
+ return {
26073
+ lastTrayOccurredAt: data === null || data === void 0 ? void 0 : data.lastTrayOccurredAt,
26074
+ lastTraySeenAt: data === null || data === void 0 ? void 0 : data.lastTraySeenAt,
26075
+ isSeen,
26076
+ };
26077
+ },
26078
+ });
26079
+ };
26080
+ /* end_public_function */
26081
+
26082
+ /**
26083
+ * TODO: handle cache receive cache option, and cache policy
26084
+ * TODO: check if querybyIds is supported
26085
+ */
26086
+ class NotificationTrayItemsPaginationController extends PaginationController {
26087
+ async getRequest(queryParams, token) {
26088
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
26089
+ const options = token ? { token } : { limit };
26090
+ const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
26091
+ params: Object.assign(Object.assign({}, params), { options }),
26092
+ });
26093
+ return queryResponse;
26094
+ }
26095
+ }
26096
+
26097
+ class NotificationTrayItemsQuerystreamController extends QueryStreamController {
26098
+ constructor(query, cacheKey, notifyChange, preparePayload) {
26099
+ super(query, cacheKey);
26100
+ this.notifyChange = notifyChange;
26101
+ this.preparePayload = preparePayload;
26102
+ }
26103
+ async saveToMainDB(response) {
26104
+ const processedPayload = await this.preparePayload(response);
26105
+ const client = getActiveClient();
26106
+ const cachedAt = client.cache && Date.now();
26107
+ if (client.cache) {
26108
+ ingestInCache(processedPayload, { cachedAt });
26109
+ }
26110
+ }
26111
+ appendToQueryStream(response, direction, refresh = false) {
26112
+ var _a, _b;
26113
+ if (refresh) {
26114
+ pushToCache(this.cacheKey, {
26115
+ data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
26116
+ });
26117
+ }
26118
+ else {
26119
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26120
+ const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
26121
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
26122
+ ...new Set([
26123
+ ...notifications,
26124
+ ...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
26125
+ ]),
26126
+ ] }));
26127
+ }
26128
+ }
26129
+ }
26130
+
26131
+ const prepareNotificationTrayItemsPayload = (rawPayload) => {
26132
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
26133
+ return Object.assign(Object.assign({}, rawPayload), { users });
26134
+ };
26135
+
26136
+ class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
26137
+ constructor(query, callback) {
26138
+ const queryStreamId = hash__default["default"](query);
26139
+ const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
26140
+ const paginationController = new NotificationTrayItemsPaginationController(query);
26141
+ super(paginationController, queryStreamId, cacheKey, callback);
26142
+ this.query = query;
26143
+ this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
26144
+ this.callback = callback.bind(this);
26145
+ this.loadPage({ initial: true });
26146
+ }
26147
+ setup() {
26148
+ var _a;
26149
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26150
+ if (!collection) {
26151
+ pushToCache(this.cacheKey, {
26152
+ data: [],
26153
+ params: {},
26154
+ });
26155
+ }
26156
+ }
26157
+ async persistModel(queryPayload) {
26158
+ await this.queryStreamController.saveToMainDB(queryPayload);
26159
+ }
26160
+ persistQueryStream({ response, direction, refresh, }) {
26161
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
26162
+ }
26163
+ // eslint-disable-next-line class-methods-use-this
26164
+ startSubscription() {
26165
+ return [];
26166
+ }
26167
+ notifyChange({ origin, loading, error }) {
26168
+ var _a, _b;
26169
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
26170
+ if (!collection)
26171
+ return;
26172
+ const data = ((_b = collection.data
26173
+ .map(id => pullFromCache(['notificationTrayItem', 'get', id]))
26174
+ .filter(isNonNullable)
26175
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
26176
+ if (!this.shouldNotify(data) && origin === 'event')
26177
+ return;
26178
+ this.callback({
26179
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
26180
+ data,
26181
+ hasNextPage: !!this.paginationController.getNextToken(),
26182
+ loading,
26183
+ error,
26184
+ });
26185
+ }
26186
+ }
26187
+
26188
+ /**
26189
+ * Get notification tray items for a notification tray page
26190
+ *
26191
+ * @param params the limit query parameters
26192
+ * @param callback the callback to be called when the notification tray items are updated
26193
+ * @returns items in the notification tray
26194
+ *
26195
+ * @category Notification tray items Live Collection
26196
+ *
26197
+ */
26198
+ const getNotificationTrayItems = (params, callback, config) => {
26199
+ const { log, cache } = getActiveClient();
26200
+ if (!cache) {
26201
+ console.log(ENABLE_CACHE_MESSAGE);
26202
+ }
26203
+ const timestamp = Date.now();
26204
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
26205
+ const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
26206
+ const disposers = notiTrayItemsLiveCollection.startSubscription();
26207
+ const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
26208
+ disposers.push(() => dropFromCache(cacheKey));
26209
+ return () => {
26210
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
26211
+ disposers.forEach(fn => fn());
26212
+ };
26213
+ };
26214
+
26215
+ /* begin_public_function
26216
+ id: notificationTrayItem.markSeen
26217
+ */
26218
+ /**
26219
+ * ```js
26220
+ * import { notificationTray } from '@amityco/ts-sdk'
26221
+ * const updated = await notificationTray.markItemsSeen()
26222
+ * ```
26223
+ *
26224
+ * Updates an {@link Amity.NotificationItemSeen}
26225
+ *
26226
+ * @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
26227
+ * @returns the updated {@link Amity.NotificationItemSeen} object
26228
+ *
26229
+ * @category NotificationItemSeen API
26230
+ * @async
26231
+ */
26232
+ const markItemsSeen = async (trayItems) => {
26233
+ const client = getActiveClient();
26234
+ client.log('notificationTray/markItemsSeen', {});
26235
+ const { data: payload } = await client.http.post(`api/v1/notification-tray/items/seen`, {
26236
+ trayItems: trayItems.map(item => ({
26237
+ id: item.id,
26238
+ lastSeenAt: item.lastSeenAt,
26239
+ })),
26240
+ });
26241
+ const updatedData = trayItems
26242
+ .map(patchItem => {
26243
+ var _a;
26244
+ const cacheData = (_a = pullFromCache([
26245
+ 'notificationTrayItem',
26246
+ 'get',
26247
+ patchItem.id,
26248
+ ])) === null || _a === void 0 ? void 0 : _a.data;
26249
+ if (!cacheData)
26250
+ return;
26251
+ const data = Object.assign(Object.assign({}, cacheData), payload);
26252
+ if (client.cache) {
26253
+ const cachedAt = Date.now();
26254
+ pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
26255
+ }
26256
+ return data;
26257
+ })
26258
+ .filter(Boolean);
26259
+ fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
26260
+ };
26261
+ /* end_public_function */
26262
+
26263
+ /* begin_public_function
26264
+ id: notificationTray.markSeen
26265
+ */
26266
+ /**
26267
+ * ```js
26268
+ * import { notificationTray } from '@amityco/ts-sdk'
26269
+ * const updated = await notificationTray.markTraySeen({
26270
+ * lastSeenAt: Amity.timestamp,
26271
+ * })
26272
+ * ```
26273
+ *
26274
+ * Updates an {@link Amity.NotificationTraySeen}
26275
+ *
26276
+ * @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
26277
+ * @param lastSeenAt The patch data to apply
26278
+ * @returns the updated {@link Amity.NotificationTraySeen} object
26279
+ *
26280
+ * @category Post API
26281
+ * @async
26282
+ */
26283
+ const markTraySeen = async (lastSeenAt) => {
26284
+ var _a;
26285
+ const client = getActiveClient();
26286
+ client.log('notificationTray/markTraySeen', {});
26287
+ const { data: payload } = await client.http.post(`api/v1/notification-tray/tray/seen`, {
26288
+ lastSeenAt,
26289
+ });
26290
+ const cacheData = (_a = pullFromCache([
26291
+ 'notificationTraySeen',
26292
+ 'get',
26293
+ ])) === null || _a === void 0 ? void 0 : _a.data;
26294
+ const data = {
26295
+ userId: client.userId,
26296
+ lastTraySeenAt: payload.lastSeenAt,
26297
+ };
26298
+ const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
26299
+ const cachedAt = client.cache && Date.now();
26300
+ if (client.cache)
26301
+ pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
26302
+ fireEvent('local.notificationTraySeen.updated', data);
26303
+ return {
26304
+ data: payload,
26305
+ cachedAt,
26306
+ };
26307
+ };
26308
+ /* end_public_function */
26309
+
26310
+ var index = /*#__PURE__*/Object.freeze({
26311
+ __proto__: null,
26312
+ getNotificationTraySeen: getNotificationTraySeen,
26313
+ getNotificationTrayItems: getNotificationTrayItems,
26314
+ markItemsSeen: markItemsSeen,
26315
+ markTraySeen: markTraySeen,
26316
+ onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
26317
+ });
26318
+
25933
26319
  exports.API_REGIONS = API_REGIONS;
25934
- exports.AdRepository = index;
25935
- exports.CategoryRepository = index$8;
25936
- exports.ChannelRepository = index$c;
25937
- exports.Client = index$l;
25938
- exports.CommentRepository = index$6;
26320
+ exports.AdRepository = index$1;
26321
+ exports.CategoryRepository = index$9;
26322
+ exports.ChannelRepository = index$d;
26323
+ exports.Client = index$m;
26324
+ exports.CommentRepository = index$7;
25939
26325
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
25940
26326
  exports.CommunityPostSettings = CommunityPostSettings;
25941
- exports.CommunityRepository = index$9;
26327
+ exports.CommunityRepository = index$a;
25942
26328
  exports.ContentFeedType = ContentFeedType;
25943
26329
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
25944
- exports.FeedRepository = index$7;
25945
- exports.FileRepository = index$i;
26330
+ exports.FeedRepository = index$8;
26331
+ exports.FileRepository = index$j;
25946
26332
  exports.FileType = FileType;
25947
- exports.LiveStreamPlayer = index$2;
26333
+ exports.LiveStreamPlayer = index$3;
25948
26334
  exports.MessageContentType = MessageContentType;
25949
- exports.MessageRepository = index$g;
25950
- exports.PollRepository = index$3;
26335
+ exports.MessageRepository = index$h;
26336
+ exports.PollRepository = index$4;
25951
26337
  exports.PostContentType = PostContentType;
25952
- exports.PostRepository = index$5;
25953
- exports.ReactionRepository = index$h;
25954
- exports.StoryRepository = index$1;
25955
- exports.StreamRepository = index$4;
25956
- exports.SubChannelRepository = index$f;
25957
- exports.UserRepository = index$j;
26338
+ exports.PostRepository = index$6;
26339
+ exports.ReactionRepository = index$i;
26340
+ exports.StoryRepository = index$2;
26341
+ exports.StreamRepository = index$5;
26342
+ exports.SubChannelRepository = index$g;
26343
+ exports.UserRepository = index$k;
25958
26344
  exports.VERSION = VERSION;
25959
26345
  exports.VideoResolution = VideoResolution;
25960
26346
  exports.VideoSize = VideoSize;
@@ -26007,6 +26393,7 @@ exports.isPaged = isPaged;
26007
26393
  exports.isReportedByMe = isReportedByMe;
26008
26394
  exports.isSkip = isSkip;
26009
26395
  exports.mergeInCache = mergeInCache;
26396
+ exports.notificationTray = index;
26010
26397
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
26011
26398
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
26012
26399
  exports.onFeedMarkerUpdated = onFeedMarkerUpdated;
package/dist/index.d.ts CHANGED
@@ -25,4 +25,5 @@ export * as LiveStreamPlayer from './liveStreamPlayer';
25
25
  export * as StoryRepository from './storyRepository';
26
26
  export * as AdRepository from './adRepository';
27
27
  export * from './external/api';
28
+ export * as notificationTray from './notificationTray';
28
29
  //# 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;AAEvD,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"}
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;AAEvD,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"}