@amityco/ts-sdk 7.11.1-b8fc6951.0 → 7.11.1-bc56fe41.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 (68) 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 +2 -0
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/permissions.d.ts +5 -1
  6. package/dist/@types/core/permissions.d.ts.map +1 -1
  7. package/dist/@types/domains/community.d.ts +3 -0
  8. package/dist/@types/domains/community.d.ts.map +1 -1
  9. package/dist/@types/domains/event.d.ts +33 -10
  10. package/dist/@types/domains/event.d.ts.map +1 -1
  11. package/dist/@types/domains/notification.d.ts +3 -1
  12. package/dist/@types/domains/notification.d.ts.map +1 -1
  13. package/dist/core/events.d.ts +3 -3
  14. package/dist/core/events.d.ts.map +1 -1
  15. package/dist/core/model/idResolvers.d.ts.map +1 -1
  16. package/dist/eventRepository/events/enums.d.ts +3 -1
  17. package/dist/eventRepository/events/enums.d.ts.map +1 -1
  18. package/dist/eventRepository/events/index.d.ts +7 -0
  19. package/dist/eventRepository/events/index.d.ts.map +1 -1
  20. package/dist/eventRepository/events/onLocalEventCreated.d.ts +17 -0
  21. package/dist/eventRepository/events/onLocalEventCreated.d.ts.map +1 -0
  22. package/dist/eventRepository/events/onLocalEventDeleted.d.ts +17 -0
  23. package/dist/eventRepository/events/onLocalEventDeleted.d.ts.map +1 -0
  24. package/dist/eventRepository/events/onLocalEventUpdated.d.ts +17 -0
  25. package/dist/eventRepository/events/onLocalEventUpdated.d.ts.map +1 -0
  26. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts +17 -0
  27. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts.map +1 -0
  28. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts +17 -0
  29. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts.map +1 -0
  30. package/dist/eventRepository/events/onRSVPCreated.d.ts +17 -0
  31. package/dist/eventRepository/events/onRSVPCreated.d.ts.map +1 -0
  32. package/dist/eventRepository/events/onRSVPUpdated.d.ts +17 -0
  33. package/dist/eventRepository/events/onRSVPUpdated.d.ts.map +1 -0
  34. package/dist/eventRepository/internalApi/createRSVP.d.ts +16 -0
  35. package/dist/eventRepository/internalApi/createRSVP.d.ts.map +1 -0
  36. package/dist/eventRepository/internalApi/getMyRSVP.d.ts +32 -0
  37. package/dist/eventRepository/internalApi/getMyRSVP.d.ts.map +1 -0
  38. package/dist/eventRepository/internalApi/index.d.ts +3 -0
  39. package/dist/eventRepository/internalApi/index.d.ts.map +1 -1
  40. package/dist/eventRepository/internalApi/updateRSVP.d.ts +17 -0
  41. package/dist/eventRepository/internalApi/updateRSVP.d.ts.map +1 -0
  42. package/dist/eventRepository/observers/getEvent.d.ts.map +1 -1
  43. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +1 -1
  44. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts +13 -0
  45. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -0
  46. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts +5 -0
  47. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts.map +1 -0
  48. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts +15 -0
  49. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +1 -0
  50. package/dist/eventRepository/observers/getMyEvents.d.ts +12 -0
  51. package/dist/eventRepository/observers/getMyEvents.d.ts.map +1 -0
  52. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts +13 -0
  53. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts.map +1 -0
  54. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts +5 -0
  55. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts.map +1 -0
  56. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts +15 -0
  57. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts.map +1 -0
  58. package/dist/eventRepository/observers/getRSVPs.d.ts +12 -0
  59. package/dist/eventRepository/observers/getRSVPs.d.ts.map +1 -0
  60. package/dist/eventRepository/observers/index.d.ts +2 -0
  61. package/dist/eventRepository/observers/index.d.ts.map +1 -1
  62. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +1 -1
  63. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -1
  64. package/dist/index.cjs.js +595 -34
  65. package/dist/index.esm.js +596 -35
  66. package/dist/index.umd.js +3 -3
  67. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -1
  68. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -194,6 +194,11 @@ var AmityEventStatus;
194
194
  AmityEventStatus["Ended"] = "ended";
195
195
  AmityEventStatus["Cancelled"] = "cancelled";
196
196
  })(AmityEventStatus || (AmityEventStatus = {}));
197
+ var AmityEventResponseStatus;
198
+ (function (AmityEventResponseStatus) {
199
+ AmityEventResponseStatus["Going"] = "going";
200
+ AmityEventResponseStatus["NotGoing"] = "not_going";
201
+ })(AmityEventResponseStatus || (AmityEventResponseStatus = {}));
197
202
 
198
203
  function getVersion() {
199
204
  try {
@@ -644,6 +649,7 @@ const idResolvers = {
644
649
  invitation: ({ _id }) => _id,
645
650
  joinRequest: ({ joinRequestId }) => joinRequestId,
646
651
  event: ({ eventId }) => eventId,
652
+ discussionCommunity: ({ communityId }) => communityId,
647
653
  };
648
654
  /**
649
655
  * Retrieve the id resolver matching a domain name
@@ -700,7 +706,7 @@ const PAYLOAD2MODEL = {
700
706
  invitations: 'invitation',
701
707
  joinRequests: 'joinRequest',
702
708
  events: 'event',
703
- discussionCommunities: 'community',
709
+ discussionCommunities: 'discussionCommunity',
704
710
  };
705
711
  /** hidden */
706
712
  const isOutdated = (prevData, nextData) => {
@@ -29771,6 +29777,155 @@ const communityLinkedObject = (community) => {
29771
29777
  } });
29772
29778
  };
29773
29779
 
29780
+ const prepareEventPayload = (rawPayload) => {
29781
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
29782
+ };
29783
+
29784
+ const createEventEventSubscriber = (event, callback) => {
29785
+ const client = getActiveClient();
29786
+ const filter = (payload) => {
29787
+ const unpackedPayload = prepareEventPayload(payload);
29788
+ if (!client.cache) {
29789
+ callback(unpackedPayload.events[0]);
29790
+ }
29791
+ else {
29792
+ ingestInCache(unpackedPayload);
29793
+ const event = pullFromCache([
29794
+ 'event',
29795
+ 'get',
29796
+ unpackedPayload.events[0].eventId,
29797
+ ]);
29798
+ callback(event.data);
29799
+ }
29800
+ };
29801
+ return createEventSubscriber(client, event, event, filter);
29802
+ };
29803
+
29804
+ /* begin_public_function
29805
+ id: event.rsvp.create
29806
+ */
29807
+ /**
29808
+ * ```js
29809
+ * import { event } from '@amityco/ts-sdk'
29810
+ * const response = await event.createRSVP(eventId, status)
29811
+ * ```
29812
+ *
29813
+ * Creates an {@link Amity.InternalEvent}
29814
+ *
29815
+ * @param bundle The data necessary to create a new {@link Amity.InternalEvent}
29816
+ * @returns The newly created {@link Amity.InternalEvent}
29817
+ *
29818
+ * @category Event API
29819
+ * @async
29820
+ */
29821
+ const createRSVP = async (eventId, status) => {
29822
+ const client = getActiveClient();
29823
+ client.log('event/createRSVP', eventId, status);
29824
+ const { data: payload } = await client.http.post(`/api/v1/events/${eventId}/rsvp`, { status });
29825
+ fireEvent('local.rsvp.created', payload);
29826
+ const preparedPayload = prepareEventPayload(payload);
29827
+ const cachedAt = client.cache && Date.now();
29828
+ if (client.cache)
29829
+ ingestInCache(preparedPayload, { cachedAt });
29830
+ return {
29831
+ data: preparedPayload.events[0],
29832
+ cachedAt,
29833
+ };
29834
+ };
29835
+ /* end_public_function */
29836
+
29837
+ /* begin_public_function
29838
+ id: event.update
29839
+ */
29840
+ /**
29841
+ * ```js
29842
+ * import { event } from '@amityco/ts-sdk'
29843
+ * const response = await event.updateRSVP(eventId, status)
29844
+ * ```
29845
+ *
29846
+ * Updates an {@link Amity.InternalEvent}
29847
+ *
29848
+ * @param eventId The ID of the {@link Amity.InternalEvent} to edit
29849
+ * @param bundle The data necessary to update an existing {@link Amity.InternalEvent}
29850
+ * @returns the updated {@link Amity.InternalEvent}
29851
+ *
29852
+ * @category Event API
29853
+ * @async
29854
+ */
29855
+ const updateRSVP = async (eventId, status) => {
29856
+ const client = getActiveClient();
29857
+ client.log('event/updateRSVP', eventId, status);
29858
+ const { data: payload } = await client.http.put(`/api/v1/events/${eventId}/rsvp`, { status });
29859
+ fireEvent('local.rsvp.updated', payload);
29860
+ const preparedPayload = prepareEventPayload(payload);
29861
+ const cachedAt = client.cache && Date.now();
29862
+ if (client.cache)
29863
+ ingestInCache(preparedPayload, { cachedAt });
29864
+ return {
29865
+ data: preparedPayload.events.find(event => event.eventId === eventId),
29866
+ cachedAt,
29867
+ };
29868
+ };
29869
+ /* end_public_function */
29870
+
29871
+ /* begin_public_function
29872
+ id: event.rsvp.me
29873
+ */
29874
+ /**
29875
+ * ```js
29876
+ * import { event } from '@amityco/ts-sdk'
29877
+ * const myRSVP = await event.getMyRSVP(status)
29878
+ * ```
29879
+ *
29880
+ * Joins a {@link Amity.InternalEvent} object
29881
+ *
29882
+ * @param eventId the {@link Amity.InternalEvent} to get RSVP for
29883
+ * @returns A success boolean if the {@link Amity.InternalEvent} RSVP was retrieved
29884
+ *
29885
+ * @category Event API
29886
+ * @async
29887
+ */
29888
+ const getMyRSVP = async (eventId, status) => {
29889
+ const client = getActiveClient();
29890
+ client.log('event/getMyRSVP', eventId);
29891
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}/me/rsvp`, { params: { status } });
29892
+ const data = prepareEventPayload(payload);
29893
+ const cachedAt = client.cache && Date.now();
29894
+ if (client.cache)
29895
+ ingestInCache(data, { cachedAt });
29896
+ return {
29897
+ data: data.events.find(event => event.eventId === eventId),
29898
+ cachedAt,
29899
+ };
29900
+ };
29901
+ /* end_public_function */
29902
+ /**
29903
+ * ```js
29904
+ * import { event } from '@amityco/ts-sdk'
29905
+ * const event = event.getMyRSVP.locally(eventId)
29906
+ * ```
29907
+ *
29908
+ * Fetches a {@link Amity.InternalEvent} object in cache
29909
+ *
29910
+ * @param eventId the ID of the {@link Amity.InternalEvent} to fetch
29911
+ * @returns the associated {@link Amity.InternalEvent} object
29912
+ *
29913
+ * @category Event API
29914
+ */
29915
+ getMyRSVP.locally = (eventId) => {
29916
+ const client = getActiveClient();
29917
+ client.log('event/getMyRSVP.locally', eventId);
29918
+ if (!client.cache)
29919
+ return;
29920
+ const cache = pullFromCache(['event', 'getMyRSVP', eventId]);
29921
+ if (!cache)
29922
+ return;
29923
+ return {
29924
+ data: cache.data,
29925
+ cachedAt: cache.cachedAt,
29926
+ };
29927
+ };
29928
+
29774
29929
  const eventLinkedObject = (event) => {
29775
29930
  return Object.assign(Object.assign({}, event), { get creator() {
29776
29931
  const cacheData = pullFromCache(['user', 'get', event.userId]);
@@ -29782,7 +29937,7 @@ const eventLinkedObject = (event) => {
29782
29937
  if (!event.discussionCommunityId)
29783
29938
  return;
29784
29939
  const cacheData = pullFromCache([
29785
- 'community',
29940
+ 'discussionCommunity',
29786
29941
  'get',
29787
29942
  event.discussionCommunityId,
29788
29943
  ]);
@@ -29790,6 +29945,22 @@ const eventLinkedObject = (event) => {
29790
29945
  return;
29791
29946
  return communityLinkedObject(cacheData.data);
29792
29947
  },
29948
+ get targetCommunity() {
29949
+ if (!event.originId)
29950
+ return;
29951
+ const cacheData = pullFromCache(['community', 'get', event.originId]);
29952
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29953
+ return;
29954
+ return communityLinkedObject(cacheData.data);
29955
+ },
29956
+ get coverImage() {
29957
+ if (!event.coverImageFileId)
29958
+ return;
29959
+ const cacheData = pullFromCache(['file', 'get', event.coverImageFileId]);
29960
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29961
+ return;
29962
+ return cacheData.data;
29963
+ },
29793
29964
  get liveStream() {
29794
29965
  if (!event.livestreamId)
29795
29966
  return;
@@ -29797,6 +29968,15 @@ const eventLinkedObject = (event) => {
29797
29968
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29798
29969
  return;
29799
29970
  return cacheData.data;
29971
+ }, createRSVP: async (status) => {
29972
+ const { data } = await createRSVP(event.eventId, status);
29973
+ return data;
29974
+ }, updateRSVP: async (status) => {
29975
+ const { data } = await updateRSVP(event.eventId, status);
29976
+ return data;
29977
+ }, getMyRSVP: async (status) => {
29978
+ const { data } = await getMyRSVP(event.eventId, status);
29979
+ return data;
29800
29980
  } });
29801
29981
  };
29802
29982
 
@@ -46436,30 +46616,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
46436
46616
  getReactions: getReactions
46437
46617
  });
46438
46618
 
46439
- const prepareEventPayload = (rawPayload) => {
46440
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
46441
- };
46442
-
46443
- const createEventEventSubscriber = (event, callback) => {
46444
- const client = getActiveClient();
46445
- const filter = (payload) => {
46446
- const unpackedPayload = prepareEventPayload(payload);
46447
- if (!client.cache) {
46448
- callback(unpackedPayload.events[0]);
46449
- }
46450
- else {
46451
- ingestInCache(unpackedPayload);
46452
- const event = pullFromCache([
46453
- 'event',
46454
- 'get',
46455
- unpackedPayload.events[0].eventId,
46456
- ]);
46457
- callback(event.data);
46458
- }
46459
- };
46460
- return createEventSubscriber(client, event, event, filter);
46461
- };
46462
-
46463
46619
  /* begin_public_function
46464
46620
  id: event.create
46465
46621
  */
@@ -46481,7 +46637,7 @@ const createEvent = async (bundle) => {
46481
46637
  const client = getActiveClient();
46482
46638
  client.log('event/createEvent', bundle);
46483
46639
  const { data: payload } = await client.http.post('/api/v1/events', bundle);
46484
- fireEvent('event.created', payload);
46640
+ fireEvent('local.event.created', payload);
46485
46641
  const preparedPayload = prepareEventPayload(payload);
46486
46642
  const cachedAt = client.cache && Date.now();
46487
46643
  if (client.cache)
@@ -46515,7 +46671,7 @@ const updateEvent = async (eventId, bundle) => {
46515
46671
  const client = getActiveClient();
46516
46672
  client.log('event/updateEvent', eventId, bundle);
46517
46673
  const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
46518
- fireEvent('event.updated', payload);
46674
+ fireEvent('local.event.updated', payload);
46519
46675
  const preparedPayload = prepareEventPayload(payload);
46520
46676
  const cachedAt = client.cache && Date.now();
46521
46677
  if (client.cache)
@@ -46547,7 +46703,7 @@ const updateEvent = async (eventId, bundle) => {
46547
46703
  const getEvent$1 = async (eventId) => {
46548
46704
  const client = getActiveClient();
46549
46705
  client.log('event/getEvent', eventId);
46550
- const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
46706
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
46551
46707
  const data = prepareEventPayload(payload);
46552
46708
  const cachedAt = client.cache && Date.now();
46553
46709
  if (client.cache)
@@ -46605,10 +46761,10 @@ const deleteEvent = async (eventId) => {
46605
46761
  const client = getActiveClient();
46606
46762
  client.log('event/deleteEvent', eventId);
46607
46763
  const event = await getEvent$1(eventId);
46608
- await client.http.delete(`/api/v3/events/${eventId}`);
46764
+ await client.http.delete(`/api/v1/events/${eventId}`);
46609
46765
  const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
46610
46766
  upsertInCache(['event', 'get', eventId], deletedEvent);
46611
- fireEvent('event.deleted', {
46767
+ fireEvent('local.event.deleted', {
46612
46768
  users: [],
46613
46769
  files: [],
46614
46770
  communities: [],
@@ -46670,6 +46826,125 @@ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated',
46670
46826
  */
46671
46827
  const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
46672
46828
 
46829
+ /**
46830
+ * ```js
46831
+ * import { EventRepository } from '@amityco/ts-sdk'
46832
+ * const dispose = EventRepository.onLocalEventCreated(event => {
46833
+ * // ...
46834
+ * })
46835
+ * ```
46836
+ *
46837
+ * Fired when a {@link Amity.Event} has been created
46838
+ *
46839
+ * @param callback The function to call when the event was fired
46840
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
46841
+ *
46842
+ * @category Event Events
46843
+ */
46844
+ const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
46845
+
46846
+ /**
46847
+ * ```js
46848
+ * import { EventRepository } from '@amityco/ts-sdk'
46849
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
46850
+ * // ...
46851
+ * })
46852
+ * ```
46853
+ *
46854
+ * Fired when a {@link Amity.Event} has been updated
46855
+ *
46856
+ * @param callback The function to call when the event was fired
46857
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
46858
+ *
46859
+ * @category Event Events
46860
+ */
46861
+ const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
46862
+
46863
+ /**
46864
+ * ```js
46865
+ * import { EventRepository } from '@amityco/ts-sdk'
46866
+ * const dispose = EventRepository.onLocalEventDeleted(event => {
46867
+ * // ...
46868
+ * })
46869
+ * ```
46870
+ *
46871
+ * Fired when a {@link Amity.Event} has been deleted
46872
+ *
46873
+ * @param callback The function to call when the event was fired
46874
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
46875
+ *
46876
+ * @category Event Events
46877
+ */
46878
+ const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
46879
+
46880
+ /**
46881
+ * ```js
46882
+ * import { EventRepository } from '@amityco/ts-sdk'
46883
+ * const dispose = EventRepository.onRSVPCreated(event => {
46884
+ * // ...
46885
+ * })
46886
+ * ```
46887
+ *
46888
+ * Fired when a {@link Amity.Event} has been created
46889
+ *
46890
+ * @param callback The function to call when the event was fired
46891
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
46892
+ *
46893
+ * @category Event Events
46894
+ */
46895
+ const onRSVPCreated = (callback) => createEventEventSubscriber('event.rsvp.created', callback);
46896
+
46897
+ /**
46898
+ * ```js
46899
+ * import { EventRepository } from '@amityco/ts-sdk'
46900
+ * const dispose = EventRepository.onRSVPUpdated(event => {
46901
+ * // ...
46902
+ * })
46903
+ * ```
46904
+ *
46905
+ * Fired when a {@link Amity.Event} has been updated
46906
+ *
46907
+ * @param callback The function to call when the event was fired
46908
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
46909
+ *
46910
+ * @category Event Events
46911
+ */
46912
+ const onRSVPUpdated = (callback) => createEventEventSubscriber('event.rsvp.updated', callback);
46913
+
46914
+ /**
46915
+ * ```js
46916
+ * import { EventRepository } from '@amityco/ts-sdk'
46917
+ * const dispose = EventRepository.onLocalRSVPCreated(event => {
46918
+ * // ...
46919
+ * })
46920
+ * ```
46921
+ *
46922
+ * Fired when a {@link Amity.Event} has been created
46923
+ *
46924
+ * @param callback The function to call when the event was fired
46925
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
46926
+ *
46927
+ * @category Event Events
46928
+ */
46929
+ const onLocalRSVPCreated = (callback) => createEventEventSubscriber('local.rsvp.created', callback);
46930
+
46931
+ /**
46932
+ * ```js
46933
+ * import { EventRepository } from '@amityco/ts-sdk'
46934
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
46935
+ * // ...
46936
+ * })
46937
+ * ```
46938
+ *
46939
+ * Fired when a {@link Amity.Event} has been updated
46940
+ *
46941
+ * @param callback The function to call when the event was fired
46942
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
46943
+ *
46944
+ * @category Event Events
46945
+ */
46946
+ const onLocalRSVPUpdated = (callback) => createEventEventSubscriber('local.rsvp.updated', callback);
46947
+
46673
46948
  /* begin_public_function
46674
46949
  id: event.get
46675
46950
  */
@@ -46693,7 +46968,7 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
46693
46968
  * @category Event Live Object
46694
46969
  */
46695
46970
  const getEvent = (eventId, callback) => {
46696
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
46971
+ return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
46697
46972
  callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
46698
46973
  });
46699
46974
  };
@@ -46704,6 +46979,8 @@ var EventActionsEnum;
46704
46979
  EventActionsEnum["OnEventCreated"] = "onEventCreated";
46705
46980
  EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
46706
46981
  EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
46982
+ EventActionsEnum["OnRSVPCreated"] = "onRSVPCreated";
46983
+ EventActionsEnum["OnRSVPUpdated"] = "onRSVPUpdated";
46707
46984
  })(EventActionsEnum || (EventActionsEnum = {}));
46708
46985
 
46709
46986
  class EventPaginationController extends PaginationController {
@@ -46788,6 +47065,9 @@ class EventLiveCollectionController extends LiveCollectionController {
46788
47065
  { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
46789
47066
  { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
46790
47067
  { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
47068
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
47069
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
47070
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
46791
47071
  ]);
46792
47072
  }
46793
47073
  notifyChange({ origin, loading, error }) {
@@ -46799,7 +47079,7 @@ class EventLiveCollectionController extends LiveCollectionController {
46799
47079
  .map(eventId => pullFromCache(['event', 'get', eventId]))
46800
47080
  .filter(isNonNullable)
46801
47081
  .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
46802
- if (!this.shouldNotify(data) && origin === 'event')
47082
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
46803
47083
  return;
46804
47084
  this.callback({
46805
47085
  data,
@@ -46837,6 +47117,278 @@ const getEvents = (params, callback, config) => {
46837
47117
  };
46838
47118
  };
46839
47119
 
47120
+ class MyEventPaginationController extends PaginationController {
47121
+ async getRequest(queryParams, token) {
47122
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
47123
+ const options = token ? { token } : { limit };
47124
+ const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
47125
+ return response;
47126
+ }
47127
+ }
47128
+
47129
+ class MyEventQueryStreamController extends QueryStreamController {
47130
+ constructor(query, cacheKey, notifyChange, preparePayload) {
47131
+ super(query, cacheKey);
47132
+ this.notifyChange = notifyChange;
47133
+ this.preparePayload = preparePayload;
47134
+ }
47135
+ async saveToMainDB(response) {
47136
+ const processedPayload = this.preparePayload(response);
47137
+ const client = getActiveClient();
47138
+ const cachedAt = client.cache && Date.now();
47139
+ if (client.cache)
47140
+ ingestInCache(processedPayload, { cachedAt });
47141
+ }
47142
+ appendToQueryStream(response, direction, refresh = false) {
47143
+ var _a, _b;
47144
+ if (refresh) {
47145
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
47146
+ }
47147
+ else {
47148
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47149
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
47150
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
47151
+ }
47152
+ }
47153
+ reactor(action) {
47154
+ return (event) => {
47155
+ var _a;
47156
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47157
+ if (!collection)
47158
+ return;
47159
+ if (action === EventActionsEnum.OnEventCreated) {
47160
+ const client = getActiveClient();
47161
+ if (client.userId !== event.userId)
47162
+ return;
47163
+ collection.data = [...new Set([event.eventId, ...collection.data])];
47164
+ }
47165
+ if (action === EventActionsEnum.OnEventDeleted) {
47166
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
47167
+ }
47168
+ pushToCache(this.cacheKey, collection);
47169
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
47170
+ };
47171
+ }
47172
+ subscribeRTE(createSubscriber) {
47173
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
47174
+ }
47175
+ }
47176
+
47177
+ class MyEventLiveCollectionController extends LiveCollectionController {
47178
+ constructor(query, callback) {
47179
+ const queryStreamId = hash(query);
47180
+ const cacheKey = ['event', 'collection', queryStreamId];
47181
+ const paginationController = new MyEventPaginationController(query);
47182
+ super(paginationController, queryStreamId, cacheKey, callback);
47183
+ this.query = query;
47184
+ this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
47185
+ this.callback = callback.bind(this);
47186
+ this.loadPage({ initial: true });
47187
+ }
47188
+ setup() {
47189
+ var _a;
47190
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47191
+ if (!collection)
47192
+ pushToCache(this.cacheKey, { data: [], params: {} });
47193
+ }
47194
+ async persistModel(queryPayload) {
47195
+ await this.queryStreamController.saveToMainDB(queryPayload);
47196
+ }
47197
+ persistQueryStream({ response, direction, refresh, }) {
47198
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
47199
+ }
47200
+ startSubscription() {
47201
+ return this.queryStreamController.subscribeRTE([
47202
+ { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
47203
+ { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
47204
+ { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
47205
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
47206
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
47207
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
47208
+ ]);
47209
+ }
47210
+ notifyChange({ origin, loading, error }) {
47211
+ var _a, _b;
47212
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47213
+ if (!collection)
47214
+ return;
47215
+ const data = ((_b = collection.data
47216
+ .map(eventId => pullFromCache(['event', 'get', eventId]))
47217
+ .filter(isNonNullable)
47218
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
47219
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
47220
+ return;
47221
+ this.callback({
47222
+ data,
47223
+ error,
47224
+ loading,
47225
+ hasNextPage: !!this.paginationController.getNextToken(),
47226
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
47227
+ });
47228
+ }
47229
+ }
47230
+
47231
+ /**
47232
+ * Get my events
47233
+ *
47234
+ * @param params the query parameters
47235
+ * @param callback the callback to be called when the events are updated
47236
+ * @returns events
47237
+ *
47238
+ * @category Event Live Collection
47239
+ *
47240
+ */
47241
+ const getMyEvents = (params, callback, config) => {
47242
+ const { log, cache } = getActiveClient();
47243
+ if (!cache)
47244
+ console.log(ENABLE_CACHE_MESSAGE);
47245
+ const timestamp = Date.now();
47246
+ log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
47247
+ const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
47248
+ const disposers = myEventLiveCollection.startSubscription();
47249
+ const cacheKey = myEventLiveCollection.getCacheKey();
47250
+ disposers.push(() => dropFromCache(cacheKey));
47251
+ return () => {
47252
+ log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
47253
+ disposers.forEach(fn => fn());
47254
+ };
47255
+ };
47256
+
47257
+ class RSVPPaginationController extends PaginationController {
47258
+ async getRequest(queryParams, token) {
47259
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, eventId } = queryParams, params = __rest(queryParams, ["limit", "eventId"]);
47260
+ const options = token ? { token } : { limit };
47261
+ const { data: response } = await this.http.get(`/api/v1/events/${eventId}/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
47262
+ return response;
47263
+ }
47264
+ }
47265
+
47266
+ class RSVPQueryStreamController extends QueryStreamController {
47267
+ constructor(query, cacheKey, notifyChange, preparePayload) {
47268
+ super(query, cacheKey);
47269
+ this.notifyChange = notifyChange;
47270
+ this.preparePayload = preparePayload;
47271
+ }
47272
+ async saveToMainDB(response) {
47273
+ const processedPayload = this.preparePayload(response);
47274
+ const client = getActiveClient();
47275
+ const cachedAt = client.cache && Date.now();
47276
+ if (client.cache)
47277
+ ingestInCache(processedPayload, { cachedAt });
47278
+ }
47279
+ appendToQueryStream(response, direction, refresh = false) {
47280
+ var _a, _b;
47281
+ if (refresh) {
47282
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
47283
+ }
47284
+ else {
47285
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47286
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
47287
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
47288
+ }
47289
+ }
47290
+ reactor(action) {
47291
+ return (event) => {
47292
+ var _a;
47293
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47294
+ if (!collection)
47295
+ return;
47296
+ if (action === EventActionsEnum.OnEventCreated) {
47297
+ const client = getActiveClient();
47298
+ if (client.userId !== event.userId)
47299
+ return;
47300
+ collection.data = [...new Set([event.eventId, ...collection.data])];
47301
+ }
47302
+ if (action === EventActionsEnum.OnEventDeleted) {
47303
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
47304
+ }
47305
+ pushToCache(this.cacheKey, collection);
47306
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
47307
+ };
47308
+ }
47309
+ subscribeRTE(createSubscriber) {
47310
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
47311
+ }
47312
+ }
47313
+
47314
+ class RSVPLiveCollectionController extends LiveCollectionController {
47315
+ constructor(query, callback) {
47316
+ const queryStreamId = hash(query);
47317
+ const cacheKey = ['event', 'collection', queryStreamId];
47318
+ const paginationController = new RSVPPaginationController(query);
47319
+ super(paginationController, queryStreamId, cacheKey, callback);
47320
+ this.query = query;
47321
+ this.queryStreamController = new RSVPQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
47322
+ this.callback = callback.bind(this);
47323
+ this.loadPage({ initial: true });
47324
+ }
47325
+ setup() {
47326
+ var _a;
47327
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47328
+ if (!collection)
47329
+ pushToCache(this.cacheKey, { data: [], params: {} });
47330
+ }
47331
+ async persistModel(queryPayload) {
47332
+ await this.queryStreamController.saveToMainDB(queryPayload);
47333
+ }
47334
+ persistQueryStream({ response, direction, refresh, }) {
47335
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
47336
+ }
47337
+ startSubscription() {
47338
+ return this.queryStreamController.subscribeRTE([
47339
+ { fn: onRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
47340
+ { fn: onRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
47341
+ { fn: onLocalRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
47342
+ { fn: onLocalRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
47343
+ ]);
47344
+ }
47345
+ notifyChange({ origin, loading, error }) {
47346
+ var _a, _b;
47347
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47348
+ if (!collection)
47349
+ return;
47350
+ const data = ((_b = collection.data
47351
+ .map(eventId => pullFromCache(['event', 'get', eventId]))
47352
+ .filter(isNonNullable)
47353
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
47354
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
47355
+ return;
47356
+ this.callback({
47357
+ data,
47358
+ error,
47359
+ loading,
47360
+ hasNextPage: !!this.paginationController.getNextToken(),
47361
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
47362
+ });
47363
+ }
47364
+ }
47365
+
47366
+ /**
47367
+ * Get events
47368
+ *
47369
+ * @param params the query parameters
47370
+ * @param callback the callback to be called when the events are updated
47371
+ * @returns events
47372
+ *
47373
+ * @category RSVP Live Collection
47374
+ *
47375
+ */
47376
+ const getRSVPs = (params, callback, config) => {
47377
+ const { log, cache } = getActiveClient();
47378
+ if (!cache)
47379
+ console.log(ENABLE_CACHE_MESSAGE);
47380
+ const timestamp = Date.now();
47381
+ log(`getRSVPs: (tmpid: ${timestamp}) > listen`);
47382
+ const eventLiveCollection = new RSVPLiveCollectionController(params, callback);
47383
+ const disposers = eventLiveCollection.startSubscription();
47384
+ const cacheKey = eventLiveCollection.getCacheKey();
47385
+ disposers.push(() => dropFromCache(cacheKey));
47386
+ return () => {
47387
+ log(`getRSVPs (tmpid: ${timestamp}) > dispose`);
47388
+ disposers.forEach(fn => fn());
47389
+ };
47390
+ };
47391
+
46840
47392
  var index = /*#__PURE__*/Object.freeze({
46841
47393
  __proto__: null,
46842
47394
  createEvent: createEvent,
@@ -46845,8 +47397,17 @@ var index = /*#__PURE__*/Object.freeze({
46845
47397
  onEventCreated: onEventCreated,
46846
47398
  onEventUpdated: onEventUpdated,
46847
47399
  onEventDeleted: onEventDeleted,
47400
+ onLocalEventCreated: onLocalEventCreated,
47401
+ onLocalEventUpdated: onLocalEventUpdated,
47402
+ onLocalEventDeleted: onLocalEventDeleted,
47403
+ onRSVPCreated: onRSVPCreated,
47404
+ onRSVPUpdated: onRSVPUpdated,
47405
+ onLocalRSVPCreated: onLocalRSVPCreated,
47406
+ onLocalRSVPUpdated: onLocalRSVPUpdated,
46848
47407
  getEvent: getEvent,
46849
- getEvents: getEvents
47408
+ getEvents: getEvents,
47409
+ getMyEvents: getMyEvents,
47410
+ getRSVPs: getRSVPs
46850
47411
  });
46851
47412
 
46852
- export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, AmityEventStatus, AmityEventType, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$7 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$5 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, 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, getLiveReactionTopic, 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$3 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 };
47413
+ export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, AmityEventResponseStatus, AmityEventStatus, AmityEventType, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$7 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$5 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, 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, getLiveReactionTopic, 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$3 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 };