@amityco/ts-sdk 7.11.1-ed060e83.0 → 7.11.1-f0f4372a.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 (60) 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/domains/community.d.ts +3 -0
  6. package/dist/@types/domains/community.d.ts.map +1 -1
  7. package/dist/@types/domains/event.d.ts +16 -8
  8. package/dist/@types/domains/event.d.ts.map +1 -1
  9. package/dist/@types/domains/notification.d.ts +3 -1
  10. package/dist/@types/domains/notification.d.ts.map +1 -1
  11. package/dist/core/events.d.ts +3 -3
  12. package/dist/core/events.d.ts.map +1 -1
  13. package/dist/core/model/idResolvers.d.ts.map +1 -1
  14. package/dist/eventRepository/events/enums.d.ts +3 -1
  15. package/dist/eventRepository/events/enums.d.ts.map +1 -1
  16. package/dist/eventRepository/events/index.d.ts +7 -0
  17. package/dist/eventRepository/events/index.d.ts.map +1 -1
  18. package/dist/eventRepository/events/onLocalEventCreated.d.ts +17 -0
  19. package/dist/eventRepository/events/onLocalEventCreated.d.ts.map +1 -0
  20. package/dist/eventRepository/events/onLocalEventDeleted.d.ts +17 -0
  21. package/dist/eventRepository/events/onLocalEventDeleted.d.ts.map +1 -0
  22. package/dist/eventRepository/events/onLocalEventUpdated.d.ts +17 -0
  23. package/dist/eventRepository/events/onLocalEventUpdated.d.ts.map +1 -0
  24. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts +17 -0
  25. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts.map +1 -0
  26. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts +17 -0
  27. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts.map +1 -0
  28. package/dist/eventRepository/events/onRSVPCreated.d.ts +17 -0
  29. package/dist/eventRepository/events/onRSVPCreated.d.ts.map +1 -0
  30. package/dist/eventRepository/events/onRSVPUpdated.d.ts +17 -0
  31. package/dist/eventRepository/events/onRSVPUpdated.d.ts.map +1 -0
  32. package/dist/eventRepository/internalApi/createRSVP.d.ts +16 -0
  33. package/dist/eventRepository/internalApi/createRSVP.d.ts.map +1 -0
  34. package/dist/eventRepository/internalApi/getMyRSVP.d.ts +32 -0
  35. package/dist/eventRepository/internalApi/getMyRSVP.d.ts.map +1 -0
  36. package/dist/eventRepository/internalApi/index.d.ts +3 -0
  37. package/dist/eventRepository/internalApi/index.d.ts.map +1 -1
  38. package/dist/eventRepository/internalApi/updateRSVP.d.ts +17 -0
  39. package/dist/eventRepository/internalApi/updateRSVP.d.ts.map +1 -0
  40. package/dist/eventRepository/observers/getEvent.d.ts.map +1 -1
  41. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +1 -1
  42. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -1
  43. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +1 -1
  44. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts +13 -0
  45. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts.map +1 -0
  46. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts +5 -0
  47. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts.map +1 -0
  48. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts +15 -0
  49. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts.map +1 -0
  50. package/dist/eventRepository/observers/getRSVPs.d.ts +12 -0
  51. package/dist/eventRepository/observers/getRSVPs.d.ts.map +1 -0
  52. package/dist/eventRepository/observers/index.d.ts +1 -0
  53. package/dist/eventRepository/observers/index.d.ts.map +1 -1
  54. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +1 -1
  55. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -1
  56. package/dist/index.cjs.js +462 -36
  57. package/dist/index.esm.js +462 -36
  58. package/dist/index.umd.js +3 -3
  59. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -1
  60. package/package.json +1 -1
package/dist/index.cjs.js CHANGED
@@ -212,7 +212,6 @@ exports.AmityEventStatus = void 0;
212
212
  exports.AmityEventResponseStatus = void 0;
213
213
  (function (AmityEventResponseStatus) {
214
214
  AmityEventResponseStatus["Going"] = "going";
215
- AmityEventResponseStatus["Interested"] = "interested";
216
215
  AmityEventResponseStatus["NotGoing"] = "not_going";
217
216
  })(exports.AmityEventResponseStatus || (exports.AmityEventResponseStatus = {}));
218
217
 
@@ -665,6 +664,7 @@ const idResolvers = {
665
664
  invitation: ({ _id }) => _id,
666
665
  joinRequest: ({ joinRequestId }) => joinRequestId,
667
666
  event: ({ eventId }) => eventId,
667
+ discussionCommunity: ({ communityId }) => communityId,
668
668
  };
669
669
  /**
670
670
  * Retrieve the id resolver matching a domain name
@@ -721,7 +721,7 @@ const PAYLOAD2MODEL = {
721
721
  invitations: 'invitation',
722
722
  joinRequests: 'joinRequest',
723
723
  events: 'event',
724
- discussionCommunities: 'community',
724
+ discussionCommunities: 'discussionCommunity',
725
725
  };
726
726
  /** hidden */
727
727
  const isOutdated = (prevData, nextData) => {
@@ -13685,6 +13685,155 @@ const communityLinkedObject = (community) => {
13685
13685
  } });
13686
13686
  };
13687
13687
 
13688
+ const prepareEventPayload = (rawPayload) => {
13689
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
13690
+ };
13691
+
13692
+ const createEventEventSubscriber = (event, callback) => {
13693
+ const client = getActiveClient();
13694
+ const filter = (payload) => {
13695
+ const unpackedPayload = prepareEventPayload(payload);
13696
+ if (!client.cache) {
13697
+ callback(unpackedPayload.events[0]);
13698
+ }
13699
+ else {
13700
+ ingestInCache(unpackedPayload);
13701
+ const event = pullFromCache([
13702
+ 'event',
13703
+ 'get',
13704
+ unpackedPayload.events[0].eventId,
13705
+ ]);
13706
+ callback(event.data);
13707
+ }
13708
+ };
13709
+ return createEventSubscriber(client, event, event, filter);
13710
+ };
13711
+
13712
+ /* begin_public_function
13713
+ id: event.rsvp.create
13714
+ */
13715
+ /**
13716
+ * ```js
13717
+ * import { event } from '@amityco/ts-sdk'
13718
+ * const response = await event.createRSVP(eventId, status)
13719
+ * ```
13720
+ *
13721
+ * Creates an {@link Amity.InternalEvent}
13722
+ *
13723
+ * @param bundle The data necessary to create a new {@link Amity.InternalEvent}
13724
+ * @returns The newly created {@link Amity.InternalEvent}
13725
+ *
13726
+ * @category Event API
13727
+ * @async
13728
+ */
13729
+ const createRSVP = async (eventId, status) => {
13730
+ const client = getActiveClient();
13731
+ client.log('event/createRSVP', eventId, status);
13732
+ const { data: payload } = await client.http.post(`/api/v1/events/${eventId}/rsvp`, { status });
13733
+ fireEvent('local.rsvp.created', payload);
13734
+ const preparedPayload = prepareEventPayload(payload);
13735
+ const cachedAt = client.cache && Date.now();
13736
+ if (client.cache)
13737
+ ingestInCache(preparedPayload, { cachedAt });
13738
+ return {
13739
+ data: preparedPayload.events[0],
13740
+ cachedAt,
13741
+ };
13742
+ };
13743
+ /* end_public_function */
13744
+
13745
+ /* begin_public_function
13746
+ id: event.update
13747
+ */
13748
+ /**
13749
+ * ```js
13750
+ * import { event } from '@amityco/ts-sdk'
13751
+ * const response = await event.updateRSVP(eventId, status)
13752
+ * ```
13753
+ *
13754
+ * Updates an {@link Amity.InternalEvent}
13755
+ *
13756
+ * @param eventId The ID of the {@link Amity.InternalEvent} to edit
13757
+ * @param bundle The data necessary to update an existing {@link Amity.InternalEvent}
13758
+ * @returns the updated {@link Amity.InternalEvent}
13759
+ *
13760
+ * @category Event API
13761
+ * @async
13762
+ */
13763
+ const updateRSVP = async (eventId, status) => {
13764
+ const client = getActiveClient();
13765
+ client.log('event/updateRSVP', eventId, status);
13766
+ const { data: payload } = await client.http.put(`/api/v1/events/${eventId}/rsvp`, { status });
13767
+ fireEvent('local.rsvp.updated', payload);
13768
+ const preparedPayload = prepareEventPayload(payload);
13769
+ const cachedAt = client.cache && Date.now();
13770
+ if (client.cache)
13771
+ ingestInCache(preparedPayload, { cachedAt });
13772
+ return {
13773
+ data: preparedPayload.events.find(event => event.eventId === eventId),
13774
+ cachedAt,
13775
+ };
13776
+ };
13777
+ /* end_public_function */
13778
+
13779
+ /* begin_public_function
13780
+ id: event.rsvp.me
13781
+ */
13782
+ /**
13783
+ * ```js
13784
+ * import { event } from '@amityco/ts-sdk'
13785
+ * const myRSVP = await event.getMyRSVP(eventId)
13786
+ * ```
13787
+ *
13788
+ * Joins a {@link Amity.InternalEvent} object
13789
+ *
13790
+ * @param eventId the {@link Amity.InternalEvent} to get RSVP for
13791
+ * @returns A success boolean if the {@link Amity.InternalEvent} RSVP was retrieved
13792
+ *
13793
+ * @category Event API
13794
+ * @async
13795
+ */
13796
+ const getMyRSVP = async (eventId) => {
13797
+ const client = getActiveClient();
13798
+ client.log('event/getMyRSVP', eventId);
13799
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}/me/rsvp`);
13800
+ const data = prepareEventPayload(payload);
13801
+ const cachedAt = client.cache && Date.now();
13802
+ if (client.cache)
13803
+ ingestInCache(data, { cachedAt });
13804
+ return {
13805
+ data: data.events.find(event => event.eventId === eventId),
13806
+ cachedAt,
13807
+ };
13808
+ };
13809
+ /* end_public_function */
13810
+ /**
13811
+ * ```js
13812
+ * import { event } from '@amityco/ts-sdk'
13813
+ * const event = event.getMyRSVP.locally(eventId)
13814
+ * ```
13815
+ *
13816
+ * Fetches a {@link Amity.InternalEvent} object in cache
13817
+ *
13818
+ * @param eventId the ID of the {@link Amity.InternalEvent} to fetch
13819
+ * @returns the associated {@link Amity.InternalEvent} object
13820
+ *
13821
+ * @category Event API
13822
+ */
13823
+ getMyRSVP.locally = (eventId) => {
13824
+ const client = getActiveClient();
13825
+ client.log('event/getMyRSVP.locally', eventId);
13826
+ if (!client.cache)
13827
+ return;
13828
+ const cache = pullFromCache(['event', 'getMyRSVP', eventId]);
13829
+ if (!cache)
13830
+ return;
13831
+ return {
13832
+ data: cache.data,
13833
+ cachedAt: cache.cachedAt,
13834
+ };
13835
+ };
13836
+
13688
13837
  const eventLinkedObject = (event) => {
13689
13838
  return Object.assign(Object.assign({}, event), { get creator() {
13690
13839
  const cacheData = pullFromCache(['user', 'get', event.userId]);
@@ -13696,7 +13845,7 @@ const eventLinkedObject = (event) => {
13696
13845
  if (!event.discussionCommunityId)
13697
13846
  return;
13698
13847
  const cacheData = pullFromCache([
13699
- 'community',
13848
+ 'discussionCommunity',
13700
13849
  'get',
13701
13850
  event.discussionCommunityId,
13702
13851
  ]);
@@ -13704,6 +13853,22 @@ const eventLinkedObject = (event) => {
13704
13853
  return;
13705
13854
  return communityLinkedObject(cacheData.data);
13706
13855
  },
13856
+ get targetCommunity() {
13857
+ if (!event.originId)
13858
+ return;
13859
+ const cacheData = pullFromCache(['community', 'get', event.originId]);
13860
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13861
+ return;
13862
+ return communityLinkedObject(cacheData.data);
13863
+ },
13864
+ get coverImage() {
13865
+ if (!event.coverImageFileId)
13866
+ return;
13867
+ const cacheData = pullFromCache(['file', 'get', event.coverImageFileId]);
13868
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13869
+ return;
13870
+ return cacheData.data;
13871
+ },
13707
13872
  get liveStream() {
13708
13873
  if (!event.livestreamId)
13709
13874
  return;
@@ -13711,6 +13876,15 @@ const eventLinkedObject = (event) => {
13711
13876
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13712
13877
  return;
13713
13878
  return cacheData.data;
13879
+ }, createRSVP: async (status) => {
13880
+ const { data } = await createRSVP(event.eventId, status);
13881
+ return data;
13882
+ }, updateRSVP: async (status) => {
13883
+ const { data } = await updateRSVP(event.eventId, status);
13884
+ return data;
13885
+ }, getMyRSVP: async () => {
13886
+ const { data } = await getMyRSVP(event.eventId);
13887
+ return data;
13714
13888
  } });
13715
13889
  };
13716
13890
 
@@ -30350,30 +30524,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
30350
30524
  getReactions: getReactions
30351
30525
  });
30352
30526
 
30353
- const prepareEventPayload = (rawPayload) => {
30354
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
30355
- };
30356
-
30357
- const createEventEventSubscriber = (event, callback) => {
30358
- const client = getActiveClient();
30359
- const filter = (payload) => {
30360
- const unpackedPayload = prepareEventPayload(payload);
30361
- if (!client.cache) {
30362
- callback(unpackedPayload.events[0]);
30363
- }
30364
- else {
30365
- ingestInCache(unpackedPayload);
30366
- const event = pullFromCache([
30367
- 'event',
30368
- 'get',
30369
- unpackedPayload.events[0].eventId,
30370
- ]);
30371
- callback(event.data);
30372
- }
30373
- };
30374
- return createEventSubscriber(client, event, event, filter);
30375
- };
30376
-
30377
30527
  /* begin_public_function
30378
30528
  id: event.create
30379
30529
  */
@@ -30395,7 +30545,7 @@ const createEvent = async (bundle) => {
30395
30545
  const client = getActiveClient();
30396
30546
  client.log('event/createEvent', bundle);
30397
30547
  const { data: payload } = await client.http.post('/api/v1/events', bundle);
30398
- fireEvent('event.created', payload);
30548
+ fireEvent('local.event.created', payload);
30399
30549
  const preparedPayload = prepareEventPayload(payload);
30400
30550
  const cachedAt = client.cache && Date.now();
30401
30551
  if (client.cache)
@@ -30429,7 +30579,7 @@ const updateEvent = async (eventId, bundle) => {
30429
30579
  const client = getActiveClient();
30430
30580
  client.log('event/updateEvent', eventId, bundle);
30431
30581
  const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
30432
- fireEvent('event.updated', payload);
30582
+ fireEvent('local.event.updated', payload);
30433
30583
  const preparedPayload = prepareEventPayload(payload);
30434
30584
  const cachedAt = client.cache && Date.now();
30435
30585
  if (client.cache)
@@ -30461,7 +30611,7 @@ const updateEvent = async (eventId, bundle) => {
30461
30611
  const getEvent$1 = async (eventId) => {
30462
30612
  const client = getActiveClient();
30463
30613
  client.log('event/getEvent', eventId);
30464
- const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
30614
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
30465
30615
  const data = prepareEventPayload(payload);
30466
30616
  const cachedAt = client.cache && Date.now();
30467
30617
  if (client.cache)
@@ -30519,10 +30669,10 @@ const deleteEvent = async (eventId) => {
30519
30669
  const client = getActiveClient();
30520
30670
  client.log('event/deleteEvent', eventId);
30521
30671
  const event = await getEvent$1(eventId);
30522
- await client.http.delete(`/api/v3/events/${eventId}`);
30672
+ await client.http.delete(`/api/v1/events/${eventId}`);
30523
30673
  const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
30524
30674
  upsertInCache(['event', 'get', eventId], deletedEvent);
30525
- fireEvent('event.deleted', {
30675
+ fireEvent('local.event.deleted', {
30526
30676
  users: [],
30527
30677
  files: [],
30528
30678
  communities: [],
@@ -30584,6 +30734,125 @@ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated',
30584
30734
  */
30585
30735
  const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
30586
30736
 
30737
+ /**
30738
+ * ```js
30739
+ * import { EventRepository } from '@amityco/ts-sdk'
30740
+ * const dispose = EventRepository.onLocalEventCreated(event => {
30741
+ * // ...
30742
+ * })
30743
+ * ```
30744
+ *
30745
+ * Fired when a {@link Amity.Event} has been created
30746
+ *
30747
+ * @param callback The function to call when the event was fired
30748
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30749
+ *
30750
+ * @category Event Events
30751
+ */
30752
+ const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
30753
+
30754
+ /**
30755
+ * ```js
30756
+ * import { EventRepository } from '@amityco/ts-sdk'
30757
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
30758
+ * // ...
30759
+ * })
30760
+ * ```
30761
+ *
30762
+ * Fired when a {@link Amity.Event} has been updated
30763
+ *
30764
+ * @param callback The function to call when the event was fired
30765
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30766
+ *
30767
+ * @category Event Events
30768
+ */
30769
+ const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
30770
+
30771
+ /**
30772
+ * ```js
30773
+ * import { EventRepository } from '@amityco/ts-sdk'
30774
+ * const dispose = EventRepository.onLocalEventDeleted(event => {
30775
+ * // ...
30776
+ * })
30777
+ * ```
30778
+ *
30779
+ * Fired when a {@link Amity.Event} has been deleted
30780
+ *
30781
+ * @param callback The function to call when the event was fired
30782
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30783
+ *
30784
+ * @category Event Events
30785
+ */
30786
+ const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
30787
+
30788
+ /**
30789
+ * ```js
30790
+ * import { EventRepository } from '@amityco/ts-sdk'
30791
+ * const dispose = EventRepository.onRSVPCreated(event => {
30792
+ * // ...
30793
+ * })
30794
+ * ```
30795
+ *
30796
+ * Fired when a {@link Amity.Event} has been created
30797
+ *
30798
+ * @param callback The function to call when the event was fired
30799
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30800
+ *
30801
+ * @category Event Events
30802
+ */
30803
+ const onRSVPCreated = (callback) => createEventEventSubscriber('event.rsvp.created', callback);
30804
+
30805
+ /**
30806
+ * ```js
30807
+ * import { EventRepository } from '@amityco/ts-sdk'
30808
+ * const dispose = EventRepository.onRSVPUpdated(event => {
30809
+ * // ...
30810
+ * })
30811
+ * ```
30812
+ *
30813
+ * Fired when a {@link Amity.Event} has been updated
30814
+ *
30815
+ * @param callback The function to call when the event was fired
30816
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30817
+ *
30818
+ * @category Event Events
30819
+ */
30820
+ const onRSVPUpdated = (callback) => createEventEventSubscriber('event.rsvp.updated', callback);
30821
+
30822
+ /**
30823
+ * ```js
30824
+ * import { EventRepository } from '@amityco/ts-sdk'
30825
+ * const dispose = EventRepository.onLocalRSVPCreated(event => {
30826
+ * // ...
30827
+ * })
30828
+ * ```
30829
+ *
30830
+ * Fired when a {@link Amity.Event} has been created
30831
+ *
30832
+ * @param callback The function to call when the event was fired
30833
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30834
+ *
30835
+ * @category Event Events
30836
+ */
30837
+ const onLocalRSVPCreated = (callback) => createEventEventSubscriber('local.rsvp.created', callback);
30838
+
30839
+ /**
30840
+ * ```js
30841
+ * import { EventRepository } from '@amityco/ts-sdk'
30842
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
30843
+ * // ...
30844
+ * })
30845
+ * ```
30846
+ *
30847
+ * Fired when a {@link Amity.Event} has been updated
30848
+ *
30849
+ * @param callback The function to call when the event was fired
30850
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30851
+ *
30852
+ * @category Event Events
30853
+ */
30854
+ const onLocalRSVPUpdated = (callback) => createEventEventSubscriber('local.rsvp.updated', callback);
30855
+
30587
30856
  /* begin_public_function
30588
30857
  id: event.get
30589
30858
  */
@@ -30607,7 +30876,7 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
30607
30876
  * @category Event Live Object
30608
30877
  */
30609
30878
  const getEvent = (eventId, callback) => {
30610
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
30879
+ return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
30611
30880
  callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
30612
30881
  });
30613
30882
  };
@@ -30618,6 +30887,8 @@ var EventActionsEnum;
30618
30887
  EventActionsEnum["OnEventCreated"] = "onEventCreated";
30619
30888
  EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
30620
30889
  EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
30890
+ EventActionsEnum["OnRSVPCreated"] = "onRSVPCreated";
30891
+ EventActionsEnum["OnRSVPUpdated"] = "onRSVPUpdated";
30621
30892
  })(EventActionsEnum || (EventActionsEnum = {}));
30622
30893
 
30623
30894
  class EventPaginationController extends PaginationController {
@@ -30702,6 +30973,9 @@ class EventLiveCollectionController extends LiveCollectionController {
30702
30973
  { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
30703
30974
  { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
30704
30975
  { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
30976
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
30977
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
30978
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
30705
30979
  ]);
30706
30980
  }
30707
30981
  notifyChange({ origin, loading, error }) {
@@ -30713,7 +30987,7 @@ class EventLiveCollectionController extends LiveCollectionController {
30713
30987
  .map(eventId => pullFromCache(['event', 'get', eventId]))
30714
30988
  .filter(isNonNullable)
30715
30989
  .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
30716
- if (!this.shouldNotify(data) && origin === 'event')
30990
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
30717
30991
  return;
30718
30992
  this.callback({
30719
30993
  data,
@@ -30790,6 +31064,12 @@ class MyEventQueryStreamController extends QueryStreamController {
30790
31064
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30791
31065
  if (!collection)
30792
31066
  return;
31067
+ if (action === EventActionsEnum.OnEventCreated) {
31068
+ const client = getActiveClient();
31069
+ if (client.userId !== event.userId)
31070
+ return;
31071
+ collection.data = [...new Set([event.eventId, ...collection.data])];
31072
+ }
30793
31073
  if (action === EventActionsEnum.OnEventDeleted) {
30794
31074
  collection.data = collection.data.filter(eventId => eventId !== event.eventId);
30795
31075
  }
@@ -30830,6 +31110,9 @@ class MyEventLiveCollectionController extends LiveCollectionController {
30830
31110
  { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
30831
31111
  { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
30832
31112
  { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
31113
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
31114
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
31115
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
30833
31116
  ]);
30834
31117
  }
30835
31118
  notifyChange({ origin, loading, error }) {
@@ -30841,7 +31124,7 @@ class MyEventLiveCollectionController extends LiveCollectionController {
30841
31124
  .map(eventId => pullFromCache(['event', 'get', eventId]))
30842
31125
  .filter(isNonNullable)
30843
31126
  .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
30844
- if (!this.shouldNotify(data) && origin === 'event')
31127
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
30845
31128
  return;
30846
31129
  this.callback({
30847
31130
  data,
@@ -30879,6 +31162,141 @@ const getMyEvents = (params, callback, config) => {
30879
31162
  };
30880
31163
  };
30881
31164
 
31165
+ class RSVPPaginationController extends PaginationController {
31166
+ async getRequest(queryParams, token) {
31167
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, eventId } = queryParams, params = __rest(queryParams, ["limit", "eventId"]);
31168
+ const options = token ? { token } : { limit };
31169
+ const { data: response } = await this.http.get(`/api/v1/events/${eventId}/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
31170
+ return response;
31171
+ }
31172
+ }
31173
+
31174
+ class RSVPQueryStreamController extends QueryStreamController {
31175
+ constructor(query, cacheKey, notifyChange, preparePayload) {
31176
+ super(query, cacheKey);
31177
+ this.notifyChange = notifyChange;
31178
+ this.preparePayload = preparePayload;
31179
+ }
31180
+ async saveToMainDB(response) {
31181
+ const processedPayload = this.preparePayload(response);
31182
+ const client = getActiveClient();
31183
+ const cachedAt = client.cache && Date.now();
31184
+ if (client.cache)
31185
+ ingestInCache(processedPayload, { cachedAt });
31186
+ }
31187
+ appendToQueryStream(response, direction, refresh = false) {
31188
+ var _a, _b;
31189
+ if (refresh) {
31190
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
31191
+ }
31192
+ else {
31193
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31194
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
31195
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
31196
+ }
31197
+ }
31198
+ reactor(action) {
31199
+ return (event) => {
31200
+ var _a;
31201
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31202
+ if (!collection)
31203
+ return;
31204
+ if (action === EventActionsEnum.OnEventCreated) {
31205
+ const client = getActiveClient();
31206
+ if (client.userId !== event.userId)
31207
+ return;
31208
+ collection.data = [...new Set([event.eventId, ...collection.data])];
31209
+ }
31210
+ if (action === EventActionsEnum.OnEventDeleted) {
31211
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
31212
+ }
31213
+ pushToCache(this.cacheKey, collection);
31214
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
31215
+ };
31216
+ }
31217
+ subscribeRTE(createSubscriber) {
31218
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
31219
+ }
31220
+ }
31221
+
31222
+ class RSVPLiveCollectionController extends LiveCollectionController {
31223
+ constructor(query, callback) {
31224
+ const queryStreamId = hash__default["default"](query);
31225
+ const cacheKey = ['event', 'collection', queryStreamId];
31226
+ const paginationController = new RSVPPaginationController(query);
31227
+ super(paginationController, queryStreamId, cacheKey, callback);
31228
+ this.query = query;
31229
+ this.queryStreamController = new RSVPQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
31230
+ this.callback = callback.bind(this);
31231
+ this.loadPage({ initial: true });
31232
+ }
31233
+ setup() {
31234
+ var _a;
31235
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31236
+ if (!collection)
31237
+ pushToCache(this.cacheKey, { data: [], params: {} });
31238
+ }
31239
+ async persistModel(queryPayload) {
31240
+ await this.queryStreamController.saveToMainDB(queryPayload);
31241
+ }
31242
+ persistQueryStream({ response, direction, refresh, }) {
31243
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
31244
+ }
31245
+ startSubscription() {
31246
+ return this.queryStreamController.subscribeRTE([
31247
+ { fn: onRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
31248
+ { fn: onRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
31249
+ { fn: onLocalRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
31250
+ { fn: onLocalRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
31251
+ ]);
31252
+ }
31253
+ notifyChange({ origin, loading, error }) {
31254
+ var _a, _b;
31255
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31256
+ if (!collection)
31257
+ return;
31258
+ const data = ((_b = collection.data
31259
+ .map(eventId => pullFromCache(['event', 'get', eventId]))
31260
+ .filter(isNonNullable)
31261
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
31262
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
31263
+ return;
31264
+ this.callback({
31265
+ data,
31266
+ error,
31267
+ loading,
31268
+ hasNextPage: !!this.paginationController.getNextToken(),
31269
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
31270
+ });
31271
+ }
31272
+ }
31273
+
31274
+ /**
31275
+ * Get events
31276
+ *
31277
+ * @param params the query parameters
31278
+ * @param callback the callback to be called when the events are updated
31279
+ * @returns events
31280
+ *
31281
+ * @category RSVP Live Collection
31282
+ *
31283
+ */
31284
+ const getRSVPs = (params, callback, config) => {
31285
+ const { log, cache } = getActiveClient();
31286
+ if (!cache)
31287
+ console.log(ENABLE_CACHE_MESSAGE);
31288
+ const timestamp = Date.now();
31289
+ log(`getRSVPs: (tmpid: ${timestamp}) > listen`);
31290
+ const eventLiveCollection = new RSVPLiveCollectionController(params, callback);
31291
+ const disposers = eventLiveCollection.startSubscription();
31292
+ const cacheKey = eventLiveCollection.getCacheKey();
31293
+ disposers.push(() => dropFromCache(cacheKey));
31294
+ return () => {
31295
+ log(`getRSVPs (tmpid: ${timestamp}) > dispose`);
31296
+ disposers.forEach(fn => fn());
31297
+ };
31298
+ };
31299
+
30882
31300
  var index = /*#__PURE__*/Object.freeze({
30883
31301
  __proto__: null,
30884
31302
  createEvent: createEvent,
@@ -30887,9 +31305,17 @@ var index = /*#__PURE__*/Object.freeze({
30887
31305
  onEventCreated: onEventCreated,
30888
31306
  onEventUpdated: onEventUpdated,
30889
31307
  onEventDeleted: onEventDeleted,
31308
+ onLocalEventCreated: onLocalEventCreated,
31309
+ onLocalEventUpdated: onLocalEventUpdated,
31310
+ onLocalEventDeleted: onLocalEventDeleted,
31311
+ onRSVPCreated: onRSVPCreated,
31312
+ onRSVPUpdated: onRSVPUpdated,
31313
+ onLocalRSVPCreated: onLocalRSVPCreated,
31314
+ onLocalRSVPUpdated: onLocalRSVPUpdated,
30890
31315
  getEvent: getEvent,
30891
31316
  getEvents: getEvents,
30892
- getMyEvents: getMyEvents
31317
+ getMyEvents: getMyEvents,
31318
+ getRSVPs: getRSVPs
30893
31319
  });
30894
31320
 
30895
31321
  exports.API_REGIONS = API_REGIONS;