@amityco/ts-sdk 7.1.1-5d7c3fd0.0 → 7.1.1-611ceb49.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 (87) 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/client.d.ts +0 -1
  8. package/dist/@types/domains/client.d.ts.map +1 -1
  9. package/dist/@types/domains/notification.d.ts +81 -0
  10. package/dist/@types/domains/notification.d.ts.map +1 -0
  11. package/dist/client/api/createClient.d.ts +0 -1
  12. package/dist/client/api/createClient.d.ts.map +1 -1
  13. package/dist/client/utils/endpoints.d.ts +0 -1
  14. package/dist/client/utils/endpoints.d.ts.map +1 -1
  15. package/dist/client/utils/setClientToken.d.ts.map +1 -1
  16. package/dist/core/events.d.ts +3 -3
  17. package/dist/core/events.d.ts.map +1 -1
  18. package/dist/core/model/idResolvers.d.ts.map +1 -1
  19. package/dist/core/model/index.d.ts.map +1 -1
  20. package/dist/index.cjs.js +425 -60
  21. package/dist/index.d.ts +1 -0
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.esm.js +408 -44
  24. package/dist/index.umd.js +4 -4
  25. package/dist/notificationTrayRepository/api/index.d.ts +3 -0
  26. package/dist/notificationTrayRepository/api/index.d.ts.map +1 -0
  27. package/dist/notificationTrayRepository/api/markNotificationItemsSeen.d.ts +16 -0
  28. package/dist/notificationTrayRepository/api/markNotificationItemsSeen.d.ts.map +1 -0
  29. package/dist/notificationTrayRepository/api/markNotificationTraySeen.d.ts +19 -0
  30. package/dist/notificationTrayRepository/api/markNotificationTraySeen.d.ts.map +1 -0
  31. package/dist/notificationTrayRepository/events/index.d.ts +2 -0
  32. package/dist/notificationTrayRepository/events/index.d.ts.map +1 -0
  33. package/dist/notificationTrayRepository/events/onNotificationTraySeenUpdated.d.ts +17 -0
  34. package/dist/notificationTrayRepository/events/onNotificationTraySeenUpdated.d.ts.map +1 -0
  35. package/dist/notificationTrayRepository/index.d.ts +4 -0
  36. package/dist/notificationTrayRepository/index.d.ts.map +1 -0
  37. package/dist/notificationTrayRepository/internalApi/getNotificationTraySeen.d.ts +30 -0
  38. package/dist/notificationTrayRepository/internalApi/getNotificationTraySeen.d.ts.map +1 -0
  39. package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +13 -0
  40. package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +1 -0
  41. package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +9 -0
  42. package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +1 -0
  43. package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +9 -0
  44. package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +1 -0
  45. package/dist/notificationTrayRepository/observers/getNotificationTrayItems.d.ts +12 -0
  46. package/dist/notificationTrayRepository/observers/getNotificationTrayItems.d.ts.map +1 -0
  47. package/dist/notificationTrayRepository/observers/getNotificationTraySeen.d.ts +21 -0
  48. package/dist/notificationTrayRepository/observers/getNotificationTraySeen.d.ts.map +1 -0
  49. package/dist/notificationTrayRepository/observers/index.d.ts +3 -0
  50. package/dist/notificationTrayRepository/observers/index.d.ts.map +1 -0
  51. package/dist/notificationTrayRepository/utils/prepareNotificationTrayItemsPayload.d.ts +2 -0
  52. package/dist/notificationTrayRepository/utils/prepareNotificationTrayItemsPayload.d.ts.map +1 -0
  53. package/dist/utils/linkedObject/index.d.ts +1 -0
  54. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  55. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +2 -0
  56. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -0
  57. package/package.json +1 -1
  58. package/src/@types/core/events.ts +5 -0
  59. package/src/@types/core/model.ts +6 -0
  60. package/src/@types/core/payload.ts +25 -0
  61. package/src/@types/domains/client.ts +0 -1
  62. package/src/@types/domains/notification.ts +90 -0
  63. package/src/client/api/createClient.ts +1 -4
  64. package/src/client/utils/endpoints.ts +0 -1
  65. package/src/client/utils/setClientToken.ts +0 -8
  66. package/src/core/model/idResolvers.ts +3 -0
  67. package/src/core/model/index.ts +2 -0
  68. package/src/fileRepository/api/uploadFile.ts +1 -1
  69. package/src/fileRepository/api/uploadImage.ts +1 -1
  70. package/src/fileRepository/api/uploadVideo.ts +1 -1
  71. package/src/index.ts +2 -0
  72. package/src/notificationTrayRepository/api/index.ts +2 -0
  73. package/src/notificationTrayRepository/api/markNotificationItemsSeen.ts +59 -0
  74. package/src/notificationTrayRepository/api/markNotificationTraySeen.ts +65 -0
  75. package/src/notificationTrayRepository/events/index.ts +1 -0
  76. package/src/notificationTrayRepository/events/onNotificationTraySeenUpdated.ts +36 -0
  77. package/src/notificationTrayRepository/index.ts +3 -0
  78. package/src/notificationTrayRepository/internalApi/getNotificationTraySeen.ts +81 -0
  79. package/src/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +96 -0
  80. package/src/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +31 -0
  81. package/src/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +68 -0
  82. package/src/notificationTrayRepository/observers/getNotificationTrayItems.ts +44 -0
  83. package/src/notificationTrayRepository/observers/getNotificationTraySeen.ts +43 -0
  84. package/src/notificationTrayRepository/observers/index.ts +2 -0
  85. package/src/notificationTrayRepository/utils/prepareNotificationTrayItemsPayload.ts +12 -0
  86. package/src/utils/linkedObject/index.ts +2 -0
  87. 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) => {
@@ -1561,7 +1565,6 @@ const API_REGIONS = {
1561
1565
  };
1562
1566
  const URLS = {
1563
1567
  http: 'https://apix.{region}.amity.co',
1564
- upload: 'https://upload.{region}.amity.co',
1565
1568
  mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
1566
1569
  };
1567
1570
  function computeUrl(type, region) {
@@ -5994,6 +5997,65 @@ const pinnedPostLinkedObject = (pinnedPost) => {
5994
5997
  } });
5995
5998
  };
5996
5999
 
6000
+ /* begin_public_function
6001
+ id: notificationTrayItem.markSeen
6002
+ */
6003
+ /**
6004
+ * ```js
6005
+ * import { NotificationTrayRepository } from '@amityco/ts-sdk'
6006
+ * const updated = await NotificationTrayRepository.markNotificationItemsSeen()
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 markNotificationItemsSeen = async (patch) => {
6018
+ const client = getActiveClient();
6019
+ client.log('notificationTray/markNotificationItemsSeen', {});
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: () => markNotificationItemsSeen({
6050
+ trayItems: [
6051
+ {
6052
+ id: noti._id,
6053
+ lastSeenAt: noti.lastSeenAt,
6054
+ },
6055
+ ],
6056
+ }) });
6057
+ };
6058
+
5997
6059
  const LinkedObject = {
5998
6060
  ad: adLinkedObject,
5999
6061
  comment: commentLinkedObject,
@@ -6007,6 +6069,7 @@ const LinkedObject = {
6007
6069
  reactor: reactorLinkedObject,
6008
6070
  channel: channelLinkedObject,
6009
6071
  pinnedPost: pinnedPostLinkedObject,
6072
+ notificationTray: notificationTrayLinkedObject,
6010
6073
  };
6011
6074
 
6012
6075
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -7607,12 +7670,6 @@ const setClientToken = async (params) => {
7607
7670
  isGlobalBanned: false,
7608
7671
  isUserDeleted: false,
7609
7672
  };
7610
- client.upload.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
7611
- client.upload.defaults.metadata = {
7612
- tokenExpiry: expiresAt,
7613
- isGlobalBanned: false,
7614
- isUserDeleted: false,
7615
- };
7616
7673
  // manually setup the token for ws transport
7617
7674
  if (client.ws)
7618
7675
  client.ws.io.opts.query = { token: accessToken };
@@ -9261,17 +9318,15 @@ const DEFAULT_DEBUG_SESSION = 'amity';
9261
9318
  * @category Client API
9262
9319
  * */
9263
9320
  const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, } = {}) => {
9264
- var _a, _b, _c;
9321
+ var _a, _b;
9265
9322
  const log = createLogger(debugSession);
9266
9323
  log('client/api/createClient', {
9267
9324
  apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
9268
9325
  apiRegion,
9269
9326
  });
9270
9327
  const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
9271
- const uploadEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.upload) !== null && _b !== void 0 ? _b : computeUrl('upload', apiRegion);
9272
- const mqttEndpoint = (_c = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _c !== void 0 ? _c : computeUrl('mqtt', apiRegion);
9328
+ const mqttEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _b !== void 0 ? _b : computeUrl('mqtt', apiRegion);
9273
9329
  const http = createHttpTransport(httpEndpoint);
9274
- const upload = createHttpTransport(uploadEndpoint);
9275
9330
  let ws;
9276
9331
  let mqtt;
9277
9332
  if (rteEnabled) {
@@ -9300,7 +9355,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
9300
9355
  http,
9301
9356
  ws,
9302
9357
  mqtt,
9303
- upload,
9304
9358
  emitter,
9305
9359
  /*
9306
9360
  * Session Components
@@ -9329,7 +9383,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
9329
9383
  return activeClient;
9330
9384
  setActiveClient(client);
9331
9385
  }
9332
- catch (_d) {
9386
+ catch (_c) {
9333
9387
  setActiveClient(client);
9334
9388
  }
9335
9389
  return client;
@@ -9786,7 +9840,7 @@ const getUserUnread = (callback) => {
9786
9840
  };
9787
9841
  };
9788
9842
 
9789
- var index$l = /*#__PURE__*/Object.freeze({
9843
+ var index$m = /*#__PURE__*/Object.freeze({
9790
9844
  __proto__: null,
9791
9845
  getActiveClient: getActiveClient,
9792
9846
  getActiveUser: getActiveUser,
@@ -10993,7 +11047,7 @@ const getMyFollowInfo = (callback) => {
10993
11047
  };
10994
11048
  /* end_public_function */
10995
11049
 
10996
- var index$k = /*#__PURE__*/Object.freeze({
11050
+ var index$l = /*#__PURE__*/Object.freeze({
10997
11051
  __proto__: null,
10998
11052
  blockUser: blockUser,
10999
11053
  unBlockUser: unBlockUser,
@@ -12008,9 +12062,9 @@ var AmityUserSearchMatchType;
12008
12062
  AmityUserSearchMatchType["PARTIAL"] = "partial";
12009
12063
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
12010
12064
 
12011
- var index$j = /*#__PURE__*/Object.freeze({
12065
+ var index$k = /*#__PURE__*/Object.freeze({
12012
12066
  __proto__: null,
12013
- Relationship: index$k,
12067
+ Relationship: index$l,
12014
12068
  getUserByIds: getUserByIds,
12015
12069
  updateUser: updateUser,
12016
12070
  flagUser: flagUser,
@@ -12118,7 +12172,7 @@ const uploadFile = async (formData, onProgress) => {
12118
12172
  const headers = 'getHeaders' in formData
12119
12173
  ? formData.getHeaders()
12120
12174
  : { 'content-type': 'multipart/form-data' };
12121
- const { data } = await client.upload.post('/api/v4/files', formData, {
12175
+ const { data } = await client.http.post('/api/v4/files', formData, {
12122
12176
  headers,
12123
12177
  onUploadProgress({ loaded, total = 100 }) {
12124
12178
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -12208,7 +12262,7 @@ const uploadVideo = async (formData, feedType, onProgress) => {
12208
12262
  const headers = 'getHeaders' in formData
12209
12263
  ? formData.getHeaders()
12210
12264
  : { 'content-type': 'multipart/form-data' };
12211
- const { data } = await client.upload.post('/api/v4/videos', formData, {
12265
+ const { data } = await client.http.post('/api/v4/videos', formData, {
12212
12266
  headers,
12213
12267
  onUploadProgress({ loaded, total = 100 }) {
12214
12268
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -12256,7 +12310,7 @@ const uploadImage = async (formData, onProgress) => {
12256
12310
  const headers = 'getHeaders' in formData
12257
12311
  ? formData.getHeaders()
12258
12312
  : { 'content-type': 'multipart/form-data' };
12259
- const { data } = await client.upload.post('/api/v4/images', formData, {
12313
+ const { data } = await client.http.post('/api/v4/images', formData, {
12260
12314
  headers,
12261
12315
  onUploadProgress({ loaded, total = 100 }) {
12262
12316
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -12274,7 +12328,7 @@ const uploadImage = async (formData, onProgress) => {
12274
12328
  };
12275
12329
  /* end_public_function */
12276
12330
 
12277
- var index$i = /*#__PURE__*/Object.freeze({
12331
+ var index$j = /*#__PURE__*/Object.freeze({
12278
12332
  __proto__: null,
12279
12333
  getFile: getFile,
12280
12334
  uploadFile: uploadFile,
@@ -14086,7 +14140,7 @@ const getReactions = (params, callback, config) => {
14086
14140
  };
14087
14141
  /* end_public_function */
14088
14142
 
14089
- var index$h = /*#__PURE__*/Object.freeze({
14143
+ var index$i = /*#__PURE__*/Object.freeze({
14090
14144
  __proto__: null,
14091
14145
  addReaction: addReaction,
14092
14146
  removeReaction: removeReaction,
@@ -15902,7 +15956,7 @@ const getMessages = (params, callback, config) => {
15902
15956
  };
15903
15957
  /* end_public_function */
15904
15958
 
15905
- var index$g = /*#__PURE__*/Object.freeze({
15959
+ var index$h = /*#__PURE__*/Object.freeze({
15906
15960
  __proto__: null,
15907
15961
  createMessage: createMessage,
15908
15962
  updateMessage: updateMessage,
@@ -16428,7 +16482,7 @@ const stopMessageReceiptSync = (subChannelId) => {
16428
16482
  };
16429
16483
  /* end_public_function */
16430
16484
 
16431
- var index$f = /*#__PURE__*/Object.freeze({
16485
+ var index$g = /*#__PURE__*/Object.freeze({
16432
16486
  __proto__: null,
16433
16487
  getSubChannelByIds: getSubChannels$1,
16434
16488
  createSubChannel: createSubChannel,
@@ -17605,7 +17659,7 @@ const searchMembers$1 = (params, callback, config) => {
17605
17659
  };
17606
17660
  /* end_public_function */
17607
17661
 
17608
- var index$e = /*#__PURE__*/Object.freeze({
17662
+ var index$f = /*#__PURE__*/Object.freeze({
17609
17663
  __proto__: null,
17610
17664
  addMembers: addMembers$1,
17611
17665
  removeMembers: removeMembers$1,
@@ -17808,7 +17862,7 @@ const unmuteMembers = async (channelId, userIds) => {
17808
17862
  };
17809
17863
  /* end_public_function */
17810
17864
 
17811
- var index$d = /*#__PURE__*/Object.freeze({
17865
+ var index$e = /*#__PURE__*/Object.freeze({
17812
17866
  __proto__: null,
17813
17867
  addRole: addRole,
17814
17868
  removeRole: removeRole,
@@ -17818,10 +17872,10 @@ var index$d = /*#__PURE__*/Object.freeze({
17818
17872
  unmuteMembers: unmuteMembers
17819
17873
  });
17820
17874
 
17821
- var index$c = /*#__PURE__*/Object.freeze({
17875
+ var index$d = /*#__PURE__*/Object.freeze({
17822
17876
  __proto__: null,
17823
- Membership: index$e,
17824
- Moderation: index$d,
17877
+ Membership: index$f,
17878
+ Moderation: index$e,
17825
17879
  getChannelByIds: getChannelByIds$1,
17826
17880
  createChannel: createChannel,
17827
17881
  updateChannel: updateChannel,
@@ -19200,7 +19254,7 @@ const searchMembers = (params, callback, config) => {
19200
19254
  };
19201
19255
  /* end_public_function */
19202
19256
 
19203
- var index$b = /*#__PURE__*/Object.freeze({
19257
+ var index$c = /*#__PURE__*/Object.freeze({
19204
19258
  __proto__: null,
19205
19259
  addMembers: addMembers,
19206
19260
  removeMembers: removeMembers,
@@ -20225,7 +20279,7 @@ const unbanMembers = async (communityId, userIds) => {
20225
20279
  };
20226
20280
  /* end_public_function */
20227
20281
 
20228
- var index$a = /*#__PURE__*/Object.freeze({
20282
+ var index$b = /*#__PURE__*/Object.freeze({
20229
20283
  __proto__: null,
20230
20284
  addRoles: addRoles,
20231
20285
  removeRoles: removeRoles,
@@ -20233,10 +20287,10 @@ var index$a = /*#__PURE__*/Object.freeze({
20233
20287
  unbanMembers: unbanMembers
20234
20288
  });
20235
20289
 
20236
- var index$9 = /*#__PURE__*/Object.freeze({
20290
+ var index$a = /*#__PURE__*/Object.freeze({
20237
20291
  __proto__: null,
20238
- Moderation: index$a,
20239
- Membership: index$b,
20292
+ Moderation: index$b,
20293
+ Membership: index$c,
20240
20294
  getCommunityByIds: getCommunities$1,
20241
20295
  createCommunity: createCommunity,
20242
20296
  updateCommunity: updateCommunity,
@@ -20469,7 +20523,7 @@ const getCategories = (params, callback, config) => {
20469
20523
  };
20470
20524
  /* end_public_function */
20471
20525
 
20472
- var index$8 = /*#__PURE__*/Object.freeze({
20526
+ var index$9 = /*#__PURE__*/Object.freeze({
20473
20527
  __proto__: null,
20474
20528
  getCategory: getCategory,
20475
20529
  getCategories: getCategories
@@ -20637,7 +20691,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
20637
20691
  : undefined;
20638
20692
  };
20639
20693
 
20640
- var index$7 = /*#__PURE__*/Object.freeze({
20694
+ var index$8 = /*#__PURE__*/Object.freeze({
20641
20695
  __proto__: null,
20642
20696
  queryGlobalFeed: queryGlobalFeed,
20643
20697
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -21952,7 +22006,7 @@ const getComments = (params, callback, config) => {
21952
22006
  };
21953
22007
  /* end_public_function */
21954
22008
 
21955
- var index$6 = /*#__PURE__*/Object.freeze({
22009
+ var index$7 = /*#__PURE__*/Object.freeze({
21956
22010
  __proto__: null,
21957
22011
  getCommentByIds: getCommentByIds,
21958
22012
  createComment: createComment,
@@ -22959,7 +23013,7 @@ const semanticSearchPosts = (params, callback, config) => {
22959
23013
  };
22960
23014
  };
22961
23015
 
22962
- var index$5 = /*#__PURE__*/Object.freeze({
23016
+ var index$6 = /*#__PURE__*/Object.freeze({
22963
23017
  __proto__: null,
22964
23018
  getPostByIds: getPostByIds,
22965
23019
  createPost: createPost,
@@ -23493,7 +23547,7 @@ const getStreams = (params, callback, config) => {
23493
23547
  };
23494
23548
  };
23495
23549
 
23496
- var index$4 = /*#__PURE__*/Object.freeze({
23550
+ var index$5 = /*#__PURE__*/Object.freeze({
23497
23551
  __proto__: null,
23498
23552
  createStream: createStream,
23499
23553
  updateStream: updateStream,
@@ -23780,7 +23834,7 @@ const getPoll = (pollId, callback) => {
23780
23834
  };
23781
23835
  /* end_public_function */
23782
23836
 
23783
- var index$3 = /*#__PURE__*/Object.freeze({
23837
+ var index$4 = /*#__PURE__*/Object.freeze({
23784
23838
  __proto__: null,
23785
23839
  createPoll: createPoll,
23786
23840
  closePoll: closePoll,
@@ -24151,7 +24205,7 @@ const getPlayer = async (parameters) => {
24151
24205
  return video;
24152
24206
  };
24153
24207
 
24154
- var index$2 = /*#__PURE__*/Object.freeze({
24208
+ var index$3 = /*#__PURE__*/Object.freeze({
24155
24209
  __proto__: null,
24156
24210
  getPlayer: getPlayer
24157
24211
  });
@@ -25324,7 +25378,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
25324
25378
  };
25325
25379
  };
25326
25380
 
25327
- var index$1 = /*#__PURE__*/Object.freeze({
25381
+ var index$2 = /*#__PURE__*/Object.freeze({
25328
25382
  __proto__: null,
25329
25383
  createImageStory: createImageStory,
25330
25384
  createVideoStory: createVideoStory,
@@ -25361,7 +25415,7 @@ const getNetworkAds = async () => {
25361
25415
  };
25362
25416
  };
25363
25417
 
25364
- var index = /*#__PURE__*/Object.freeze({
25418
+ var index$1 = /*#__PURE__*/Object.freeze({
25365
25419
  __proto__: null,
25366
25420
  getNetworkAds: getNetworkAds
25367
25421
  });
@@ -25388,31 +25442,342 @@ const createUserToken = async (apiKey, apiRegion, params) => {
25388
25442
  return { accessToken: data.accessToken };
25389
25443
  };
25390
25444
 
25445
+ /* begin_public_function
25446
+ id: notificationTray.getNotificationTraySeen
25447
+ */
25448
+ /**
25449
+ * ```js
25450
+ * import { NotificationTrayRepository } from '@amityco/ts-sdk'
25451
+ * const notificationTraySeen = await NotificationTrayRepository.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 { NotificationTrayRepository } from '@amityco/ts-sdk'
25487
+ * const notificationTraySeen = await NotificationTrayRepository.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 { NotificationTrayRepository } from '@amityco/ts-sdk'
25708
+ * const updated = await NotificationTrayRepository.markNotificationTraySeen({
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 markNotificationTraySeen = async (lastSeenAt) => {
25723
+ var _a;
25724
+ const client = getActiveClient();
25725
+ client.log('notificationTray/markNotificationTraySeen', {});
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
+ markNotificationItemsSeen: markNotificationItemsSeen,
25751
+ markNotificationTraySeen: markNotificationTraySeen,
25752
+ onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
25753
+ });
25754
+
25391
25755
  exports.API_REGIONS = API_REGIONS;
25392
- exports.AdRepository = index;
25393
- exports.CategoryRepository = index$8;
25394
- exports.ChannelRepository = index$c;
25395
- exports.Client = index$l;
25396
- 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;
25397
25761
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
25398
25762
  exports.CommunityPostSettings = CommunityPostSettings;
25399
- exports.CommunityRepository = index$9;
25763
+ exports.CommunityRepository = index$a;
25400
25764
  exports.ContentFeedType = ContentFeedType;
25401
25765
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
25402
- exports.FeedRepository = index$7;
25403
- exports.FileRepository = index$i;
25766
+ exports.FeedRepository = index$8;
25767
+ exports.FileRepository = index$j;
25404
25768
  exports.FileType = FileType;
25405
- exports.LiveStreamPlayer = index$2;
25769
+ exports.LiveStreamPlayer = index$3;
25406
25770
  exports.MessageContentType = MessageContentType;
25407
- exports.MessageRepository = index$g;
25408
- exports.PollRepository = index$3;
25771
+ exports.MessageRepository = index$h;
25772
+ exports.NotificationTrayRepository = index;
25773
+ exports.PollRepository = index$4;
25409
25774
  exports.PostContentType = PostContentType;
25410
- exports.PostRepository = index$5;
25411
- exports.ReactionRepository = index$h;
25412
- exports.StoryRepository = index$1;
25413
- exports.StreamRepository = index$4;
25414
- exports.SubChannelRepository = index$f;
25415
- exports.UserRepository = index$j;
25775
+ exports.PostRepository = index$6;
25776
+ exports.ReactionRepository = index$i;
25777
+ exports.StoryRepository = index$2;
25778
+ exports.StreamRepository = index$5;
25779
+ exports.SubChannelRepository = index$g;
25780
+ exports.UserRepository = index$k;
25416
25781
  exports.VERSION = VERSION;
25417
25782
  exports.VideoResolution = VideoResolution;
25418
25783
  exports.VideoSize = VideoSize;