@amityco/ts-sdk 7.0.3-7f3fd9b.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 (79) 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 +18 -0
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/notification.d.ts +81 -0
  8. package/dist/@types/domains/notification.d.ts.map +1 -0
  9. package/dist/core/events.d.ts +3 -3
  10. package/dist/core/events.d.ts.map +1 -1
  11. package/dist/core/model/idResolvers.d.ts.map +1 -1
  12. package/dist/core/model/index.d.ts.map +1 -1
  13. package/dist/index.cjs.js +427 -46
  14. package/dist/index.d.ts +1 -0
  15. package/dist/index.d.ts.map +1 -1
  16. package/dist/index.esm.js +410 -30
  17. package/dist/index.umd.js +4 -4
  18. package/dist/notificationTray/api/index.d.ts +3 -0
  19. package/dist/notificationTray/api/index.d.ts.map +1 -0
  20. package/dist/notificationTray/api/markItemsSeen.d.ts +16 -0
  21. package/dist/notificationTray/api/markItemsSeen.d.ts.map +1 -0
  22. package/dist/notificationTray/api/markTraySeen.d.ts +19 -0
  23. package/dist/notificationTray/api/markTraySeen.d.ts.map +1 -0
  24. package/dist/notificationTray/events/index.d.ts +2 -0
  25. package/dist/notificationTray/events/index.d.ts.map +1 -0
  26. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts +17 -0
  27. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts.map +1 -0
  28. package/dist/notificationTray/index.d.ts +4 -0
  29. package/dist/notificationTray/index.d.ts.map +1 -0
  30. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts +30 -0
  31. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts.map +1 -0
  32. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +13 -0
  33. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +1 -0
  34. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +9 -0
  35. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +1 -0
  36. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +9 -0
  37. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +1 -0
  38. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts +12 -0
  39. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts.map +1 -0
  40. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts +21 -0
  41. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts.map +1 -0
  42. package/dist/notificationTray/observers/index.d.ts +3 -0
  43. package/dist/notificationTray/observers/index.d.ts.map +1 -0
  44. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts +2 -0
  45. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts.map +1 -0
  46. package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  47. package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  48. package/dist/reactionRepository/observers/getReactions/ReactionPaginationController.d.ts.map +1 -1
  49. package/dist/utils/linkedObject/index.d.ts +1 -0
  50. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  51. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +2 -0
  52. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -0
  53. package/package.json +1 -1
  54. package/src/@types/core/events.ts +5 -0
  55. package/src/@types/core/model.ts +6 -0
  56. package/src/@types/core/payload.ts +25 -0
  57. package/src/@types/domains/notification.ts +90 -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 +59 -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 +81 -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 +43 -0
  73. package/src/notificationTray/observers/index.ts +2 -0
  74. package/src/notificationTray/utils/prepareNotificationTrayItemsPayload.ts +12 -0
  75. package/src/reactionRepository/api/addReaction.ts +8 -0
  76. package/src/reactionRepository/api/removeReaction.ts +8 -0
  77. package/src/reactionRepository/observers/getReactions/ReactionPaginationController.ts +8 -0
  78. package/src/utils/linkedObject/index.ts +2 -0
  79. package/src/utils/linkedObject/notificationTrayLinkedObject.ts +28 -0
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"}
package/dist/index.esm.js CHANGED
@@ -87,8 +87,8 @@ const PostContentType = Object.freeze({
87
87
 
88
88
  function getVersion() {
89
89
  try {
90
- // the string ''v7.0.2-esm'' should be replaced by actual value by @rollup/plugin-replace
91
- return 'v7.0.2-esm';
90
+ // the string ''v7.1.0-esm'' should be replaced by actual value by @rollup/plugin-replace
91
+ return 'v7.1.0-esm';
92
92
  }
93
93
  catch (error) {
94
94
  return '__dev__';
@@ -106,6 +106,7 @@ const SECOND$1 = 1000;
106
106
  const MINUTE = 60 * SECOND$1;
107
107
  const HOUR = 60 * MINUTE;
108
108
  const DAY = 24 * HOUR;
109
+ const WEEK = 7 * DAY;
109
110
  const YEAR = 365 * DAY;
110
111
  const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
111
112
 
@@ -527,6 +528,8 @@ const idResolvers = {
527
528
  advertiser: ({ advertiserId }) => advertiserId,
528
529
  pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
529
530
  pinTarget: ({ targetId }) => targetId,
531
+ notificationTrayItem: ({ _id }) => _id,
532
+ notificationTraySeen: ({ userId }) => userId,
530
533
  };
531
534
  /**
532
535
  * Retrieve the id resolver matching a domain name
@@ -578,6 +581,7 @@ const PAYLOAD2MODEL = {
578
581
  advertisers: 'advertiser',
579
582
  pinTargets: 'pinTarget',
580
583
  pins: 'pin',
584
+ notificationTrayItems: 'notificationTrayItem',
581
585
  };
582
586
  /** hidden */
583
587
  const isOutdated = (prevData, nextData) => {
@@ -22085,6 +22089,65 @@ const pinnedPostLinkedObject = (pinnedPost) => {
22085
22089
  } });
22086
22090
  };
22087
22091
 
22092
+ /* begin_public_function
22093
+ id: notificationTrayItem.markSeen
22094
+ */
22095
+ /**
22096
+ * ```js
22097
+ * import { notificationTray } from '@amityco/ts-sdk'
22098
+ * const updated = await notificationTray.markItemsSeen()
22099
+ * ```
22100
+ *
22101
+ * Updates an {@link Amity.NotificationItemSeen}
22102
+ *
22103
+ * @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
22104
+ * @returns the updated {@link Amity.NotificationItemSeen} object
22105
+ *
22106
+ * @category NotificationItemSeen API
22107
+ * @async
22108
+ */
22109
+ const markItemsSeen = async (patch) => {
22110
+ const client = getActiveClient();
22111
+ client.log('notificationTray/markItemsSeen', {});
22112
+ const { data: payload } = await client.http.put(`api/v1/notification-tray/items/seen`, {
22113
+ patch,
22114
+ });
22115
+ const updatedData = patch.trayItems
22116
+ .map(patchItem => {
22117
+ var _a;
22118
+ const cacheData = (_a = pullFromCache([
22119
+ 'notificationTraySeen',
22120
+ 'get',
22121
+ patchItem.id,
22122
+ ])) === null || _a === void 0 ? void 0 : _a.data;
22123
+ if (!cacheData)
22124
+ return;
22125
+ const data = Object.assign(Object.assign({}, cacheData), payload);
22126
+ if (client.cache) {
22127
+ const cachedAt = Date.now();
22128
+ pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
22129
+ }
22130
+ return data;
22131
+ })
22132
+ .filter(Boolean);
22133
+ fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
22134
+ };
22135
+ /* end_public_function */
22136
+
22137
+ const notificationTrayLinkedObject = (noti) => {
22138
+ return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccuredAt, isRecent: new Date(noti.lastOccuredAt).getTime() >= Date.now() - WEEK, users: noti.actors
22139
+ .map(userId => { var _a; return (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data; })
22140
+ .filter(isNonNullable)
22141
+ .map(user => userLinkedObject(user)), markRead: () => markItemsSeen({
22142
+ trayItems: [
22143
+ {
22144
+ id: noti._id,
22145
+ lastSeenAt: noti.lastSeenAt,
22146
+ },
22147
+ ],
22148
+ }) });
22149
+ };
22150
+
22088
22151
  const LinkedObject = {
22089
22152
  ad: adLinkedObject,
22090
22153
  comment: commentLinkedObject,
@@ -22098,6 +22161,7 @@ const LinkedObject = {
22098
22161
  reactor: reactorLinkedObject,
22099
22162
  channel: channelLinkedObject,
22100
22163
  pinnedPost: pinnedPostLinkedObject,
22164
+ notificationTray: notificationTrayLinkedObject,
22101
22165
  };
22102
22166
 
22103
22167
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -25868,7 +25932,7 @@ const getUserUnread = (callback) => {
25868
25932
  };
25869
25933
  };
25870
25934
 
25871
- var index$l = /*#__PURE__*/Object.freeze({
25935
+ var index$m = /*#__PURE__*/Object.freeze({
25872
25936
  __proto__: null,
25873
25937
  getActiveClient: getActiveClient,
25874
25938
  getActiveUser: getActiveUser,
@@ -27075,7 +27139,7 @@ const getMyFollowInfo = (callback) => {
27075
27139
  };
27076
27140
  /* end_public_function */
27077
27141
 
27078
- var index$k = /*#__PURE__*/Object.freeze({
27142
+ var index$l = /*#__PURE__*/Object.freeze({
27079
27143
  __proto__: null,
27080
27144
  blockUser: blockUser,
27081
27145
  unBlockUser: unBlockUser,
@@ -28090,9 +28154,9 @@ var AmityUserSearchMatchType;
28090
28154
  AmityUserSearchMatchType["PARTIAL"] = "partial";
28091
28155
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
28092
28156
 
28093
- var index$j = /*#__PURE__*/Object.freeze({
28157
+ var index$k = /*#__PURE__*/Object.freeze({
28094
28158
  __proto__: null,
28095
- Relationship: index$k,
28159
+ Relationship: index$l,
28096
28160
  getUserByIds: getUserByIds,
28097
28161
  updateUser: updateUser,
28098
28162
  flagUser: flagUser,
@@ -28356,7 +28420,7 @@ const uploadImage = async (formData, onProgress) => {
28356
28420
  };
28357
28421
  /* end_public_function */
28358
28422
 
28359
- var index$i = /*#__PURE__*/Object.freeze({
28423
+ var index$j = /*#__PURE__*/Object.freeze({
28360
28424
  __proto__: null,
28361
28425
  getFile: getFile,
28362
28426
  uploadFile: uploadFile,
@@ -28832,6 +28896,8 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
28832
28896
  referenceType,
28833
28897
  reactionName,
28834
28898
  });
28899
+ if (!['post', 'comment', 'story', 'message'].includes(referenceType))
28900
+ throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
28835
28901
  const { data } = await client.http.post('/api/v2/reactions', {
28836
28902
  referenceId,
28837
28903
  referenceType,
@@ -28951,6 +29017,8 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
28951
29017
  referenceType,
28952
29018
  reactionName,
28953
29019
  });
29020
+ if (!['post', 'comment', 'story', 'message'].includes(referenceType))
29021
+ throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
28954
29022
  const { data } = await client.http.delete(`/api/v2/reactions`, {
28955
29023
  data: {
28956
29024
  referenceId,
@@ -29876,6 +29944,8 @@ class ReactionPaginationController extends PaginationController {
29876
29944
  const client = getActiveClient();
29877
29945
  client.log('reaction/queryReactions', queryParams);
29878
29946
  const path = '/api/v3/reactions';
29947
+ if (!['post', 'comment', 'story', 'message'].includes(params.referenceType))
29948
+ throw new ASCApiError('The reference type is not valid. It should be one of post, comment, story, or message', 400000 /* Amity.ServerError.BAD_REQUEST */, "error" /* Amity.ErrorLevel.ERROR */);
29879
29949
  const { data: queryResponse } = await this.http.get(path, {
29880
29950
  params: Object.assign(Object.assign({}, params), { referenceVersion: REFERENCE_API_V5, // Need to put this param to make it can query reaction for message in sub-channel
29881
29951
  options }),
@@ -30162,7 +30232,7 @@ const getReactions = (params, callback, config) => {
30162
30232
  };
30163
30233
  /* end_public_function */
30164
30234
 
30165
- var index$h = /*#__PURE__*/Object.freeze({
30235
+ var index$i = /*#__PURE__*/Object.freeze({
30166
30236
  __proto__: null,
30167
30237
  addReaction: addReaction,
30168
30238
  removeReaction: removeReaction,
@@ -31978,7 +32048,7 @@ const getMessages = (params, callback, config) => {
31978
32048
  };
31979
32049
  /* end_public_function */
31980
32050
 
31981
- var index$g = /*#__PURE__*/Object.freeze({
32051
+ var index$h = /*#__PURE__*/Object.freeze({
31982
32052
  __proto__: null,
31983
32053
  createMessage: createMessage,
31984
32054
  updateMessage: updateMessage,
@@ -32504,7 +32574,7 @@ const stopMessageReceiptSync = (subChannelId) => {
32504
32574
  };
32505
32575
  /* end_public_function */
32506
32576
 
32507
- var index$f = /*#__PURE__*/Object.freeze({
32577
+ var index$g = /*#__PURE__*/Object.freeze({
32508
32578
  __proto__: null,
32509
32579
  getSubChannelByIds: getSubChannels$1,
32510
32580
  createSubChannel: createSubChannel,
@@ -33681,7 +33751,7 @@ const searchMembers$1 = (params, callback, config) => {
33681
33751
  };
33682
33752
  /* end_public_function */
33683
33753
 
33684
- var index$e = /*#__PURE__*/Object.freeze({
33754
+ var index$f = /*#__PURE__*/Object.freeze({
33685
33755
  __proto__: null,
33686
33756
  addMembers: addMembers$1,
33687
33757
  removeMembers: removeMembers$1,
@@ -33884,7 +33954,7 @@ const unmuteMembers = async (channelId, userIds) => {
33884
33954
  };
33885
33955
  /* end_public_function */
33886
33956
 
33887
- var index$d = /*#__PURE__*/Object.freeze({
33957
+ var index$e = /*#__PURE__*/Object.freeze({
33888
33958
  __proto__: null,
33889
33959
  addRole: addRole,
33890
33960
  removeRole: removeRole,
@@ -33894,10 +33964,10 @@ var index$d = /*#__PURE__*/Object.freeze({
33894
33964
  unmuteMembers: unmuteMembers
33895
33965
  });
33896
33966
 
33897
- var index$c = /*#__PURE__*/Object.freeze({
33967
+ var index$d = /*#__PURE__*/Object.freeze({
33898
33968
  __proto__: null,
33899
- Membership: index$e,
33900
- Moderation: index$d,
33969
+ Membership: index$f,
33970
+ Moderation: index$e,
33901
33971
  getChannelByIds: getChannelByIds$1,
33902
33972
  createChannel: createChannel,
33903
33973
  updateChannel: updateChannel,
@@ -35276,7 +35346,7 @@ const searchMembers = (params, callback, config) => {
35276
35346
  };
35277
35347
  /* end_public_function */
35278
35348
 
35279
- var index$b = /*#__PURE__*/Object.freeze({
35349
+ var index$c = /*#__PURE__*/Object.freeze({
35280
35350
  __proto__: null,
35281
35351
  addMembers: addMembers,
35282
35352
  removeMembers: removeMembers,
@@ -36301,7 +36371,7 @@ const unbanMembers = async (communityId, userIds) => {
36301
36371
  };
36302
36372
  /* end_public_function */
36303
36373
 
36304
- var index$a = /*#__PURE__*/Object.freeze({
36374
+ var index$b = /*#__PURE__*/Object.freeze({
36305
36375
  __proto__: null,
36306
36376
  addRoles: addRoles,
36307
36377
  removeRoles: removeRoles,
@@ -36309,10 +36379,10 @@ var index$a = /*#__PURE__*/Object.freeze({
36309
36379
  unbanMembers: unbanMembers
36310
36380
  });
36311
36381
 
36312
- var index$9 = /*#__PURE__*/Object.freeze({
36382
+ var index$a = /*#__PURE__*/Object.freeze({
36313
36383
  __proto__: null,
36314
- Moderation: index$a,
36315
- Membership: index$b,
36384
+ Moderation: index$b,
36385
+ Membership: index$c,
36316
36386
  getCommunityByIds: getCommunities$1,
36317
36387
  createCommunity: createCommunity,
36318
36388
  updateCommunity: updateCommunity,
@@ -36545,7 +36615,7 @@ const getCategories = (params, callback, config) => {
36545
36615
  };
36546
36616
  /* end_public_function */
36547
36617
 
36548
- var index$8 = /*#__PURE__*/Object.freeze({
36618
+ var index$9 = /*#__PURE__*/Object.freeze({
36549
36619
  __proto__: null,
36550
36620
  getCategory: getCategory,
36551
36621
  getCategories: getCategories
@@ -36713,7 +36783,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
36713
36783
  : undefined;
36714
36784
  };
36715
36785
 
36716
- var index$7 = /*#__PURE__*/Object.freeze({
36786
+ var index$8 = /*#__PURE__*/Object.freeze({
36717
36787
  __proto__: null,
36718
36788
  queryGlobalFeed: queryGlobalFeed,
36719
36789
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -38028,7 +38098,7 @@ const getComments = (params, callback, config) => {
38028
38098
  };
38029
38099
  /* end_public_function */
38030
38100
 
38031
- var index$6 = /*#__PURE__*/Object.freeze({
38101
+ var index$7 = /*#__PURE__*/Object.freeze({
38032
38102
  __proto__: null,
38033
38103
  getCommentByIds: getCommentByIds,
38034
38104
  createComment: createComment,
@@ -39035,7 +39105,7 @@ const semanticSearchPosts = (params, callback, config) => {
39035
39105
  };
39036
39106
  };
39037
39107
 
39038
- var index$5 = /*#__PURE__*/Object.freeze({
39108
+ var index$6 = /*#__PURE__*/Object.freeze({
39039
39109
  __proto__: null,
39040
39110
  getPostByIds: getPostByIds,
39041
39111
  createPost: createPost,
@@ -39569,7 +39639,7 @@ const getStreams = (params, callback, config) => {
39569
39639
  };
39570
39640
  };
39571
39641
 
39572
- var index$4 = /*#__PURE__*/Object.freeze({
39642
+ var index$5 = /*#__PURE__*/Object.freeze({
39573
39643
  __proto__: null,
39574
39644
  createStream: createStream,
39575
39645
  updateStream: updateStream,
@@ -39856,7 +39926,7 @@ const getPoll = (pollId, callback) => {
39856
39926
  };
39857
39927
  /* end_public_function */
39858
39928
 
39859
- var index$3 = /*#__PURE__*/Object.freeze({
39929
+ var index$4 = /*#__PURE__*/Object.freeze({
39860
39930
  __proto__: null,
39861
39931
  createPoll: createPoll,
39862
39932
  closePoll: closePoll,
@@ -40227,7 +40297,7 @@ const getPlayer = async (parameters) => {
40227
40297
  return video;
40228
40298
  };
40229
40299
 
40230
- var index$2 = /*#__PURE__*/Object.freeze({
40300
+ var index$3 = /*#__PURE__*/Object.freeze({
40231
40301
  __proto__: null,
40232
40302
  getPlayer: getPlayer
40233
40303
  });
@@ -41400,7 +41470,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
41400
41470
  };
41401
41471
  };
41402
41472
 
41403
- var index$1 = /*#__PURE__*/Object.freeze({
41473
+ var index$2 = /*#__PURE__*/Object.freeze({
41404
41474
  __proto__: null,
41405
41475
  createImageStory: createImageStory,
41406
41476
  createVideoStory: createVideoStory,
@@ -41437,7 +41507,7 @@ const getNetworkAds = async () => {
41437
41507
  };
41438
41508
  };
41439
41509
 
41440
- var index = /*#__PURE__*/Object.freeze({
41510
+ var index$1 = /*#__PURE__*/Object.freeze({
41441
41511
  __proto__: null,
41442
41512
  getNetworkAds: getNetworkAds
41443
41513
  });
@@ -41464,4 +41534,314 @@ const createUserToken = async (apiKey, apiRegion, params) => {
41464
41534
  return { accessToken: data.accessToken };
41465
41535
  };
41466
41536
 
41467
- export { API_REGIONS, index as AdRepository, index$8 as CategoryRepository, index$c as ChannelRepository, index$l as Client, index$6 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$9 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$7 as FeedRepository, FileAccessTypeEnum, index$i as FileRepository, FileType, index$2 as LiveStreamPlayer, MessageContentType, index$g as MessageRepository, index$3 as PollRepository, PostContentType, index$5 as PostRepository, index$h as ReactionRepository, index$1 as StoryRepository, index$4 as StreamRepository, index$f as SubChannelRepository, SubscriptionLevels, index$j as UserRepository, 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, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, 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 };
41537
+ /* begin_public_function
41538
+ id: notificationTray.getNotificationTraySeen
41539
+ */
41540
+ /**
41541
+ * ```js
41542
+ * import { notificationTray } from '@amityco/ts-sdk'
41543
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen()
41544
+ * ```
41545
+ *
41546
+ *
41547
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
41548
+ *
41549
+ * @category NotificationTray API
41550
+ * @async
41551
+ * */
41552
+ const getNotificationTraySeen$1 = async () => {
41553
+ const client = getActiveClient();
41554
+ client.log('notificationTray/getNotificationTraySeen', {});
41555
+ const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
41556
+ const cachedAt = client.cache && Date.now();
41557
+ if (client.cache) {
41558
+ const cacheKey = ['notificationTraySeen', 'get', client.userId];
41559
+ pushToCache(cacheKey, {
41560
+ userId: client.userId,
41561
+ lastTraySeenAt: payload.lastTraySeenAt,
41562
+ lastTrayOccuredAt: payload.lastTrayOccuredAt,
41563
+ });
41564
+ }
41565
+ return {
41566
+ data: {
41567
+ userId: client.userId,
41568
+ lastTraySeenAt: payload.lastTraySeenAt,
41569
+ lastTrayOccuredAt: payload.lastTrayOccuredAt,
41570
+ isSeen: payload.lastTraySeenAt > payload.lastTrayOccuredAt,
41571
+ },
41572
+ cachedAt,
41573
+ };
41574
+ };
41575
+ /* end_public_function */
41576
+ /**
41577
+ * ```js
41578
+ * import { notificationTray } from '@amityco/ts-sdk'
41579
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen.locally()
41580
+ * ```
41581
+ *
41582
+ * Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
41583
+ *
41584
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
41585
+ *
41586
+ * @category NotificationTray API
41587
+ * @async
41588
+ * */
41589
+ getNotificationTraySeen$1.locally = () => {
41590
+ var _a;
41591
+ const client = getActiveClient();
41592
+ client.log('notificationTray/getNotificationTraySeen.locally', {});
41593
+ if (!client.cache)
41594
+ return;
41595
+ const queryKey = ['notificationTraySeen', 'get'];
41596
+ const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
41597
+ if (!(data === null || data === void 0 ? void 0 : data.notificationTraySeen))
41598
+ return;
41599
+ return { data: data.notificationTraySeen, cachedAt };
41600
+ };
41601
+
41602
+ /**
41603
+ * ```js
41604
+ * import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
41605
+ * const dispose = onNotificationTraySeenUpdated(data => {
41606
+ * // ...
41607
+ * })
41608
+ * ```
41609
+ *
41610
+ * Fired when an {@link Amity.NotificationTraySeen} has been updated
41611
+ *
41612
+ * @param callback The function to call when the event was fired
41613
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
41614
+ *
41615
+ * @category NotificationTraySeen Events
41616
+ */
41617
+ const onNotificationTraySeenUpdated = (callback) => {
41618
+ const client = getActiveClient();
41619
+ const disposers = [
41620
+ createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
41621
+ ];
41622
+ return () => {
41623
+ disposers.forEach(fn => fn());
41624
+ };
41625
+ };
41626
+
41627
+ /* begin_public_function
41628
+ id: notificationTraySeen.get
41629
+ */
41630
+ /**
41631
+ * ```js
41632
+ * import { getNotificationTraySeen } from '@amityco/ts-sdk';
41633
+ *
41634
+ * let notificationTraySeen;
41635
+ *
41636
+ * const unsubscribe = getNotificationTraySeen(userId, response => {
41637
+ * notificationTraySeen = response.data;
41638
+ * });
41639
+ * ```
41640
+ *
41641
+ * Observe all mutation on a given {@link Amity.NotificationTraySeen}
41642
+ *
41643
+ * @param userId the ID of the user to observe
41644
+ * @param callback the function to call when new data are available
41645
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
41646
+ *
41647
+ * @category NotificationTraySeen Live Object
41648
+ */
41649
+ const getNotificationTraySeen = (callback) => {
41650
+ const responder = (snapshot) => {
41651
+ const { data } = snapshot;
41652
+ callback(Object.assign(Object.assign({}, snapshot), { data }));
41653
+ };
41654
+ const { userId } = getActiveUser();
41655
+ return liveObject(userId, responder, 'userId', getNotificationTraySeen$1, [
41656
+ onNotificationTraySeenUpdated,
41657
+ ]);
41658
+ };
41659
+ /* end_public_function */
41660
+
41661
+ /**
41662
+ * TODO: handle cache receive cache option, and cache policy
41663
+ * TODO: check if querybyIds is supported
41664
+ */
41665
+ class NotificationTrayItemsPaginationController extends PaginationController {
41666
+ async getRequest(queryParams, token) {
41667
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
41668
+ const options = token ? { token } : { limit };
41669
+ const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
41670
+ params: Object.assign(Object.assign({}, params), { options }),
41671
+ });
41672
+ return queryResponse;
41673
+ }
41674
+ }
41675
+
41676
+ class NotificationTrayItemsQuerystreamController extends QueryStreamController {
41677
+ constructor(query, cacheKey, notifyChange, preparePayload) {
41678
+ super(query, cacheKey);
41679
+ this.notifyChange = notifyChange;
41680
+ this.preparePayload = preparePayload;
41681
+ }
41682
+ async saveToMainDB(response) {
41683
+ const processedPayload = await this.preparePayload(response);
41684
+ const client = getActiveClient();
41685
+ const cachedAt = client.cache && Date.now();
41686
+ if (client.cache) {
41687
+ ingestInCache(processedPayload, { cachedAt });
41688
+ }
41689
+ }
41690
+ appendToQueryStream(response, direction, refresh = false) {
41691
+ var _a, _b;
41692
+ if (refresh) {
41693
+ pushToCache(this.cacheKey, {
41694
+ data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
41695
+ });
41696
+ }
41697
+ else {
41698
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41699
+ const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
41700
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
41701
+ ...new Set([
41702
+ ...notifications,
41703
+ ...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
41704
+ ]),
41705
+ ] }));
41706
+ }
41707
+ }
41708
+ }
41709
+
41710
+ const prepareNotificationTrayItemsPayload = (rawPayload) => {
41711
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
41712
+ return Object.assign(Object.assign({}, rawPayload), { users });
41713
+ };
41714
+
41715
+ class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
41716
+ constructor(query, callback) {
41717
+ const queryStreamId = hash(query);
41718
+ const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
41719
+ const paginationController = new NotificationTrayItemsPaginationController(query);
41720
+ super(paginationController, queryStreamId, cacheKey, callback);
41721
+ this.query = query;
41722
+ this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
41723
+ this.callback = callback.bind(this);
41724
+ this.loadPage({ initial: true });
41725
+ }
41726
+ setup() {
41727
+ var _a;
41728
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41729
+ if (!collection) {
41730
+ pushToCache(this.cacheKey, {
41731
+ data: [],
41732
+ params: {},
41733
+ });
41734
+ }
41735
+ }
41736
+ async persistModel(queryPayload) {
41737
+ await this.queryStreamController.saveToMainDB(queryPayload);
41738
+ }
41739
+ persistQueryStream({ response, direction, refresh, }) {
41740
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
41741
+ }
41742
+ // eslint-disable-next-line class-methods-use-this
41743
+ startSubscription() {
41744
+ return [];
41745
+ }
41746
+ notifyChange({ origin, loading, error }) {
41747
+ var _a, _b;
41748
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41749
+ if (!collection)
41750
+ return;
41751
+ const data = ((_b = collection.data
41752
+ .map(id => pullFromCache(['notificationTrayItem', 'get', id]))
41753
+ .filter(isNonNullable)
41754
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
41755
+ if (!this.shouldNotify(data) && origin === 'event')
41756
+ return;
41757
+ this.callback({
41758
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
41759
+ data,
41760
+ hasNextPage: !!this.paginationController.getNextToken(),
41761
+ loading,
41762
+ error,
41763
+ });
41764
+ }
41765
+ }
41766
+
41767
+ /**
41768
+ * Get notification tray items for a notification tray page
41769
+ *
41770
+ * @param params the limit query parameters
41771
+ * @param callback the callback to be called when the notification tray items are updated
41772
+ * @returns items in the notification tray
41773
+ *
41774
+ * @category Notification tray items Live Collection
41775
+ *
41776
+ */
41777
+ const getNotificationTrayItems = (params, callback, config) => {
41778
+ const { log, cache } = getActiveClient();
41779
+ if (!cache) {
41780
+ console.log(ENABLE_CACHE_MESSAGE);
41781
+ }
41782
+ const timestamp = Date.now();
41783
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
41784
+ const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
41785
+ const disposers = notiTrayItemsLiveCollection.startSubscription();
41786
+ const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
41787
+ disposers.push(() => dropFromCache(cacheKey));
41788
+ return () => {
41789
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
41790
+ disposers.forEach(fn => fn());
41791
+ };
41792
+ };
41793
+
41794
+ /* begin_public_function
41795
+ id: notificationTray.markSeen
41796
+ */
41797
+ /**
41798
+ * ```js
41799
+ * import { notificationTray } from '@amityco/ts-sdk'
41800
+ * const updated = await notificationTray.markTraySeen({
41801
+ * lastSeenAt: Amity.timestamp,
41802
+ * })
41803
+ * ```
41804
+ *
41805
+ * Updates an {@link Amity.NotificationTraySeen}
41806
+ *
41807
+ * @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
41808
+ * @param lastSeenAt The patch data to apply
41809
+ * @returns the updated {@link Amity.NotificationTraySeen} object
41810
+ *
41811
+ * @category Post API
41812
+ * @async
41813
+ */
41814
+ const markTraySeen = async (lastSeenAt) => {
41815
+ var _a;
41816
+ const client = getActiveClient();
41817
+ client.log('notificationTray/markTraySeen', {});
41818
+ const { data: payload } = await client.http.put(`api/v1/notification-tray/tray/seen`, {
41819
+ lastSeenAt,
41820
+ });
41821
+ const cacheData = (_a = pullFromCache([
41822
+ 'notificationTraySeen',
41823
+ 'get',
41824
+ ])) === null || _a === void 0 ? void 0 : _a.data;
41825
+ const data = Object.assign({ userId: client.userId }, payload);
41826
+ const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
41827
+ const cachedAt = client.cache && Date.now();
41828
+ if (client.cache)
41829
+ pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
41830
+ fireEvent('local.notificationTraySeen.updated', data);
41831
+ return {
41832
+ data: payload,
41833
+ cachedAt,
41834
+ };
41835
+ };
41836
+ /* end_public_function */
41837
+
41838
+ var index = /*#__PURE__*/Object.freeze({
41839
+ __proto__: null,
41840
+ getNotificationTraySeen: getNotificationTraySeen,
41841
+ getNotificationTrayItems: getNotificationTrayItems,
41842
+ markItemsSeen: markItemsSeen,
41843
+ markTraySeen: markTraySeen,
41844
+ onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
41845
+ });
41846
+
41847
+ export { API_REGIONS, index$1 as AdRepository, index$9 as CategoryRepository, index$d as ChannelRepository, index$m as Client, index$7 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$a as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$8 as FeedRepository, FileAccessTypeEnum, index$j as FileRepository, FileType, index$3 as LiveStreamPlayer, MessageContentType, index$h as MessageRepository, index$4 as PollRepository, PostContentType, index$6 as PostRepository, index$i as ReactionRepository, index$2 as StoryRepository, index$5 as StreamRepository, index$g as SubChannelRepository, SubscriptionLevels, index$k as UserRepository, 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, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index 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 };