@amityco/ts-sdk 7.4.1-d23fab2f.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.
- package/dist/@types/core/events.d.ts +3 -3
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +14 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +4 -0
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/invitation.d.ts +48 -3
- package/dist/@types/domains/invitation.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getRecommendedCommunities.d.ts +3 -1
- package/dist/communityRepository/api/getRecommendedCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getTrendingCommunities.d.ts +3 -1
- package/dist/communityRepository/api/getTrendingCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/updateCommunity.d.ts +2 -2
- package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
- package/dist/index.cjs.js +1849 -1325
- package/dist/index.esm.js +2067 -1543
- package/dist/index.umd.js +4 -4
- package/dist/invitationRepository/events/index.d.ts +2 -0
- package/dist/invitationRepository/events/index.d.ts.map +1 -1
- package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts +1 -1
- package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts.map +1 -1
- package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts +1 -1
- package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts.map +1 -1
- package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts +1 -1
- package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts.map +1 -1
- package/dist/invitationRepository/index.d.ts +1 -0
- package/dist/invitationRepository/index.d.ts.map +1 -1
- package/dist/invitationRepository/internalApi/createInvitations.d.ts.map +1 -1
- package/dist/invitationRepository/internalApi/getInvitation.d.ts +17 -0
- package/dist/invitationRepository/internalApi/getInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.d.ts +14 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsPaginationController.d.ts +5 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsPaginationController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.d.ts +15 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/enums.d.ts +6 -0
- package/dist/invitationRepository/observers/getInvitations/enums.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations.d.ts +12 -0
- package/dist/invitationRepository/observers/getInvitations.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyCommunityInvitations.d.ts +12 -0
- package/dist/invitationRepository/observers/getMyCommunityInvitations.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts +14 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts +5 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts +15 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/index.d.ts +2 -0
- package/dist/invitationRepository/observers/index.d.ts.map +1 -0
- package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.d.ts +2 -0
- package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/utils/index.d.ts +2 -0
- package/dist/invitationRepository/utils/index.d.ts.map +1 -0
- package/dist/invitationRepository/utils/prepareInvitationPayload.d.ts +2 -0
- package/dist/invitationRepository/utils/prepareInvitationPayload.d.ts.map +1 -0
- package/dist/invitationRepository/utils/prepareMyInvitationsPayload.d.ts +2 -0
- package/dist/invitationRepository/utils/prepareMyInvitationsPayload.d.ts.map +1 -0
- package/dist/utils/linkedObject/communityLinkedObject.d.ts +1 -1
- package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/index.d.ts +2 -2
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts +1 -1
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +3 -3
- package/src/@types/core/payload.ts +17 -0
- package/src/@types/domains/community.ts +7 -0
- package/src/@types/domains/invitation.ts +67 -3
- package/src/communityRepository/api/getCommunities.ts +5 -1
- package/src/communityRepository/api/getCommunity.ts +1 -1
- package/src/communityRepository/api/getRecommendedCommunities.ts +9 -3
- package/src/communityRepository/api/getTrendingCommunities.ts +9 -3
- package/src/communityRepository/api/updateCommunity.ts +9 -2
- package/src/core/liveCollection/PaginationController.ts +1 -1
- package/src/core/liveCollection/PaginationNoPageController.ts +1 -1
- package/src/invitationRepository/events/index.ts +2 -0
- package/src/invitationRepository/events/onLocalInvitationCreated.ts +1 -1
- package/src/invitationRepository/events/onLocalInvitationDeleted.ts +1 -1
- package/src/invitationRepository/events/onLocalInvitationUpdated.ts +1 -1
- package/src/invitationRepository/index.ts +1 -0
- package/src/invitationRepository/internalApi/acceptInvitation.ts +1 -1
- package/src/invitationRepository/internalApi/cancelInvitation.ts +1 -1
- package/src/invitationRepository/internalApi/createInvitations.ts +8 -2
- package/src/invitationRepository/internalApi/getInvitation.ts +47 -0
- package/src/invitationRepository/internalApi/rejectInvitation.ts +1 -1
- package/src/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.ts +148 -0
- package/src/invitationRepository/observers/getInvitations/InvitationsPaginationController.ts +19 -0
- package/src/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.ts +97 -0
- package/src/invitationRepository/observers/getInvitations/enums.ts +5 -0
- package/src/invitationRepository/observers/getInvitations.ts +44 -0
- package/src/invitationRepository/observers/getMyCommunityInvitations.ts +48 -0
- package/src/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.ts +148 -0
- package/src/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.ts +22 -0
- package/src/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.ts +105 -0
- package/src/invitationRepository/observers/index.ts +1 -0
- package/src/invitationRepository/utils/convertRawInvitationToInternalInvitation.ts +8 -0
- package/src/invitationRepository/utils/index.ts +1 -0
- package/src/invitationRepository/utils/prepareInvitationPayload.ts +12 -0
- package/src/invitationRepository/utils/prepareMyInvitationsPayload.ts +12 -0
- package/src/messagePreview/utils/getChannelMessagePreviewWithUser.ts +3 -3
- package/src/utils/linkedObject/communityLinkedObject.ts +21 -1
- package/src/utils/linkedObject/invitationLinkedObject.ts +25 -1
package/src/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
|
|
2
|
+
import { PaginationController } from '~/core/liveCollection/PaginationController';
|
|
3
|
+
import { getCommunityByIds } from '~/communityRepository';
|
|
4
|
+
|
|
5
|
+
export class MyInvitationsPaginationController extends PaginationController<
|
|
6
|
+
'myInvitation',
|
|
7
|
+
Amity.MyInvitationsLiveCollection
|
|
8
|
+
> {
|
|
9
|
+
async getRequest(queryParams: Amity.MyInvitationsLiveCollection, token: string | undefined) {
|
|
10
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, ...params } = queryParams;
|
|
11
|
+
const options = token ? { token } : { limit };
|
|
12
|
+
|
|
13
|
+
const { data } = await this.http.get<Amity.MyInvitationsPayload & Amity.Pagination>(
|
|
14
|
+
'/api/v1/invitations/me',
|
|
15
|
+
{ params: { ...params, options } },
|
|
16
|
+
);
|
|
17
|
+
|
|
18
|
+
await getCommunityByIds(data.invitations.map(invitation => invitation.targetId));
|
|
19
|
+
|
|
20
|
+
return data;
|
|
21
|
+
}
|
|
22
|
+
}
|
package/src/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.ts
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
import { getResolver } from '~/core/model';
|
|
3
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
import { QueryStreamController } from '~/core/liveCollection/QueryStreamController';
|
|
6
|
+
import { InvitationActionsEnum } from '../getInvitations/enums';
|
|
7
|
+
|
|
8
|
+
export class MyInvitationsQueryStreamController extends QueryStreamController<
|
|
9
|
+
Amity.MyInvitationsPayload,
|
|
10
|
+
Amity.MyInvitationsLiveCollection
|
|
11
|
+
> {
|
|
12
|
+
private notifyChange: (params: Amity.LiveCollectionNotifyParams) => void;
|
|
13
|
+
|
|
14
|
+
private preparePayload: (
|
|
15
|
+
response: Amity.MyInvitationsPayload,
|
|
16
|
+
) => Amity.ProcessedMyInvitationsPayload;
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
query: Amity.MyInvitationsLiveCollection,
|
|
20
|
+
cacheKey: string[],
|
|
21
|
+
notifyChange: (params: Amity.LiveCollectionNotifyParams) => void,
|
|
22
|
+
preparePayload: (response: Amity.MyInvitationsPayload) => Amity.ProcessedMyInvitationsPayload,
|
|
23
|
+
) {
|
|
24
|
+
super(query, cacheKey);
|
|
25
|
+
this.notifyChange = notifyChange;
|
|
26
|
+
this.preparePayload = preparePayload;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
async saveToMainDB(response: Amity.MyInvitationsPayload) {
|
|
30
|
+
const processedPayload = await this.preparePayload(response);
|
|
31
|
+
|
|
32
|
+
const client = getActiveClient();
|
|
33
|
+
const cachedAt = client.cache && Date.now();
|
|
34
|
+
|
|
35
|
+
if (client.cache) {
|
|
36
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
appendToQueryStream(
|
|
41
|
+
response: Amity.MyInvitationsPayload & Partial<Amity.Pagination>,
|
|
42
|
+
direction: Amity.LiveCollectionPageDirection,
|
|
43
|
+
refresh = false,
|
|
44
|
+
) {
|
|
45
|
+
if (refresh) {
|
|
46
|
+
pushToCache(this.cacheKey, {
|
|
47
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
48
|
+
});
|
|
49
|
+
} else {
|
|
50
|
+
const collection = pullFromCache<Amity.MyInvitationsLiveCollectionCache>(this.cacheKey)?.data;
|
|
51
|
+
|
|
52
|
+
const invitations = collection?.data ?? [];
|
|
53
|
+
|
|
54
|
+
pushToCache(this.cacheKey, {
|
|
55
|
+
...collection,
|
|
56
|
+
data: [
|
|
57
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
58
|
+
],
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
reactor(action: InvitationActionsEnum) {
|
|
64
|
+
return (invitations: Amity.InternalInvitation[]) => {
|
|
65
|
+
const collection = pullFromCache<Amity.InvitationLiveCollectionCache>(this.cacheKey)?.data;
|
|
66
|
+
if (!collection) return;
|
|
67
|
+
|
|
68
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
69
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
70
|
+
if (!isExist) return;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
74
|
+
const client = getActiveClient();
|
|
75
|
+
|
|
76
|
+
const myInvitations = invitations.filter(
|
|
77
|
+
invitation => invitation.invitedUserId === client.userId,
|
|
78
|
+
);
|
|
79
|
+
|
|
80
|
+
collection.data = [
|
|
81
|
+
...new Set([
|
|
82
|
+
...myInvitations.map(invitation => invitation.invitationId),
|
|
83
|
+
...collection.data,
|
|
84
|
+
]),
|
|
85
|
+
];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
89
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
pushToCache(this.cacheKey, collection);
|
|
93
|
+
this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
subscribeRTE(
|
|
98
|
+
createSubscriber: {
|
|
99
|
+
fn: (reactor: Amity.Listener<Amity.InternalInvitation[]>) => Amity.Unsubscriber;
|
|
100
|
+
action: InvitationActionsEnum;
|
|
101
|
+
}[],
|
|
102
|
+
) {
|
|
103
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
104
|
+
}
|
|
105
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getMyCommunityInvitations';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './prepareInvitationPayload';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { convertRawUserToInternalUser } from '~/userRepository/utils/convertRawUserToInternalUser';
|
|
2
|
+
import { convertRawInvitationToInternalInvitation } from './convertRawInvitationToInternalInvitation';
|
|
3
|
+
|
|
4
|
+
export const prepareInvitationPayload = (
|
|
5
|
+
rawPayload: Amity.InvitationPayload,
|
|
6
|
+
): Amity.ProcessedInvitationPayload => {
|
|
7
|
+
return {
|
|
8
|
+
...rawPayload,
|
|
9
|
+
invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation),
|
|
10
|
+
users: rawPayload.users.map(convertRawUserToInternalUser),
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { convertRawUserToInternalUser } from '~/userRepository/utils/convertRawUserToInternalUser';
|
|
2
|
+
import { convertRawInvitationToInternalInvitation } from './convertRawInvitationToInternalInvitation';
|
|
3
|
+
|
|
4
|
+
export const prepareMyInvitationsPayload = (
|
|
5
|
+
rawPayload: Amity.MyInvitationsPayload,
|
|
6
|
+
): Amity.ProcessedMyInvitationsPayload => {
|
|
7
|
+
return {
|
|
8
|
+
...rawPayload,
|
|
9
|
+
users: rawPayload.users.map(convertRawUserToInternalUser),
|
|
10
|
+
invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation),
|
|
11
|
+
};
|
|
12
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { pullFromCache } from '~/cache/api';
|
|
1
|
+
import { pullFromCache } from '~/cache/api/pullFromCache';
|
|
2
2
|
import { getChannelMessagePreview } from './getChannelMessagePreview';
|
|
3
|
-
import {
|
|
3
|
+
import { userLinkedObject } from '~/utils/linkedObject/userLinkedObject';
|
|
4
4
|
|
|
5
5
|
export const getChannelMessagePreviewWithUser = (
|
|
6
6
|
channel: Amity.StaticInternalChannel,
|
|
@@ -20,7 +20,7 @@ export const getChannelMessagePreviewWithUser = (
|
|
|
20
20
|
const messagePreviewWithUser = messagePreview
|
|
21
21
|
? {
|
|
22
22
|
...messagePreview,
|
|
23
|
-
user: internalUser ?
|
|
23
|
+
user: internalUser ? userLinkedObject(internalUser) : undefined,
|
|
24
24
|
}
|
|
25
25
|
: null;
|
|
26
26
|
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { InvitationTypeEnum } from '~/@types';
|
|
2
2
|
import { createInvitations } from '~/invitationRepository/internalApi';
|
|
3
|
+
import { getInvitation } from '~/invitationRepository/internalApi/getInvitation';
|
|
4
|
+
import { getInvitations } from '~/invitationRepository/observers/getInvitations';
|
|
3
5
|
|
|
4
|
-
export const communityLinkedObject = (community: Amity.
|
|
6
|
+
export const communityLinkedObject = (community: Amity.InternalCommunity): Amity.Community => {
|
|
5
7
|
return {
|
|
6
8
|
...community,
|
|
7
9
|
createInvitations: async (userIds: string[]): Promise<void> => {
|
|
@@ -12,5 +14,23 @@ export const communityLinkedObject = (community: Amity.RawCommunity): Amity.Comm
|
|
|
12
14
|
userIds,
|
|
13
15
|
});
|
|
14
16
|
},
|
|
17
|
+
getMemberInvitations: (
|
|
18
|
+
params: Pick<Amity.InvitationLiveCollection, 'limit' | 'sortBy' | 'statuses'>,
|
|
19
|
+
callback: Amity.LiveCollectionCallback<Amity.Invitation>,
|
|
20
|
+
): Amity.Unsubscriber => {
|
|
21
|
+
return getInvitations(
|
|
22
|
+
{
|
|
23
|
+
...params,
|
|
24
|
+
targetId: community.communityId,
|
|
25
|
+
targetType: 'community',
|
|
26
|
+
type: InvitationTypeEnum.CommunityMemberInvite,
|
|
27
|
+
},
|
|
28
|
+
callback,
|
|
29
|
+
);
|
|
30
|
+
},
|
|
31
|
+
getInvitation: async () => {
|
|
32
|
+
const { data } = await getInvitation('community', community.communityId);
|
|
33
|
+
return data;
|
|
34
|
+
},
|
|
15
35
|
};
|
|
16
36
|
};
|
|
@@ -1,12 +1,36 @@
|
|
|
1
|
+
import { pullFromCache } from '~/cache/api';
|
|
2
|
+
import { userLinkedObject } from './userLinkedObject';
|
|
1
3
|
import {
|
|
2
4
|
acceptInvitation,
|
|
3
5
|
cancelInvitation,
|
|
4
6
|
rejectInvitation,
|
|
5
7
|
} from '~/invitationRepository/internalApi';
|
|
6
8
|
|
|
7
|
-
export const invitationLinkedObject = (invitation: Amity.
|
|
9
|
+
export const invitationLinkedObject = (invitation: Amity.InternalInvitation): Amity.Invitation => {
|
|
8
10
|
return {
|
|
9
11
|
...invitation,
|
|
12
|
+
get user(): Amity.User | undefined {
|
|
13
|
+
const cacheData = pullFromCache<Amity.User>(['user', 'get', invitation.invitedUserPublicId]);
|
|
14
|
+
if (cacheData?.data) return userLinkedObject(cacheData.data);
|
|
15
|
+
return undefined;
|
|
16
|
+
},
|
|
17
|
+
get createdBy(): Amity.User | undefined {
|
|
18
|
+
const cacheData = pullFromCache<Amity.User>(['user', 'get', invitation.inviterUserPublicId]);
|
|
19
|
+
if (cacheData?.data) return userLinkedObject(cacheData.data);
|
|
20
|
+
return undefined;
|
|
21
|
+
},
|
|
22
|
+
get target(): Amity.InvitationTarget<Amity.InvitationTargetType> | undefined {
|
|
23
|
+
if (invitation.targetType === 'community') {
|
|
24
|
+
const cacheData = pullFromCache<Amity.InternalCommunity>([
|
|
25
|
+
'community',
|
|
26
|
+
'get',
|
|
27
|
+
invitation.targetId,
|
|
28
|
+
]);
|
|
29
|
+
if (cacheData?.data) return cacheData.data;
|
|
30
|
+
return undefined;
|
|
31
|
+
}
|
|
32
|
+
return undefined;
|
|
33
|
+
},
|
|
10
34
|
accept: async () => {
|
|
11
35
|
await acceptInvitation(invitation._id);
|
|
12
36
|
},
|