@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.cjs.js CHANGED
@@ -209,6 +209,11 @@ exports.AmityEventStatus = void 0;
209
209
  AmityEventStatus["Ended"] = "ended";
210
210
  AmityEventStatus["Cancelled"] = "cancelled";
211
211
  })(exports.AmityEventStatus || (exports.AmityEventStatus = {}));
212
+ exports.AmityEventResponseStatus = void 0;
213
+ (function (AmityEventResponseStatus) {
214
+ AmityEventResponseStatus["Going"] = "going";
215
+ AmityEventResponseStatus["NotGoing"] = "not_going";
216
+ })(exports.AmityEventResponseStatus || (exports.AmityEventResponseStatus = {}));
212
217
 
213
218
  function getVersion() {
214
219
  try {
@@ -659,6 +664,7 @@ const idResolvers = {
659
664
  invitation: ({ _id }) => _id,
660
665
  joinRequest: ({ joinRequestId }) => joinRequestId,
661
666
  event: ({ eventId }) => eventId,
667
+ discussionCommunity: ({ communityId }) => communityId,
662
668
  };
663
669
  /**
664
670
  * Retrieve the id resolver matching a domain name
@@ -715,7 +721,7 @@ const PAYLOAD2MODEL = {
715
721
  invitations: 'invitation',
716
722
  joinRequests: 'joinRequest',
717
723
  events: 'event',
718
- discussionCommunities: 'community',
724
+ discussionCommunities: 'discussionCommunity',
719
725
  };
720
726
  /** hidden */
721
727
  const isOutdated = (prevData, nextData) => {
@@ -13679,6 +13685,155 @@ const communityLinkedObject = (community) => {
13679
13685
  } });
13680
13686
  };
13681
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(status)
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, status) => {
13797
+ const client = getActiveClient();
13798
+ client.log('event/getMyRSVP', eventId);
13799
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}/me/rsvp`, { params: { status } });
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
+
13682
13837
  const eventLinkedObject = (event) => {
13683
13838
  return Object.assign(Object.assign({}, event), { get creator() {
13684
13839
  const cacheData = pullFromCache(['user', 'get', event.userId]);
@@ -13690,7 +13845,7 @@ const eventLinkedObject = (event) => {
13690
13845
  if (!event.discussionCommunityId)
13691
13846
  return;
13692
13847
  const cacheData = pullFromCache([
13693
- 'community',
13848
+ 'discussionCommunity',
13694
13849
  'get',
13695
13850
  event.discussionCommunityId,
13696
13851
  ]);
@@ -13698,6 +13853,22 @@ const eventLinkedObject = (event) => {
13698
13853
  return;
13699
13854
  return communityLinkedObject(cacheData.data);
13700
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
+ },
13701
13872
  get liveStream() {
13702
13873
  if (!event.livestreamId)
13703
13874
  return;
@@ -13705,6 +13876,15 @@ const eventLinkedObject = (event) => {
13705
13876
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13706
13877
  return;
13707
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 (status) => {
13886
+ const { data } = await getMyRSVP(event.eventId, status);
13887
+ return data;
13708
13888
  } });
13709
13889
  };
13710
13890
 
@@ -30344,30 +30524,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
30344
30524
  getReactions: getReactions
30345
30525
  });
30346
30526
 
30347
- const prepareEventPayload = (rawPayload) => {
30348
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
30349
- };
30350
-
30351
- const createEventEventSubscriber = (event, callback) => {
30352
- const client = getActiveClient();
30353
- const filter = (payload) => {
30354
- const unpackedPayload = prepareEventPayload(payload);
30355
- if (!client.cache) {
30356
- callback(unpackedPayload.events[0]);
30357
- }
30358
- else {
30359
- ingestInCache(unpackedPayload);
30360
- const event = pullFromCache([
30361
- 'event',
30362
- 'get',
30363
- unpackedPayload.events[0].eventId,
30364
- ]);
30365
- callback(event.data);
30366
- }
30367
- };
30368
- return createEventSubscriber(client, event, event, filter);
30369
- };
30370
-
30371
30527
  /* begin_public_function
30372
30528
  id: event.create
30373
30529
  */
@@ -30389,7 +30545,7 @@ const createEvent = async (bundle) => {
30389
30545
  const client = getActiveClient();
30390
30546
  client.log('event/createEvent', bundle);
30391
30547
  const { data: payload } = await client.http.post('/api/v1/events', bundle);
30392
- fireEvent('event.created', payload);
30548
+ fireEvent('local.event.created', payload);
30393
30549
  const preparedPayload = prepareEventPayload(payload);
30394
30550
  const cachedAt = client.cache && Date.now();
30395
30551
  if (client.cache)
@@ -30423,7 +30579,7 @@ const updateEvent = async (eventId, bundle) => {
30423
30579
  const client = getActiveClient();
30424
30580
  client.log('event/updateEvent', eventId, bundle);
30425
30581
  const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
30426
- fireEvent('event.updated', payload);
30582
+ fireEvent('local.event.updated', payload);
30427
30583
  const preparedPayload = prepareEventPayload(payload);
30428
30584
  const cachedAt = client.cache && Date.now();
30429
30585
  if (client.cache)
@@ -30455,7 +30611,7 @@ const updateEvent = async (eventId, bundle) => {
30455
30611
  const getEvent$1 = async (eventId) => {
30456
30612
  const client = getActiveClient();
30457
30613
  client.log('event/getEvent', eventId);
30458
- const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
30614
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
30459
30615
  const data = prepareEventPayload(payload);
30460
30616
  const cachedAt = client.cache && Date.now();
30461
30617
  if (client.cache)
@@ -30513,10 +30669,10 @@ const deleteEvent = async (eventId) => {
30513
30669
  const client = getActiveClient();
30514
30670
  client.log('event/deleteEvent', eventId);
30515
30671
  const event = await getEvent$1(eventId);
30516
- await client.http.delete(`/api/v3/events/${eventId}`);
30672
+ await client.http.delete(`/api/v1/events/${eventId}`);
30517
30673
  const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
30518
30674
  upsertInCache(['event', 'get', eventId], deletedEvent);
30519
- fireEvent('event.deleted', {
30675
+ fireEvent('local.event.deleted', {
30520
30676
  users: [],
30521
30677
  files: [],
30522
30678
  communities: [],
@@ -30578,6 +30734,125 @@ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated',
30578
30734
  */
30579
30735
  const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
30580
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
+
30581
30856
  /* begin_public_function
30582
30857
  id: event.get
30583
30858
  */
@@ -30601,7 +30876,7 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
30601
30876
  * @category Event Live Object
30602
30877
  */
30603
30878
  const getEvent = (eventId, callback) => {
30604
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
30879
+ return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
30605
30880
  callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
30606
30881
  });
30607
30882
  };
@@ -30612,6 +30887,8 @@ var EventActionsEnum;
30612
30887
  EventActionsEnum["OnEventCreated"] = "onEventCreated";
30613
30888
  EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
30614
30889
  EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
30890
+ EventActionsEnum["OnRSVPCreated"] = "onRSVPCreated";
30891
+ EventActionsEnum["OnRSVPUpdated"] = "onRSVPUpdated";
30615
30892
  })(EventActionsEnum || (EventActionsEnum = {}));
30616
30893
 
30617
30894
  class EventPaginationController extends PaginationController {
@@ -30696,6 +30973,9 @@ class EventLiveCollectionController extends LiveCollectionController {
30696
30973
  { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
30697
30974
  { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
30698
30975
  { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
30976
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
30977
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
30978
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
30699
30979
  ]);
30700
30980
  }
30701
30981
  notifyChange({ origin, loading, error }) {
@@ -30707,7 +30987,7 @@ class EventLiveCollectionController extends LiveCollectionController {
30707
30987
  .map(eventId => pullFromCache(['event', 'get', eventId]))
30708
30988
  .filter(isNonNullable)
30709
30989
  .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
30710
- if (!this.shouldNotify(data) && origin === 'event')
30990
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
30711
30991
  return;
30712
30992
  this.callback({
30713
30993
  data,
@@ -30745,6 +31025,278 @@ const getEvents = (params, callback, config) => {
30745
31025
  };
30746
31026
  };
30747
31027
 
31028
+ class MyEventPaginationController extends PaginationController {
31029
+ async getRequest(queryParams, token) {
31030
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
31031
+ const options = token ? { token } : { limit };
31032
+ const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
31033
+ return response;
31034
+ }
31035
+ }
31036
+
31037
+ class MyEventQueryStreamController extends QueryStreamController {
31038
+ constructor(query, cacheKey, notifyChange, preparePayload) {
31039
+ super(query, cacheKey);
31040
+ this.notifyChange = notifyChange;
31041
+ this.preparePayload = preparePayload;
31042
+ }
31043
+ async saveToMainDB(response) {
31044
+ const processedPayload = this.preparePayload(response);
31045
+ const client = getActiveClient();
31046
+ const cachedAt = client.cache && Date.now();
31047
+ if (client.cache)
31048
+ ingestInCache(processedPayload, { cachedAt });
31049
+ }
31050
+ appendToQueryStream(response, direction, refresh = false) {
31051
+ var _a, _b;
31052
+ if (refresh) {
31053
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
31054
+ }
31055
+ else {
31056
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31057
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
31058
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
31059
+ }
31060
+ }
31061
+ reactor(action) {
31062
+ return (event) => {
31063
+ var _a;
31064
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31065
+ if (!collection)
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
+ }
31073
+ if (action === EventActionsEnum.OnEventDeleted) {
31074
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
31075
+ }
31076
+ pushToCache(this.cacheKey, collection);
31077
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
31078
+ };
31079
+ }
31080
+ subscribeRTE(createSubscriber) {
31081
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
31082
+ }
31083
+ }
31084
+
31085
+ class MyEventLiveCollectionController extends LiveCollectionController {
31086
+ constructor(query, callback) {
31087
+ const queryStreamId = hash__default["default"](query);
31088
+ const cacheKey = ['event', 'collection', queryStreamId];
31089
+ const paginationController = new MyEventPaginationController(query);
31090
+ super(paginationController, queryStreamId, cacheKey, callback);
31091
+ this.query = query;
31092
+ this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
31093
+ this.callback = callback.bind(this);
31094
+ this.loadPage({ initial: true });
31095
+ }
31096
+ setup() {
31097
+ var _a;
31098
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31099
+ if (!collection)
31100
+ pushToCache(this.cacheKey, { data: [], params: {} });
31101
+ }
31102
+ async persistModel(queryPayload) {
31103
+ await this.queryStreamController.saveToMainDB(queryPayload);
31104
+ }
31105
+ persistQueryStream({ response, direction, refresh, }) {
31106
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
31107
+ }
31108
+ startSubscription() {
31109
+ return this.queryStreamController.subscribeRTE([
31110
+ { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
31111
+ { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
31112
+ { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
31113
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
31114
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
31115
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
31116
+ ]);
31117
+ }
31118
+ notifyChange({ origin, loading, error }) {
31119
+ var _a, _b;
31120
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31121
+ if (!collection)
31122
+ return;
31123
+ const data = ((_b = collection.data
31124
+ .map(eventId => pullFromCache(['event', 'get', eventId]))
31125
+ .filter(isNonNullable)
31126
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
31127
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
31128
+ return;
31129
+ this.callback({
31130
+ data,
31131
+ error,
31132
+ loading,
31133
+ hasNextPage: !!this.paginationController.getNextToken(),
31134
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
31135
+ });
31136
+ }
31137
+ }
31138
+
31139
+ /**
31140
+ * Get my events
31141
+ *
31142
+ * @param params the query parameters
31143
+ * @param callback the callback to be called when the events are updated
31144
+ * @returns events
31145
+ *
31146
+ * @category Event Live Collection
31147
+ *
31148
+ */
31149
+ const getMyEvents = (params, callback, config) => {
31150
+ const { log, cache } = getActiveClient();
31151
+ if (!cache)
31152
+ console.log(ENABLE_CACHE_MESSAGE);
31153
+ const timestamp = Date.now();
31154
+ log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
31155
+ const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
31156
+ const disposers = myEventLiveCollection.startSubscription();
31157
+ const cacheKey = myEventLiveCollection.getCacheKey();
31158
+ disposers.push(() => dropFromCache(cacheKey));
31159
+ return () => {
31160
+ log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
31161
+ disposers.forEach(fn => fn());
31162
+ };
31163
+ };
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
+
30748
31300
  var index = /*#__PURE__*/Object.freeze({
30749
31301
  __proto__: null,
30750
31302
  createEvent: createEvent,
@@ -30753,8 +31305,17 @@ var index = /*#__PURE__*/Object.freeze({
30753
31305
  onEventCreated: onEventCreated,
30754
31306
  onEventUpdated: onEventUpdated,
30755
31307
  onEventDeleted: onEventDeleted,
31308
+ onLocalEventCreated: onLocalEventCreated,
31309
+ onLocalEventUpdated: onLocalEventUpdated,
31310
+ onLocalEventDeleted: onLocalEventDeleted,
31311
+ onRSVPCreated: onRSVPCreated,
31312
+ onRSVPUpdated: onRSVPUpdated,
31313
+ onLocalRSVPCreated: onLocalRSVPCreated,
31314
+ onLocalRSVPUpdated: onLocalRSVPUpdated,
30756
31315
  getEvent: getEvent,
30757
- getEvents: getEvents
31316
+ getEvents: getEvents,
31317
+ getMyEvents: getMyEvents,
31318
+ getRSVPs: getRSVPs
30758
31319
  });
30759
31320
 
30760
31321
  exports.API_REGIONS = API_REGIONS;