@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.esm.js CHANGED
@@ -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) => {
@@ -1546,7 +1550,6 @@ const API_REGIONS = {
1546
1550
  };
1547
1551
  const URLS = {
1548
1552
  http: 'https://apix.{region}.amity.co',
1549
- upload: 'https://upload.{region}.amity.co',
1550
1553
  mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
1551
1554
  };
1552
1555
  function computeUrl(type, region) {
@@ -22086,6 +22089,65 @@ const pinnedPostLinkedObject = (pinnedPost) => {
22086
22089
  } });
22087
22090
  };
22088
22091
 
22092
+ /* begin_public_function
22093
+ id: notificationTrayItem.markSeen
22094
+ */
22095
+ /**
22096
+ * ```js
22097
+ * import { NotificationTrayRepository } from '@amityco/ts-sdk'
22098
+ * const updated = await NotificationTrayRepository.markNotificationItemsSeen()
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 markNotificationItemsSeen = async (patch) => {
22110
+ const client = getActiveClient();
22111
+ client.log('notificationTray/markNotificationItemsSeen', {});
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: () => markNotificationItemsSeen({
22142
+ trayItems: [
22143
+ {
22144
+ id: noti._id,
22145
+ lastSeenAt: noti.lastSeenAt,
22146
+ },
22147
+ ],
22148
+ }) });
22149
+ };
22150
+
22089
22151
  const LinkedObject = {
22090
22152
  ad: adLinkedObject,
22091
22153
  comment: commentLinkedObject,
@@ -22099,6 +22161,7 @@ const LinkedObject = {
22099
22161
  reactor: reactorLinkedObject,
22100
22162
  channel: channelLinkedObject,
22101
22163
  pinnedPost: pinnedPostLinkedObject,
22164
+ notificationTray: notificationTrayLinkedObject,
22102
22165
  };
22103
22166
 
22104
22167
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -23699,12 +23762,6 @@ const setClientToken = async (params) => {
23699
23762
  isGlobalBanned: false,
23700
23763
  isUserDeleted: false,
23701
23764
  };
23702
- client.upload.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
23703
- client.upload.defaults.metadata = {
23704
- tokenExpiry: expiresAt,
23705
- isGlobalBanned: false,
23706
- isUserDeleted: false,
23707
- };
23708
23765
  // manually setup the token for ws transport
23709
23766
  if (client.ws)
23710
23767
  client.ws.io.opts.query = { token: accessToken };
@@ -25353,17 +25410,15 @@ const DEFAULT_DEBUG_SESSION = 'amity';
25353
25410
  * @category Client API
25354
25411
  * */
25355
25412
  const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, } = {}) => {
25356
- var _a, _b, _c;
25413
+ var _a, _b;
25357
25414
  const log = createLogger(debugSession);
25358
25415
  log('client/api/createClient', {
25359
25416
  apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
25360
25417
  apiRegion,
25361
25418
  });
25362
25419
  const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
25363
- const uploadEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.upload) !== null && _b !== void 0 ? _b : computeUrl('upload', apiRegion);
25364
- const mqttEndpoint = (_c = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _c !== void 0 ? _c : computeUrl('mqtt', apiRegion);
25420
+ const mqttEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _b !== void 0 ? _b : computeUrl('mqtt', apiRegion);
25365
25421
  const http = createHttpTransport(httpEndpoint);
25366
- const upload = createHttpTransport(uploadEndpoint);
25367
25422
  let ws;
25368
25423
  let mqtt;
25369
25424
  if (rteEnabled) {
@@ -25392,7 +25447,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25392
25447
  http,
25393
25448
  ws,
25394
25449
  mqtt,
25395
- upload,
25396
25450
  emitter,
25397
25451
  /*
25398
25452
  * Session Components
@@ -25421,7 +25475,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25421
25475
  return activeClient;
25422
25476
  setActiveClient(client);
25423
25477
  }
25424
- catch (_d) {
25478
+ catch (_c) {
25425
25479
  setActiveClient(client);
25426
25480
  }
25427
25481
  return client;
@@ -25878,7 +25932,7 @@ const getUserUnread = (callback) => {
25878
25932
  };
25879
25933
  };
25880
25934
 
25881
- var index$l = /*#__PURE__*/Object.freeze({
25935
+ var index$m = /*#__PURE__*/Object.freeze({
25882
25936
  __proto__: null,
25883
25937
  getActiveClient: getActiveClient,
25884
25938
  getActiveUser: getActiveUser,
@@ -27085,7 +27139,7 @@ const getMyFollowInfo = (callback) => {
27085
27139
  };
27086
27140
  /* end_public_function */
27087
27141
 
27088
- var index$k = /*#__PURE__*/Object.freeze({
27142
+ var index$l = /*#__PURE__*/Object.freeze({
27089
27143
  __proto__: null,
27090
27144
  blockUser: blockUser,
27091
27145
  unBlockUser: unBlockUser,
@@ -28100,9 +28154,9 @@ var AmityUserSearchMatchType;
28100
28154
  AmityUserSearchMatchType["PARTIAL"] = "partial";
28101
28155
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
28102
28156
 
28103
- var index$j = /*#__PURE__*/Object.freeze({
28157
+ var index$k = /*#__PURE__*/Object.freeze({
28104
28158
  __proto__: null,
28105
- Relationship: index$k,
28159
+ Relationship: index$l,
28106
28160
  getUserByIds: getUserByIds,
28107
28161
  updateUser: updateUser,
28108
28162
  flagUser: flagUser,
@@ -28210,7 +28264,7 @@ const uploadFile = async (formData, onProgress) => {
28210
28264
  const headers = 'getHeaders' in formData
28211
28265
  ? formData.getHeaders()
28212
28266
  : { 'content-type': 'multipart/form-data' };
28213
- const { data } = await client.upload.post('/api/v4/files', formData, {
28267
+ const { data } = await client.http.post('/api/v4/files', formData, {
28214
28268
  headers,
28215
28269
  onUploadProgress({ loaded, total = 100 }) {
28216
28270
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -28300,7 +28354,7 @@ const uploadVideo = async (formData, feedType, onProgress) => {
28300
28354
  const headers = 'getHeaders' in formData
28301
28355
  ? formData.getHeaders()
28302
28356
  : { 'content-type': 'multipart/form-data' };
28303
- const { data } = await client.upload.post('/api/v4/videos', formData, {
28357
+ const { data } = await client.http.post('/api/v4/videos', formData, {
28304
28358
  headers,
28305
28359
  onUploadProgress({ loaded, total = 100 }) {
28306
28360
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -28348,7 +28402,7 @@ const uploadImage = async (formData, onProgress) => {
28348
28402
  const headers = 'getHeaders' in formData
28349
28403
  ? formData.getHeaders()
28350
28404
  : { 'content-type': 'multipart/form-data' };
28351
- const { data } = await client.upload.post('/api/v4/images', formData, {
28405
+ const { data } = await client.http.post('/api/v4/images', formData, {
28352
28406
  headers,
28353
28407
  onUploadProgress({ loaded, total = 100 }) {
28354
28408
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -28366,7 +28420,7 @@ const uploadImage = async (formData, onProgress) => {
28366
28420
  };
28367
28421
  /* end_public_function */
28368
28422
 
28369
- var index$i = /*#__PURE__*/Object.freeze({
28423
+ var index$j = /*#__PURE__*/Object.freeze({
28370
28424
  __proto__: null,
28371
28425
  getFile: getFile,
28372
28426
  uploadFile: uploadFile,
@@ -30178,7 +30232,7 @@ const getReactions = (params, callback, config) => {
30178
30232
  };
30179
30233
  /* end_public_function */
30180
30234
 
30181
- var index$h = /*#__PURE__*/Object.freeze({
30235
+ var index$i = /*#__PURE__*/Object.freeze({
30182
30236
  __proto__: null,
30183
30237
  addReaction: addReaction,
30184
30238
  removeReaction: removeReaction,
@@ -31994,7 +32048,7 @@ const getMessages = (params, callback, config) => {
31994
32048
  };
31995
32049
  /* end_public_function */
31996
32050
 
31997
- var index$g = /*#__PURE__*/Object.freeze({
32051
+ var index$h = /*#__PURE__*/Object.freeze({
31998
32052
  __proto__: null,
31999
32053
  createMessage: createMessage,
32000
32054
  updateMessage: updateMessage,
@@ -32520,7 +32574,7 @@ const stopMessageReceiptSync = (subChannelId) => {
32520
32574
  };
32521
32575
  /* end_public_function */
32522
32576
 
32523
- var index$f = /*#__PURE__*/Object.freeze({
32577
+ var index$g = /*#__PURE__*/Object.freeze({
32524
32578
  __proto__: null,
32525
32579
  getSubChannelByIds: getSubChannels$1,
32526
32580
  createSubChannel: createSubChannel,
@@ -33697,7 +33751,7 @@ const searchMembers$1 = (params, callback, config) => {
33697
33751
  };
33698
33752
  /* end_public_function */
33699
33753
 
33700
- var index$e = /*#__PURE__*/Object.freeze({
33754
+ var index$f = /*#__PURE__*/Object.freeze({
33701
33755
  __proto__: null,
33702
33756
  addMembers: addMembers$1,
33703
33757
  removeMembers: removeMembers$1,
@@ -33900,7 +33954,7 @@ const unmuteMembers = async (channelId, userIds) => {
33900
33954
  };
33901
33955
  /* end_public_function */
33902
33956
 
33903
- var index$d = /*#__PURE__*/Object.freeze({
33957
+ var index$e = /*#__PURE__*/Object.freeze({
33904
33958
  __proto__: null,
33905
33959
  addRole: addRole,
33906
33960
  removeRole: removeRole,
@@ -33910,10 +33964,10 @@ var index$d = /*#__PURE__*/Object.freeze({
33910
33964
  unmuteMembers: unmuteMembers
33911
33965
  });
33912
33966
 
33913
- var index$c = /*#__PURE__*/Object.freeze({
33967
+ var index$d = /*#__PURE__*/Object.freeze({
33914
33968
  __proto__: null,
33915
- Membership: index$e,
33916
- Moderation: index$d,
33969
+ Membership: index$f,
33970
+ Moderation: index$e,
33917
33971
  getChannelByIds: getChannelByIds$1,
33918
33972
  createChannel: createChannel,
33919
33973
  updateChannel: updateChannel,
@@ -35292,7 +35346,7 @@ const searchMembers = (params, callback, config) => {
35292
35346
  };
35293
35347
  /* end_public_function */
35294
35348
 
35295
- var index$b = /*#__PURE__*/Object.freeze({
35349
+ var index$c = /*#__PURE__*/Object.freeze({
35296
35350
  __proto__: null,
35297
35351
  addMembers: addMembers,
35298
35352
  removeMembers: removeMembers,
@@ -36317,7 +36371,7 @@ const unbanMembers = async (communityId, userIds) => {
36317
36371
  };
36318
36372
  /* end_public_function */
36319
36373
 
36320
- var index$a = /*#__PURE__*/Object.freeze({
36374
+ var index$b = /*#__PURE__*/Object.freeze({
36321
36375
  __proto__: null,
36322
36376
  addRoles: addRoles,
36323
36377
  removeRoles: removeRoles,
@@ -36325,10 +36379,10 @@ var index$a = /*#__PURE__*/Object.freeze({
36325
36379
  unbanMembers: unbanMembers
36326
36380
  });
36327
36381
 
36328
- var index$9 = /*#__PURE__*/Object.freeze({
36382
+ var index$a = /*#__PURE__*/Object.freeze({
36329
36383
  __proto__: null,
36330
- Moderation: index$a,
36331
- Membership: index$b,
36384
+ Moderation: index$b,
36385
+ Membership: index$c,
36332
36386
  getCommunityByIds: getCommunities$1,
36333
36387
  createCommunity: createCommunity,
36334
36388
  updateCommunity: updateCommunity,
@@ -36561,7 +36615,7 @@ const getCategories = (params, callback, config) => {
36561
36615
  };
36562
36616
  /* end_public_function */
36563
36617
 
36564
- var index$8 = /*#__PURE__*/Object.freeze({
36618
+ var index$9 = /*#__PURE__*/Object.freeze({
36565
36619
  __proto__: null,
36566
36620
  getCategory: getCategory,
36567
36621
  getCategories: getCategories
@@ -36729,7 +36783,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
36729
36783
  : undefined;
36730
36784
  };
36731
36785
 
36732
- var index$7 = /*#__PURE__*/Object.freeze({
36786
+ var index$8 = /*#__PURE__*/Object.freeze({
36733
36787
  __proto__: null,
36734
36788
  queryGlobalFeed: queryGlobalFeed,
36735
36789
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -38044,7 +38098,7 @@ const getComments = (params, callback, config) => {
38044
38098
  };
38045
38099
  /* end_public_function */
38046
38100
 
38047
- var index$6 = /*#__PURE__*/Object.freeze({
38101
+ var index$7 = /*#__PURE__*/Object.freeze({
38048
38102
  __proto__: null,
38049
38103
  getCommentByIds: getCommentByIds,
38050
38104
  createComment: createComment,
@@ -39051,7 +39105,7 @@ const semanticSearchPosts = (params, callback, config) => {
39051
39105
  };
39052
39106
  };
39053
39107
 
39054
- var index$5 = /*#__PURE__*/Object.freeze({
39108
+ var index$6 = /*#__PURE__*/Object.freeze({
39055
39109
  __proto__: null,
39056
39110
  getPostByIds: getPostByIds,
39057
39111
  createPost: createPost,
@@ -39585,7 +39639,7 @@ const getStreams = (params, callback, config) => {
39585
39639
  };
39586
39640
  };
39587
39641
 
39588
- var index$4 = /*#__PURE__*/Object.freeze({
39642
+ var index$5 = /*#__PURE__*/Object.freeze({
39589
39643
  __proto__: null,
39590
39644
  createStream: createStream,
39591
39645
  updateStream: updateStream,
@@ -39872,7 +39926,7 @@ const getPoll = (pollId, callback) => {
39872
39926
  };
39873
39927
  /* end_public_function */
39874
39928
 
39875
- var index$3 = /*#__PURE__*/Object.freeze({
39929
+ var index$4 = /*#__PURE__*/Object.freeze({
39876
39930
  __proto__: null,
39877
39931
  createPoll: createPoll,
39878
39932
  closePoll: closePoll,
@@ -40243,7 +40297,7 @@ const getPlayer = async (parameters) => {
40243
40297
  return video;
40244
40298
  };
40245
40299
 
40246
- var index$2 = /*#__PURE__*/Object.freeze({
40300
+ var index$3 = /*#__PURE__*/Object.freeze({
40247
40301
  __proto__: null,
40248
40302
  getPlayer: getPlayer
40249
40303
  });
@@ -41416,7 +41470,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
41416
41470
  };
41417
41471
  };
41418
41472
 
41419
- var index$1 = /*#__PURE__*/Object.freeze({
41473
+ var index$2 = /*#__PURE__*/Object.freeze({
41420
41474
  __proto__: null,
41421
41475
  createImageStory: createImageStory,
41422
41476
  createVideoStory: createVideoStory,
@@ -41453,7 +41507,7 @@ const getNetworkAds = async () => {
41453
41507
  };
41454
41508
  };
41455
41509
 
41456
- var index = /*#__PURE__*/Object.freeze({
41510
+ var index$1 = /*#__PURE__*/Object.freeze({
41457
41511
  __proto__: null,
41458
41512
  getNetworkAds: getNetworkAds
41459
41513
  });
@@ -41480,4 +41534,314 @@ const createUserToken = async (apiKey, apiRegion, params) => {
41480
41534
  return { accessToken: data.accessToken };
41481
41535
  };
41482
41536
 
41483
- 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 { NotificationTrayRepository } from '@amityco/ts-sdk'
41543
+ * const notificationTraySeen = await NotificationTrayRepository.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 { NotificationTrayRepository } from '@amityco/ts-sdk'
41579
+ * const notificationTraySeen = await NotificationTrayRepository.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 { NotificationTrayRepository } from '@amityco/ts-sdk'
41800
+ * const updated = await NotificationTrayRepository.markNotificationTraySeen({
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 markNotificationTraySeen = async (lastSeenAt) => {
41815
+ var _a;
41816
+ const client = getActiveClient();
41817
+ client.log('notificationTray/markNotificationTraySeen', {});
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
+ markNotificationItemsSeen: markNotificationItemsSeen,
41843
+ markNotificationTraySeen: markNotificationTraySeen,
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 as NotificationTrayRepository, 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, 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 };