@amityco/ts-sdk 7.1.0 → 7.1.1-1325f22d.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 (74) hide show
  1. package/.env +26 -26
  2. package/dist/@types/core/events.d.ts +4 -0
  3. package/dist/@types/core/events.d.ts.map +1 -1
  4. package/dist/@types/core/model.d.ts +4 -0
  5. package/dist/@types/core/model.d.ts.map +1 -1
  6. package/dist/@types/core/payload.d.ts +18 -0
  7. package/dist/@types/core/payload.d.ts.map +1 -1
  8. package/dist/@types/domains/notification.d.ts +81 -0
  9. package/dist/@types/domains/notification.d.ts.map +1 -0
  10. package/dist/core/events.d.ts +3 -3
  11. package/dist/core/events.d.ts.map +1 -1
  12. package/dist/core/model/idResolvers.d.ts.map +1 -1
  13. package/dist/core/model/index.d.ts.map +1 -1
  14. package/dist/index.cjs.js +420 -45
  15. package/dist/index.d.ts +1 -0
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.esm.js +403 -29
  18. package/dist/index.umd.js +4 -4
  19. package/dist/notificationTray/api/index.d.ts +3 -0
  20. package/dist/notificationTray/api/index.d.ts.map +1 -0
  21. package/dist/notificationTray/api/markItemsSeen.d.ts +16 -0
  22. package/dist/notificationTray/api/markItemsSeen.d.ts.map +1 -0
  23. package/dist/notificationTray/api/markTraySeen.d.ts +19 -0
  24. package/dist/notificationTray/api/markTraySeen.d.ts.map +1 -0
  25. package/dist/notificationTray/events/index.d.ts +2 -0
  26. package/dist/notificationTray/events/index.d.ts.map +1 -0
  27. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts +17 -0
  28. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts.map +1 -0
  29. package/dist/notificationTray/index.d.ts +4 -0
  30. package/dist/notificationTray/index.d.ts.map +1 -0
  31. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts +30 -0
  32. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts.map +1 -0
  33. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +13 -0
  34. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +1 -0
  35. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +9 -0
  36. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +1 -0
  37. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +9 -0
  38. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +1 -0
  39. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts +12 -0
  40. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts.map +1 -0
  41. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts +21 -0
  42. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts.map +1 -0
  43. package/dist/notificationTray/observers/index.d.ts +3 -0
  44. package/dist/notificationTray/observers/index.d.ts.map +1 -0
  45. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts +2 -0
  46. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts.map +1 -0
  47. package/dist/utils/linkedObject/index.d.ts +1 -0
  48. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  49. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +2 -0
  50. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -0
  51. package/package.json +1 -1
  52. package/src/@types/core/events.ts +5 -0
  53. package/src/@types/core/model.ts +6 -0
  54. package/src/@types/core/payload.ts +25 -0
  55. package/src/@types/domains/notification.ts +90 -0
  56. package/src/core/model/idResolvers.ts +3 -0
  57. package/src/core/model/index.ts +2 -0
  58. package/src/index.ts +2 -0
  59. package/src/notificationTray/api/index.ts +2 -0
  60. package/src/notificationTray/api/markItemsSeen.ts +59 -0
  61. package/src/notificationTray/api/markTraySeen.ts +65 -0
  62. package/src/notificationTray/events/index.ts +1 -0
  63. package/src/notificationTray/events/onNotificationTraySeenUpdated.ts +36 -0
  64. package/src/notificationTray/index.ts +3 -0
  65. package/src/notificationTray/internalApi/getNotificationTraySeen.ts +81 -0
  66. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +96 -0
  67. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +31 -0
  68. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +68 -0
  69. package/src/notificationTray/observers/getNotificationTrayItems.ts +44 -0
  70. package/src/notificationTray/observers/getNotificationTraySeen.ts +43 -0
  71. package/src/notificationTray/observers/index.ts +2 -0
  72. package/src/notificationTray/utils/prepareNotificationTrayItemsPayload.ts +12 -0
  73. package/src/utils/linkedObject/index.ts +2 -0
  74. package/src/utils/linkedObject/notificationTrayLinkedObject.ts +28 -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
 
@@ -542,6 +543,8 @@ const idResolvers = {
542
543
  advertiser: ({ advertiserId }) => advertiserId,
543
544
  pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
544
545
  pinTarget: ({ targetId }) => targetId,
546
+ notificationTrayItem: ({ _id }) => _id,
547
+ notificationTraySeen: ({ userId }) => userId,
545
548
  };
546
549
  /**
547
550
  * Retrieve the id resolver matching a domain name
@@ -593,6 +596,7 @@ const PAYLOAD2MODEL = {
593
596
  advertisers: 'advertiser',
594
597
  pinTargets: 'pinTarget',
595
598
  pins: 'pin',
599
+ notificationTrayItems: 'notificationTrayItem',
596
600
  };
597
601
  /** hidden */
598
602
  const isOutdated = (prevData, nextData) => {
@@ -5993,6 +5997,65 @@ const pinnedPostLinkedObject = (pinnedPost) => {
5993
5997
  } });
5994
5998
  };
5995
5999
 
6000
+ /* begin_public_function
6001
+ id: notificationTrayItem.markSeen
6002
+ */
6003
+ /**
6004
+ * ```js
6005
+ * import { notificationTray } from '@amityco/ts-sdk'
6006
+ * const updated = await notificationTray.markItemsSeen()
6007
+ * ```
6008
+ *
6009
+ * Updates an {@link Amity.NotificationItemSeen}
6010
+ *
6011
+ * @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
6012
+ * @returns the updated {@link Amity.NotificationItemSeen} object
6013
+ *
6014
+ * @category NotificationItemSeen API
6015
+ * @async
6016
+ */
6017
+ const markItemsSeen = async (patch) => {
6018
+ const client = getActiveClient();
6019
+ client.log('notificationTray/markItemsSeen', {});
6020
+ const { data: payload } = await client.http.put(`api/v1/notification-tray/items/seen`, {
6021
+ patch,
6022
+ });
6023
+ const updatedData = patch.trayItems
6024
+ .map(patchItem => {
6025
+ var _a;
6026
+ const cacheData = (_a = pullFromCache([
6027
+ 'notificationTraySeen',
6028
+ 'get',
6029
+ patchItem.id,
6030
+ ])) === null || _a === void 0 ? void 0 : _a.data;
6031
+ if (!cacheData)
6032
+ return;
6033
+ const data = Object.assign(Object.assign({}, cacheData), payload);
6034
+ if (client.cache) {
6035
+ const cachedAt = Date.now();
6036
+ pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
6037
+ }
6038
+ return data;
6039
+ })
6040
+ .filter(Boolean);
6041
+ fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
6042
+ };
6043
+ /* end_public_function */
6044
+
6045
+ const notificationTrayLinkedObject = (noti) => {
6046
+ return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccuredAt, isRecent: new Date(noti.lastOccuredAt).getTime() >= Date.now() - WEEK, users: noti.actors
6047
+ .map(userId => { var _a; return (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data; })
6048
+ .filter(isNonNullable)
6049
+ .map(user => userLinkedObject(user)), markRead: () => markItemsSeen({
6050
+ trayItems: [
6051
+ {
6052
+ id: noti._id,
6053
+ lastSeenAt: noti.lastSeenAt,
6054
+ },
6055
+ ],
6056
+ }) });
6057
+ };
6058
+
5996
6059
  const LinkedObject = {
5997
6060
  ad: adLinkedObject,
5998
6061
  comment: commentLinkedObject,
@@ -6006,6 +6069,7 @@ const LinkedObject = {
6006
6069
  reactor: reactorLinkedObject,
6007
6070
  channel: channelLinkedObject,
6008
6071
  pinnedPost: pinnedPostLinkedObject,
6072
+ notificationTray: notificationTrayLinkedObject,
6009
6073
  };
6010
6074
 
6011
6075
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -9776,7 +9840,7 @@ const getUserUnread = (callback) => {
9776
9840
  };
9777
9841
  };
9778
9842
 
9779
- var index$l = /*#__PURE__*/Object.freeze({
9843
+ var index$m = /*#__PURE__*/Object.freeze({
9780
9844
  __proto__: null,
9781
9845
  getActiveClient: getActiveClient,
9782
9846
  getActiveUser: getActiveUser,
@@ -10983,7 +11047,7 @@ const getMyFollowInfo = (callback) => {
10983
11047
  };
10984
11048
  /* end_public_function */
10985
11049
 
10986
- var index$k = /*#__PURE__*/Object.freeze({
11050
+ var index$l = /*#__PURE__*/Object.freeze({
10987
11051
  __proto__: null,
10988
11052
  blockUser: blockUser,
10989
11053
  unBlockUser: unBlockUser,
@@ -11998,9 +12062,9 @@ var AmityUserSearchMatchType;
11998
12062
  AmityUserSearchMatchType["PARTIAL"] = "partial";
11999
12063
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
12000
12064
 
12001
- var index$j = /*#__PURE__*/Object.freeze({
12065
+ var index$k = /*#__PURE__*/Object.freeze({
12002
12066
  __proto__: null,
12003
- Relationship: index$k,
12067
+ Relationship: index$l,
12004
12068
  getUserByIds: getUserByIds,
12005
12069
  updateUser: updateUser,
12006
12070
  flagUser: flagUser,
@@ -12264,7 +12328,7 @@ const uploadImage = async (formData, onProgress) => {
12264
12328
  };
12265
12329
  /* end_public_function */
12266
12330
 
12267
- var index$i = /*#__PURE__*/Object.freeze({
12331
+ var index$j = /*#__PURE__*/Object.freeze({
12268
12332
  __proto__: null,
12269
12333
  getFile: getFile,
12270
12334
  uploadFile: uploadFile,
@@ -14076,7 +14140,7 @@ const getReactions = (params, callback, config) => {
14076
14140
  };
14077
14141
  /* end_public_function */
14078
14142
 
14079
- var index$h = /*#__PURE__*/Object.freeze({
14143
+ var index$i = /*#__PURE__*/Object.freeze({
14080
14144
  __proto__: null,
14081
14145
  addReaction: addReaction,
14082
14146
  removeReaction: removeReaction,
@@ -15892,7 +15956,7 @@ const getMessages = (params, callback, config) => {
15892
15956
  };
15893
15957
  /* end_public_function */
15894
15958
 
15895
- var index$g = /*#__PURE__*/Object.freeze({
15959
+ var index$h = /*#__PURE__*/Object.freeze({
15896
15960
  __proto__: null,
15897
15961
  createMessage: createMessage,
15898
15962
  updateMessage: updateMessage,
@@ -16418,7 +16482,7 @@ const stopMessageReceiptSync = (subChannelId) => {
16418
16482
  };
16419
16483
  /* end_public_function */
16420
16484
 
16421
- var index$f = /*#__PURE__*/Object.freeze({
16485
+ var index$g = /*#__PURE__*/Object.freeze({
16422
16486
  __proto__: null,
16423
16487
  getSubChannelByIds: getSubChannels$1,
16424
16488
  createSubChannel: createSubChannel,
@@ -17595,7 +17659,7 @@ const searchMembers$1 = (params, callback, config) => {
17595
17659
  };
17596
17660
  /* end_public_function */
17597
17661
 
17598
- var index$e = /*#__PURE__*/Object.freeze({
17662
+ var index$f = /*#__PURE__*/Object.freeze({
17599
17663
  __proto__: null,
17600
17664
  addMembers: addMembers$1,
17601
17665
  removeMembers: removeMembers$1,
@@ -17798,7 +17862,7 @@ const unmuteMembers = async (channelId, userIds) => {
17798
17862
  };
17799
17863
  /* end_public_function */
17800
17864
 
17801
- var index$d = /*#__PURE__*/Object.freeze({
17865
+ var index$e = /*#__PURE__*/Object.freeze({
17802
17866
  __proto__: null,
17803
17867
  addRole: addRole,
17804
17868
  removeRole: removeRole,
@@ -17808,10 +17872,10 @@ var index$d = /*#__PURE__*/Object.freeze({
17808
17872
  unmuteMembers: unmuteMembers
17809
17873
  });
17810
17874
 
17811
- var index$c = /*#__PURE__*/Object.freeze({
17875
+ var index$d = /*#__PURE__*/Object.freeze({
17812
17876
  __proto__: null,
17813
- Membership: index$e,
17814
- Moderation: index$d,
17877
+ Membership: index$f,
17878
+ Moderation: index$e,
17815
17879
  getChannelByIds: getChannelByIds$1,
17816
17880
  createChannel: createChannel,
17817
17881
  updateChannel: updateChannel,
@@ -19190,7 +19254,7 @@ const searchMembers = (params, callback, config) => {
19190
19254
  };
19191
19255
  /* end_public_function */
19192
19256
 
19193
- var index$b = /*#__PURE__*/Object.freeze({
19257
+ var index$c = /*#__PURE__*/Object.freeze({
19194
19258
  __proto__: null,
19195
19259
  addMembers: addMembers,
19196
19260
  removeMembers: removeMembers,
@@ -20215,7 +20279,7 @@ const unbanMembers = async (communityId, userIds) => {
20215
20279
  };
20216
20280
  /* end_public_function */
20217
20281
 
20218
- var index$a = /*#__PURE__*/Object.freeze({
20282
+ var index$b = /*#__PURE__*/Object.freeze({
20219
20283
  __proto__: null,
20220
20284
  addRoles: addRoles,
20221
20285
  removeRoles: removeRoles,
@@ -20223,10 +20287,10 @@ var index$a = /*#__PURE__*/Object.freeze({
20223
20287
  unbanMembers: unbanMembers
20224
20288
  });
20225
20289
 
20226
- var index$9 = /*#__PURE__*/Object.freeze({
20290
+ var index$a = /*#__PURE__*/Object.freeze({
20227
20291
  __proto__: null,
20228
- Moderation: index$a,
20229
- Membership: index$b,
20292
+ Moderation: index$b,
20293
+ Membership: index$c,
20230
20294
  getCommunityByIds: getCommunities$1,
20231
20295
  createCommunity: createCommunity,
20232
20296
  updateCommunity: updateCommunity,
@@ -20459,7 +20523,7 @@ const getCategories = (params, callback, config) => {
20459
20523
  };
20460
20524
  /* end_public_function */
20461
20525
 
20462
- var index$8 = /*#__PURE__*/Object.freeze({
20526
+ var index$9 = /*#__PURE__*/Object.freeze({
20463
20527
  __proto__: null,
20464
20528
  getCategory: getCategory,
20465
20529
  getCategories: getCategories
@@ -20627,7 +20691,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
20627
20691
  : undefined;
20628
20692
  };
20629
20693
 
20630
- var index$7 = /*#__PURE__*/Object.freeze({
20694
+ var index$8 = /*#__PURE__*/Object.freeze({
20631
20695
  __proto__: null,
20632
20696
  queryGlobalFeed: queryGlobalFeed,
20633
20697
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -21942,7 +22006,7 @@ const getComments = (params, callback, config) => {
21942
22006
  };
21943
22007
  /* end_public_function */
21944
22008
 
21945
- var index$6 = /*#__PURE__*/Object.freeze({
22009
+ var index$7 = /*#__PURE__*/Object.freeze({
21946
22010
  __proto__: null,
21947
22011
  getCommentByIds: getCommentByIds,
21948
22012
  createComment: createComment,
@@ -22949,7 +23013,7 @@ const semanticSearchPosts = (params, callback, config) => {
22949
23013
  };
22950
23014
  };
22951
23015
 
22952
- var index$5 = /*#__PURE__*/Object.freeze({
23016
+ var index$6 = /*#__PURE__*/Object.freeze({
22953
23017
  __proto__: null,
22954
23018
  getPostByIds: getPostByIds,
22955
23019
  createPost: createPost,
@@ -23483,7 +23547,7 @@ const getStreams = (params, callback, config) => {
23483
23547
  };
23484
23548
  };
23485
23549
 
23486
- var index$4 = /*#__PURE__*/Object.freeze({
23550
+ var index$5 = /*#__PURE__*/Object.freeze({
23487
23551
  __proto__: null,
23488
23552
  createStream: createStream,
23489
23553
  updateStream: updateStream,
@@ -23770,7 +23834,7 @@ const getPoll = (pollId, callback) => {
23770
23834
  };
23771
23835
  /* end_public_function */
23772
23836
 
23773
- var index$3 = /*#__PURE__*/Object.freeze({
23837
+ var index$4 = /*#__PURE__*/Object.freeze({
23774
23838
  __proto__: null,
23775
23839
  createPoll: createPoll,
23776
23840
  closePoll: closePoll,
@@ -23781,7 +23845,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
23781
23845
  getPoll: getPoll
23782
23846
  });
23783
23847
 
23784
- const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN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C3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
23785
23849
  /*
23786
23850
  * The crypto algorithm used for importing key and signing string
23787
23851
  */
@@ -24141,7 +24205,7 @@ const getPlayer = async (parameters) => {
24141
24205
  return video;
24142
24206
  };
24143
24207
 
24144
- var index$2 = /*#__PURE__*/Object.freeze({
24208
+ var index$3 = /*#__PURE__*/Object.freeze({
24145
24209
  __proto__: null,
24146
24210
  getPlayer: getPlayer
24147
24211
  });
@@ -25314,7 +25378,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
25314
25378
  };
25315
25379
  };
25316
25380
 
25317
- var index$1 = /*#__PURE__*/Object.freeze({
25381
+ var index$2 = /*#__PURE__*/Object.freeze({
25318
25382
  __proto__: null,
25319
25383
  createImageStory: createImageStory,
25320
25384
  createVideoStory: createVideoStory,
@@ -25351,7 +25415,7 @@ const getNetworkAds = async () => {
25351
25415
  };
25352
25416
  };
25353
25417
 
25354
- var index = /*#__PURE__*/Object.freeze({
25418
+ var index$1 = /*#__PURE__*/Object.freeze({
25355
25419
  __proto__: null,
25356
25420
  getNetworkAds: getNetworkAds
25357
25421
  });
@@ -25378,31 +25442,341 @@ const createUserToken = async (apiKey, apiRegion, params) => {
25378
25442
  return { accessToken: data.accessToken };
25379
25443
  };
25380
25444
 
25445
+ /* begin_public_function
25446
+ id: notificationTray.getNotificationTraySeen
25447
+ */
25448
+ /**
25449
+ * ```js
25450
+ * import { notificationTray } from '@amityco/ts-sdk'
25451
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen()
25452
+ * ```
25453
+ *
25454
+ *
25455
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
25456
+ *
25457
+ * @category NotificationTray API
25458
+ * @async
25459
+ * */
25460
+ const getNotificationTraySeen$1 = async () => {
25461
+ const client = getActiveClient();
25462
+ client.log('notificationTray/getNotificationTraySeen', {});
25463
+ const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
25464
+ const cachedAt = client.cache && Date.now();
25465
+ if (client.cache) {
25466
+ const cacheKey = ['notificationTraySeen', 'get', client.userId];
25467
+ pushToCache(cacheKey, {
25468
+ userId: client.userId,
25469
+ lastTraySeenAt: payload.lastTraySeenAt,
25470
+ lastTrayOccuredAt: payload.lastTrayOccuredAt,
25471
+ });
25472
+ }
25473
+ return {
25474
+ data: {
25475
+ userId: client.userId,
25476
+ lastTraySeenAt: payload.lastTraySeenAt,
25477
+ lastTrayOccuredAt: payload.lastTrayOccuredAt,
25478
+ isSeen: payload.lastTraySeenAt > payload.lastTrayOccuredAt,
25479
+ },
25480
+ cachedAt,
25481
+ };
25482
+ };
25483
+ /* end_public_function */
25484
+ /**
25485
+ * ```js
25486
+ * import { notificationTray } from '@amityco/ts-sdk'
25487
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen.locally()
25488
+ * ```
25489
+ *
25490
+ * Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
25491
+ *
25492
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
25493
+ *
25494
+ * @category NotificationTray API
25495
+ * @async
25496
+ * */
25497
+ getNotificationTraySeen$1.locally = () => {
25498
+ var _a;
25499
+ const client = getActiveClient();
25500
+ client.log('notificationTray/getNotificationTraySeen.locally', {});
25501
+ if (!client.cache)
25502
+ return;
25503
+ const queryKey = ['notificationTraySeen', 'get'];
25504
+ const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
25505
+ if (!(data === null || data === void 0 ? void 0 : data.notificationTraySeen))
25506
+ return;
25507
+ return { data: data.notificationTraySeen, cachedAt };
25508
+ };
25509
+
25510
+ /**
25511
+ * ```js
25512
+ * import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
25513
+ * const dispose = onNotificationTraySeenUpdated(data => {
25514
+ * // ...
25515
+ * })
25516
+ * ```
25517
+ *
25518
+ * Fired when an {@link Amity.NotificationTraySeen} has been updated
25519
+ *
25520
+ * @param callback The function to call when the event was fired
25521
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
25522
+ *
25523
+ * @category NotificationTraySeen Events
25524
+ */
25525
+ const onNotificationTraySeenUpdated = (callback) => {
25526
+ const client = getActiveClient();
25527
+ const disposers = [
25528
+ createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
25529
+ ];
25530
+ return () => {
25531
+ disposers.forEach(fn => fn());
25532
+ };
25533
+ };
25534
+
25535
+ /* begin_public_function
25536
+ id: notificationTraySeen.get
25537
+ */
25538
+ /**
25539
+ * ```js
25540
+ * import { getNotificationTraySeen } from '@amityco/ts-sdk';
25541
+ *
25542
+ * let notificationTraySeen;
25543
+ *
25544
+ * const unsubscribe = getNotificationTraySeen(userId, response => {
25545
+ * notificationTraySeen = response.data;
25546
+ * });
25547
+ * ```
25548
+ *
25549
+ * Observe all mutation on a given {@link Amity.NotificationTraySeen}
25550
+ *
25551
+ * @param userId the ID of the user to observe
25552
+ * @param callback the function to call when new data are available
25553
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
25554
+ *
25555
+ * @category NotificationTraySeen Live Object
25556
+ */
25557
+ const getNotificationTraySeen = (callback) => {
25558
+ const responder = (snapshot) => {
25559
+ const { data } = snapshot;
25560
+ callback(Object.assign(Object.assign({}, snapshot), { data }));
25561
+ };
25562
+ const { userId } = getActiveUser();
25563
+ return liveObject(userId, responder, 'userId', getNotificationTraySeen$1, [
25564
+ onNotificationTraySeenUpdated,
25565
+ ]);
25566
+ };
25567
+ /* end_public_function */
25568
+
25569
+ /**
25570
+ * TODO: handle cache receive cache option, and cache policy
25571
+ * TODO: check if querybyIds is supported
25572
+ */
25573
+ class NotificationTrayItemsPaginationController extends PaginationController {
25574
+ async getRequest(queryParams, token) {
25575
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
25576
+ const options = token ? { token } : { limit };
25577
+ const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
25578
+ params: Object.assign(Object.assign({}, params), { options }),
25579
+ });
25580
+ return queryResponse;
25581
+ }
25582
+ }
25583
+
25584
+ class NotificationTrayItemsQuerystreamController extends QueryStreamController {
25585
+ constructor(query, cacheKey, notifyChange, preparePayload) {
25586
+ super(query, cacheKey);
25587
+ this.notifyChange = notifyChange;
25588
+ this.preparePayload = preparePayload;
25589
+ }
25590
+ async saveToMainDB(response) {
25591
+ const processedPayload = await this.preparePayload(response);
25592
+ const client = getActiveClient();
25593
+ const cachedAt = client.cache && Date.now();
25594
+ if (client.cache) {
25595
+ ingestInCache(processedPayload, { cachedAt });
25596
+ }
25597
+ }
25598
+ appendToQueryStream(response, direction, refresh = false) {
25599
+ var _a, _b;
25600
+ if (refresh) {
25601
+ pushToCache(this.cacheKey, {
25602
+ data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
25603
+ });
25604
+ }
25605
+ else {
25606
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25607
+ const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
25608
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
25609
+ ...new Set([
25610
+ ...notifications,
25611
+ ...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
25612
+ ]),
25613
+ ] }));
25614
+ }
25615
+ }
25616
+ }
25617
+
25618
+ const prepareNotificationTrayItemsPayload = (rawPayload) => {
25619
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
25620
+ return Object.assign(Object.assign({}, rawPayload), { users });
25621
+ };
25622
+
25623
+ class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
25624
+ constructor(query, callback) {
25625
+ const queryStreamId = hash__default["default"](query);
25626
+ const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
25627
+ const paginationController = new NotificationTrayItemsPaginationController(query);
25628
+ super(paginationController, queryStreamId, cacheKey, callback);
25629
+ this.query = query;
25630
+ this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
25631
+ this.callback = callback.bind(this);
25632
+ this.loadPage({ initial: true });
25633
+ }
25634
+ setup() {
25635
+ var _a;
25636
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25637
+ if (!collection) {
25638
+ pushToCache(this.cacheKey, {
25639
+ data: [],
25640
+ params: {},
25641
+ });
25642
+ }
25643
+ }
25644
+ async persistModel(queryPayload) {
25645
+ await this.queryStreamController.saveToMainDB(queryPayload);
25646
+ }
25647
+ persistQueryStream({ response, direction, refresh, }) {
25648
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
25649
+ }
25650
+ // eslint-disable-next-line class-methods-use-this
25651
+ startSubscription() {
25652
+ return [];
25653
+ }
25654
+ notifyChange({ origin, loading, error }) {
25655
+ var _a, _b;
25656
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25657
+ if (!collection)
25658
+ return;
25659
+ const data = ((_b = collection.data
25660
+ .map(id => pullFromCache(['notificationTrayItem', 'get', id]))
25661
+ .filter(isNonNullable)
25662
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
25663
+ if (!this.shouldNotify(data) && origin === 'event')
25664
+ return;
25665
+ this.callback({
25666
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
25667
+ data,
25668
+ hasNextPage: !!this.paginationController.getNextToken(),
25669
+ loading,
25670
+ error,
25671
+ });
25672
+ }
25673
+ }
25674
+
25675
+ /**
25676
+ * Get notification tray items for a notification tray page
25677
+ *
25678
+ * @param params the limit query parameters
25679
+ * @param callback the callback to be called when the notification tray items are updated
25680
+ * @returns items in the notification tray
25681
+ *
25682
+ * @category Notification tray items Live Collection
25683
+ *
25684
+ */
25685
+ const getNotificationTrayItems = (params, callback, config) => {
25686
+ const { log, cache } = getActiveClient();
25687
+ if (!cache) {
25688
+ console.log(ENABLE_CACHE_MESSAGE);
25689
+ }
25690
+ const timestamp = Date.now();
25691
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
25692
+ const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
25693
+ const disposers = notiTrayItemsLiveCollection.startSubscription();
25694
+ const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
25695
+ disposers.push(() => dropFromCache(cacheKey));
25696
+ return () => {
25697
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
25698
+ disposers.forEach(fn => fn());
25699
+ };
25700
+ };
25701
+
25702
+ /* begin_public_function
25703
+ id: notificationTray.markSeen
25704
+ */
25705
+ /**
25706
+ * ```js
25707
+ * import { notificationTray } from '@amityco/ts-sdk'
25708
+ * const updated = await notificationTray.markTraySeen({
25709
+ * lastSeenAt: Amity.timestamp,
25710
+ * })
25711
+ * ```
25712
+ *
25713
+ * Updates an {@link Amity.NotificationTraySeen}
25714
+ *
25715
+ * @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
25716
+ * @param lastSeenAt The patch data to apply
25717
+ * @returns the updated {@link Amity.NotificationTraySeen} object
25718
+ *
25719
+ * @category Post API
25720
+ * @async
25721
+ */
25722
+ const markTraySeen = async (lastSeenAt) => {
25723
+ var _a;
25724
+ const client = getActiveClient();
25725
+ client.log('notificationTray/markTraySeen', {});
25726
+ const { data: payload } = await client.http.put(`api/v1/notification-tray/tray/seen`, {
25727
+ lastSeenAt,
25728
+ });
25729
+ const cacheData = (_a = pullFromCache([
25730
+ 'notificationTraySeen',
25731
+ 'get',
25732
+ ])) === null || _a === void 0 ? void 0 : _a.data;
25733
+ const data = Object.assign({ userId: client.userId }, payload);
25734
+ const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
25735
+ const cachedAt = client.cache && Date.now();
25736
+ if (client.cache)
25737
+ pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
25738
+ fireEvent('local.notificationTraySeen.updated', data);
25739
+ return {
25740
+ data: payload,
25741
+ cachedAt,
25742
+ };
25743
+ };
25744
+ /* end_public_function */
25745
+
25746
+ var index = /*#__PURE__*/Object.freeze({
25747
+ __proto__: null,
25748
+ getNotificationTraySeen: getNotificationTraySeen,
25749
+ getNotificationTrayItems: getNotificationTrayItems,
25750
+ markItemsSeen: markItemsSeen,
25751
+ markTraySeen: markTraySeen,
25752
+ onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
25753
+ });
25754
+
25381
25755
  exports.API_REGIONS = API_REGIONS;
25382
- exports.AdRepository = index;
25383
- exports.CategoryRepository = index$8;
25384
- exports.ChannelRepository = index$c;
25385
- exports.Client = index$l;
25386
- exports.CommentRepository = index$6;
25756
+ exports.AdRepository = index$1;
25757
+ exports.CategoryRepository = index$9;
25758
+ exports.ChannelRepository = index$d;
25759
+ exports.Client = index$m;
25760
+ exports.CommentRepository = index$7;
25387
25761
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
25388
25762
  exports.CommunityPostSettings = CommunityPostSettings;
25389
- exports.CommunityRepository = index$9;
25763
+ exports.CommunityRepository = index$a;
25390
25764
  exports.ContentFeedType = ContentFeedType;
25391
25765
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
25392
- exports.FeedRepository = index$7;
25393
- exports.FileRepository = index$i;
25766
+ exports.FeedRepository = index$8;
25767
+ exports.FileRepository = index$j;
25394
25768
  exports.FileType = FileType;
25395
- exports.LiveStreamPlayer = index$2;
25769
+ exports.LiveStreamPlayer = index$3;
25396
25770
  exports.MessageContentType = MessageContentType;
25397
- exports.MessageRepository = index$g;
25398
- exports.PollRepository = index$3;
25771
+ exports.MessageRepository = index$h;
25772
+ exports.PollRepository = index$4;
25399
25773
  exports.PostContentType = PostContentType;
25400
- exports.PostRepository = index$5;
25401
- exports.ReactionRepository = index$h;
25402
- exports.StoryRepository = index$1;
25403
- exports.StreamRepository = index$4;
25404
- exports.SubChannelRepository = index$f;
25405
- exports.UserRepository = index$j;
25774
+ exports.PostRepository = index$6;
25775
+ exports.ReactionRepository = index$i;
25776
+ exports.StoryRepository = index$2;
25777
+ exports.StreamRepository = index$5;
25778
+ exports.SubChannelRepository = index$g;
25779
+ exports.UserRepository = index$k;
25406
25780
  exports.VERSION = VERSION;
25407
25781
  exports.VideoResolution = VideoResolution;
25408
25782
  exports.VideoSize = VideoSize;
@@ -25455,6 +25829,7 @@ exports.isPaged = isPaged;
25455
25829
  exports.isReportedByMe = isReportedByMe;
25456
25830
  exports.isSkip = isSkip;
25457
25831
  exports.mergeInCache = mergeInCache;
25832
+ exports.notificationTray = index;
25458
25833
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
25459
25834
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
25460
25835
  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