@amityco/ts-sdk 7.4.1-c116567e.0 → 7.4.1-e8631ca7.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 (48) hide show
  1. package/dist/@types/core/payload.d.ts +11 -0
  2. package/dist/@types/core/payload.d.ts.map +1 -1
  3. package/dist/@types/domains/community.d.ts +2 -1
  4. package/dist/@types/domains/community.d.ts.map +1 -1
  5. package/dist/@types/domains/invitation.d.ts +18 -2
  6. package/dist/@types/domains/invitation.d.ts.map +1 -1
  7. package/dist/index.cjs.js +252 -21
  8. package/dist/index.esm.js +252 -21
  9. package/dist/index.umd.js +4 -4
  10. package/dist/invitationRepository/index.d.ts +1 -0
  11. package/dist/invitationRepository/index.d.ts.map +1 -1
  12. package/dist/invitationRepository/internalApi/getInvitation.d.ts +17 -0
  13. package/dist/invitationRepository/internalApi/getInvitation.d.ts.map +1 -0
  14. package/dist/invitationRepository/observers/getMyCommunityInvitations.d.ts +12 -0
  15. package/dist/invitationRepository/observers/getMyCommunityInvitations.d.ts.map +1 -0
  16. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts +14 -0
  17. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts.map +1 -0
  18. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts +5 -0
  19. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts.map +1 -0
  20. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts +15 -0
  21. package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts.map +1 -0
  22. package/dist/invitationRepository/observers/index.d.ts +2 -0
  23. package/dist/invitationRepository/observers/index.d.ts.map +1 -0
  24. package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.d.ts +2 -0
  25. package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.d.ts.map +1 -0
  26. package/dist/invitationRepository/utils/prepareInvitationPayload.d.ts.map +1 -1
  27. package/dist/invitationRepository/utils/prepareMyInvitationsPayload.d.ts +2 -0
  28. package/dist/invitationRepository/utils/prepareMyInvitationsPayload.d.ts.map +1 -0
  29. package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
  30. package/package.json +1 -1
  31. package/src/@types/core/payload.ts +13 -0
  32. package/src/@types/domains/community.ts +2 -0
  33. package/src/@types/domains/invitation.ts +26 -2
  34. package/src/communityRepository/api/getCommunity.ts +1 -1
  35. package/src/invitationRepository/index.ts +1 -0
  36. package/src/invitationRepository/internalApi/getInvitation.ts +47 -0
  37. package/src/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.ts +1 -1
  38. package/src/invitationRepository/observers/getInvitations/InvitationsPaginationController.ts +1 -1
  39. package/src/invitationRepository/observers/getMyCommunityInvitations.ts +48 -0
  40. package/src/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.ts +148 -0
  41. package/src/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.ts +22 -0
  42. package/src/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.ts +105 -0
  43. package/src/invitationRepository/observers/index.ts +1 -0
  44. package/src/invitationRepository/utils/convertRawInvitationToInternalInvitation.ts +8 -0
  45. package/src/invitationRepository/utils/prepareInvitationPayload.ts +6 -5
  46. package/src/invitationRepository/utils/prepareMyInvitationsPayload.ts +12 -0
  47. package/src/utils/linkedObject/communityLinkedObject.ts +7 -0
  48. package/src/utils/linkedObject/invitationLinkedObject.ts +5 -5
package/dist/index.esm.js CHANGED
@@ -23446,10 +23446,12 @@ const notificationTrayLinkedObject = (noti) => {
23446
23446
  .map(user => userLinkedObject(user)) });
23447
23447
  };
23448
23448
 
23449
+ const convertRawInvitationToInternalInvitation = (rawInvitation) => {
23450
+ return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
23451
+ };
23452
+
23449
23453
  const prepareInvitationPayload = (rawPayload) => {
23450
- return {
23451
- invitations: rawPayload.invitations.map(invitation => (Object.assign(Object.assign({}, invitation), { invitationId: invitation._id, createdById: invitation.createdBy }))),
23452
- };
23454
+ return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
23453
23455
  };
23454
23456
 
23455
23457
  /* begin_public_function
@@ -23595,22 +23597,19 @@ const cancelInvitation = async (invitationId) => {
23595
23597
  };
23596
23598
  /* end_public_function */
23597
23599
 
23598
- var InvitationActionsEnum;
23599
- (function (InvitationActionsEnum) {
23600
- InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
23601
- InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
23602
- InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
23603
- })(InvitationActionsEnum || (InvitationActionsEnum = {}));
23600
+ const prepareMyInvitationsPayload = (rawPayload) => {
23601
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
23602
+ };
23604
23603
 
23605
23604
  const invitationLinkedObject = (invitation) => {
23606
23605
  return Object.assign(Object.assign({}, invitation), { get user() {
23607
- const cacheData = pullFromCache(['user', 'get', invitation.userId]);
23606
+ const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
23608
23607
  if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
23609
23608
  return userLinkedObject(cacheData.data);
23610
23609
  return undefined;
23611
23610
  },
23612
23611
  get createdBy() {
23613
- const cacheData = pullFromCache(['user', 'get', invitation.createdById]);
23612
+ const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
23614
23613
  if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
23615
23614
  return userLinkedObject(cacheData.data);
23616
23615
  return undefined;
@@ -23636,6 +23635,46 @@ const invitationLinkedObject = (invitation) => {
23636
23635
  } });
23637
23636
  };
23638
23637
 
23638
+ /* begin_public_function
23639
+ id: invitation.get
23640
+ */
23641
+ /**
23642
+ * ```js
23643
+ * import { getInvitation } from '@amityco/ts-sdk'
23644
+ * const { invitation } = await getInvitation(targetType, targetId)
23645
+ * ```
23646
+ *
23647
+ * Get a {@link Amity.Invitation} object
23648
+ *
23649
+ * @param targetType The type of the target of the {@link Amity.Invitation}
23650
+ * @param targetId The ID of the target of the {@link Amity.Invitation}
23651
+ * @returns A {@link Amity.Invitation} object
23652
+ *
23653
+ * @category Invitation API
23654
+ * @async
23655
+ */
23656
+ const getInvitation = async (targetType, targetId) => {
23657
+ const client = getActiveClient();
23658
+ client.log('invitation/getInvitation', targetType, targetId);
23659
+ const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params: { targetType, targetId } });
23660
+ const data = prepareMyInvitationsPayload(payload);
23661
+ const cachedAt = client.cache && Date.now();
23662
+ if (client.cache)
23663
+ ingestInCache(data, { cachedAt });
23664
+ return {
23665
+ data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
23666
+ cachedAt,
23667
+ };
23668
+ };
23669
+ /* end_public_function */
23670
+
23671
+ var InvitationActionsEnum;
23672
+ (function (InvitationActionsEnum) {
23673
+ InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
23674
+ InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
23675
+ InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
23676
+ })(InvitationActionsEnum || (InvitationActionsEnum = {}));
23677
+
23639
23678
  class PaginationController {
23640
23679
  constructor(queryParams) {
23641
23680
  const { http } = getActiveClient();
@@ -23685,7 +23724,7 @@ class InvitationsPaginationController extends PaginationController {
23685
23724
  async getRequest(queryParams, token) {
23686
23725
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
23687
23726
  const options = token ? { token } : { limit };
23688
- const { data } = await this.http.get(`/api/v1/invitations`, { params: Object.assign(Object.assign({}, params), { options }) });
23727
+ const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
23689
23728
  return data;
23690
23729
  }
23691
23730
  }
@@ -23984,7 +24023,7 @@ class InvitationsLiveCollectionController extends LiveCollectionController {
23984
24023
  if (!collection) {
23985
24024
  pushToCache(this.cacheKey, {
23986
24025
  data: [],
23987
- params: {},
24026
+ params: this.query,
23988
24027
  });
23989
24028
  }
23990
24029
  }
@@ -24095,12 +24134,11 @@ const communityLinkedObject = (community) => {
24095
24134
  targetId: community.communityId,
24096
24135
  userIds,
24097
24136
  });
24098
- }, getMemberInvitations: (callback) => {
24099
- return getInvitations({
24100
- targetId: community.communityId,
24101
- targetType: 'community',
24102
- type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */,
24103
- }, callback);
24137
+ }, getMemberInvitations: (params, callback) => {
24138
+ return getInvitations(Object.assign(Object.assign({}, params), { targetId: community.communityId, targetType: 'community', type: "communityMemberInvite" /* InvitationTypeEnum.CommunityMemberInvite */ }), callback);
24139
+ }, getInvitation: async () => {
24140
+ const { data } = await getInvitation('community', community.communityId);
24141
+ return data;
24104
24142
  } });
24105
24143
  };
24106
24144
 
@@ -35311,7 +35349,7 @@ getCommunity$1.locally = (communityId) => {
35311
35349
  if (!cached)
35312
35350
  return;
35313
35351
  return {
35314
- data: cached.data,
35352
+ data: LinkedObject.community(cached.data),
35315
35353
  cachedAt: cached.cachedAt,
35316
35354
  };
35317
35355
  };
@@ -43036,11 +43074,204 @@ var index$1 = /*#__PURE__*/Object.freeze({
43036
43074
  onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
43037
43075
  });
43038
43076
 
43077
+ class MyInvitationsPaginationController extends PaginationController {
43078
+ async getRequest(queryParams, token) {
43079
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
43080
+ const options = token ? { token } : { limit };
43081
+ const { data } = await this.http.get('/api/v1/invitations/me', { params: Object.assign(Object.assign({}, params), { options }) });
43082
+ await getCommunities$1(data.invitations.map(invitation => invitation.targetId));
43083
+ return data;
43084
+ }
43085
+ }
43086
+
43087
+ class MyInvitationsQueryStreamController extends QueryStreamController {
43088
+ constructor(query, cacheKey, notifyChange, preparePayload) {
43089
+ super(query, cacheKey);
43090
+ this.notifyChange = notifyChange;
43091
+ this.preparePayload = preparePayload;
43092
+ }
43093
+ async saveToMainDB(response) {
43094
+ const processedPayload = await this.preparePayload(response);
43095
+ const client = getActiveClient();
43096
+ const cachedAt = client.cache && Date.now();
43097
+ if (client.cache) {
43098
+ ingestInCache(processedPayload, { cachedAt });
43099
+ }
43100
+ }
43101
+ appendToQueryStream(response, direction, refresh = false) {
43102
+ var _a, _b;
43103
+ if (refresh) {
43104
+ pushToCache(this.cacheKey, {
43105
+ data: response.invitations.map(getResolver('invitation')),
43106
+ });
43107
+ }
43108
+ else {
43109
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
43110
+ const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
43111
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
43112
+ ...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
43113
+ ] }));
43114
+ }
43115
+ }
43116
+ reactor(action) {
43117
+ return (invitations) => {
43118
+ var _a;
43119
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
43120
+ if (!collection)
43121
+ return;
43122
+ if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
43123
+ const isExist = collection.data.find(id => id === invitations[0].invitationId);
43124
+ if (!isExist)
43125
+ return;
43126
+ }
43127
+ if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
43128
+ const client = getActiveClient();
43129
+ const myInvitations = invitations.filter(invitation => invitation.invitedUserId === client.userId);
43130
+ collection.data = [
43131
+ ...new Set([
43132
+ ...myInvitations.map(invitation => invitation.invitationId),
43133
+ ...collection.data,
43134
+ ]),
43135
+ ];
43136
+ }
43137
+ if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
43138
+ collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
43139
+ }
43140
+ pushToCache(this.cacheKey, collection);
43141
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
43142
+ };
43143
+ }
43144
+ subscribeRTE(createSubscriber) {
43145
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
43146
+ }
43147
+ }
43148
+
43149
+ class MyInvitationsLiveCollectionController extends LiveCollectionController {
43150
+ constructor(query, callback) {
43151
+ const queryStreamId = hash(query);
43152
+ const cacheKey = ['invitation', 'collection', queryStreamId];
43153
+ const paginationController = new MyInvitationsPaginationController(query);
43154
+ super(paginationController, queryStreamId, cacheKey, callback);
43155
+ this.query = query;
43156
+ this.queryStreamController = new MyInvitationsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareMyInvitationsPayload);
43157
+ this.callback = callback.bind(this);
43158
+ this.loadPage({ initial: true });
43159
+ }
43160
+ setup() {
43161
+ var _a;
43162
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
43163
+ if (!collection) {
43164
+ pushToCache(this.cacheKey, {
43165
+ data: [],
43166
+ params: this.query,
43167
+ });
43168
+ }
43169
+ }
43170
+ async persistModel(queryPayload) {
43171
+ await this.queryStreamController.saveToMainDB(queryPayload);
43172
+ }
43173
+ persistQueryStream({ response, direction, refresh, }) {
43174
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
43175
+ }
43176
+ startSubscription() {
43177
+ return this.queryStreamController.subscribeRTE([
43178
+ {
43179
+ fn: onLocalInvitationCreated,
43180
+ action: InvitationActionsEnum.OnLocalInvitationCreated,
43181
+ },
43182
+ {
43183
+ fn: onLocalInvitationUpdated,
43184
+ action: InvitationActionsEnum.OnLocalInvitationUpdated,
43185
+ },
43186
+ {
43187
+ fn: onLocalInvitationDeleted,
43188
+ action: InvitationActionsEnum.OnLocalInvitationDeleted,
43189
+ },
43190
+ ]);
43191
+ }
43192
+ notifyChange({ origin, loading, error }) {
43193
+ var _a, _b;
43194
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
43195
+ if (!collection)
43196
+ return;
43197
+ const data = this.applyFilter((_b = collection.data
43198
+ .map(id => pullFromCache(['invitation', 'get', id]))
43199
+ .filter(isNonNullable)
43200
+ .map(({ data }) => invitationLinkedObject(data))) !== null && _b !== void 0 ? _b : []);
43201
+ if (!this.shouldNotify(data) && origin === 'event')
43202
+ return;
43203
+ this.callback({
43204
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
43205
+ data,
43206
+ hasNextPage: !!this.paginationController.getNextToken(),
43207
+ loading,
43208
+ error,
43209
+ });
43210
+ }
43211
+ applyFilter(data) {
43212
+ let invitations = data;
43213
+ if (this.query.targetId) {
43214
+ invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
43215
+ }
43216
+ if (this.query.statuses) {
43217
+ invitations = invitations.filter(invitation => { var _a; return (_a = this.query.statuses) === null || _a === void 0 ? void 0 : _a.includes(invitation.status); });
43218
+ }
43219
+ if (this.query.targetType) {
43220
+ invitations = invitations.filter(invitation => invitation.targetType === this.query.targetType);
43221
+ }
43222
+ if (this.query.type) {
43223
+ invitations = invitations.filter(invitation => invitation.type === this.query.type);
43224
+ }
43225
+ const sortFn = (() => {
43226
+ switch (this.query.sortBy) {
43227
+ case 'firstCreated':
43228
+ return sortByFirstCreated;
43229
+ case 'lastCreated':
43230
+ return sortByLastCreated;
43231
+ default:
43232
+ return sortByLastCreated;
43233
+ }
43234
+ })();
43235
+ invitations = invitations.sort(sortFn);
43236
+ return invitations;
43237
+ }
43238
+ }
43239
+
43240
+ /**
43241
+ * Get my community invitations
43242
+ *
43243
+ * @param params the query parameters
43244
+ * @param callback the callback to be called when the invitations are fetched
43245
+ * @returns invitations
43246
+ *
43247
+ * @category My Community Invitations Live Collection
43248
+ *
43249
+ */
43250
+ const getMyCommunityInvitations = (params, callback, config) => {
43251
+ const { log, cache } = getActiveClient();
43252
+ if (!cache) {
43253
+ console.log(ENABLE_CACHE_MESSAGE);
43254
+ }
43255
+ const timestamp = Date.now();
43256
+ log(`getMyCommunityInvitations: (tmpid: ${timestamp}) > listen`);
43257
+ const invitationsLiveCollection = new MyInvitationsLiveCollectionController(Object.assign(Object.assign({}, params), { targetType: 'community', statuses: ["pending" /* InvitationStatusEnum.Pending */] }), callback);
43258
+ const disposers = invitationsLiveCollection.startSubscription();
43259
+ const cacheKey = invitationsLiveCollection.getCacheKey();
43260
+ disposers.push(() => {
43261
+ dropFromCache(cacheKey);
43262
+ });
43263
+ return () => {
43264
+ log(`getInvitations (tmpid: ${timestamp}) > dispose`);
43265
+ disposers.forEach(fn => fn());
43266
+ };
43267
+ };
43268
+
43039
43269
  var index = /*#__PURE__*/Object.freeze({
43040
43270
  __proto__: null,
43041
43271
  onLocalInvitationCreated: onLocalInvitationCreated,
43042
43272
  onLocalInvitationUpdated: onLocalInvitationUpdated,
43043
- onLocalInvitationDeleted: onLocalInvitationDeleted
43273
+ onLocalInvitationDeleted: onLocalInvitationDeleted,
43274
+ getMyCommunityInvitations: getMyCommunityInvitations
43044
43275
  });
43045
43276
 
43046
43277
  export { API_REGIONS, index$2 as AdRepository, index$a as CategoryRepository, index$e as ChannelRepository, index$n as Client, index$8 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$b as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$9 as FeedRepository, FileAccessTypeEnum, index$k as FileRepository, FileType, index as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, index$4 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$i as MessageRepository, index$5 as PollRepository, PostContentType, index$7 as PostRepository, index$j as ReactionRepository, index$3 as StoryRepository, index$6 as StreamRepository, index$h as SubChannelRepository, SubscriptionLevels, index$l as UserRepository, 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, 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$1 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 };