@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.esm.js CHANGED
@@ -197,7 +197,6 @@ var AmityEventStatus;
197
197
  var AmityEventResponseStatus;
198
198
  (function (AmityEventResponseStatus) {
199
199
  AmityEventResponseStatus["Going"] = "going";
200
- AmityEventResponseStatus["Interested"] = "interested";
201
200
  AmityEventResponseStatus["NotGoing"] = "not_going";
202
201
  })(AmityEventResponseStatus || (AmityEventResponseStatus = {}));
203
202
 
@@ -650,6 +649,8 @@ const idResolvers = {
650
649
  invitation: ({ _id }) => _id,
651
650
  joinRequest: ({ joinRequestId }) => joinRequestId,
652
651
  event: ({ eventId }) => eventId,
652
+ eventResponse: ({ eventId }) => eventId,
653
+ discussionCommunity: ({ communityId }) => communityId,
653
654
  };
654
655
  /**
655
656
  * Retrieve the id resolver matching a domain name
@@ -706,7 +707,8 @@ const PAYLOAD2MODEL = {
706
707
  invitations: 'invitation',
707
708
  joinRequests: 'joinRequest',
708
709
  events: 'event',
709
- discussionCommunities: 'community',
710
+ eventResponse: 'eventResponse',
711
+ discussionCommunities: 'discussionCommunity',
710
712
  };
711
713
  /** hidden */
712
714
  const isOutdated = (prevData, nextData) => {
@@ -29777,6 +29779,503 @@ const communityLinkedObject = (community) => {
29777
29779
  } });
29778
29780
  };
29779
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
+
29780
30279
  const eventLinkedObject = (event) => {
29781
30280
  return Object.assign(Object.assign({}, event), { get creator() {
29782
30281
  const cacheData = pullFromCache(['user', 'get', event.userId]);
@@ -29788,7 +30287,7 @@ const eventLinkedObject = (event) => {
29788
30287
  if (!event.discussionCommunityId)
29789
30288
  return;
29790
30289
  const cacheData = pullFromCache([
29791
- 'community',
30290
+ 'discussionCommunity',
29792
30291
  'get',
29793
30292
  event.discussionCommunityId,
29794
30293
  ]);
@@ -29796,6 +30295,22 @@ const eventLinkedObject = (event) => {
29796
30295
  return;
29797
30296
  return communityLinkedObject(cacheData.data);
29798
30297
  },
30298
+ get targetCommunity() {
30299
+ if (!event.originId)
30300
+ return;
30301
+ const cacheData = pullFromCache(['community', 'get', event.originId]);
30302
+ if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
30303
+ return;
30304
+ return communityLinkedObject(cacheData.data);
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
+ },
29799
30314
  get liveStream() {
29800
30315
  if (!event.livestreamId)
29801
30316
  return;
@@ -29803,6 +30318,17 @@ const eventLinkedObject = (event) => {
29803
30318
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
29804
30319
  return;
29805
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: (params, callback) => {
30331
+ return getRSVPs(Object.assign({ eventId: event.eventId }, params), callback);
29806
30332
  } });
29807
30333
  };
29808
30334
 
@@ -46442,30 +46968,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
46442
46968
  getReactions: getReactions
46443
46969
  });
46444
46970
 
46445
- const prepareEventPayload = (rawPayload) => {
46446
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
46447
- };
46448
-
46449
- const createEventEventSubscriber = (event, callback) => {
46450
- const client = getActiveClient();
46451
- const filter = (payload) => {
46452
- const unpackedPayload = prepareEventPayload(payload);
46453
- if (!client.cache) {
46454
- callback(unpackedPayload.events[0]);
46455
- }
46456
- else {
46457
- ingestInCache(unpackedPayload);
46458
- const event = pullFromCache([
46459
- 'event',
46460
- 'get',
46461
- unpackedPayload.events[0].eventId,
46462
- ]);
46463
- callback(event.data);
46464
- }
46465
- };
46466
- return createEventSubscriber(client, event, event, filter);
46467
- };
46468
-
46469
46971
  /* begin_public_function
46470
46972
  id: event.create
46471
46973
  */
@@ -46487,7 +46989,7 @@ const createEvent = async (bundle) => {
46487
46989
  const client = getActiveClient();
46488
46990
  client.log('event/createEvent', bundle);
46489
46991
  const { data: payload } = await client.http.post('/api/v1/events', bundle);
46490
- fireEvent('event.created', payload);
46992
+ fireEvent('local.event.created', payload);
46491
46993
  const preparedPayload = prepareEventPayload(payload);
46492
46994
  const cachedAt = client.cache && Date.now();
46493
46995
  if (client.cache)
@@ -46521,7 +47023,7 @@ const updateEvent = async (eventId, bundle) => {
46521
47023
  const client = getActiveClient();
46522
47024
  client.log('event/updateEvent', eventId, bundle);
46523
47025
  const { data: payload } = await client.http.put(`/api/v1/events/${eventId}`, bundle);
46524
- fireEvent('event.updated', payload);
47026
+ fireEvent('local.event.updated', payload);
46525
47027
  const preparedPayload = prepareEventPayload(payload);
46526
47028
  const cachedAt = client.cache && Date.now();
46527
47029
  if (client.cache)
@@ -46553,7 +47055,7 @@ const updateEvent = async (eventId, bundle) => {
46553
47055
  const getEvent$1 = async (eventId) => {
46554
47056
  const client = getActiveClient();
46555
47057
  client.log('event/getEvent', eventId);
46556
- const { data: payload } = await client.http.get(`/api/v3/events/${eventId}`);
47058
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}`);
46557
47059
  const data = prepareEventPayload(payload);
46558
47060
  const cachedAt = client.cache && Date.now();
46559
47061
  if (client.cache)
@@ -46611,10 +47113,10 @@ const deleteEvent = async (eventId) => {
46611
47113
  const client = getActiveClient();
46612
47114
  client.log('event/deleteEvent', eventId);
46613
47115
  const event = await getEvent$1(eventId);
46614
- await client.http.delete(`/api/v3/events/${eventId}`);
47116
+ await client.http.delete(`/api/v1/events/${eventId}`);
46615
47117
  const deletedEvent = Object.assign(Object.assign({}, event.data), { isDeleted: true });
46616
47118
  upsertInCache(['event', 'get', eventId], deletedEvent);
46617
- fireEvent('event.deleted', {
47119
+ fireEvent('local.event.deleted', {
46618
47120
  users: [],
46619
47121
  files: [],
46620
47122
  communities: [],
@@ -46625,57 +47127,6 @@ const deleteEvent = async (eventId) => {
46625
47127
  };
46626
47128
  /* end_public_function */
46627
47129
 
46628
- /**
46629
- * ```js
46630
- * import { EventRepository } from '@amityco/ts-sdk'
46631
- * const dispose = EventRepository.onEventCreated(event => {
46632
- * // ...
46633
- * })
46634
- * ```
46635
- *
46636
- * Fired when a {@link Amity.Event} has been created
46637
- *
46638
- * @param callback The function to call when the event was fired
46639
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46640
- *
46641
- * @category Event Events
46642
- */
46643
- const onEventCreated = (callback) => createEventEventSubscriber('event.created', callback);
46644
-
46645
- /**
46646
- * ```js
46647
- * import { EventRepository } from '@amityco/ts-sdk'
46648
- * const dispose = EventRepository.onEventUpdated(event => {
46649
- * // ...
46650
- * })
46651
- * ```
46652
- *
46653
- * Fired when a {@link Amity.Event} has been updated
46654
- *
46655
- * @param callback The function to call when the event was fired
46656
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46657
- *
46658
- * @category Event Events
46659
- */
46660
- const onEventUpdated = (callback) => createEventEventSubscriber('event.updated', callback);
46661
-
46662
- /**
46663
- * ```js
46664
- * import { EventRepository } from '@amityco/ts-sdk'
46665
- * const dispose = EventRepository.onEventDeleted(event => {
46666
- * // ...
46667
- * })
46668
- * ```
46669
- *
46670
- * Fired when a {@link Amity.Event} has been deleted
46671
- *
46672
- * @param callback The function to call when the event was fired
46673
- * @returns an {@link Amity.Unsubscriber} function to stop listening
46674
- *
46675
- * @category Event Events
46676
- */
46677
- const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted', callback);
46678
-
46679
47130
  /* begin_public_function
46680
47131
  id: event.get
46681
47132
  */
@@ -46699,19 +47150,12 @@ const onEventDeleted = (callback) => createEventEventSubscriber('event.deleted',
46699
47150
  * @category Event Live Object
46700
47151
  */
46701
47152
  const getEvent = (eventId, callback) => {
46702
- return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventCreated, onEventUpdated, onEventDeleted], {
47153
+ return liveObject(eventId, callback, 'eventId', getEvent$1, [onEventUpdated, onEventDeleted, onLocalEventUpdated, onLocalEventDeleted], {
46703
47154
  callbackDataSelector: (data) => (data ? eventLinkedObject(data) : data),
46704
47155
  });
46705
47156
  };
46706
47157
  /* end_public_function */
46707
47158
 
46708
- var EventActionsEnum;
46709
- (function (EventActionsEnum) {
46710
- EventActionsEnum["OnEventCreated"] = "onEventCreated";
46711
- EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
46712
- EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
46713
- })(EventActionsEnum || (EventActionsEnum = {}));
46714
-
46715
47159
  class EventPaginationController extends PaginationController {
46716
47160
  async getRequest(queryParams, token) {
46717
47161
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
@@ -46769,7 +47213,7 @@ class EventQueryStreamController extends QueryStreamController {
46769
47213
  class EventLiveCollectionController extends LiveCollectionController {
46770
47214
  constructor(query, callback) {
46771
47215
  const queryStreamId = hash(query);
46772
- const cacheKey = ['event', 'collection', queryStreamId];
47216
+ const cacheKey = ['eventResponse', 'collection', queryStreamId];
46773
47217
  const paginationController = new EventPaginationController(query);
46774
47218
  super(paginationController, queryStreamId, cacheKey, callback);
46775
47219
  this.query = query;
@@ -46794,6 +47238,9 @@ class EventLiveCollectionController extends LiveCollectionController {
46794
47238
  { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
46795
47239
  { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
46796
47240
  { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
47241
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
47242
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
47243
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
46797
47244
  ]);
46798
47245
  }
46799
47246
  notifyChange({ origin, loading, error }) {
@@ -46802,10 +47249,10 @@ class EventLiveCollectionController extends LiveCollectionController {
46802
47249
  if (!collection)
46803
47250
  return;
46804
47251
  const data = ((_b = collection.data
46805
- .map(eventId => pullFromCache(['event', 'get', eventId]))
47252
+ .map(eventId => pullFromCache(['eventRSVPs', 'get', eventId]))
46806
47253
  .filter(isNonNullable)
46807
47254
  .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
46808
- if (!this.shouldNotify(data) && origin === 'event')
47255
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
46809
47256
  return;
46810
47257
  this.callback({
46811
47258
  data,
@@ -46882,6 +47329,12 @@ class MyEventQueryStreamController extends QueryStreamController {
46882
47329
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
46883
47330
  if (!collection)
46884
47331
  return;
47332
+ if (action === EventActionsEnum.OnEventCreated) {
47333
+ const client = getActiveClient();
47334
+ if (client.userId !== event.userId)
47335
+ return;
47336
+ collection.data = [...new Set([event.eventId, ...collection.data])];
47337
+ }
46885
47338
  if (action === EventActionsEnum.OnEventDeleted) {
46886
47339
  collection.data = collection.data.filter(eventId => eventId !== event.eventId);
46887
47340
  }
@@ -46922,6 +47375,9 @@ class MyEventLiveCollectionController extends LiveCollectionController {
46922
47375
  { fn: onEventCreated, action: EventActionsEnum.OnEventCreated },
46923
47376
  { fn: onEventUpdated, action: EventActionsEnum.OnEventUpdated },
46924
47377
  { fn: onEventDeleted, action: EventActionsEnum.OnEventDeleted },
47378
+ { fn: onLocalEventCreated, action: EventActionsEnum.OnEventCreated },
47379
+ { fn: onLocalEventUpdated, action: EventActionsEnum.OnEventUpdated },
47380
+ { fn: onLocalEventDeleted, action: EventActionsEnum.OnEventDeleted },
46925
47381
  ]);
46926
47382
  }
46927
47383
  notifyChange({ origin, loading, error }) {
@@ -46933,7 +47389,7 @@ class MyEventLiveCollectionController extends LiveCollectionController {
46933
47389
  .map(eventId => pullFromCache(['event', 'get', eventId]))
46934
47390
  .filter(isNonNullable)
46935
47391
  .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
46936
- if (!this.shouldNotify(data) && origin === 'event')
47392
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
46937
47393
  return;
46938
47394
  this.callback({
46939
47395
  data,
@@ -46979,9 +47435,17 @@ var index = /*#__PURE__*/Object.freeze({
46979
47435
  onEventCreated: onEventCreated,
46980
47436
  onEventUpdated: onEventUpdated,
46981
47437
  onEventDeleted: onEventDeleted,
47438
+ onLocalEventCreated: onLocalEventCreated,
47439
+ onLocalEventUpdated: onLocalEventUpdated,
47440
+ onLocalEventDeleted: onLocalEventDeleted,
47441
+ onRSVPCreated: onRSVPCreated,
47442
+ onRSVPUpdated: onRSVPUpdated,
47443
+ onLocalRSVPCreated: onLocalRSVPCreated,
47444
+ onLocalRSVPUpdated: onLocalRSVPUpdated,
46982
47445
  getEvent: getEvent,
46983
47446
  getEvents: getEvents,
46984
- getMyEvents: getMyEvents
47447
+ getMyEvents: getMyEvents,
47448
+ getRSVPs: getRSVPs
46985
47449
  });
46986
47450
 
46987
47451
  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 };