@amityco/ts-sdk 7.11.1-302f84d7.0 → 7.11.1-3344f12c.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 (69) 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 +14 -0
  6. package/dist/@types/core/payload.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 +43 -11
  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/core/model/index.d.ts.map +1 -1
  17. package/dist/eventRepository/events/enums.d.ts +3 -1
  18. package/dist/eventRepository/events/enums.d.ts.map +1 -1
  19. package/dist/eventRepository/events/index.d.ts +7 -0
  20. package/dist/eventRepository/events/index.d.ts.map +1 -1
  21. package/dist/eventRepository/events/onLocalEventCreated.d.ts +17 -0
  22. package/dist/eventRepository/events/onLocalEventCreated.d.ts.map +1 -0
  23. package/dist/eventRepository/events/onLocalEventDeleted.d.ts +17 -0
  24. package/dist/eventRepository/events/onLocalEventDeleted.d.ts.map +1 -0
  25. package/dist/eventRepository/events/onLocalEventUpdated.d.ts +17 -0
  26. package/dist/eventRepository/events/onLocalEventUpdated.d.ts.map +1 -0
  27. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts +17 -0
  28. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts.map +1 -0
  29. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts +17 -0
  30. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts.map +1 -0
  31. package/dist/eventRepository/events/onRSVPCreated.d.ts +17 -0
  32. package/dist/eventRepository/events/onRSVPCreated.d.ts.map +1 -0
  33. package/dist/eventRepository/events/onRSVPUpdated.d.ts +17 -0
  34. package/dist/eventRepository/events/onRSVPUpdated.d.ts.map +1 -0
  35. package/dist/eventRepository/internalApi/createRSVP.d.ts +16 -0
  36. package/dist/eventRepository/internalApi/createRSVP.d.ts.map +1 -0
  37. package/dist/eventRepository/internalApi/getMyRSVP.d.ts +32 -0
  38. package/dist/eventRepository/internalApi/getMyRSVP.d.ts.map +1 -0
  39. package/dist/eventRepository/internalApi/index.d.ts +3 -0
  40. package/dist/eventRepository/internalApi/index.d.ts.map +1 -1
  41. package/dist/eventRepository/internalApi/updateRSVP.d.ts +17 -0
  42. package/dist/eventRepository/internalApi/updateRSVP.d.ts.map +1 -0
  43. package/dist/eventRepository/observers/getEvent.d.ts.map +1 -1
  44. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +1 -1
  45. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -1
  46. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +1 -1
  47. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts +13 -0
  48. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts.map +1 -0
  49. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts +5 -0
  50. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts.map +1 -0
  51. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts +15 -0
  52. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts.map +1 -0
  53. package/dist/eventRepository/observers/getRSVPs.d.ts +12 -0
  54. package/dist/eventRepository/observers/getRSVPs.d.ts.map +1 -0
  55. package/dist/eventRepository/observers/index.d.ts +1 -0
  56. package/dist/eventRepository/observers/index.d.ts.map +1 -1
  57. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +1 -1
  58. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -1
  59. package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts +2 -0
  60. package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts.map +1 -0
  61. package/dist/eventRepository/utils/index.d.ts +2 -0
  62. package/dist/eventRepository/utils/index.d.ts.map +1 -1
  63. package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts +2 -0
  64. package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts.map +1 -0
  65. package/dist/index.cjs.js +560 -96
  66. package/dist/index.esm.js +560 -96
  67. package/dist/index.umd.js +3 -3
  68. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -1
  69. 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,503 @@ 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
+
13869
+ var EventActionsEnum;
13870
+ (function (EventActionsEnum) {
13871
+ EventActionsEnum["OnEventCreated"] = "onEventCreated";
13872
+ EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
13873
+ EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
13874
+ EventActionsEnum["OnRSVPCreated"] = "onRSVPCreated";
13875
+ EventActionsEnum["OnRSVPUpdated"] = "onRSVPUpdated";
13876
+ })(EventActionsEnum || (EventActionsEnum = {}));
13877
+
13878
+ class RSVPPaginationController extends PaginationController {
13879
+ async getRequest(queryParams, token) {
13880
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, eventId } = queryParams, params = __rest(queryParams, ["limit", "eventId"]);
13881
+ const options = token ? { token } : { limit };
13882
+ const { data: response } = await this.http.get(`/api/v1/events/${eventId}/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
13883
+ return response;
13884
+ }
13885
+ }
13886
+
13887
+ class RSVPQueryStreamController extends QueryStreamController {
13888
+ constructor(query, cacheKey, notifyChange, preparePayload) {
13889
+ super(query, cacheKey);
13890
+ this.notifyChange = notifyChange;
13891
+ this.preparePayload = preparePayload;
13892
+ }
13893
+ async saveToMainDB(response) {
13894
+ const processedPayload = this.preparePayload(response);
13895
+ const client = getActiveClient();
13896
+ const cachedAt = client.cache && Date.now();
13897
+ if (client.cache)
13898
+ ingestInCache({ eventResponses: [processedPayload] }, { cachedAt });
13899
+ }
13900
+ appendToQueryStream(response, direction, refresh = false) {
13901
+ var _a, _b;
13902
+ if (refresh) {
13903
+ pushToCache(this.cacheKey, {
13904
+ data: response.eventResponses.map(getResolver('eventResponse')),
13905
+ });
13906
+ }
13907
+ else {
13908
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
13909
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
13910
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
13911
+ ...new Set([...events, ...response.eventResponses.map(getResolver('eventResponse'))]),
13912
+ ] }));
13913
+ }
13914
+ }
13915
+ reactor(action) {
13916
+ return (event) => {
13917
+ var _a;
13918
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
13919
+ if (!collection)
13920
+ return;
13921
+ if (action === EventActionsEnum.OnRSVPCreated) {
13922
+ const client = getActiveClient();
13923
+ if (client.userId !== event.userId)
13924
+ return;
13925
+ collection.data = [...new Set([event.eventId, ...collection.data])];
13926
+ }
13927
+ if (action === EventActionsEnum.OnEventDeleted) {
13928
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
13929
+ }
13930
+ pushToCache(this.cacheKey, collection);
13931
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
13932
+ };
13933
+ }
13934
+ subscribeRTE(createSubscriber) {
13935
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
13936
+ }
13937
+ }
13938
+
13939
+ /**
13940
+ * ```js
13941
+ * import { EventRepository } from '@amityco/ts-sdk'
13942
+ * const dispose = EventRepository.onEventCreated(event => {
13943
+ * // ...
13944
+ * })
13945
+ * ```
13946
+ *
13947
+ * Fired when a {@link Amity.Event} has been created
13948
+ *
13949
+ * @param callback The function to call when the event was fired
13950
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
13951
+ *
13952
+ * @category Event Events
13953
+ */
13954
+ const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
13955
+
13956
+ /**
13957
+ * ```js
13958
+ * import { EventRepository } from '@amityco/ts-sdk'
13959
+ * const dispose = EventRepository.onEventUpdated(event => {
13960
+ * // ...
13961
+ * })
13962
+ * ```
13963
+ *
13964
+ * Fired when a {@link Amity.Event} has been updated
13965
+ *
13966
+ * @param callback The function to call when the event was fired
13967
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
13968
+ *
13969
+ * @category Event Events
13970
+ */
13971
+ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
13972
+
13973
+ /**
13974
+ * ```js
13975
+ * import { EventRepository } from '@amityco/ts-sdk'
13976
+ * const dispose = EventRepository.onEventDeleted(event => {
13977
+ * // ...
13978
+ * })
13979
+ * ```
13980
+ *
13981
+ * Fired when a {@link Amity.Event} has been deleted
13982
+ *
13983
+ * @param callback The function to call when the event was fired
13984
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
13985
+ *
13986
+ * @category Event Events
13987
+ */
13988
+ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
13989
+
13990
+ /**
13991
+ * ```js
13992
+ * import { EventRepository } from '@amityco/ts-sdk'
13993
+ * const dispose = EventRepository.onLocalEventCreated(event => {
13994
+ * // ...
13995
+ * })
13996
+ * ```
13997
+ *
13998
+ * Fired when a {@link Amity.Event} has been created
13999
+ *
14000
+ * @param callback The function to call when the event was fired
14001
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
14002
+ *
14003
+ * @category Event Events
14004
+ */
14005
+ const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
14006
+
14007
+ /**
14008
+ * ```js
14009
+ * import { EventRepository } from '@amityco/ts-sdk'
14010
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
14011
+ * // ...
14012
+ * })
14013
+ * ```
14014
+ *
14015
+ * Fired when a {@link Amity.Event} has been updated
14016
+ *
14017
+ * @param callback The function to call when the event was fired
14018
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
14019
+ *
14020
+ * @category Event Events
14021
+ */
14022
+ const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
14023
+
14024
+ /**
14025
+ * ```js
14026
+ * import { EventRepository } from '@amityco/ts-sdk'
14027
+ * const dispose = EventRepository.onLocalEventDeleted(event => {
14028
+ * // ...
14029
+ * })
14030
+ * ```
14031
+ *
14032
+ * Fired when a {@link Amity.Event} has been deleted
14033
+ *
14034
+ * @param callback The function to call when the event was fired
14035
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
14036
+ *
14037
+ * @category Event Events
14038
+ */
14039
+ const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
14040
+
14041
+ /**
14042
+ * ```js
14043
+ * import { EventRepository } from '@amityco/ts-sdk'
14044
+ * const dispose = EventRepository.onRSVPCreated(event => {
14045
+ * // ...
14046
+ * })
14047
+ * ```
14048
+ *
14049
+ * Fired when a {@link Amity.Event} has been created
14050
+ *
14051
+ * @param callback The function to call when the event was fired
14052
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
14053
+ *
14054
+ * @category Event Events
14055
+ */
14056
+ const onRSVPCreated = (callback) => createEventResponseSubscriber('event.rsvp.created', callback);
14057
+
14058
+ /**
14059
+ * ```js
14060
+ * import { EventRepository } from '@amityco/ts-sdk'
14061
+ * const dispose = EventRepository.onRSVPUpdated(event => {
14062
+ * // ...
14063
+ * })
14064
+ * ```
14065
+ *
14066
+ * Fired when a {@link Amity.InternalEventResponse} has been updated
14067
+ *
14068
+ * @param callback The function to call when the event was fired
14069
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
14070
+ *
14071
+ * @category Event Events
14072
+ */
14073
+ const onRSVPUpdated = (callback) => createEventResponseSubscriber('event.rsvp.updated', callback);
14074
+
14075
+ /**
14076
+ * ```js
14077
+ * import { EventRepository } from '@amityco/ts-sdk'
14078
+ * const dispose = EventRepository.onLocalRSVPCreated(event => {
14079
+ * // ...
14080
+ * })
14081
+ * ```
14082
+ *
14083
+ * Fired when a {@link Amity.Event} has been created
14084
+ *
14085
+ * @param callback The function to call when the event was fired
14086
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
14087
+ *
14088
+ * @category Event Events
14089
+ */
14090
+ const onLocalRSVPCreated = (callback) => createEventResponseSubscriber('local.rsvp.created', callback);
14091
+
14092
+ /**
14093
+ * ```js
14094
+ * import { EventRepository } from '@amityco/ts-sdk'
14095
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
14096
+ * // ...
14097
+ * })
14098
+ * ```
14099
+ *
14100
+ * Fired when a {@link Amity.Event} has been updated
14101
+ *
14102
+ * @param callback The function to call when the event was fired
14103
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
14104
+ *
14105
+ * @category Event Events
14106
+ */
14107
+ const onLocalRSVPUpdated = (callback) => createEventResponseSubscriber('local.rsvp.updated', callback);
14108
+
14109
+ class RSVPLiveCollectionController extends LiveCollectionController {
14110
+ constructor(query, callback) {
14111
+ const queryStreamId = hash__default["default"](query);
14112
+ const cacheKey = ['eventResponse', 'collection', queryStreamId];
14113
+ const paginationController = new RSVPPaginationController(query);
14114
+ super(paginationController, queryStreamId, cacheKey, callback);
14115
+ this.query = query;
14116
+ this.queryStreamController = new RSVPQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventResponsePayload);
14117
+ this.callback = callback.bind(this);
14118
+ this.loadPage({ initial: true });
14119
+ }
14120
+ setup() {
14121
+ var _a;
14122
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
14123
+ if (!collection)
14124
+ pushToCache(this.cacheKey, { data: [], params: this.query });
14125
+ }
14126
+ async persistModel(queryPayload) {
14127
+ await this.queryStreamController.saveToMainDB(queryPayload);
14128
+ }
14129
+ persistQueryStream({ response, direction, refresh, }) {
14130
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
14131
+ }
14132
+ startSubscription() {
14133
+ return this.queryStreamController.subscribeRTE([
14134
+ { fn: onRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
14135
+ { fn: onRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
14136
+ { fn: onLocalRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
14137
+ { fn: onLocalRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
14138
+ ]);
14139
+ }
14140
+ notifyChange({ origin, loading, error }) {
14141
+ var _a, _b;
14142
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
14143
+ if (!collection)
14144
+ return;
14145
+ const data = (_b = collection.data
14146
+ .map(eventId => pullFromCache(['eventResponse', 'get', eventId]))
14147
+ .filter(isNonNullable)
14148
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
14149
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
14150
+ return;
14151
+ this.callback({
14152
+ data,
14153
+ error,
14154
+ loading,
14155
+ hasNextPage: !!this.paginationController.getNextToken(),
14156
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
14157
+ });
14158
+ }
14159
+ }
14160
+
14161
+ /**
14162
+ * Get events
14163
+ *
14164
+ * @param params the query parameters
14165
+ * @param callback the callback to be called when the events are updated
14166
+ * @returns events
14167
+ *
14168
+ * @category RSVP Live Collection
14169
+ *
14170
+ */
14171
+ const getRSVPs = (params, callback, config) => {
14172
+ const { log, cache } = getActiveClient();
14173
+ if (!cache)
14174
+ console.log(ENABLE_CACHE_MESSAGE);
14175
+ const timestamp = Date.now();
14176
+ log(`getRSVPs: (tmpid: ${timestamp}) > listen`);
14177
+ const eventLiveCollection = new RSVPLiveCollectionController(params, callback);
14178
+ const disposers = eventLiveCollection.startSubscription();
14179
+ const cacheKey = eventLiveCollection.getCacheKey();
14180
+ disposers.push(() => dropFromCache(cacheKey));
14181
+ return () => {
14182
+ log(`getRSVPs (tmpid: ${timestamp}) > dispose`);
14183
+ disposers.forEach(fn => fn());
14184
+ };
14185
+ };
14186
+
13688
14187
  const eventLinkedObject = (event) => {
13689
14188
  return Object.assign(Object.assign({}, event), { get creator() {
13690
14189
  const cacheData = pullFromCache(['user', 'get', event.userId]);
@@ -13696,7 +14195,7 @@ const eventLinkedObject = (event) => {
13696
14195
  if (!event.discussionCommunityId)
13697
14196
  return;
13698
14197
  const cacheData = pullFromCache([
13699
- 'community',
14198
+ 'discussionCommunity',
13700
14199
  'get',
13701
14200
  event.discussionCommunityId,
13702
14201
  ]);
@@ -13704,6 +14203,22 @@ const eventLinkedObject = (event) => {
13704
14203
  return;
13705
14204
  return communityLinkedObject(cacheData.data);
13706
14205
  },
14206
+ get targetCommunity() {
14207
+ if (!event.originId)
14208
+ return;
14209
+ const cacheData = pullFromCache(['community', 'get', event.originId]);
14210
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
14211
+ return;
14212
+ return communityLinkedObject(cacheData.data);
14213
+ },
14214
+ get coverImage() {
14215
+ if (!event.coverImageFileId)
14216
+ return;
14217
+ const cacheData = pullFromCache(['file', 'get', event.coverImageFileId]);
14218
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
14219
+ return;
14220
+ return cacheData.data;
14221
+ },
13707
14222
  get liveStream() {
13708
14223
  if (!event.livestreamId)
13709
14224
  return;
@@ -13711,6 +14226,17 @@ const eventLinkedObject = (event) => {
13711
14226
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13712
14227
  return;
13713
14228
  return cacheData.data;
14229
+ }, createRSVP: async (status) => {
14230
+ const { data } = await createRSVP(event.eventId, status);
14231
+ return data;
14232
+ }, updateRSVP: async (status) => {
14233
+ const { data } = await updateRSVP(event.eventId, status);
14234
+ return data;
14235
+ }, getMyRSVP: async () => {
14236
+ const { data } = await getMyRSVP(event.eventId);
14237
+ return data;
14238
+ }, getRSVPs: (params, callback) => {
14239
+ return getRSVPs(Object.assign({ eventId: event.eventId }, params), callback);
13714
14240
  } });
13715
14241
  };
13716
14242
 
@@ -30350,30 +30876,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
30350
30876
  getReactions: getReactions
30351
30877
  });
30352
30878
 
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
30879
  /* begin_public_function
30378
30880
  id: event.create
30379
30881
  */
@@ -30395,7 +30897,7 @@ const createEvent = async (bundle) => {
30395
30897
  const client = getActiveClient();
30396
30898
  client.log('event/createEvent', bundle);
30397
30899
  const { data: payload } = await client.http.post('/api/v1/events', bundle);
30398
- fireEvent('event.created', payload);
30900
+ fireEvent('local.event.created', payload);
30399
30901
  const preparedPayload = prepareEventPayload(payload);
30400
30902
  const cachedAt = client.cache && Date.now();
30401
30903
  if (client.cache)
@@ -30429,7 +30931,7 @@ const updateEvent = async (eventId, bundle) => {
30429
30931
  const client = getActiveClient();
30430
30932
  client.log('event/updateEvent', eventId, bundle);
30431
30933
  const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
30432
- fireEvent('event.updated', payload);
30934
+ fireEvent('local.event.updated', payload);
30433
30935
  const preparedPayload = prepareEventPayload(payload);
30434
30936
  const cachedAt = client.cache && Date.now();
30435
30937
  if (client.cache)
@@ -30461,7 +30963,7 @@ const updateEvent = async (eventId, bundle) => {
30461
30963
  const getEvent$1 = async (eventId) => {
30462
30964
  const client = getActiveClient();
30463
30965
  client.log('event/getEvent', eventId);
30464
- const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
30966
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
30465
30967
  const data = prepareEventPayload(payload);
30466
30968
  const cachedAt = client.cache && Date.now();
30467
30969
  if (client.cache)
@@ -30519,10 +31021,10 @@ const deleteEvent = async (eventId) => {
30519
31021
  const client = getActiveClient();
30520
31022
  client.log('event/deleteEvent', eventId);
30521
31023
  const event = await getEvent$1(eventId);
30522
- await client.http.delete(`/api/v3/events/${eventId}`);
31024
+ await client.http.delete(`/api/v1/events/${eventId}`);
30523
31025
  const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
30524
31026
  upsertInCache(['event', 'get', eventId], deletedEvent);
30525
- fireEvent('event.deleted', {
31027
+ fireEvent('local.event.deleted', {
30526
31028
  users: [],
30527
31029
  files: [],
30528
31030
  communities: [],
@@ -30533,57 +31035,6 @@ const deleteEvent = async (eventId) => {
30533
31035
  };
30534
31036
  /* end_public_function */
30535
31037
 
30536
- /**
30537
- * ```js
30538
- * import { EventRepository } from '@amityco/ts-sdk'
30539
- * const dispose = EventRepository.onEventCreated(event => {
30540
- * // ...
30541
- * })
30542
- * ```
30543
- *
30544
- * Fired when a {@link Amity.Event} has been created
30545
- *
30546
- * @param callback The function to call when the event was fired
30547
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30548
- *
30549
- * @category Event Events
30550
- */
30551
- const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
30552
-
30553
- /**
30554
- * ```js
30555
- * import { EventRepository } from '@amityco/ts-sdk'
30556
- * const dispose = EventRepository.onEventUpdated(event => {
30557
- * // ...
30558
- * })
30559
- * ```
30560
- *
30561
- * Fired when a {@link Amity.Event} has been updated
30562
- *
30563
- * @param callback The function to call when the event was fired
30564
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30565
- *
30566
- * @category Event Events
30567
- */
30568
- const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
30569
-
30570
- /**
30571
- * ```js
30572
- * import { EventRepository } from '@amityco/ts-sdk'
30573
- * const dispose = EventRepository.onEventDeleted(event => {
30574
- * // ...
30575
- * })
30576
- * ```
30577
- *
30578
- * Fired when a {@link Amity.Event} has been deleted
30579
- *
30580
- * @param callback The function to call when the event was fired
30581
- * @returns an {@link Amity.Unsubscriber} function to stop listening
30582
- *
30583
- * @category Event Events
30584
- */
30585
- const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
30586
-
30587
31038
  /* begin_public_function
30588
31039
  id: event.get
30589
31040
  */
@@ -30607,19 +31058,12 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
30607
31058
  * @category Event Live Object
30608
31059
  */
30609
31060
  const getEvent = (eventId, callback) => {
30610
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
31061
+ return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
30611
31062
  callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
30612
31063
  });
30613
31064
  };
30614
31065
  /* end_public_function */
30615
31066
 
30616
- var EventActionsEnum;
30617
- (function (EventActionsEnum) {
30618
- EventActionsEnum["OnEventCreated"] = "onEventCreated";
30619
- EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
30620
- EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
30621
- })(EventActionsEnum || (EventActionsEnum = {}));
30622
-
30623
31067
  class EventPaginationController extends PaginationController {
30624
31068
  async getRequest(queryParams, token) {
30625
31069
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
@@ -30677,7 +31121,7 @@ class EventQueryStreamController extends QueryStreamController {
30677
31121
  class EventLiveCollectionController extends LiveCollectionController {
30678
31122
  constructor(query, callback) {
30679
31123
  const queryStreamId = hash__default["default"](query);
30680
- const cacheKey = ['event', 'collection', queryStreamId];
31124
+ const cacheKey = ['eventResponse', 'collection', queryStreamId];
30681
31125
  const paginationController = new EventPaginationController(query);
30682
31126
  super(paginationController, queryStreamId, cacheKey, callback);
30683
31127
  this.query = query;
@@ -30702,6 +31146,9 @@ class EventLiveCollectionController extends LiveCollectionController {
30702
31146
  { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
30703
31147
  { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
30704
31148
  { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
31149
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
31150
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
31151
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
30705
31152
  ]);
30706
31153
  }
30707
31154
  notifyChange({ origin, loading, error }) {
@@ -30710,10 +31157,10 @@ class EventLiveCollectionController extends LiveCollectionController {
30710
31157
  if (!collection)
30711
31158
  return;
30712
31159
  const data = ((_b = collection.data
30713
- .map(eventId => pullFromCache(['event', 'get', eventId]))
31160
+ .map(eventId => pullFromCache(['eventRSVPs', 'get', eventId]))
30714
31161
  .filter(isNonNullable)
30715
31162
  .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
30716
- if (!this.shouldNotify(data) && origin === 'event')
31163
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
30717
31164
  return;
30718
31165
  this.callback({
30719
31166
  data,
@@ -30790,6 +31237,12 @@ class MyEventQueryStreamController extends QueryStreamController {
30790
31237
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30791
31238
  if (!collection)
30792
31239
  return;
31240
+ if (action === EventActionsEnum.OnEventCreated) {
31241
+ const client = getActiveClient();
31242
+ if (client.userId !== event.userId)
31243
+ return;
31244
+ collection.data = [...new Set([event.eventId, ...collection.data])];
31245
+ }
30793
31246
  if (action === EventActionsEnum.OnEventDeleted) {
30794
31247
  collection.data = collection.data.filter(eventId => eventId !== event.eventId);
30795
31248
  }
@@ -30830,6 +31283,9 @@ class MyEventLiveCollectionController extends LiveCollectionController {
30830
31283
  { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
30831
31284
  { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
30832
31285
  { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
31286
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
31287
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
31288
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
30833
31289
  ]);
30834
31290
  }
30835
31291
  notifyChange({ origin, loading, error }) {
@@ -30841,7 +31297,7 @@ class MyEventLiveCollectionController extends LiveCollectionController {
30841
31297
  .map(eventId => pullFromCache(['event', 'get', eventId]))
30842
31298
  .filter(isNonNullable)
30843
31299
  .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
30844
- if (!this.shouldNotify(data) && origin === 'event')
31300
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
30845
31301
  return;
30846
31302
  this.callback({
30847
31303
  data,
@@ -30887,9 +31343,17 @@ var index = /*#__PURE__*/Object.freeze({
30887
31343
  onEventCreated: onEventCreated,
30888
31344
  onEventUpdated: onEventUpdated,
30889
31345
  onEventDeleted: onEventDeleted,
31346
+ onLocalEventCreated: onLocalEventCreated,
31347
+ onLocalEventUpdated: onLocalEventUpdated,
31348
+ onLocalEventDeleted: onLocalEventDeleted,
31349
+ onRSVPCreated: onRSVPCreated,
31350
+ onRSVPUpdated: onRSVPUpdated,
31351
+ onLocalRSVPCreated: onLocalRSVPCreated,
31352
+ onLocalRSVPUpdated: onLocalRSVPUpdated,
30890
31353
  getEvent: getEvent,
30891
31354
  getEvents: getEvents,
30892
- getMyEvents: getMyEvents
31355
+ getMyEvents: getMyEvents,
31356
+ getRSVPs: getRSVPs
30893
31357
  });
30894
31358
 
30895
31359
  exports.API_REGIONS = API_REGIONS;