@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.
- package/dist/@types/core/payload.d.ts +11 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +2 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/invitation.d.ts +18 -2
- package/dist/@types/domains/invitation.d.ts.map +1 -1
- package/dist/index.cjs.js +252 -21
- package/dist/index.esm.js +252 -21
- package/dist/index.umd.js +4 -4
- package/dist/invitationRepository/index.d.ts +1 -0
- package/dist/invitationRepository/index.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/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/prepareInvitationPayload.d.ts.map +1 -1
- 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.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/payload.ts +13 -0
- package/src/@types/domains/community.ts +2 -0
- package/src/@types/domains/invitation.ts +26 -2
- package/src/communityRepository/api/getCommunity.ts +1 -1
- package/src/invitationRepository/index.ts +1 -0
- package/src/invitationRepository/internalApi/getInvitation.ts +47 -0
- package/src/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.ts +1 -1
- package/src/invitationRepository/observers/getInvitations/InvitationsPaginationController.ts +1 -1
- 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/prepareInvitationPayload.ts +6 -5
- package/src/invitationRepository/utils/prepareMyInvitationsPayload.ts +12 -0
- package/src/utils/linkedObject/communityLinkedObject.ts +7 -0
- package/src/utils/linkedObject/invitationLinkedObject.ts +5 -5
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/invitationRepository/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/invitationRepository/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ```js
|
|
3
|
+
* import { getInvitation } from '@amityco/ts-sdk'
|
|
4
|
+
* const { invitation } = await getInvitation(targetType, targetId)
|
|
5
|
+
* ```
|
|
6
|
+
*
|
|
7
|
+
* Get a {@link Amity.Invitation} object
|
|
8
|
+
*
|
|
9
|
+
* @param targetType The type of the target of the {@link Amity.Invitation}
|
|
10
|
+
* @param targetId The ID of the target of the {@link Amity.Invitation}
|
|
11
|
+
* @returns A {@link Amity.Invitation} object
|
|
12
|
+
*
|
|
13
|
+
* @category Invitation API
|
|
14
|
+
* @async
|
|
15
|
+
*/
|
|
16
|
+
export declare const getInvitation: (targetType: Amity.Invitation['targetType'], targetId: Amity.Invitation['targetId']) => Promise<Amity.Cached<Amity.Invitation | undefined>>;
|
|
17
|
+
//# sourceMappingURL=getInvitation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getInvitation.d.ts","sourceRoot":"","sources":["../../../src/invitationRepository/internalApi/getInvitation.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,aAAa,eACZ,MAAM,UAAU,CAAC,YAAY,CAAC,YAChC,MAAM,UAAU,CAAC,UAAU,CAAC,KACrC,QAAQ,MAAM,MAAM,CAAC,MAAM,UAAU,GAAG,SAAS,CAAC,CAmBpD,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Get my community invitations
|
|
3
|
+
*
|
|
4
|
+
* @param params the query parameters
|
|
5
|
+
* @param callback the callback to be called when the invitations are fetched
|
|
6
|
+
* @returns invitations
|
|
7
|
+
*
|
|
8
|
+
* @category My Community Invitations Live Collection
|
|
9
|
+
*
|
|
10
|
+
*/
|
|
11
|
+
export declare const getMyCommunityInvitations: (params: Amity.MyInvitationsLiveCollection, callback: Amity.LiveCollectionCallback<Amity.Invitation>, config?: Amity.LiveCollectionConfig) => () => void;
|
|
12
|
+
//# sourceMappingURL=getMyCommunityInvitations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"getMyCommunityInvitations.d.ts","sourceRoot":"","sources":["../../../src/invitationRepository/observers/getMyCommunityInvitations.ts"],"names":[],"mappings":"AAMA;;;;;;;;;GASG;AACH,eAAO,MAAM,yBAAyB,WAC5B,MAAM,2BAA2B,YAC/B,MAAM,sBAAsB,CAAC,MAAM,UAAU,CAAC,WAC/C,MAAM,oBAAoB,eA4BpC,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { MyInvitationsPaginationController } from './MyInvitationsPaginationController';
|
|
2
|
+
import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
|
|
3
|
+
export declare class MyInvitationsLiveCollectionController extends LiveCollectionController<'myInvitation', Amity.MyInvitationsLiveCollection, Amity.Invitation, MyInvitationsPaginationController> {
|
|
4
|
+
private queryStreamController;
|
|
5
|
+
private query;
|
|
6
|
+
constructor(query: Amity.MyInvitationsLiveCollection, callback: Amity.LiveCollectionCallback<Amity.Invitation>);
|
|
7
|
+
protected setup(): void;
|
|
8
|
+
protected persistModel(queryPayload: Amity.MyInvitationsPayload & Amity.Pagination): Promise<void>;
|
|
9
|
+
protected persistQueryStream({ response, direction, refresh, }: Amity.LiveCollectionPersistQueryStreamParams<'myInvitation'>): void;
|
|
10
|
+
startSubscription(): Amity.Unsubscriber[];
|
|
11
|
+
notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams): void;
|
|
12
|
+
applyFilter(data: Amity.Invitation[]): Amity.Invitation[];
|
|
13
|
+
}
|
|
14
|
+
//# sourceMappingURL=MyInvitationsLiveCollectionController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MyInvitationsLiveCollectionController.d.ts","sourceRoot":"","sources":["../../../../src/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,iCAAiC,EAAE,MAAM,qCAAqC,CAAC;AAExF,OAAO,EAAE,wBAAwB,EAAE,MAAM,gDAAgD,CAAC;AAS1F,qBAAa,qCAAsC,SAAQ,wBAAwB,CACjF,cAAc,EACd,KAAK,CAAC,2BAA2B,EACjC,KAAK,CAAC,UAAU,EAChB,iCAAiC,CAClC;IACC,OAAO,CAAC,qBAAqB,CAAqC;IAElE,OAAO,CAAC,KAAK,CAAoC;gBAG/C,KAAK,EAAE,KAAK,CAAC,2BAA2B,EACxC,QAAQ,EAAE,KAAK,CAAC,sBAAsB,CAAC,KAAK,CAAC,UAAU,CAAC;IAoB1D,SAAS,CAAC,KAAK;cAUC,YAAY,CAAC,YAAY,EAAE,KAAK,CAAC,oBAAoB,GAAG,KAAK,CAAC,UAAU;IAIxF,SAAS,CAAC,kBAAkB,CAAC,EAC3B,QAAQ,EACR,SAAS,EACT,OAAO,GACR,EAAE,KAAK,CAAC,sCAAsC,CAAC,cAAc,CAAC;IAI/D,iBAAiB;IAiBjB,YAAY,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,0BAA0B;IAsBzE,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,UAAU,EAAE;CAsCrC"}
|
package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { PaginationController } from '~/core/liveCollection/PaginationController';
|
|
2
|
+
export declare class MyInvitationsPaginationController extends PaginationController<'myInvitation', Amity.MyInvitationsLiveCollection> {
|
|
3
|
+
getRequest(queryParams: Amity.MyInvitationsLiveCollection, token: string | undefined): Promise<Amity.MyInvitationsPayload & Amity.Pagination>;
|
|
4
|
+
}
|
|
5
|
+
//# sourceMappingURL=MyInvitationsPaginationController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MyInvitationsPaginationController.d.ts","sourceRoot":"","sources":["../../../../src/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,MAAM,4CAA4C,CAAC;AAGlF,qBAAa,iCAAkC,SAAQ,oBAAoB,CACzE,cAAc,EACd,KAAK,CAAC,2BAA2B,CAClC;IACO,UAAU,CAAC,WAAW,EAAE,KAAK,CAAC,2BAA2B,EAAE,KAAK,EAAE,MAAM,GAAG,SAAS;CAa3F"}
|
package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { QueryStreamController } from '~/core/liveCollection/QueryStreamController';
|
|
2
|
+
import { InvitationActionsEnum } from '../getInvitations/enums';
|
|
3
|
+
export declare class MyInvitationsQueryStreamController extends QueryStreamController<Amity.MyInvitationsPayload, Amity.MyInvitationsLiveCollection> {
|
|
4
|
+
private notifyChange;
|
|
5
|
+
private preparePayload;
|
|
6
|
+
constructor(query: Amity.MyInvitationsLiveCollection, cacheKey: string[], notifyChange: (params: Amity.LiveCollectionNotifyParams) => void, preparePayload: (response: Amity.MyInvitationsPayload) => Amity.ProcessedMyInvitationsPayload);
|
|
7
|
+
saveToMainDB(response: Amity.MyInvitationsPayload): Promise<void>;
|
|
8
|
+
appendToQueryStream(response: Amity.MyInvitationsPayload & Partial<Amity.Pagination>, direction: Amity.LiveCollectionPageDirection, refresh?: boolean): void;
|
|
9
|
+
reactor(action: InvitationActionsEnum): (invitations: Amity.InternalInvitation[]) => void;
|
|
10
|
+
subscribeRTE(createSubscriber: {
|
|
11
|
+
fn: (reactor: Amity.Listener<Amity.InternalInvitation[]>) => Amity.Unsubscriber;
|
|
12
|
+
action: InvitationActionsEnum;
|
|
13
|
+
}[]): Amity.Unsubscriber[];
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=MyInvitationsQueryStreamController.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MyInvitationsQueryStreamController.d.ts","sourceRoot":"","sources":["../../../../src/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6CAA6C,CAAC;AACpF,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,qBAAa,kCAAmC,SAAQ,qBAAqB,CAC3E,KAAK,CAAC,oBAAoB,EAC1B,KAAK,CAAC,2BAA2B,CAClC;IACC,OAAO,CAAC,YAAY,CAAqD;IAEzE,OAAO,CAAC,cAAc,CAEmB;gBAGvC,KAAK,EAAE,KAAK,CAAC,2BAA2B,EACxC,QAAQ,EAAE,MAAM,EAAE,EAClB,YAAY,EAAE,CAAC,MAAM,EAAE,KAAK,CAAC,0BAA0B,KAAK,IAAI,EAChE,cAAc,EAAE,CAAC,QAAQ,EAAE,KAAK,CAAC,oBAAoB,KAAK,KAAK,CAAC,6BAA6B;IAOzF,YAAY,CAAC,QAAQ,EAAE,KAAK,CAAC,oBAAoB;IAWvD,mBAAmB,CACjB,QAAQ,EAAE,KAAK,CAAC,oBAAoB,GAAG,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,EAChE,SAAS,EAAE,KAAK,CAAC,2BAA2B,EAC5C,OAAO,UAAQ;IAoBjB,OAAO,CAAC,MAAM,EAAE,qBAAqB,iBACd,MAAM,kBAAkB,EAAE;IAiCjD,YAAY,CACV,gBAAgB,EAAE;QAChB,EAAE,EAAE,CAAC,OAAO,EAAE,KAAK,CAAC,QAAQ,CAAC,KAAK,CAAC,kBAAkB,EAAE,CAAC,KAAK,KAAK,CAAC,YAAY,CAAC;QAChF,MAAM,EAAE,qBAAqB,CAAC;KAC/B,EAAE;CAIN"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/invitationRepository/observers/index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"convertRawInvitationToInternalInvitation.d.ts","sourceRoot":"","sources":["../../../src/invitationRepository/utils/convertRawInvitationToInternalInvitation.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,wCAAwC,kBACpC,MAAM,aAAa,KACjC,MAAM,kBAKR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareInvitationPayload.d.ts","sourceRoot":"","sources":["../../../src/invitationRepository/utils/prepareInvitationPayload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prepareInvitationPayload.d.ts","sourceRoot":"","sources":["../../../src/invitationRepository/utils/prepareInvitationPayload.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,wBAAwB,eACvB,MAAM,iBAAiB,KAClC,MAAM,0BAMR,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"prepareMyInvitationsPayload.d.ts","sourceRoot":"","sources":["../../../src/invitationRepository/utils/prepareMyInvitationsPayload.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,2BAA2B,eAC1B,MAAM,oBAAoB,KACrC,MAAM,6BAMR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"communityLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/communityLinkedObject.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"communityLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/communityLinkedObject.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,qBAAqB,cAAe,MAAM,iBAAiB,KAAG,MAAM,SA8BhF,CAAC"}
|
package/package.json
CHANGED
|
@@ -28,6 +28,7 @@ declare global {
|
|
|
28
28
|
semanticSearchCommunity: Amity.SemanticSearchCommunityPayload;
|
|
29
29
|
notificationTrayItem: Amity.NotificationTrayPayload;
|
|
30
30
|
invitation: Amity.InvitationPayload;
|
|
31
|
+
myInvitation: Amity.MyInvitationsPayload;
|
|
31
32
|
};
|
|
32
33
|
|
|
33
34
|
type UserPayload = {
|
|
@@ -549,10 +550,22 @@ declare global {
|
|
|
549
550
|
|
|
550
551
|
type InvitationPayload = {
|
|
551
552
|
invitations: Amity.RawInvitation[];
|
|
553
|
+
users: Amity.RawUser[];
|
|
552
554
|
};
|
|
553
555
|
|
|
554
556
|
type ProcessedInvitationPayload = {
|
|
555
557
|
invitations: Amity.InternalInvitation[];
|
|
558
|
+
users: Amity.InternalUser[];
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
type MyInvitationsPayload = {
|
|
562
|
+
invitations: Amity.RawInvitation[];
|
|
563
|
+
users: Amity.RawUser[];
|
|
564
|
+
};
|
|
565
|
+
|
|
566
|
+
type ProcessedMyInvitationsPayload = {
|
|
567
|
+
invitations: Amity.InternalInvitation[];
|
|
568
|
+
users: Amity.InternalUser[];
|
|
556
569
|
};
|
|
557
570
|
}
|
|
558
571
|
}
|
|
@@ -223,8 +223,10 @@ declare global {
|
|
|
223
223
|
type CommunityLinkedObject = {
|
|
224
224
|
createInvitations: (userIds: string[]) => Promise<void>;
|
|
225
225
|
getMemberInvitations: (
|
|
226
|
+
params: Pick<Amity.InvitationLiveCollection, 'limit' | 'sortBy' | 'statuses'>,
|
|
226
227
|
callback: Amity.LiveCollectionCallback<Amity.Invitation>,
|
|
227
228
|
) => Amity.Unsubscriber;
|
|
229
|
+
getInvitation: () => Promise<Amity.Invitation | undefined>;
|
|
228
230
|
};
|
|
229
231
|
}
|
|
230
232
|
}
|
|
@@ -43,10 +43,16 @@ declare global {
|
|
|
43
43
|
status: Amity.InvitationStatus;
|
|
44
44
|
respondedAt: Amity.timestamp;
|
|
45
45
|
createdBy: string;
|
|
46
|
+
invitationId: string;
|
|
47
|
+
invitedUserId: string;
|
|
48
|
+
invitedUserInternalId: string;
|
|
49
|
+
invitedUserPublicId: string;
|
|
50
|
+
inviterUserId: string;
|
|
51
|
+
inviterUserInternalId: string;
|
|
52
|
+
inviterUserPublicId: string;
|
|
46
53
|
} & Amity.Timestamps;
|
|
47
54
|
|
|
48
55
|
type InternalInvitation = Omit<RawInvitation, 'createdBy'> & {
|
|
49
|
-
invitationId: string;
|
|
50
56
|
createdById: string;
|
|
51
57
|
};
|
|
52
58
|
|
|
@@ -55,7 +61,6 @@ declare global {
|
|
|
55
61
|
user?: Amity.User;
|
|
56
62
|
createdById: string;
|
|
57
63
|
createdBy?: Amity.User;
|
|
58
|
-
invitationId: string;
|
|
59
64
|
target?: Amity.InvitationTarget<Amity.InvitationTargetType>;
|
|
60
65
|
};
|
|
61
66
|
|
|
@@ -76,6 +81,25 @@ declare global {
|
|
|
76
81
|
Pick<QueryInvitations, 'limit'>
|
|
77
82
|
>;
|
|
78
83
|
|
|
84
|
+
type QueryMyInvitations = {
|
|
85
|
+
targetId?: string;
|
|
86
|
+
token?: Amity.Token;
|
|
87
|
+
type?: Amity.InvitationType;
|
|
88
|
+
sortBy?: Amity.InvitationSortBy;
|
|
89
|
+
limit?: Amity.PageLimit['limit'];
|
|
90
|
+
statuses?: InvitationStatusEnum[];
|
|
91
|
+
targetType?: Amity.InvitationTargetType;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
type MyInvitationsLiveCollection = Amity.LiveCollectionParams<
|
|
95
|
+
Omit<QueryMyInvitations, 'limit'>
|
|
96
|
+
>;
|
|
97
|
+
|
|
98
|
+
type MyInvitationsLiveCollectionCache = Amity.LiveCollectionCache<
|
|
99
|
+
Amity.InternalInvitation['_id'],
|
|
100
|
+
Pick<QueryMyInvitations, 'limit'>
|
|
101
|
+
>;
|
|
102
|
+
|
|
79
103
|
type InvitationLinkedObject = {
|
|
80
104
|
accept: () => Promise<void>;
|
|
81
105
|
reject: () => Promise<void>;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
3
|
+
import { prepareMyInvitationsPayload } from '../utils/prepareMyInvitationsPayload';
|
|
4
|
+
import { invitationLinkedObject } from '~/utils/linkedObject/invitationLinkedObject';
|
|
5
|
+
|
|
6
|
+
/* begin_public_function
|
|
7
|
+
id: invitation.get
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* ```js
|
|
11
|
+
* import { getInvitation } from '@amityco/ts-sdk'
|
|
12
|
+
* const { invitation } = await getInvitation(targetType, targetId)
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Get a {@link Amity.Invitation} object
|
|
16
|
+
*
|
|
17
|
+
* @param targetType The type of the target of the {@link Amity.Invitation}
|
|
18
|
+
* @param targetId The ID of the target of the {@link Amity.Invitation}
|
|
19
|
+
* @returns A {@link Amity.Invitation} object
|
|
20
|
+
*
|
|
21
|
+
* @category Invitation API
|
|
22
|
+
* @async
|
|
23
|
+
*/
|
|
24
|
+
export const getInvitation = async (
|
|
25
|
+
targetType: Amity.Invitation['targetType'],
|
|
26
|
+
targetId: Amity.Invitation['targetId'],
|
|
27
|
+
): Promise<Amity.Cached<Amity.Invitation | undefined>> => {
|
|
28
|
+
const client = getActiveClient();
|
|
29
|
+
client.log('invitation/getInvitation', targetType, targetId);
|
|
30
|
+
|
|
31
|
+
const { data: payload } = await client.http.get<Amity.MyInvitationsPayload>(
|
|
32
|
+
`/api/v1/invitations/me`,
|
|
33
|
+
{ params: { targetType, targetId } },
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
37
|
+
|
|
38
|
+
const cachedAt = client.cache && Date.now();
|
|
39
|
+
|
|
40
|
+
if (client.cache) ingestInCache(data, { cachedAt });
|
|
41
|
+
|
|
42
|
+
return {
|
|
43
|
+
data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
|
|
44
|
+
cachedAt,
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
/* end_public_function */
|
package/src/invitationRepository/observers/getInvitations/InvitationsPaginationController.ts
CHANGED
|
@@ -10,7 +10,7 @@ export class InvitationsPaginationController extends PaginationController<
|
|
|
10
10
|
const options = token ? { token } : { limit };
|
|
11
11
|
|
|
12
12
|
const { data } = await this.http.get<Amity.InvitationPayload & Amity.Pagination>(
|
|
13
|
-
|
|
13
|
+
'/api/v1/invitations',
|
|
14
14
|
{ params: { ...params, options } },
|
|
15
15
|
);
|
|
16
16
|
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { dropFromCache } from '~/cache/api';
|
|
2
|
+
import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
|
|
3
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
4
|
+
import { MyInvitationsLiveCollectionController } from './getMyInvitations/MyInvitationsLiveCollectionController';
|
|
5
|
+
import { InvitationStatusEnum } from '~/@types';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Get my community invitations
|
|
9
|
+
*
|
|
10
|
+
* @param params the query parameters
|
|
11
|
+
* @param callback the callback to be called when the invitations are fetched
|
|
12
|
+
* @returns invitations
|
|
13
|
+
*
|
|
14
|
+
* @category My Community Invitations Live Collection
|
|
15
|
+
*
|
|
16
|
+
*/
|
|
17
|
+
export const getMyCommunityInvitations = (
|
|
18
|
+
params: Amity.MyInvitationsLiveCollection,
|
|
19
|
+
callback: Amity.LiveCollectionCallback<Amity.Invitation>,
|
|
20
|
+
config?: Amity.LiveCollectionConfig,
|
|
21
|
+
) => {
|
|
22
|
+
const { log, cache } = getActiveClient();
|
|
23
|
+
|
|
24
|
+
if (!cache) {
|
|
25
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const timestamp = Date.now();
|
|
29
|
+
log(`getMyCommunityInvitations: (tmpid: ${timestamp}) > listen`);
|
|
30
|
+
|
|
31
|
+
const invitationsLiveCollection = new MyInvitationsLiveCollectionController(
|
|
32
|
+
{ ...params, targetType: 'community', statuses: [InvitationStatusEnum.Pending] },
|
|
33
|
+
callback,
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const disposers = invitationsLiveCollection.startSubscription();
|
|
37
|
+
|
|
38
|
+
const cacheKey = invitationsLiveCollection.getCacheKey();
|
|
39
|
+
|
|
40
|
+
disposers.push(() => {
|
|
41
|
+
dropFromCache(cacheKey);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
return () => {
|
|
45
|
+
log(`getInvitations (tmpid: ${timestamp}) > dispose`);
|
|
46
|
+
disposers.forEach(fn => fn());
|
|
47
|
+
};
|
|
48
|
+
};
|
package/src/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.ts
ADDED
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { isNonNullable } from '~/utils';
|
|
3
|
+
import { invitationLinkedObject } from '~/utils/linkedObject/invitationLinkedObject';
|
|
4
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
5
|
+
import { sortByFirstCreated, sortByLastCreated } from '~/core/query';
|
|
6
|
+
import { MyInvitationsPaginationController } from './MyInvitationsPaginationController';
|
|
7
|
+
import { MyInvitationsQueryStreamController } from './MyInvitationsQueryStreamController';
|
|
8
|
+
import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
|
|
9
|
+
import {
|
|
10
|
+
onLocalInvitationCreated,
|
|
11
|
+
onLocalInvitationDeleted,
|
|
12
|
+
onLocalInvitationUpdated,
|
|
13
|
+
} from '~/invitationRepository/events';
|
|
14
|
+
import { prepareMyInvitationsPayload } from '~/invitationRepository/utils/prepareMyInvitationsPayload';
|
|
15
|
+
import { InvitationActionsEnum } from '../getInvitations/enums';
|
|
16
|
+
|
|
17
|
+
export class MyInvitationsLiveCollectionController extends LiveCollectionController<
|
|
18
|
+
'myInvitation',
|
|
19
|
+
Amity.MyInvitationsLiveCollection,
|
|
20
|
+
Amity.Invitation,
|
|
21
|
+
MyInvitationsPaginationController
|
|
22
|
+
> {
|
|
23
|
+
private queryStreamController: MyInvitationsQueryStreamController;
|
|
24
|
+
|
|
25
|
+
private query: Amity.MyInvitationsLiveCollection;
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
query: Amity.MyInvitationsLiveCollection,
|
|
29
|
+
callback: Amity.LiveCollectionCallback<Amity.Invitation>,
|
|
30
|
+
) {
|
|
31
|
+
const queryStreamId = hash(query);
|
|
32
|
+
const cacheKey = ['invitation', 'collection', queryStreamId];
|
|
33
|
+
const paginationController = new MyInvitationsPaginationController(query);
|
|
34
|
+
|
|
35
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
36
|
+
|
|
37
|
+
this.query = query;
|
|
38
|
+
this.queryStreamController = new MyInvitationsQueryStreamController(
|
|
39
|
+
this.query,
|
|
40
|
+
this.cacheKey,
|
|
41
|
+
this.notifyChange.bind(this),
|
|
42
|
+
prepareMyInvitationsPayload,
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
this.callback = callback.bind(this);
|
|
46
|
+
this.loadPage({ initial: true });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
protected setup() {
|
|
50
|
+
const collection = pullFromCache<Amity.MyInvitationsLiveCollectionCache>(this.cacheKey)?.data;
|
|
51
|
+
if (!collection) {
|
|
52
|
+
pushToCache(this.cacheKey, {
|
|
53
|
+
data: [],
|
|
54
|
+
params: this.query,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
protected async persistModel(queryPayload: Amity.MyInvitationsPayload & Amity.Pagination) {
|
|
60
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected persistQueryStream({
|
|
64
|
+
response,
|
|
65
|
+
direction,
|
|
66
|
+
refresh,
|
|
67
|
+
}: Amity.LiveCollectionPersistQueryStreamParams<'myInvitation'>) {
|
|
68
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
startSubscription() {
|
|
72
|
+
return this.queryStreamController.subscribeRTE([
|
|
73
|
+
{
|
|
74
|
+
fn: onLocalInvitationCreated,
|
|
75
|
+
action: InvitationActionsEnum.OnLocalInvitationCreated,
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
fn: onLocalInvitationUpdated,
|
|
79
|
+
action: InvitationActionsEnum.OnLocalInvitationUpdated,
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
fn: onLocalInvitationDeleted,
|
|
83
|
+
action: InvitationActionsEnum.OnLocalInvitationDeleted,
|
|
84
|
+
},
|
|
85
|
+
]);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
|
|
89
|
+
const collection = pullFromCache<Amity.MyInvitationsLiveCollectionCache>(this.cacheKey)?.data;
|
|
90
|
+
if (!collection) return;
|
|
91
|
+
|
|
92
|
+
const data = this.applyFilter(
|
|
93
|
+
collection.data
|
|
94
|
+
.map(id => pullFromCache<Amity.InternalInvitation>(['invitation', 'get', id])!)
|
|
95
|
+
.filter(isNonNullable)
|
|
96
|
+
.map(({ data }) => invitationLinkedObject(data)) ?? [],
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
if (!this.shouldNotify(data) && origin === 'event') return;
|
|
100
|
+
|
|
101
|
+
this.callback({
|
|
102
|
+
onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
|
|
103
|
+
data,
|
|
104
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
105
|
+
loading,
|
|
106
|
+
error,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
applyFilter(data: Amity.Invitation[]) {
|
|
111
|
+
let invitations = data;
|
|
112
|
+
|
|
113
|
+
if (this.query.targetId) {
|
|
114
|
+
invitations = invitations.filter(invitation => invitation.targetId === this.query.targetId);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
if (this.query.statuses) {
|
|
118
|
+
invitations = invitations.filter(invitation =>
|
|
119
|
+
this.query.statuses?.includes(invitation.status),
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (this.query.targetType) {
|
|
124
|
+
invitations = invitations.filter(
|
|
125
|
+
invitation => invitation.targetType === this.query.targetType,
|
|
126
|
+
);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (this.query.type) {
|
|
130
|
+
invitations = invitations.filter(invitation => invitation.type === this.query.type);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const sortFn = (() => {
|
|
134
|
+
switch (this.query.sortBy) {
|
|
135
|
+
case 'firstCreated':
|
|
136
|
+
return sortByFirstCreated;
|
|
137
|
+
case 'lastCreated':
|
|
138
|
+
return sortByLastCreated;
|
|
139
|
+
default:
|
|
140
|
+
return sortByLastCreated;
|
|
141
|
+
}
|
|
142
|
+
})();
|
|
143
|
+
|
|
144
|
+
invitations = invitations.sort(sortFn);
|
|
145
|
+
|
|
146
|
+
return invitations;
|
|
147
|
+
}
|
|
148
|
+
}
|
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';
|