@amityco/ts-sdk 7.11.1-9f733521.0 → 7.11.1-b4621cc1.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 (70) 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 +13 -0
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/core/permissions.d.ts +5 -1
  8. package/dist/@types/core/permissions.d.ts.map +1 -1
  9. package/dist/@types/domains/community.d.ts +3 -0
  10. package/dist/@types/domains/community.d.ts.map +1 -1
  11. package/dist/@types/domains/event.d.ts +37 -11
  12. package/dist/@types/domains/event.d.ts.map +1 -1
  13. package/dist/@types/domains/notification.d.ts +3 -1
  14. package/dist/@types/domains/notification.d.ts.map +1 -1
  15. package/dist/core/events.d.ts +3 -3
  16. package/dist/core/events.d.ts.map +1 -1
  17. package/dist/core/model/idResolvers.d.ts.map +1 -1
  18. package/dist/core/model/index.d.ts.map +1 -1
  19. package/dist/eventRepository/events/enums.d.ts +3 -1
  20. package/dist/eventRepository/events/enums.d.ts.map +1 -1
  21. package/dist/eventRepository/events/index.d.ts +7 -0
  22. package/dist/eventRepository/events/index.d.ts.map +1 -1
  23. package/dist/eventRepository/events/onLocalEventCreated.d.ts +17 -0
  24. package/dist/eventRepository/events/onLocalEventCreated.d.ts.map +1 -0
  25. package/dist/eventRepository/events/onLocalEventDeleted.d.ts +17 -0
  26. package/dist/eventRepository/events/onLocalEventDeleted.d.ts.map +1 -0
  27. package/dist/eventRepository/events/onLocalEventUpdated.d.ts +17 -0
  28. package/dist/eventRepository/events/onLocalEventUpdated.d.ts.map +1 -0
  29. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts +17 -0
  30. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts.map +1 -0
  31. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts +17 -0
  32. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts.map +1 -0
  33. package/dist/eventRepository/events/onRSVPCreated.d.ts +17 -0
  34. package/dist/eventRepository/events/onRSVPCreated.d.ts.map +1 -0
  35. package/dist/eventRepository/events/onRSVPUpdated.d.ts +17 -0
  36. package/dist/eventRepository/events/onRSVPUpdated.d.ts.map +1 -0
  37. package/dist/eventRepository/internalApi/createRSVP.d.ts +16 -0
  38. package/dist/eventRepository/internalApi/createRSVP.d.ts.map +1 -0
  39. package/dist/eventRepository/internalApi/getMyRSVP.d.ts +32 -0
  40. package/dist/eventRepository/internalApi/getMyRSVP.d.ts.map +1 -0
  41. package/dist/eventRepository/internalApi/index.d.ts +3 -0
  42. package/dist/eventRepository/internalApi/index.d.ts.map +1 -1
  43. package/dist/eventRepository/internalApi/updateRSVP.d.ts +17 -0
  44. package/dist/eventRepository/internalApi/updateRSVP.d.ts.map +1 -0
  45. package/dist/eventRepository/observers/getEvent.d.ts.map +1 -1
  46. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +1 -1
  47. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -1
  48. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts +13 -0
  49. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts.map +1 -0
  50. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts +5 -0
  51. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts.map +1 -0
  52. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts +15 -0
  53. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts.map +1 -0
  54. package/dist/eventRepository/observers/getRSVPs.d.ts +12 -0
  55. package/dist/eventRepository/observers/getRSVPs.d.ts.map +1 -0
  56. package/dist/eventRepository/observers/index.d.ts +1 -0
  57. package/dist/eventRepository/observers/index.d.ts.map +1 -1
  58. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +1 -1
  59. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -1
  60. package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts +2 -0
  61. package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts.map +1 -0
  62. package/dist/eventRepository/utils/index.d.ts +2 -0
  63. package/dist/eventRepository/utils/index.d.ts.map +1 -1
  64. package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts +2 -0
  65. package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts.map +1 -0
  66. package/dist/index.cjs.js +486 -34
  67. package/dist/index.esm.js +486 -34
  68. package/dist/index.umd.js +3 -3
  69. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -1
  70. 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,8 @@ const idResolvers = {
665
664
  invitation: ({ _id }) => _id,
666
665
  joinRequest: ({ joinRequestId }) => joinRequestId,
667
666
  event: ({ eventId }) => eventId,
667
+ eventResponse: ({ eventId }) => eventId,
668
+ discussionCommunity: ({ communityId }) => communityId,
668
669
  };
669
670
  /**
670
671
  * Retrieve the id resolver matching a domain name
@@ -721,7 +722,8 @@ const PAYLOAD2MODEL = {
721
722
  invitations: 'invitation',
722
723
  joinRequests: 'joinRequest',
723
724
  events: 'event',
724
- discussionCommunities: 'community',
725
+ eventResponse: 'eventResponse',
726
+ discussionCommunities: 'discussionCommunity',
725
727
  };
726
728
  /** hidden */
727
729
  const isOutdated = (prevData, nextData) => {
@@ -13685,6 +13687,185 @@ const communityLinkedObject = (community) => {
13685
13687
  } });
13686
13688
  };
13687
13689
 
13690
+ const prepareEventResponsePayload = (rawPayload) => {
13691
+ return {
13692
+ status: rawPayload.eventResponses[0].status,
13693
+ eventId: rawPayload.eventResponses[0].eventId,
13694
+ event: rawPayload.events,
13695
+ userId: rawPayload.eventResponses[0].userId,
13696
+ user: rawPayload.users.map(convertRawUserToInternalUser),
13697
+ };
13698
+ };
13699
+
13700
+ /* begin_public_function
13701
+ id: event.rsvp.create
13702
+ */
13703
+ /**
13704
+ * ```js
13705
+ * import { event } from '@amityco/ts-sdk'
13706
+ * const response = await event.createRSVP(eventId, status)
13707
+ * ```
13708
+ *
13709
+ * Creates an {@link Amity.InternalEvent}
13710
+ *
13711
+ * @param bundle The data necessary to create a new {@link Amity.InternalEvent}
13712
+ * @returns The newly created {@link Amity.InternalEvent}
13713
+ *
13714
+ * @category Event API
13715
+ * @async
13716
+ */
13717
+ const createRSVP = async (eventId, status) => {
13718
+ const client = getActiveClient();
13719
+ client.log('event/createRSVP', eventId, status);
13720
+ const { data: payload } = await client.http.post(`/api/v1/events/${eventId}/rsvp`, { status });
13721
+ fireEvent('local.rsvp.created', payload);
13722
+ const data = prepareEventResponsePayload(payload);
13723
+ const cachedAt = client.cache && Date.now();
13724
+ if (client.cache)
13725
+ ingestInCache({ eventResponses: [data] }, { cachedAt });
13726
+ return {
13727
+ data,
13728
+ cachedAt,
13729
+ };
13730
+ };
13731
+ /* end_public_function */
13732
+
13733
+ /* begin_public_function
13734
+ id: event.update
13735
+ */
13736
+ /**
13737
+ * ```js
13738
+ * import { event } from '@amityco/ts-sdk'
13739
+ * const response = await event.updateRSVP(eventId, status)
13740
+ * ```
13741
+ *
13742
+ * Updates an {@link Amity.EventResponse}
13743
+ *
13744
+ * @param eventId The ID of the {@link Amity.EventResponse} to edit
13745
+ * @param bundle The data necessary to update an existing {@link Amity.EventResponse}
13746
+ * @returns the updated {@link Amity.EventResponse}
13747
+ *
13748
+ * @category Event API
13749
+ * @async
13750
+ */
13751
+ const updateRSVP = async (eventId, status) => {
13752
+ const client = getActiveClient();
13753
+ client.log('event/updateRSVP', eventId, status);
13754
+ const { data: payload } = await client.http.put(`/api/v1/events/${eventId}/rsvp`, { status });
13755
+ fireEvent('local.rsvp.updated', payload);
13756
+ const data = prepareEventResponsePayload(payload);
13757
+ const cachedAt = client.cache && Date.now();
13758
+ if (client.cache)
13759
+ ingestInCache({ eventResponses: [data] }, { cachedAt });
13760
+ return {
13761
+ data,
13762
+ cachedAt,
13763
+ };
13764
+ };
13765
+ /* end_public_function */
13766
+
13767
+ const prepareEventPayload = (rawPayload) => {
13768
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
13769
+ };
13770
+
13771
+ const createEventEventSubscriber = (event, callback) => {
13772
+ const client = getActiveClient();
13773
+ const filter = (payload) => {
13774
+ const unpackedPayload = prepareEventPayload(payload);
13775
+ if (!client.cache) {
13776
+ callback(unpackedPayload.events[0]);
13777
+ }
13778
+ else {
13779
+ ingestInCache(unpackedPayload);
13780
+ const event = pullFromCache([
13781
+ 'event',
13782
+ 'get',
13783
+ unpackedPayload.events[0].eventId,
13784
+ ]);
13785
+ callback(event.data);
13786
+ }
13787
+ };
13788
+ return createEventSubscriber(client, event, event, filter);
13789
+ };
13790
+
13791
+ const createEventResponseSubscriber = (event, callback) => {
13792
+ const client = getActiveClient();
13793
+ const filter = (payload) => {
13794
+ const unpackedPayload = prepareEventResponsePayload(payload);
13795
+ if (!client.cache) {
13796
+ callback(unpackedPayload);
13797
+ }
13798
+ else {
13799
+ ingestInCache(unpackedPayload.event[0]);
13800
+ const eventResponse = pullFromCache([
13801
+ 'eventResponse',
13802
+ 'get',
13803
+ payload.eventResponses[0].eventId,
13804
+ ]);
13805
+ callback(eventResponse.data);
13806
+ }
13807
+ };
13808
+ return createEventSubscriber(client, event, event, filter);
13809
+ };
13810
+
13811
+ /* begin_public_function
13812
+ id: event.rsvp.me
13813
+ */
13814
+ /**
13815
+ * ```js
13816
+ * import { event } from '@amityco/ts-sdk'
13817
+ * const myRSVP = await event.getMyRSVP()
13818
+ * ```
13819
+ *
13820
+ * Joins a {@link Amity.EventResponse} object
13821
+ *
13822
+ * @param eventId the {@link Amity.EventResponse} to get RSVP for
13823
+ * @returns A success boolean if the {@link Amity.EventResponse} RSVP was retrieved
13824
+ *
13825
+ * @category Event API
13826
+ * @async
13827
+ */
13828
+ const getMyRSVP = async (eventId) => {
13829
+ const client = getActiveClient();
13830
+ client.log('event/getMyRSVP', eventId);
13831
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}/me/rsvp`);
13832
+ const data = prepareEventResponsePayload(payload);
13833
+ const cachedAt = client.cache && Date.now();
13834
+ if (client.cache)
13835
+ ingestInCache({ eventResponses: [data] }, { cachedAt });
13836
+ return {
13837
+ data,
13838
+ cachedAt,
13839
+ };
13840
+ };
13841
+ /* end_public_function */
13842
+ /**
13843
+ * ```js
13844
+ * import { event } from '@amityco/ts-sdk'
13845
+ * const event = event.getMyRSVP.locally(eventId)
13846
+ * ```
13847
+ *
13848
+ * Fetches a {@link Amity.EventResponse} object in cache
13849
+ *
13850
+ * @param eventId the ID of the {@link Amity.EventResponse} to fetch
13851
+ * @returns the associated {@link Amity.EventResponse} object
13852
+ *
13853
+ * @category Event API
13854
+ */
13855
+ getMyRSVP.locally = (eventId) => {
13856
+ const client = getActiveClient();
13857
+ client.log('event/getMyRSVP.locally', eventId);
13858
+ if (!client.cache)
13859
+ return;
13860
+ const cache = pullFromCache(['event', 'getMyRSVP', eventId]);
13861
+ if (!cache)
13862
+ return;
13863
+ return {
13864
+ data: cache.data,
13865
+ cachedAt: cache.cachedAt,
13866
+ };
13867
+ };
13868
+
13688
13869
  const eventLinkedObject = (event) => {
13689
13870
  return Object.assign(Object.assign({}, event), { get creator() {
13690
13871
  const cacheData = pullFromCache(['user', 'get', event.userId]);
@@ -13696,7 +13877,7 @@ const eventLinkedObject = (event) => {
13696
13877
  if (!event.discussionCommunityId)
13697
13878
  return;
13698
13879
  const cacheData = pullFromCache([
13699
- 'community',
13880
+ 'discussionCommunity',
13700
13881
  'get',
13701
13882
  event.discussionCommunityId,
13702
13883
  ]);
@@ -13704,6 +13885,22 @@ const eventLinkedObject = (event) => {
13704
13885
  return;
13705
13886
  return communityLinkedObject(cacheData.data);
13706
13887
  },
13888
+ get targetCommunity() {
13889
+ if (!event.originId)
13890
+ return;
13891
+ const cacheData = pullFromCache(['community', 'get', event.originId]);
13892
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13893
+ return;
13894
+ return communityLinkedObject(cacheData.data);
13895
+ },
13896
+ get coverImage() {
13897
+ if (!event.coverImageFileId)
13898
+ return;
13899
+ const cacheData = pullFromCache(['file', 'get', event.coverImageFileId]);
13900
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13901
+ return;
13902
+ return cacheData.data;
13903
+ },
13707
13904
  get liveStream() {
13708
13905
  if (!event.livestreamId)
13709
13906
  return;
@@ -13711,6 +13908,15 @@ const eventLinkedObject = (event) => {
13711
13908
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13712
13909
  return;
13713
13910
  return cacheData.data;
13911
+ }, createRSVP: async (status) => {
13912
+ const { data } = await createRSVP(event.eventId, status);
13913
+ return data;
13914
+ }, updateRSVP: async (status) => {
13915
+ const { data } = await updateRSVP(event.eventId, status);
13916
+ return data;
13917
+ }, getMyRSVP: async () => {
13918
+ const { data } = await getMyRSVP(event.eventId);
13919
+ return data;
13714
13920
  } });
13715
13921
  };
13716
13922
 
@@ -30350,30 +30556,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
30350
30556
  getReactions: getReactions
30351
30557
  });
30352
30558
 
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
30559
  /* begin_public_function
30378
30560
  id: event.create
30379
30561
  */
@@ -30395,7 +30577,7 @@ const createEvent = async (bundle) => {
30395
30577
  const client = getActiveClient();
30396
30578
  client.log('event/createEvent', bundle);
30397
30579
  const { data: payload } = await client.http.post('/api/v1/events', bundle);
30398
- fireEvent('event.created', payload);
30580
+ fireEvent('local.event.created', payload);
30399
30581
  const preparedPayload = prepareEventPayload(payload);
30400
30582
  const cachedAt = client.cache && Date.now();
30401
30583
  if (client.cache)
@@ -30429,7 +30611,7 @@ const updateEvent = async (eventId, bundle) => {
30429
30611
  const client = getActiveClient();
30430
30612
  client.log('event/updateEvent', eventId, bundle);
30431
30613
  const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
30432
- fireEvent('event.updated', payload);
30614
+ fireEvent('local.event.updated', payload);
30433
30615
  const preparedPayload = prepareEventPayload(payload);
30434
30616
  const cachedAt = client.cache && Date.now();
30435
30617
  if (client.cache)
@@ -30461,7 +30643,7 @@ const updateEvent = async (eventId, bundle) => {
30461
30643
  const getEvent$1 = async (eventId) => {
30462
30644
  const client = getActiveClient();
30463
30645
  client.log('event/getEvent', eventId);
30464
- const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
30646
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
30465
30647
  const data = prepareEventPayload(payload);
30466
30648
  const cachedAt = client.cache && Date.now();
30467
30649
  if (client.cache)
@@ -30519,10 +30701,10 @@ const deleteEvent = async (eventId) => {
30519
30701
  const client = getActiveClient();
30520
30702
  client.log('event/deleteEvent', eventId);
30521
30703
  const event = await getEvent$1(eventId);
30522
- await client.http.delete(`/api/v3/events/${eventId}`);
30704
+ await client.http.delete(`/api/v1/events/${eventId}`);
30523
30705
  const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
30524
30706
  upsertInCache(['event', 'get', eventId], deletedEvent);
30525
- fireEvent('event.deleted', {
30707
+ fireEvent('local.event.deleted', {
30526
30708
  users: [],
30527
30709
  files: [],
30528
30710
  communities: [],
@@ -30584,6 +30766,125 @@ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated',
30584
30766
  */
30585
30767
  const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
30586
30768
 
30769
+ /**
30770
+ * ```js
30771
+ * import { EventRepository } from '@amityco/ts-sdk'
30772
+ * const dispose = EventRepository.onLocalEventCreated(event => {
30773
+ * // ...
30774
+ * })
30775
+ * ```
30776
+ *
30777
+ * Fired when a {@link Amity.Event} has been created
30778
+ *
30779
+ * @param callback The function to call when the event was fired
30780
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30781
+ *
30782
+ * @category Event Events
30783
+ */
30784
+ const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
30785
+
30786
+ /**
30787
+ * ```js
30788
+ * import { EventRepository } from '@amityco/ts-sdk'
30789
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
30790
+ * // ...
30791
+ * })
30792
+ * ```
30793
+ *
30794
+ * Fired when a {@link Amity.Event} has been updated
30795
+ *
30796
+ * @param callback The function to call when the event was fired
30797
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30798
+ *
30799
+ * @category Event Events
30800
+ */
30801
+ const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
30802
+
30803
+ /**
30804
+ * ```js
30805
+ * import { EventRepository } from '@amityco/ts-sdk'
30806
+ * const dispose = EventRepository.onLocalEventDeleted(event => {
30807
+ * // ...
30808
+ * })
30809
+ * ```
30810
+ *
30811
+ * Fired when a {@link Amity.Event} has been deleted
30812
+ *
30813
+ * @param callback The function to call when the event was fired
30814
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30815
+ *
30816
+ * @category Event Events
30817
+ */
30818
+ const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
30819
+
30820
+ /**
30821
+ * ```js
30822
+ * import { EventRepository } from '@amityco/ts-sdk'
30823
+ * const dispose = EventRepository.onRSVPCreated(event => {
30824
+ * // ...
30825
+ * })
30826
+ * ```
30827
+ *
30828
+ * Fired when a {@link Amity.Event} has been created
30829
+ *
30830
+ * @param callback The function to call when the event was fired
30831
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30832
+ *
30833
+ * @category Event Events
30834
+ */
30835
+ const onRSVPCreated = (callback) => createEventResponseSubscriber('event.rsvp.created', callback);
30836
+
30837
+ /**
30838
+ * ```js
30839
+ * import { EventRepository } from '@amityco/ts-sdk'
30840
+ * const dispose = EventRepository.onRSVPUpdated(event => {
30841
+ * // ...
30842
+ * })
30843
+ * ```
30844
+ *
30845
+ * Fired when a {@link Amity.InternalEventResponse} has been updated
30846
+ *
30847
+ * @param callback The function to call when the event was fired
30848
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30849
+ *
30850
+ * @category Event Events
30851
+ */
30852
+ const onRSVPUpdated = (callback) => createEventResponseSubscriber('event.rsvp.updated', callback);
30853
+
30854
+ /**
30855
+ * ```js
30856
+ * import { EventRepository } from '@amityco/ts-sdk'
30857
+ * const dispose = EventRepository.onLocalRSVPCreated(event => {
30858
+ * // ...
30859
+ * })
30860
+ * ```
30861
+ *
30862
+ * Fired when a {@link Amity.Event} has been created
30863
+ *
30864
+ * @param callback The function to call when the event was fired
30865
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30866
+ *
30867
+ * @category Event Events
30868
+ */
30869
+ const onLocalRSVPCreated = (callback) => createEventResponseSubscriber('local.rsvp.created', callback);
30870
+
30871
+ /**
30872
+ * ```js
30873
+ * import { EventRepository } from '@amityco/ts-sdk'
30874
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
30875
+ * // ...
30876
+ * })
30877
+ * ```
30878
+ *
30879
+ * Fired when a {@link Amity.Event} has been updated
30880
+ *
30881
+ * @param callback The function to call when the event was fired
30882
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30883
+ *
30884
+ * @category Event Events
30885
+ */
30886
+ const onLocalRSVPUpdated = (callback) => createEventResponseSubscriber('local.rsvp.updated', callback);
30887
+
30587
30888
  /* begin_public_function
30588
30889
  id: event.get
30589
30890
  */
@@ -30607,7 +30908,7 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
30607
30908
  * @category Event Live Object
30608
30909
  */
30609
30910
  const getEvent = (eventId, callback) => {
30610
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
30911
+ return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
30611
30912
  callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
30612
30913
  });
30613
30914
  };
@@ -30618,6 +30919,8 @@ var EventActionsEnum;
30618
30919
  EventActionsEnum["OnEventCreated"] = "onEventCreated";
30619
30920
  EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
30620
30921
  EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
30922
+ EventActionsEnum["OnRSVPCreated"] = "onRSVPCreated";
30923
+ EventActionsEnum["OnRSVPUpdated"] = "onRSVPUpdated";
30621
30924
  })(EventActionsEnum || (EventActionsEnum = {}));
30622
30925
 
30623
30926
  class EventPaginationController extends PaginationController {
@@ -30702,6 +31005,9 @@ class EventLiveCollectionController extends LiveCollectionController {
30702
31005
  { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
30703
31006
  { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
30704
31007
  { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
31008
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
31009
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
31010
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
30705
31011
  ]);
30706
31012
  }
30707
31013
  notifyChange({ origin, loading, error }) {
@@ -30836,6 +31142,9 @@ class MyEventLiveCollectionController extends LiveCollectionController {
30836
31142
  { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
30837
31143
  { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
30838
31144
  { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
31145
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
31146
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
31147
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
30839
31148
  ]);
30840
31149
  }
30841
31150
  notifyChange({ origin, loading, error }) {
@@ -30885,6 +31194,141 @@ const getMyEvents = (params, callback, config) => {
30885
31194
  };
30886
31195
  };
30887
31196
 
31197
+ class RSVPPaginationController extends PaginationController {
31198
+ async getRequest(queryParams, token) {
31199
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, eventId } = queryParams, params = __rest(queryParams, ["limit", "eventId"]);
31200
+ const options = token ? { token } : { limit };
31201
+ const { data: response } = await this.http.get(`/api/v1/events/${eventId}/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
31202
+ return response;
31203
+ }
31204
+ }
31205
+
31206
+ class RSVPQueryStreamController extends QueryStreamController {
31207
+ constructor(query, cacheKey, notifyChange, preparePayload) {
31208
+ super(query, cacheKey);
31209
+ this.notifyChange = notifyChange;
31210
+ this.preparePayload = preparePayload;
31211
+ }
31212
+ async saveToMainDB(response) {
31213
+ const processedPayload = this.preparePayload(response);
31214
+ const client = getActiveClient();
31215
+ const cachedAt = client.cache && Date.now();
31216
+ if (client.cache)
31217
+ ingestInCache(processedPayload, { cachedAt });
31218
+ }
31219
+ appendToQueryStream(response, direction, refresh = false) {
31220
+ var _a, _b;
31221
+ if (refresh) {
31222
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
31223
+ }
31224
+ else {
31225
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31226
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
31227
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
31228
+ }
31229
+ }
31230
+ reactor(action) {
31231
+ return (event) => {
31232
+ var _a;
31233
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31234
+ if (!collection)
31235
+ return;
31236
+ if (action === EventActionsEnum.OnEventCreated) {
31237
+ const client = getActiveClient();
31238
+ if (client.userId !== event.userId)
31239
+ return;
31240
+ collection.data = [...new Set([event.eventId, ...collection.data])];
31241
+ }
31242
+ if (action === EventActionsEnum.OnEventDeleted) {
31243
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
31244
+ }
31245
+ pushToCache(this.cacheKey, collection);
31246
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
31247
+ };
31248
+ }
31249
+ subscribeRTE(createSubscriber) {
31250
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
31251
+ }
31252
+ }
31253
+
31254
+ class RSVPLiveCollectionController extends LiveCollectionController {
31255
+ constructor(query, callback) {
31256
+ const queryStreamId = hash__default["default"](query);
31257
+ const cacheKey = ['event', 'collection', queryStreamId];
31258
+ const paginationController = new RSVPPaginationController(query);
31259
+ super(paginationController, queryStreamId, cacheKey, callback);
31260
+ this.query = query;
31261
+ this.queryStreamController = new RSVPQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
31262
+ this.callback = callback.bind(this);
31263
+ this.loadPage({ initial: true });
31264
+ }
31265
+ setup() {
31266
+ var _a;
31267
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31268
+ if (!collection)
31269
+ pushToCache(this.cacheKey, { data: [], params: {} });
31270
+ }
31271
+ async persistModel(queryPayload) {
31272
+ await this.queryStreamController.saveToMainDB(queryPayload);
31273
+ }
31274
+ persistQueryStream({ response, direction, refresh, }) {
31275
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
31276
+ }
31277
+ startSubscription() {
31278
+ return this.queryStreamController.subscribeRTE([
31279
+ { fn: onRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
31280
+ { fn: onRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
31281
+ { fn: onLocalRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
31282
+ { fn: onLocalRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
31283
+ ]);
31284
+ }
31285
+ notifyChange({ origin, loading, error }) {
31286
+ var _a, _b;
31287
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31288
+ if (!collection)
31289
+ return;
31290
+ const data = ((_b = collection.data
31291
+ .map(eventId => pullFromCache(['event', 'get', eventId]))
31292
+ .filter(isNonNullable)
31293
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
31294
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
31295
+ return;
31296
+ this.callback({
31297
+ data,
31298
+ error,
31299
+ loading,
31300
+ hasNextPage: !!this.paginationController.getNextToken(),
31301
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
31302
+ });
31303
+ }
31304
+ }
31305
+
31306
+ /**
31307
+ * Get events
31308
+ *
31309
+ * @param params the query parameters
31310
+ * @param callback the callback to be called when the events are updated
31311
+ * @returns events
31312
+ *
31313
+ * @category RSVP Live Collection
31314
+ *
31315
+ */
31316
+ const getRSVPs = (params, callback, config) => {
31317
+ const { log, cache } = getActiveClient();
31318
+ if (!cache)
31319
+ console.log(ENABLE_CACHE_MESSAGE);
31320
+ const timestamp = Date.now();
31321
+ log(`getRSVPs: (tmpid: ${timestamp}) > listen`);
31322
+ const eventLiveCollection = new RSVPLiveCollectionController(params, callback);
31323
+ const disposers = eventLiveCollection.startSubscription();
31324
+ const cacheKey = eventLiveCollection.getCacheKey();
31325
+ disposers.push(() => dropFromCache(cacheKey));
31326
+ return () => {
31327
+ log(`getRSVPs (tmpid: ${timestamp}) > dispose`);
31328
+ disposers.forEach(fn => fn());
31329
+ };
31330
+ };
31331
+
30888
31332
  var index = /*#__PURE__*/Object.freeze({
30889
31333
  __proto__: null,
30890
31334
  createEvent: createEvent,
@@ -30893,9 +31337,17 @@ var index = /*#__PURE__*/Object.freeze({
30893
31337
  onEventCreated: onEventCreated,
30894
31338
  onEventUpdated: onEventUpdated,
30895
31339
  onEventDeleted: onEventDeleted,
31340
+ onLocalEventCreated: onLocalEventCreated,
31341
+ onLocalEventUpdated: onLocalEventUpdated,
31342
+ onLocalEventDeleted: onLocalEventDeleted,
31343
+ onRSVPCreated: onRSVPCreated,
31344
+ onRSVPUpdated: onRSVPUpdated,
31345
+ onLocalRSVPCreated: onLocalRSVPCreated,
31346
+ onLocalRSVPUpdated: onLocalRSVPUpdated,
30896
31347
  getEvent: getEvent,
30897
31348
  getEvents: getEvents,
30898
- getMyEvents: getMyEvents
31349
+ getMyEvents: getMyEvents,
31350
+ getRSVPs: getRSVPs
30899
31351
  });
30900
31352
 
30901
31353
  exports.API_REGIONS = API_REGIONS;