@amityco/ts-sdk 7.11.1-084e4b1c.0 → 7.11.1-0e55a3b4.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 (43) 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/domains/event.d.ts +10 -2
  4. package/dist/@types/domains/event.d.ts.map +1 -1
  5. package/dist/@types/domains/notification.d.ts +3 -1
  6. package/dist/@types/domains/notification.d.ts.map +1 -1
  7. package/dist/core/events.d.ts +3 -3
  8. package/dist/core/events.d.ts.map +1 -1
  9. package/dist/eventRepository/events/enums.d.ts +3 -1
  10. package/dist/eventRepository/events/enums.d.ts.map +1 -1
  11. package/dist/eventRepository/events/index.d.ts +4 -0
  12. package/dist/eventRepository/events/index.d.ts.map +1 -1
  13. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts +17 -0
  14. package/dist/eventRepository/events/onLocalRSVPCreated.d.ts.map +1 -0
  15. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts +17 -0
  16. package/dist/eventRepository/events/onLocalRSVPUpdated.d.ts.map +1 -0
  17. package/dist/eventRepository/events/onRSVPCreated.d.ts +17 -0
  18. package/dist/eventRepository/events/onRSVPCreated.d.ts.map +1 -0
  19. package/dist/eventRepository/events/onRSVPUpdated.d.ts +17 -0
  20. package/dist/eventRepository/events/onRSVPUpdated.d.ts.map +1 -0
  21. package/dist/eventRepository/internalApi/createRSVP.d.ts +16 -0
  22. package/dist/eventRepository/internalApi/createRSVP.d.ts.map +1 -0
  23. package/dist/eventRepository/internalApi/getMyRSVP.d.ts +32 -0
  24. package/dist/eventRepository/internalApi/getMyRSVP.d.ts.map +1 -0
  25. package/dist/eventRepository/internalApi/index.d.ts +3 -0
  26. package/dist/eventRepository/internalApi/index.d.ts.map +1 -1
  27. package/dist/eventRepository/internalApi/updateRSVP.d.ts +17 -0
  28. package/dist/eventRepository/internalApi/updateRSVP.d.ts.map +1 -0
  29. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts +13 -0
  30. package/dist/eventRepository/observers/getRSVPs/LiveCollectionController.d.ts.map +1 -0
  31. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts +5 -0
  32. package/dist/eventRepository/observers/getRSVPs/PaginationController.d.ts.map +1 -0
  33. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts +15 -0
  34. package/dist/eventRepository/observers/getRSVPs/QueryStreamController.d.ts.map +1 -0
  35. package/dist/eventRepository/observers/getRSVPs.d.ts +12 -0
  36. package/dist/eventRepository/observers/getRSVPs.d.ts.map +1 -0
  37. package/dist/eventRepository/observers/index.d.ts +1 -0
  38. package/dist/eventRepository/observers/index.d.ts.map +1 -1
  39. package/dist/index.cjs.js +369 -26
  40. package/dist/index.esm.js +369 -26
  41. package/dist/index.umd.js +3 -3
  42. package/dist/utils/linkedObject/eventLinkObject.d.ts.map +1 -1
  43. package/package.json +1 -1
package/dist/index.cjs.js CHANGED
@@ -212,7 +212,6 @@ exports.AmityEventStatus = void 0;
212
212
  exports.AmityEventResponseStatus = void 0;
213
213
  (function (AmityEventResponseStatus) {
214
214
  AmityEventResponseStatus["Going"] = "going";
215
- AmityEventResponseStatus["Interested"] = "interested";
216
215
  AmityEventResponseStatus["NotGoing"] = "not_going";
217
216
  })(exports.AmityEventResponseStatus || (exports.AmityEventResponseStatus = {}));
218
217
 
@@ -13686,6 +13685,155 @@ const communityLinkedObject = (community) => {
13686
13685
  } });
13687
13686
  };
13688
13687
 
13688
+ const prepareEventPayload = (rawPayload) => {
13689
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
13690
+ };
13691
+
13692
+ const createEventEventSubscriber = (event, callback) => {
13693
+ const client = getActiveClient();
13694
+ const filter = (payload) => {
13695
+ const unpackedPayload = prepareEventPayload(payload);
13696
+ if (!client.cache) {
13697
+ callback(unpackedPayload.events[0]);
13698
+ }
13699
+ else {
13700
+ ingestInCache(unpackedPayload);
13701
+ const event = pullFromCache([
13702
+ 'event',
13703
+ 'get',
13704
+ unpackedPayload.events[0].eventId,
13705
+ ]);
13706
+ callback(event.data);
13707
+ }
13708
+ };
13709
+ return createEventSubscriber(client, event, event, filter);
13710
+ };
13711
+
13712
+ /* begin_public_function
13713
+ id: event.rsvp.create
13714
+ */
13715
+ /**
13716
+ * ```js
13717
+ * import { event } from '@amityco/ts-sdk'
13718
+ * const response = await event.createRSVP(eventId, status)
13719
+ * ```
13720
+ *
13721
+ * Creates an {@link Amity.InternalEvent}
13722
+ *
13723
+ * @param bundle The data necessary to create a new {@link Amity.InternalEvent}
13724
+ * @returns The newly created {@link Amity.InternalEvent}
13725
+ *
13726
+ * @category Event API
13727
+ * @async
13728
+ */
13729
+ const createRSVP = async (eventId, status) => {
13730
+ const client = getActiveClient();
13731
+ client.log('event/createRSVP', eventId, status);
13732
+ const { data: payload } = await client.http.post(`/api/v1/events/${eventId}/rsvp`, { status });
13733
+ fireEvent('local.rsvp.created', payload);
13734
+ const preparedPayload = prepareEventPayload(payload);
13735
+ const cachedAt = client.cache && Date.now();
13736
+ if (client.cache)
13737
+ ingestInCache(preparedPayload, { cachedAt });
13738
+ return {
13739
+ data: preparedPayload.events[0],
13740
+ cachedAt,
13741
+ };
13742
+ };
13743
+ /* end_public_function */
13744
+
13745
+ /* begin_public_function
13746
+ id: event.update
13747
+ */
13748
+ /**
13749
+ * ```js
13750
+ * import { event } from '@amityco/ts-sdk'
13751
+ * const response = await event.updateRSVP(eventId, status)
13752
+ * ```
13753
+ *
13754
+ * Updates an {@link Amity.InternalEvent}
13755
+ *
13756
+ * @param eventId The ID of the {@link Amity.InternalEvent} to edit
13757
+ * @param bundle The data necessary to update an existing {@link Amity.InternalEvent}
13758
+ * @returns the updated {@link Amity.InternalEvent}
13759
+ *
13760
+ * @category Event API
13761
+ * @async
13762
+ */
13763
+ const updateRSVP = async (eventId, status) => {
13764
+ const client = getActiveClient();
13765
+ client.log('event/updateRSVP', eventId, status);
13766
+ const { data: payload } = await client.http.put(`/api/v1/events/${eventId}/rsvp`, { status });
13767
+ fireEvent('local.rsvp.updated', payload);
13768
+ const preparedPayload = prepareEventPayload(payload);
13769
+ const cachedAt = client.cache && Date.now();
13770
+ if (client.cache)
13771
+ ingestInCache(preparedPayload, { cachedAt });
13772
+ return {
13773
+ data: preparedPayload.events.find(event => event.eventId === eventId),
13774
+ cachedAt,
13775
+ };
13776
+ };
13777
+ /* end_public_function */
13778
+
13779
+ /* begin_public_function
13780
+ id: event.rsvp.me
13781
+ */
13782
+ /**
13783
+ * ```js
13784
+ * import { event } from '@amityco/ts-sdk'
13785
+ * const myRSVP = await event.getMyRSVP(eventId)
13786
+ * ```
13787
+ *
13788
+ * Joins a {@link Amity.InternalEvent} object
13789
+ *
13790
+ * @param eventId the {@link Amity.InternalEvent} to get RSVP for
13791
+ * @returns A success boolean if the {@link Amity.InternalEvent} RSVP was retrieved
13792
+ *
13793
+ * @category Event API
13794
+ * @async
13795
+ */
13796
+ const getMyRSVP = async (eventId) => {
13797
+ const client = getActiveClient();
13798
+ client.log('event/getMyRSVP', eventId);
13799
+ const { data: payload } = await client.http.get(`/api/v1/events/${eventId}/me/rsvp`);
13800
+ const data = prepareEventPayload(payload);
13801
+ const cachedAt = client.cache && Date.now();
13802
+ if (client.cache)
13803
+ ingestInCache(data, { cachedAt });
13804
+ return {
13805
+ data: data.events.find(event => event.eventId === eventId),
13806
+ cachedAt,
13807
+ };
13808
+ };
13809
+ /* end_public_function */
13810
+ /**
13811
+ * ```js
13812
+ * import { event } from '@amityco/ts-sdk'
13813
+ * const event = event.getMyRSVP.locally(eventId)
13814
+ * ```
13815
+ *
13816
+ * Fetches a {@link Amity.InternalEvent} object in cache
13817
+ *
13818
+ * @param eventId the ID of the {@link Amity.InternalEvent} to fetch
13819
+ * @returns the associated {@link Amity.InternalEvent} object
13820
+ *
13821
+ * @category Event API
13822
+ */
13823
+ getMyRSVP.locally = (eventId) => {
13824
+ const client = getActiveClient();
13825
+ client.log('event/getMyRSVP.locally', eventId);
13826
+ if (!client.cache)
13827
+ return;
13828
+ const cache = pullFromCache(['event', 'getMyRSVP', eventId]);
13829
+ if (!cache)
13830
+ return;
13831
+ return {
13832
+ data: cache.data,
13833
+ cachedAt: cache.cachedAt,
13834
+ };
13835
+ };
13836
+
13689
13837
  const eventLinkedObject = (event) => {
13690
13838
  return Object.assign(Object.assign({}, event), { get creator() {
13691
13839
  const cacheData = pullFromCache(['user', 'get', event.userId]);
@@ -13728,6 +13876,15 @@ const eventLinkedObject = (event) => {
13728
13876
  if (!(cacheData === null || cacheData === void 0 ? void 0 : cacheData.data))
13729
13877
  return;
13730
13878
  return cacheData.data;
13879
+ }, createRSVP: async (status) => {
13880
+ const { data } = await createRSVP(event.eventId, status);
13881
+ return data;
13882
+ }, updateRSVP: async (status) => {
13883
+ const { data } = await updateRSVP(event.eventId, status);
13884
+ return data;
13885
+ }, getMyRSVP: async () => {
13886
+ const { data } = await getMyRSVP(event.eventId);
13887
+ return data;
13731
13888
  } });
13732
13889
  };
13733
13890
 
@@ -30367,30 +30524,6 @@ var index$1 = /*#__PURE__*/Object.freeze({
30367
30524
  getReactions: getReactions
30368
30525
  });
30369
30526
 
30370
- const prepareEventPayload = (rawPayload) => {
30371
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser) });
30372
- };
30373
-
30374
- const createEventEventSubscriber = (event, callback) => {
30375
- const client = getActiveClient();
30376
- const filter = (payload) => {
30377
- const unpackedPayload = prepareEventPayload(payload);
30378
- if (!client.cache) {
30379
- callback(unpackedPayload.events[0]);
30380
- }
30381
- else {
30382
- ingestInCache(unpackedPayload);
30383
- const event = pullFromCache([
30384
- 'event',
30385
- 'get',
30386
- unpackedPayload.events[0].eventId,
30387
- ]);
30388
- callback(event.data);
30389
- }
30390
- };
30391
- return createEventSubscriber(client, event, event, filter);
30392
- };
30393
-
30394
30527
  /* begin_public_function
30395
30528
  id: event.create
30396
30529
  */
@@ -30652,6 +30785,74 @@ const onLocalEventUpdated = (callback) => createEventEventSubscriber('local.even
30652
30785
  */
30653
30786
  const onLocalEventDeleted = (callback) => createEventEventSubscriber('local.event.deleted', callback);
30654
30787
 
30788
+ /**
30789
+ * ```js
30790
+ * import { EventRepository } from '@amityco/ts-sdk'
30791
+ * const dispose = EventRepository.onRSVPCreated(event => {
30792
+ * // ...
30793
+ * })
30794
+ * ```
30795
+ *
30796
+ * Fired when a {@link Amity.Event} has been created
30797
+ *
30798
+ * @param callback The function to call when the event was fired
30799
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30800
+ *
30801
+ * @category Event Events
30802
+ */
30803
+ const onRSVPCreated = (callback) => createEventEventSubscriber('event.rsvp.created', callback);
30804
+
30805
+ /**
30806
+ * ```js
30807
+ * import { EventRepository } from '@amityco/ts-sdk'
30808
+ * const dispose = EventRepository.onRSVPUpdated(event => {
30809
+ * // ...
30810
+ * })
30811
+ * ```
30812
+ *
30813
+ * Fired when a {@link Amity.Event} has been updated
30814
+ *
30815
+ * @param callback The function to call when the event was fired
30816
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30817
+ *
30818
+ * @category Event Events
30819
+ */
30820
+ const onRSVPUpdated = (callback) => createEventEventSubscriber('event.rsvp.updated', callback);
30821
+
30822
+ /**
30823
+ * ```js
30824
+ * import { EventRepository } from '@amityco/ts-sdk'
30825
+ * const dispose = EventRepository.onLocalRSVPCreated(event => {
30826
+ * // ...
30827
+ * })
30828
+ * ```
30829
+ *
30830
+ * Fired when a {@link Amity.Event} has been created
30831
+ *
30832
+ * @param callback The function to call when the event was fired
30833
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30834
+ *
30835
+ * @category Event Events
30836
+ */
30837
+ const onLocalRSVPCreated = (callback) => createEventEventSubscriber('local.rsvp.created', callback);
30838
+
30839
+ /**
30840
+ * ```js
30841
+ * import { EventRepository } from '@amityco/ts-sdk'
30842
+ * const dispose = EventRepository.onLocalEventUpdated(event => {
30843
+ * // ...
30844
+ * })
30845
+ * ```
30846
+ *
30847
+ * Fired when a {@link Amity.Event} has been updated
30848
+ *
30849
+ * @param callback The function to call when the event was fired
30850
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
30851
+ *
30852
+ * @category Event Events
30853
+ */
30854
+ const onLocalRSVPUpdated = (callback) => createEventEventSubscriber('local.rsvp.updated', callback);
30855
+
30655
30856
  /* begin_public_function
30656
30857
  id: event.get
30657
30858
  */
@@ -30686,6 +30887,8 @@ var EventActionsEnum;
30686
30887
  EventActionsEnum["OnEventCreated"] = "onEventCreated";
30687
30888
  EventActionsEnum["OnEventUpdated"] = "onEventUpdated";
30688
30889
  EventActionsEnum["OnEventDeleted"] = "onEventDeleted";
30890
+ EventActionsEnum["OnRSVPCreated"] = "onRSVPCreated";
30891
+ EventActionsEnum["OnRSVPUpdated"] = "onRSVPUpdated";
30689
30892
  })(EventActionsEnum || (EventActionsEnum = {}));
30690
30893
 
30691
30894
  class EventPaginationController extends PaginationController {
@@ -30959,6 +31162,141 @@ const getMyEvents = (params, callback, config) => {
30959
31162
  };
30960
31163
  };
30961
31164
 
31165
+ class RSVPPaginationController extends PaginationController {
31166
+ async getRequest(queryParams, token) {
31167
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, eventId } = queryParams, params = __rest(queryParams, ["limit", "eventId"]);
31168
+ const options = token ? { token } : { limit };
31169
+ const { data: response } = await this.http.get(`/api/v1/events/${eventId}/rsvps`, { params: Object.assign(Object.assign({}, params), { options }) });
31170
+ return response;
31171
+ }
31172
+ }
31173
+
31174
+ class RSVPQueryStreamController extends QueryStreamController {
31175
+ constructor(query, cacheKey, notifyChange, preparePayload) {
31176
+ super(query, cacheKey);
31177
+ this.notifyChange = notifyChange;
31178
+ this.preparePayload = preparePayload;
31179
+ }
31180
+ async saveToMainDB(response) {
31181
+ const processedPayload = this.preparePayload(response);
31182
+ const client = getActiveClient();
31183
+ const cachedAt = client.cache && Date.now();
31184
+ if (client.cache)
31185
+ ingestInCache(processedPayload, { cachedAt });
31186
+ }
31187
+ appendToQueryStream(response, direction, refresh = false) {
31188
+ var _a, _b;
31189
+ if (refresh) {
31190
+ pushToCache(this.cacheKey, { data: response.events.map(getResolver('event')) });
31191
+ }
31192
+ else {
31193
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31194
+ const events = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
31195
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...events, ...response.events.map(getResolver('event'))])] }));
31196
+ }
31197
+ }
31198
+ reactor(action) {
31199
+ return (event) => {
31200
+ var _a;
31201
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31202
+ if (!collection)
31203
+ return;
31204
+ if (action === EventActionsEnum.OnEventCreated) {
31205
+ const client = getActiveClient();
31206
+ if (client.userId !== event.userId)
31207
+ return;
31208
+ collection.data = [...new Set([event.eventId, ...collection.data])];
31209
+ }
31210
+ if (action === EventActionsEnum.OnEventDeleted) {
31211
+ collection.data = collection.data.filter(eventId => eventId !== event.eventId);
31212
+ }
31213
+ pushToCache(this.cacheKey, collection);
31214
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
31215
+ };
31216
+ }
31217
+ subscribeRTE(createSubscriber) {
31218
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
31219
+ }
31220
+ }
31221
+
31222
+ class RSVPLiveCollectionController extends LiveCollectionController {
31223
+ constructor(query, callback) {
31224
+ const queryStreamId = hash__default["default"](query);
31225
+ const cacheKey = ['event', 'collection', queryStreamId];
31226
+ const paginationController = new RSVPPaginationController(query);
31227
+ super(paginationController, queryStreamId, cacheKey, callback);
31228
+ this.query = query;
31229
+ this.queryStreamController = new RSVPQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareEventPayload);
31230
+ this.callback = callback.bind(this);
31231
+ this.loadPage({ initial: true });
31232
+ }
31233
+ setup() {
31234
+ var _a;
31235
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31236
+ if (!collection)
31237
+ pushToCache(this.cacheKey, { data: [], params: {} });
31238
+ }
31239
+ async persistModel(queryPayload) {
31240
+ await this.queryStreamController.saveToMainDB(queryPayload);
31241
+ }
31242
+ persistQueryStream({ response, direction, refresh, }) {
31243
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
31244
+ }
31245
+ startSubscription() {
31246
+ return this.queryStreamController.subscribeRTE([
31247
+ { fn: onRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
31248
+ { fn: onRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
31249
+ { fn: onLocalRSVPCreated, action: EventActionsEnum.OnRSVPCreated },
31250
+ { fn: onLocalRSVPUpdated, action: EventActionsEnum.OnRSVPUpdated },
31251
+ ]);
31252
+ }
31253
+ notifyChange({ origin, loading, error }) {
31254
+ var _a, _b;
31255
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
31256
+ if (!collection)
31257
+ return;
31258
+ const data = ((_b = collection.data
31259
+ .map(eventId => pullFromCache(['event', 'get', eventId]))
31260
+ .filter(isNonNullable)
31261
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.event);
31262
+ if (!this.shouldNotify(data) && origin === "event" /* Amity.LiveDataOrigin.EVENT */)
31263
+ return;
31264
+ this.callback({
31265
+ data,
31266
+ error,
31267
+ loading,
31268
+ hasNextPage: !!this.paginationController.getNextToken(),
31269
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
31270
+ });
31271
+ }
31272
+ }
31273
+
31274
+ /**
31275
+ * Get events
31276
+ *
31277
+ * @param params the query parameters
31278
+ * @param callback the callback to be called when the events are updated
31279
+ * @returns events
31280
+ *
31281
+ * @category RSVP Live Collection
31282
+ *
31283
+ */
31284
+ const getRSVPs = (params, callback, config) => {
31285
+ const { log, cache } = getActiveClient();
31286
+ if (!cache)
31287
+ console.log(ENABLE_CACHE_MESSAGE);
31288
+ const timestamp = Date.now();
31289
+ log(`getRSVPs: (tmpid: ${timestamp}) > listen`);
31290
+ const eventLiveCollection = new RSVPLiveCollectionController(params, callback);
31291
+ const disposers = eventLiveCollection.startSubscription();
31292
+ const cacheKey = eventLiveCollection.getCacheKey();
31293
+ disposers.push(() => dropFromCache(cacheKey));
31294
+ return () => {
31295
+ log(`getRSVPs (tmpid: ${timestamp}) > dispose`);
31296
+ disposers.forEach(fn => fn());
31297
+ };
31298
+ };
31299
+
30962
31300
  var index = /*#__PURE__*/Object.freeze({
30963
31301
  __proto__: null,
30964
31302
  createEvent: createEvent,
@@ -30970,9 +31308,14 @@ var index = /*#__PURE__*/Object.freeze({
30970
31308
  onLocalEventCreated: onLocalEventCreated,
30971
31309
  onLocalEventUpdated: onLocalEventUpdated,
30972
31310
  onLocalEventDeleted: onLocalEventDeleted,
31311
+ onRSVPCreated: onRSVPCreated,
31312
+ onRSVPUpdated: onRSVPUpdated,
31313
+ onLocalRSVPCreated: onLocalRSVPCreated,
31314
+ onLocalRSVPUpdated: onLocalRSVPUpdated,
30973
31315
  getEvent: getEvent,
30974
31316
  getEvents: getEvents,
30975
- getMyEvents: getMyEvents
31317
+ getMyEvents: getMyEvents,
31318
+ getRSVPs: getRSVPs
30976
31319
  });
30977
31320
 
30978
31321
  exports.API_REGIONS = API_REGIONS;