@amityco/ts-sdk 7.11.1-cc6dc67b.0 → 7.11.1-ce7af0e2.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 (93) 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/core/permissions.d.ts +5 -1
  8. package/dist/@types/core/permissions.d.ts.map +1 -1
  9. package/dist/@types/core/transport.d.ts +3 -0
  10. package/dist/@types/core/transport.d.ts.map +1 -1
  11. package/dist/@types/domains/community.d.ts +11 -1
  12. package/dist/@types/domains/community.d.ts.map +1 -1
  13. package/dist/@types/domains/event.d.ts +56 -9
  14. package/dist/@types/domains/event.d.ts.map +1 -1
  15. package/dist/@types/domains/notification.d.ts +3 -1
  16. package/dist/@types/domains/notification.d.ts.map +1 -1
  17. package/dist/@types/domains/partials.d.ts +2 -2
  18. package/dist/@types/domains/partials.d.ts.map +1 -1
  19. package/dist/core/events.d.ts +3 -3
  20. package/dist/core/events.d.ts.map +1 -1
  21. package/dist/core/model/idResolvers.d.ts.map +1 -1
  22. package/dist/core/model/index.d.ts.map +1 -1
  23. package/dist/eventRepository/api/deleteEvent.d.ts +15 -0
  24. package/dist/eventRepository/api/deleteEvent.d.ts.map +1 -0
  25. package/dist/eventRepository/api/index.d.ts +1 -0
  26. package/dist/eventRepository/api/index.d.ts.map +1 -1
  27. package/dist/eventRepository/events/enums.d.ts +8 -0
  28. package/dist/eventRepository/events/enums.d.ts.map +1 -0
  29. package/dist/eventRepository/events/index.d.ts +7 -0
  30. package/dist/eventRepository/events/index.d.ts.map +1 -1
  31. package/dist/eventRepository/events/onLocalEventCreated.d.ts +17 -0
  32. package/dist/eventRepository/events/onLocalEventCreated.d.ts.map +1 -0
  33. package/dist/eventRepository/events/onLocalEventDeleted.d.ts +17 -0
  34. package/dist/eventRepository/events/onLocalEventDeleted.d.ts.map +1 -0
  35. package/dist/eventRepository/events/onLocalEventUpdated.d.ts +17 -0
  36. package/dist/eventRepository/events/onLocalEventUpdated.d.ts.map +1 -0
  37. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts +17 -0
  38. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts.map +1 -0
  39. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts +17 -0
  40. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts.map +1 -0
  41. package/dist/eventRepository/events/onRSVPCreated.d.ts +17 -0
  42. package/dist/eventRepository/events/onRSVPCreated.d.ts.map +1 -0
  43. package/dist/eventRepository/events/onRSVPUpdated.d.ts +17 -0
  44. package/dist/eventRepository/events/onRSVPUpdated.d.ts.map +1 -0
  45. package/dist/eventRepository/internalApi/createRSVP.d.ts +16 -0
  46. package/dist/eventRepository/internalApi/createRSVP.d.ts.map +1 -0
  47. package/dist/eventRepository/internalApi/getMyRSVP.d.ts +32 -0
  48. package/dist/eventRepository/internalApi/getMyRSVP.d.ts.map +1 -0
  49. package/dist/eventRepository/internalApi/index.d.ts +3 -0
  50. package/dist/eventRepository/internalApi/index.d.ts.map +1 -1
  51. package/dist/eventRepository/internalApi/updateRSVP.d.ts +17 -0
  52. package/dist/eventRepository/internalApi/updateRSVP.d.ts.map +1 -0
  53. package/dist/eventRepository/observers/getEvent.d.ts.map +1 -1
  54. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts +13 -0
  55. package/dist/eventRepository/observers/getEvents/LiveCollectionController.d.ts.map +1 -0
  56. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts +5 -0
  57. package/dist/eventRepository/observers/getEvents/PaginationController.d.ts.map +1 -0
  58. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts +15 -0
  59. package/dist/eventRepository/observers/getEvents/QueryStreamController.d.ts.map +1 -0
  60. package/dist/eventRepository/observers/getEvents.d.ts +12 -0
  61. package/dist/eventRepository/observers/getEvents.d.ts.map +1 -0
  62. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts +13 -0
  63. package/dist/eventRepository/observers/getMyEvents/LiveCollectionController.d.ts.map +1 -0
  64. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts +5 -0
  65. package/dist/eventRepository/observers/getMyEvents/PaginationController.d.ts.map +1 -0
  66. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts +15 -0
  67. package/dist/eventRepository/observers/getMyEvents/QueryStreamController.d.ts.map +1 -0
  68. package/dist/eventRepository/observers/getMyEvents.d.ts +12 -0
  69. package/dist/eventRepository/observers/getMyEvents.d.ts.map +1 -0
  70. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts +13 -0
  71. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts.map +1 -0
  72. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts +5 -0
  73. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts.map +1 -0
  74. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts +15 -0
  75. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts.map +1 -0
  76. package/dist/eventRepository/observers/getRSVPs.d.ts +12 -0
  77. package/dist/eventRepository/observers/getRSVPs.d.ts.map +1 -0
  78. package/dist/eventRepository/observers/index.d.ts +3 -0
  79. package/dist/eventRepository/observers/index.d.ts.map +1 -1
  80. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts +1 -1
  81. package/dist/eventRepository/utils/createEventEventSubscriber.d.ts.map +1 -1
  82. package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts +2 -0
  83. package/dist/eventRepository/utils/createEventResponseSubscriber.d.ts.map +1 -0
  84. package/dist/eventRepository/utils/index.d.ts +2 -0
  85. package/dist/eventRepository/utils/index.d.ts.map +1 -1
  86. package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts +2 -0
  87. package/dist/eventRepository/utils/prepareEventResponsePayload.d.ts.map +1 -0
  88. package/dist/index.cjs.js +892 -109
  89. package/dist/index.esm.js +866 -83
  90. package/dist/index.umd.js +3 -3
  91. package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -1
  92. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -1
  93. package/package.json +1 -1
package/dist/index.esm.js CHANGED
@@ -194,6 +194,11 @@ var AmityEventStatus;
194
194
  AmityEventStatus["Ended"] = "ended";
195
195
  AmityEventStatus["Cancelled"] = "cancelled";
196
196
  })(AmityEventStatus || (AmityEventStatus = {}));
197
+ var AmityEventResponseStatus;
198
+ (function (AmityEventResponseStatus) {
199
+ AmityEventResponseStatus["Going"] = "going";
200
+ AmityEventResponseStatus["NotGoing"] = "not_going";
201
+ })(AmityEventResponseStatus || (AmityEventResponseStatus = {}));
197
202
 
198
203
  function getVersion() {
199
204
  try {
@@ -643,6 +648,9 @@ const idResolvers = {
643
648
  notificationTraySeen: ({ userId }) => userId,
644
649
  invitation: ({ _id }) => _id,
645
650
  joinRequest: ({ joinRequestId }) => joinRequestId,
651
+ event: ({ eventId }) => eventId,
652
+ eventResponse: ({ eventId }) => eventId,
653
+ discussionCommunity: ({ communityId }) => communityId,
646
654
  };
647
655
  /**
648
656
  * Retrieve the id resolver matching a domain name
@@ -698,6 +706,9 @@ const PAYLOAD2MODEL = {
698
706
  notificationTrayItems: 'notificationTrayItem',
699
707
  invitations: 'invitation',
700
708
  joinRequests: 'joinRequest',
709
+ events: 'event',
710
+ eventResponse: 'eventResponse',
711
+ discussionCommunities: 'discussionCommunity',
701
712
  };
702
713
  /** hidden */
703
714
  const isOutdated = (prevData, nextData) => {
@@ -29768,6 +29779,503 @@ const communityLinkedObject = (community) => {
29768
29779
  } });
29769
29780
  };
29770
29781
 
29782
+ const prepareEventResponsePayload = (rawPayload) => {
29783
+ return {
29784
+ status: rawPayload.eventResponses[0].status,
29785
+ eventId: rawPayload.eventResponses[0].eventId,
29786
+ event: rawPayload.events,
29787
+ userId: rawPayload.eventResponses[0].userId,
29788
+ user: rawPayload.users.map(convertRawUserToInternalUser),
29789
+ };
29790
+ };
29791
+
29792
+ /* begin_public_function
29793
+ id: event.rsvp.create
29794
+ */
29795
+ /**
29796
+ * ```js
29797
+ * import { event } from '@amityco/ts-sdk'
29798
+ * const response = await event.createRSVP(eventId, status)
29799
+ * ```
29800
+ *
29801
+ * Creates an {@link Amity.InternalEvent}
29802
+ *
29803
+ * @param bundle The data necessary to create a new {@link Amity.InternalEvent}
29804
+ * @returns The newly created {@link Amity.InternalEvent}
29805
+ *
29806
+ * @category Event API
29807
+ * @async
29808
+ */
29809
+ const createRSVP = async (eventId, status) => {
29810
+ const client = getActiveClient();
29811
+ client.log('event/createRSVP', eventId, status);
29812
+ const { data: payload } = await client.http.post(`/api/v1/events/${eventId}/rsvp`, { status });
29813
+ fireEvent('local.rsvp.created', payload);
29814
+ const data = prepareEventResponsePayload(payload);
29815
+ const cachedAt = client.cache && Date.now();
29816
+ if (client.cache)
29817
+ ingestInCache({ eventResponses: [data] }, { cachedAt });
29818
+ return {
29819
+ data,
29820
+ cachedAt,
29821
+ };
29822
+ };
29823
+ /* end_public_function */
29824
+
29825
+ /* begin_public_function
29826
+ id: event.update
29827
+ */
29828
+ /**
29829
+ * ```js
29830
+ * import { event } from '@amityco/ts-sdk'
29831
+ * const response = await event.updateRSVP(eventId, status)
29832
+ * ```
29833
+ *
29834
+ * Updates an {@link Amity.EventResponse}
29835
+ *
29836
+ * @param eventId The ID of the {@link Amity.EventResponse} to edit
29837
+ * @param bundle The data necessary to update an existing {@link Amity.EventResponse}
29838
+ * @returns the updated {@link Amity.EventResponse}
29839
+ *
29840
+ * @category Event API
29841
+ * @async
29842
+ */
29843
+ const updateRSVP = async (eventId, status) => {
29844
+ const client = getActiveClient();
29845
+ client.log('event/updateRSVP', eventId, status);
29846
+ const { data: payload } = await client.http.put(`/api/v1/events/${eventId}/rsvp`, { status });
29847
+ fireEvent('local.rsvp.updated', payload);
29848
+ const data = prepareEventResponsePayload(payload);
29849
+ const cachedAt = client.cache && Date.now();
29850
+ if (client.cache)
29851
+ ingestInCache({ eventResponses: [data] }, { cachedAt });
29852
+ return {
29853
+ data,
29854
+ cachedAt,
29855
+ };
29856
+ };
29857
+ /* end_public_function */
29858
+
29859
+ const prepareEventPayload = (rawPayload) => {
29860
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
29861
+ };
29862
+
29863
+ const createEventEventSubscriber = (event, callback) => {
29864
+ const client = getActiveClient();
29865
+ const filter = (payload) => {
29866
+ const unpackedPayload = prepareEventPayload(payload);
29867
+ if (!client.cache) {
29868
+ callback(unpackedPayload.events[0]);
29869
+ }
29870
+ else {
29871
+ ingestInCache(unpackedPayload);
29872
+ const event = pullFromCache([
29873
+ 'event',
29874
+ 'get',
29875
+ unpackedPayload.events[0].eventId,
29876
+ ]);
29877
+ callback(event.data);
29878
+ }
29879
+ };
29880
+ return createEventSubscriber(client, event, event, filter);
29881
+ };
29882
+
29883
+ const createEventResponseSubscriber = (event, callback) => {
29884
+ const client = getActiveClient();
29885
+ const filter = (payload) => {
29886
+ const unpackedPayload = prepareEventResponsePayload(payload);
29887
+ if (!client.cache) {
29888
+ callback(unpackedPayload);
29889
+ }
29890
+ else {
29891
+ ingestInCache(unpackedPayload.event[0]);
29892
+ const eventResponse = pullFromCache([
29893
+ 'eventResponse',
29894
+ 'get',
29895
+ payload.eventResponses[0].eventId,
29896
+ ]);
29897
+ callback(eventResponse.data);
29898
+ }
29899
+ };
29900
+ return createEventSubscriber(client, event, event, filter);
29901
+ };
29902
+
29903
+ /* begin_public_function
29904
+ id: event.rsvp.me
29905
+ */
29906
+ /**
29907
+ * ```js
29908
+ * import { event } from '@amityco/ts-sdk'
29909
+ * const myRSVP = await event.getMyRSVP()
29910
+ * ```
29911
+ *
29912
+ * Joins a {@link Amity.EventResponse} object
29913
+ *
29914
+ * @param eventId the {@link Amity.EventResponse} to get RSVP for
29915
+ * @returns A success boolean if the {@link Amity.EventResponse} RSVP was retrieved
29916
+ *
29917
+ * @category Event API
29918
+ * @async
29919
+ */
29920
+ const getMyRSVP = async (eventId) => {
29921
+ const client = getActiveClient();
29922
+ client.log('event/getMyRSVP', eventId);
29923
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}/me/rsvp`);
29924
+ const data = prepareEventResponsePayload(payload);
29925
+ const cachedAt = client.cache && Date.now();
29926
+ if (client.cache)
29927
+ ingestInCache({ eventResponses: [data] }, { cachedAt });
29928
+ return {
29929
+ data,
29930
+ cachedAt,
29931
+ };
29932
+ };
29933
+ /* end_public_function */
29934
+ /**
29935
+ * ```js
29936
+ * import { event } from '@amityco/ts-sdk'
29937
+ * const event = event.getMyRSVP.locally(eventId)
29938
+ * ```
29939
+ *
29940
+ * Fetches a {@link Amity.EventResponse} object in cache
29941
+ *
29942
+ * @param eventId the ID of the {@link Amity.EventResponse} to fetch
29943
+ * @returns the associated {@link Amity.EventResponse} object
29944
+ *
29945
+ * @category Event API
29946
+ */
29947
+ getMyRSVP.locally = (eventId) => {
29948
+ const client = getActiveClient();
29949
+ client.log('event/getMyRSVP.locally', eventId);
29950
+ if (!client.cache)
29951
+ return;
29952
+ const cache = pullFromCache(['event', 'getMyRSVP', eventId]);
29953
+ if (!cache)
29954
+ return;
29955
+ return {
29956
+ data: cache.data,
29957
+ cachedAt: cache.cachedAt,
29958
+ };
29959
+ };
29960
+
29961
+ var EventActionsEnum;
29962
+ (function (EventActionsEnum) {
29963
+ EventActionsEnum["OnEventCreated"] = "onEventCreated";
29964
+ EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
29965
+ EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
29966
+ EventActionsEnum["OnRSVPCreated"] = "onRSVPCreated";
29967
+ EventActionsEnum["OnRSVPUpdated"] = "onRSVPUpdated";
29968
+ })(EventActionsEnum || (EventActionsEnum = {}));
29969
+
29970
+ class RSVPPaginationController extends PaginationController {
29971
+ async getRequest(queryParams, token) {
29972
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, eventId } = queryParams, params = __rest(queryParams, ["limit", "eventId"]);
29973
+ const options = token ? { token } : { limit };
29974
+ const { data: response } = await this.http.get(`/api/v1/events/${eventId}/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
29975
+ return response;
29976
+ }
29977
+ }
29978
+
29979
+ class RSVPQueryStreamController extends QueryStreamController {
29980
+ constructor(query, cacheKey, notifyChange, preparePayload) {
29981
+ super(query, cacheKey);
29982
+ this.notifyChange = notifyChange;
29983
+ this.preparePayload = preparePayload;
29984
+ }
29985
+ async saveToMainDB(response) {
29986
+ const processedPayload = this.preparePayload(response);
29987
+ const client = getActiveClient();
29988
+ const cachedAt = client.cache && Date.now();
29989
+ if (client.cache)
29990
+ ingestInCache({ eventResponses: [processedPayload] }, { cachedAt });
29991
+ }
29992
+ appendToQueryStream(response, direction, refresh = false) {
29993
+ var _a, _b;
29994
+ if (refresh) {
29995
+ pushToCache(this.cacheKey, {
29996
+ data: response.eventResponses.map(getResolver('eventResponse')),
29997
+ });
29998
+ }
29999
+ else {
30000
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30001
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
30002
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
30003
+ ...new Set([...events, ...response.eventResponses.map(getResolver('eventResponse'))]),
30004
+ ] }));
30005
+ }
30006
+ }
30007
+ reactor(action) {
30008
+ return (event) => {
30009
+ var _a;
30010
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30011
+ if (!collection)
30012
+ return;
30013
+ if (action === EventActionsEnum.OnRSVPCreated) {
30014
+ const client = getActiveClient();
30015
+ if (client.userId !== event.userId)
30016
+ return;
30017
+ collection.data = [...new Set([event.eventId, ...collection.data])];
30018
+ }
30019
+ if (action === EventActionsEnum.OnEventDeleted) {
30020
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
30021
+ }
30022
+ pushToCache(this.cacheKey, collection);
30023
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
30024
+ };
30025
+ }
30026
+ subscribeRTE(createSubscriber) {
30027
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
30028
+ }
30029
+ }
30030
+
30031
+ /**
30032
+ * ```js
30033
+ * import { EventRepository } from '@amityco/ts-sdk'
30034
+ * const dispose = EventRepository.onEventCreated(event => {
30035
+ * // ...
30036
+ * })
30037
+ * ```
30038
+ *
30039
+ * Fired when a {@link Amity.Event} has been created
30040
+ *
30041
+ * @param callback The function to call when the event was fired
30042
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30043
+ *
30044
+ * @category Event Events
30045
+ */
30046
+ const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
30047
+
30048
+ /**
30049
+ * ```js
30050
+ * import { EventRepository } from '@amityco/ts-sdk'
30051
+ * const dispose = EventRepository.onEventUpdated(event => {
30052
+ * // ...
30053
+ * })
30054
+ * ```
30055
+ *
30056
+ * Fired when a {@link Amity.Event} has been updated
30057
+ *
30058
+ * @param callback The function to call when the event was fired
30059
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30060
+ *
30061
+ * @category Event Events
30062
+ */
30063
+ const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
30064
+
30065
+ /**
30066
+ * ```js
30067
+ * import { EventRepository } from '@amityco/ts-sdk'
30068
+ * const dispose = EventRepository.onEventDeleted(event => {
30069
+ * // ...
30070
+ * })
30071
+ * ```
30072
+ *
30073
+ * Fired when a {@link Amity.Event} has been deleted
30074
+ *
30075
+ * @param callback The function to call when the event was fired
30076
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30077
+ *
30078
+ * @category Event Events
30079
+ */
30080
+ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
30081
+
30082
+ /**
30083
+ * ```js
30084
+ * import { EventRepository } from '@amityco/ts-sdk'
30085
+ * const dispose = EventRepository.onLocalEventCreated(event => {
30086
+ * // ...
30087
+ * })
30088
+ * ```
30089
+ *
30090
+ * Fired when a {@link Amity.Event} has been created
30091
+ *
30092
+ * @param callback The function to call when the event was fired
30093
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30094
+ *
30095
+ * @category Event Events
30096
+ */
30097
+ const onLocalEventCreated = (callback) => createEventEventSubscriber('local.event.created', callback);
30098
+
30099
+ /**
30100
+ * ```js
30101
+ * import { EventRepository } from '@amityco/ts-sdk'
30102
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
30103
+ * // ...
30104
+ * })
30105
+ * ```
30106
+ *
30107
+ * Fired when a {@link Amity.Event} has been updated
30108
+ *
30109
+ * @param callback The function to call when the event was fired
30110
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30111
+ *
30112
+ * @category Event Events
30113
+ */
30114
+ const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.event.updated', callback);
30115
+
30116
+ /**
30117
+ * ```js
30118
+ * import { EventRepository } from '@amityco/ts-sdk'
30119
+ * const dispose = EventRepository.onLocalEventDeleted(event => {
30120
+ * // ...
30121
+ * })
30122
+ * ```
30123
+ *
30124
+ * Fired when a {@link Amity.Event} has been deleted
30125
+ *
30126
+ * @param callback The function to call when the event was fired
30127
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30128
+ *
30129
+ * @category Event Events
30130
+ */
30131
+ const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
30132
+
30133
+ /**
30134
+ * ```js
30135
+ * import { EventRepository } from '@amityco/ts-sdk'
30136
+ * const dispose = EventRepository.onRSVPCreated(event => {
30137
+ * // ...
30138
+ * })
30139
+ * ```
30140
+ *
30141
+ * Fired when a {@link Amity.Event} has been created
30142
+ *
30143
+ * @param callback The function to call when the event was fired
30144
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30145
+ *
30146
+ * @category Event Events
30147
+ */
30148
+ const onRSVPCreated = (callback) => createEventResponseSubscriber('event.rsvp.created', callback);
30149
+
30150
+ /**
30151
+ * ```js
30152
+ * import { EventRepository } from '@amityco/ts-sdk'
30153
+ * const dispose = EventRepository.onRSVPUpdated(event => {
30154
+ * // ...
30155
+ * })
30156
+ * ```
30157
+ *
30158
+ * Fired when a {@link Amity.InternalEventResponse} has been updated
30159
+ *
30160
+ * @param callback The function to call when the event was fired
30161
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30162
+ *
30163
+ * @category Event Events
30164
+ */
30165
+ const onRSVPUpdated = (callback) => createEventResponseSubscriber('event.rsvp.updated', callback);
30166
+
30167
+ /**
30168
+ * ```js
30169
+ * import { EventRepository } from '@amityco/ts-sdk'
30170
+ * const dispose = EventRepository.onLocalRSVPCreated(event => {
30171
+ * // ...
30172
+ * })
30173
+ * ```
30174
+ *
30175
+ * Fired when a {@link Amity.Event} has been created
30176
+ *
30177
+ * @param callback The function to call when the event was fired
30178
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30179
+ *
30180
+ * @category Event Events
30181
+ */
30182
+ const onLocalRSVPCreated = (callback) => createEventResponseSubscriber('local.rsvp.created', callback);
30183
+
30184
+ /**
30185
+ * ```js
30186
+ * import { EventRepository } from '@amityco/ts-sdk'
30187
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
30188
+ * // ...
30189
+ * })
30190
+ * ```
30191
+ *
30192
+ * Fired when a {@link Amity.Event} has been updated
30193
+ *
30194
+ * @param callback The function to call when the event was fired
30195
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30196
+ *
30197
+ * @category Event Events
30198
+ */
30199
+ const onLocalRSVPUpdated = (callback) => createEventResponseSubscriber('local.rsvp.updated', callback);
30200
+
30201
+ class RSVPLiveCollectionController extends LiveCollectionController {
30202
+ constructor(query, callback) {
30203
+ const queryStreamId = hash(query);
30204
+ const cacheKey = ['eventResponse', 'collection', queryStreamId];
30205
+ const paginationController = new RSVPPaginationController(query);
30206
+ super(paginationController, queryStreamId, cacheKey, callback);
30207
+ this.query = query;
30208
+ this.queryStreamController = new RSVPQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventResponsePayload);
30209
+ this.callback = callback.bind(this);
30210
+ this.loadPage({ initial: true });
30211
+ }
30212
+ setup() {
30213
+ var _a;
30214
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30215
+ if (!collection)
30216
+ pushToCache(this.cacheKey, { data: [], params: this.query });
30217
+ }
30218
+ async persistModel(queryPayload) {
30219
+ await this.queryStreamController.saveToMainDB(queryPayload);
30220
+ }
30221
+ persistQueryStream({ response, direction, refresh, }) {
30222
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
30223
+ }
30224
+ startSubscription() {
30225
+ return this.queryStreamController.subscribeRTE([
30226
+ { fn: onRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
30227
+ { fn: onRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
30228
+ { fn: onLocalRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
30229
+ { fn: onLocalRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
30230
+ ]);
30231
+ }
30232
+ notifyChange({ origin, loading, error }) {
30233
+ var _a, _b;
30234
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
30235
+ if (!collection)
30236
+ return;
30237
+ const data = (_b = collection.data
30238
+ .map(eventId => pullFromCache(['eventResponse', 'get', eventId]))
30239
+ .filter(isNonNullable)
30240
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
30241
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
30242
+ return;
30243
+ this.callback({
30244
+ data,
30245
+ error,
30246
+ loading,
30247
+ hasNextPage: !!this.paginationController.getNextToken(),
30248
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
30249
+ });
30250
+ }
30251
+ }
30252
+
30253
+ /**
30254
+ * Get events
30255
+ *
30256
+ * @param params the query parameters
30257
+ * @param callback the callback to be called when the events are updated
30258
+ * @returns events
30259
+ *
30260
+ * @category RSVP Live Collection
30261
+ *
30262
+ */
30263
+ const getRSVPs = (params, callback, config) => {
30264
+ const { log, cache } = getActiveClient();
30265
+ if (!cache)
30266
+ console.log(ENABLE_CACHE_MESSAGE);
30267
+ const timestamp = Date.now();
30268
+ log(`getRSVPs: (tmpid: ${timestamp}) > listen`);
30269
+ const eventLiveCollection = new RSVPLiveCollectionController(params, callback);
30270
+ const disposers = eventLiveCollection.startSubscription();
30271
+ const cacheKey = eventLiveCollection.getCacheKey();
30272
+ disposers.push(() => dropFromCache(cacheKey));
30273
+ return () => {
30274
+ log(`getRSVPs (tmpid: ${timestamp}) > dispose`);
30275
+ disposers.forEach(fn => fn());
30276
+ };
30277
+ };
30278
+
29771
30279
  const eventLinkedObject = (event) => {
29772
30280
  return Object.assign(Object.assign({}, event), { get creator() {
29773
30281
  const cacheData = pullFromCache(['user', 'get', event.userId]);
@@ -29776,13 +30284,33 @@ const eventLinkedObject = (event) => {
29776
30284
  return userLinkedObject(cacheData.data);
29777
30285
  },
29778
30286
  get discussionCommunity() {
29779
- if (!event.communityId)
30287
+ if (!event.discussionCommunityId)
30288
+ return;
30289
+ const cacheData = pullFromCache([
30290
+ 'discussionCommunity',
30291
+ 'get',
30292
+ event.discussionCommunityId,
30293
+ ]);
30294
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
30295
+ return;
30296
+ return communityLinkedObject(cacheData.data);
30297
+ },
30298
+ get targetCommunity() {
30299
+ if (!event.originId)
29780
30300
  return;
29781
- const cacheData = pullFromCache(['community', 'get', event.communityId]);
30301
+ const cacheData = pullFromCache(['community', 'get', event.originId]);
29782
30302
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29783
30303
  return;
29784
30304
  return communityLinkedObject(cacheData.data);
29785
30305
  },
30306
+ get coverImage() {
30307
+ if (!event.coverImageFileId)
30308
+ return;
30309
+ const cacheData = pullFromCache(['file', 'get', event.coverImageFileId]);
30310
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
30311
+ return;
30312
+ return cacheData.data;
30313
+ },
29786
30314
  get liveStream() {
29787
30315
  if (!event.livestreamId)
29788
30316
  return;
@@ -29790,6 +30318,20 @@ const eventLinkedObject = (event) => {
29790
30318
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29791
30319
  return;
29792
30320
  return cacheData.data;
30321
+ }, createRSVP: async (status) => {
30322
+ const { data } = await createRSVP(event.eventId, status);
30323
+ return data;
30324
+ }, updateRSVP: async (status) => {
30325
+ const { data } = await updateRSVP(event.eventId, status);
30326
+ return data;
30327
+ }, getMyRSVP: async () => {
30328
+ const { data } = await getMyRSVP(event.eventId);
30329
+ return data;
30330
+ }, getRSVPs: (status, callback) => {
30331
+ return getRSVPs({
30332
+ eventId: event.eventId,
30333
+ status,
30334
+ }, callback);
29793
30335
  } });
29794
30336
  };
29795
30337
 
@@ -46429,30 +46971,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
46429
46971
  getReactions: getReactions
46430
46972
  });
46431
46973
 
46432
- const prepareEventPayload = (rawPayload) => {
46433
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
46434
- };
46435
-
46436
- const createEventEventSubscriber = (event, callback) => {
46437
- const client = getActiveClient();
46438
- const filter = (payload) => {
46439
- const unpackedPayload = prepareEventPayload(payload);
46440
- if (!client.cache) {
46441
- callback(unpackedPayload.events[0]);
46442
- }
46443
- else {
46444
- ingestInCache(unpackedPayload);
46445
- const event = pullFromCache([
46446
- 'event',
46447
- 'get',
46448
- unpackedPayload.events[0].eventId,
46449
- ]);
46450
- callback(event.data);
46451
- }
46452
- };
46453
- return createEventSubscriber(client, event, event, filter);
46454
- };
46455
-
46456
46974
  /* begin_public_function
46457
46975
  id: event.create
46458
46976
  */
@@ -46474,7 +46992,7 @@ const createEvent = async (bundle) => {
46474
46992
  const client = getActiveClient();
46475
46993
  client.log('event/createEvent', bundle);
46476
46994
  const { data: payload } = await client.http.post('/api/v1/events', bundle);
46477
- fireEvent('event.created', payload);
46995
+ fireEvent('local.event.created', payload);
46478
46996
  const preparedPayload = prepareEventPayload(payload);
46479
46997
  const cachedAt = client.cache && Date.now();
46480
46998
  if (client.cache)
@@ -46508,7 +47026,7 @@ const updateEvent = async (eventId, bundle) => {
46508
47026
  const client = getActiveClient();
46509
47027
  client.log('event/updateEvent', eventId, bundle);
46510
47028
  const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
46511
- fireEvent('event.updated', payload);
47029
+ fireEvent('local.event.updated', payload);
46512
47030
  const preparedPayload = prepareEventPayload(payload);
46513
47031
  const cachedAt = client.cache && Date.now();
46514
47032
  if (client.cache)
@@ -46520,57 +47038,6 @@ const updateEvent = async (eventId, bundle) => {
46520
47038
  };
46521
47039
  /* end_public_function */
46522
47040
 
46523
- /**
46524
- * ```js
46525
- * import { EventRepository } from '@amityco/ts-sdk'
46526
- * const dispose = EventRepository.onEventCreated(event => {
46527
- * // ...
46528
- * })
46529
- * ```
46530
- *
46531
- * Fired when a {@link Amity.Event} has been created
46532
- *
46533
- * @param callback The function to call when the event was fired
46534
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46535
- *
46536
- * @category Event Events
46537
- */
46538
- const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
46539
-
46540
- /**
46541
- * ```js
46542
- * import { EventRepository } from '@amityco/ts-sdk'
46543
- * const dispose = EventRepository.onEventUpdated(event => {
46544
- * // ...
46545
- * })
46546
- * ```
46547
- *
46548
- * Fired when a {@link Amity.Event} has been updated
46549
- *
46550
- * @param callback The function to call when the event was fired
46551
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46552
- *
46553
- * @category Event Events
46554
- */
46555
- const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
46556
-
46557
- /**
46558
- * ```js
46559
- * import { EventRepository } from '@amityco/ts-sdk'
46560
- * const dispose = EventRepository.onEventDeleted(event => {
46561
- * // ...
46562
- * })
46563
- * ```
46564
- *
46565
- * Fired when a {@link Amity.Event} has been deleted
46566
- *
46567
- * @param callback The function to call when the event was fired
46568
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46569
- *
46570
- * @category Event Events
46571
- */
46572
- const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
46573
-
46574
47041
  /* begin_public_function
46575
47042
  id: event.get
46576
47043
  */
@@ -46591,7 +47058,7 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
46591
47058
  const getEvent$1 = async (eventId) => {
46592
47059
  const client = getActiveClient();
46593
47060
  client.log('event/getEvent', eventId);
46594
- const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
47061
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
46595
47062
  const data = prepareEventPayload(payload);
46596
47063
  const cachedAt = client.cache && Date.now();
46597
47064
  if (client.cache)
@@ -46629,6 +47096,40 @@ getEvent$1.locally = (eventId) => {
46629
47096
  };
46630
47097
  };
46631
47098
 
47099
+ /* begin_public_function
47100
+ id: event.delete
47101
+ */
47102
+ /**
47103
+ * ```js
47104
+ * import { EventRepository } from '@amityco/ts-sdk'
47105
+ * const { success } = await EventRepository.deleteEvent(eventId)
47106
+ * ```
47107
+ *
47108
+ * Deletes a {@link Amity.Event}
47109
+ *
47110
+ * @param eventId The {@link Amity.Event} ID to delete
47111
+ *
47112
+ * @category Event API
47113
+ * @async
47114
+ */
47115
+ const deleteEvent = async (eventId) => {
47116
+ const client = getActiveClient();
47117
+ client.log('event/deleteEvent', eventId);
47118
+ const event = await getEvent$1(eventId);
47119
+ await client.http.delete(`/api/v1/events/${eventId}`);
47120
+ const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
47121
+ upsertInCache(['event', 'get', eventId], deletedEvent);
47122
+ fireEvent('local.event.deleted', {
47123
+ users: [],
47124
+ files: [],
47125
+ communities: [],
47126
+ videoStreamings: [],
47127
+ events: [deletedEvent],
47128
+ discussionCommunities: [],
47129
+ });
47130
+ };
47131
+ /* end_public_function */
47132
+
46632
47133
  /* begin_public_function
46633
47134
  id: event.get
46634
47135
  */
@@ -46652,20 +47153,302 @@ getEvent$1.locally = (eventId) => {
46652
47153
  * @category Event Live Object
46653
47154
  */
46654
47155
  const getEvent = (eventId, callback) => {
46655
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
47156
+ return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
46656
47157
  callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
46657
47158
  });
46658
47159
  };
46659
47160
  /* end_public_function */
46660
47161
 
47162
+ class EventPaginationController extends PaginationController {
47163
+ async getRequest(queryParams, token) {
47164
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
47165
+ const options = token ? { token } : { limit };
47166
+ const { data: response } = await this.http.get(`/api/v1/events`, { params: Object.assign(Object.assign({}, params), { options }) });
47167
+ return response;
47168
+ }
47169
+ }
47170
+
47171
+ class EventQueryStreamController extends QueryStreamController {
47172
+ constructor(query, cacheKey, notifyChange, preparePayload) {
47173
+ super(query, cacheKey);
47174
+ this.notifyChange = notifyChange;
47175
+ this.preparePayload = preparePayload;
47176
+ }
47177
+ async saveToMainDB(response) {
47178
+ const processedPayload = this.preparePayload(response);
47179
+ const client = getActiveClient();
47180
+ const cachedAt = client.cache && Date.now();
47181
+ if (client.cache)
47182
+ ingestInCache(processedPayload, { cachedAt });
47183
+ }
47184
+ appendToQueryStream(response, direction, refresh = false) {
47185
+ var _a, _b;
47186
+ if (refresh) {
47187
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
47188
+ }
47189
+ else {
47190
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47191
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
47192
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
47193
+ }
47194
+ }
47195
+ reactor(action) {
47196
+ return (event) => {
47197
+ var _a;
47198
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47199
+ if (!collection)
47200
+ return;
47201
+ if (action === EventActionsEnum.OnEventCreated) {
47202
+ collection.data = [...new Set([event.eventId, ...collection.data])];
47203
+ }
47204
+ if (action === EventActionsEnum.OnEventDeleted) {
47205
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
47206
+ }
47207
+ pushToCache(this.cacheKey, collection);
47208
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
47209
+ };
47210
+ }
47211
+ subscribeRTE(createSubscriber) {
47212
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
47213
+ }
47214
+ }
47215
+
47216
+ class EventLiveCollectionController extends LiveCollectionController {
47217
+ constructor(query, callback) {
47218
+ const queryStreamId = hash(query);
47219
+ const cacheKey = ['eventResponse', 'collection', queryStreamId];
47220
+ const paginationController = new EventPaginationController(query);
47221
+ super(paginationController, queryStreamId, cacheKey, callback);
47222
+ this.query = query;
47223
+ this.queryStreamController = new EventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
47224
+ this.callback = callback.bind(this);
47225
+ this.loadPage({ initial: true });
47226
+ }
47227
+ setup() {
47228
+ var _a;
47229
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47230
+ if (!collection)
47231
+ pushToCache(this.cacheKey, { data: [], params: {} });
47232
+ }
47233
+ async persistModel(queryPayload) {
47234
+ await this.queryStreamController.saveToMainDB(queryPayload);
47235
+ }
47236
+ persistQueryStream({ response, direction, refresh, }) {
47237
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
47238
+ }
47239
+ startSubscription() {
47240
+ return this.queryStreamController.subscribeRTE([
47241
+ { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
47242
+ { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
47243
+ { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
47244
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
47245
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
47246
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
47247
+ ]);
47248
+ }
47249
+ notifyChange({ origin, loading, error }) {
47250
+ var _a, _b;
47251
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47252
+ if (!collection)
47253
+ return;
47254
+ const data = ((_b = collection.data
47255
+ .map(eventId => pullFromCache(['eventRSVPs', 'get', eventId]))
47256
+ .filter(isNonNullable)
47257
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
47258
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
47259
+ return;
47260
+ this.callback({
47261
+ data,
47262
+ error,
47263
+ loading,
47264
+ hasNextPage: !!this.paginationController.getNextToken(),
47265
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
47266
+ });
47267
+ }
47268
+ }
47269
+
47270
+ /**
47271
+ * Get events
47272
+ *
47273
+ * @param params the query parameters
47274
+ * @param callback the callback to be called when the events are updated
47275
+ * @returns events
47276
+ *
47277
+ * @category Event Live Collection
47278
+ *
47279
+ */
47280
+ const getEvents = (params, callback, config) => {
47281
+ const { log, cache } = getActiveClient();
47282
+ if (!cache)
47283
+ console.log(ENABLE_CACHE_MESSAGE);
47284
+ const timestamp = Date.now();
47285
+ log(`getEvents: (tmpid: ${timestamp}) > listen`);
47286
+ const eventLiveCollection = new EventLiveCollectionController(params, callback);
47287
+ const disposers = eventLiveCollection.startSubscription();
47288
+ const cacheKey = eventLiveCollection.getCacheKey();
47289
+ disposers.push(() => dropFromCache(cacheKey));
47290
+ return () => {
47291
+ log(`getEvents (tmpid: ${timestamp}) > dispose`);
47292
+ disposers.forEach(fn => fn());
47293
+ };
47294
+ };
47295
+
47296
+ class MyEventPaginationController extends PaginationController {
47297
+ async getRequest(queryParams, token) {
47298
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
47299
+ const options = token ? { token } : { limit };
47300
+ const { data: response } = await this.http.get(`/api/v1/events/me/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
47301
+ return response;
47302
+ }
47303
+ }
47304
+
47305
+ class MyEventQueryStreamController extends QueryStreamController {
47306
+ constructor(query, cacheKey, notifyChange, preparePayload) {
47307
+ super(query, cacheKey);
47308
+ this.notifyChange = notifyChange;
47309
+ this.preparePayload = preparePayload;
47310
+ }
47311
+ async saveToMainDB(response) {
47312
+ const processedPayload = this.preparePayload(response);
47313
+ const client = getActiveClient();
47314
+ const cachedAt = client.cache && Date.now();
47315
+ if (client.cache)
47316
+ ingestInCache(processedPayload, { cachedAt });
47317
+ }
47318
+ appendToQueryStream(response, direction, refresh = false) {
47319
+ var _a, _b;
47320
+ if (refresh) {
47321
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
47322
+ }
47323
+ else {
47324
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47325
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
47326
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
47327
+ }
47328
+ }
47329
+ reactor(action) {
47330
+ return (event) => {
47331
+ var _a;
47332
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47333
+ if (!collection)
47334
+ return;
47335
+ if (action === EventActionsEnum.OnEventCreated) {
47336
+ const client = getActiveClient();
47337
+ if (client.userId !== event.userId)
47338
+ return;
47339
+ collection.data = [...new Set([event.eventId, ...collection.data])];
47340
+ }
47341
+ if (action === EventActionsEnum.OnEventDeleted) {
47342
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
47343
+ }
47344
+ pushToCache(this.cacheKey, collection);
47345
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
47346
+ };
47347
+ }
47348
+ subscribeRTE(createSubscriber) {
47349
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
47350
+ }
47351
+ }
47352
+
47353
+ class MyEventLiveCollectionController extends LiveCollectionController {
47354
+ constructor(query, callback) {
47355
+ const queryStreamId = hash(query);
47356
+ const cacheKey = ['event', 'collection', queryStreamId];
47357
+ const paginationController = new MyEventPaginationController(query);
47358
+ super(paginationController, queryStreamId, cacheKey, callback);
47359
+ this.query = query;
47360
+ this.queryStreamController = new MyEventQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
47361
+ this.callback = callback.bind(this);
47362
+ this.loadPage({ initial: true });
47363
+ }
47364
+ setup() {
47365
+ var _a;
47366
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47367
+ if (!collection)
47368
+ pushToCache(this.cacheKey, { data: [], params: {} });
47369
+ }
47370
+ async persistModel(queryPayload) {
47371
+ await this.queryStreamController.saveToMainDB(queryPayload);
47372
+ }
47373
+ persistQueryStream({ response, direction, refresh, }) {
47374
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
47375
+ }
47376
+ startSubscription() {
47377
+ return this.queryStreamController.subscribeRTE([
47378
+ { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
47379
+ { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
47380
+ { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
47381
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
47382
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
47383
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
47384
+ ]);
47385
+ }
47386
+ notifyChange({ origin, loading, error }) {
47387
+ var _a, _b;
47388
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
47389
+ if (!collection)
47390
+ return;
47391
+ const data = ((_b = collection.data
47392
+ .map(eventId => pullFromCache(['event', 'get', eventId]))
47393
+ .filter(isNonNullable)
47394
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
47395
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
47396
+ return;
47397
+ this.callback({
47398
+ data,
47399
+ error,
47400
+ loading,
47401
+ hasNextPage: !!this.paginationController.getNextToken(),
47402
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
47403
+ });
47404
+ }
47405
+ }
47406
+
47407
+ /**
47408
+ * Get my events
47409
+ *
47410
+ * @param params the query parameters
47411
+ * @param callback the callback to be called when the events are updated
47412
+ * @returns events
47413
+ *
47414
+ * @category Event Live Collection
47415
+ *
47416
+ */
47417
+ const getMyEvents = (params, callback, config) => {
47418
+ const { log, cache } = getActiveClient();
47419
+ if (!cache)
47420
+ console.log(ENABLE_CACHE_MESSAGE);
47421
+ const timestamp = Date.now();
47422
+ log(`getMyEvents: (tmpid: ${timestamp}) > listen`);
47423
+ const myEventLiveCollection = new MyEventLiveCollectionController(params, callback);
47424
+ const disposers = myEventLiveCollection.startSubscription();
47425
+ const cacheKey = myEventLiveCollection.getCacheKey();
47426
+ disposers.push(() => dropFromCache(cacheKey));
47427
+ return () => {
47428
+ log(`getMyEvents (tmpid: ${timestamp}) > dispose`);
47429
+ disposers.forEach(fn => fn());
47430
+ };
47431
+ };
47432
+
46661
47433
  var index = /*#__PURE__*/Object.freeze({
46662
47434
  __proto__: null,
46663
47435
  createEvent: createEvent,
46664
47436
  updateEvent: updateEvent,
47437
+ deleteEvent: deleteEvent,
46665
47438
  onEventCreated: onEventCreated,
46666
47439
  onEventUpdated: onEventUpdated,
46667
47440
  onEventDeleted: onEventDeleted,
46668
- getEvent: getEvent
47441
+ onLocalEventCreated: onLocalEventCreated,
47442
+ onLocalEventUpdated: onLocalEventUpdated,
47443
+ onLocalEventDeleted: onLocalEventDeleted,
47444
+ onRSVPCreated: onRSVPCreated,
47445
+ onRSVPUpdated: onRSVPUpdated,
47446
+ onLocalRSVPCreated: onLocalRSVPCreated,
47447
+ onLocalRSVPUpdated: onLocalRSVPUpdated,
47448
+ getEvent: getEvent,
47449
+ getEvents: getEvents,
47450
+ getMyEvents: getMyEvents,
47451
+ getRSVPs: getRSVPs
46669
47452
  });
46670
47453
 
46671
- export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, AmityEventStatus, AmityEventType, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$7 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$5 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$3 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
47454
+ export { API_REGIONS, index$4 as AdRepository, AmityEventOriginType, AmityEventResponseStatus, AmityEventStatus, AmityEventType, index$c as CategoryRepository, index$g as ChannelRepository, index$p as Client, index$b as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$d as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index as EventRepository, FeedDataTypeEnum, index$a as FeedRepository, FeedSortByEnum, FeedSourceEnum, FileAccessTypeEnum, index$m as FileRepository, FileType, GET_WATCHER_URLS, index$2 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$1 as LiveReactionRepository, index$6 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$k as MessageRepository, index$7 as PollRepository, PostContentType, index$9 as PostRepository, PostStructureType, index$l as ReactionRepository, index$5 as StoryRepository, index$8 as StreamRepository, index$j as SubChannelRepository, SubscriptionLevels, index$n as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$3 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };