@wireapp/core 41.2.0 → 41.2.2
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/lib/conversation/ConversationService/ConversationService.d.ts +6 -16
- package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
- package/lib/conversation/ConversationService/ConversationService.js +8 -11
- package/lib/conversation/ConversationService/ConversationService.types.d.ts +29 -2
- package/lib/conversation/ConversationService/ConversationService.types.d.ts.map +1 -1
- package/lib/conversation/ConversationService/ConversationService.types.js +6 -1
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts +4 -11
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.d.ts.map +1 -1
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.js +12 -6
- package/lib/messagingProtocols/proteus/ProteusService/ProteusService.test.js +47 -50
- package/lib/messagingProtocols/proteus/ProteusService/WithMockedGenerics.test.js +2 -2
- package/lib/testUtils/index.d.ts +7 -0
- package/lib/testUtils/index.d.ts.map +1 -0
- package/lib/testUtils/index.js +34 -0
- package/package.json +5 -5
|
@@ -3,16 +3,12 @@ import { ConversationMemberLeaveEvent } from '@wireapp/api-client/lib/event';
|
|
|
3
3
|
import { QualifiedId } from '@wireapp/api-client/lib/user';
|
|
4
4
|
import { XOR } from '@wireapp/commons/lib/util/TypeUtil';
|
|
5
5
|
import { APIClient } from '@wireapp/api-client';
|
|
6
|
-
import { AddUsersParams,
|
|
6
|
+
import { AddUsersParams, MLSCreateConversationResponse, SendMlsMessageParams, SendResult } from './ConversationService.types';
|
|
7
7
|
import { MessageTimer, RemoveUsersParams } from '../../conversation/';
|
|
8
8
|
import { MLSService } from '../../messagingProtocols/mls';
|
|
9
9
|
import { ProteusService } from '../../messagingProtocols/proteus';
|
|
10
10
|
import { AddUsersToProteusConversationParams, SendProteusMessageParams } from '../../messagingProtocols/proteus/ProteusService/ProteusService.types';
|
|
11
11
|
import { RemoteData } from '../content';
|
|
12
|
-
export declare enum AddUsersFailureReasons {
|
|
13
|
-
NON_FEDERATING_BACKENDS = "NON_FEDERATING_BACKENDS",
|
|
14
|
-
UNREACHABLE_BACKENDS = "UNREACHABLE_BACKENDS"
|
|
15
|
-
}
|
|
16
12
|
export declare class ConversationService {
|
|
17
13
|
private readonly apiClient;
|
|
18
14
|
private readonly proteusService;
|
|
@@ -39,18 +35,12 @@ export declare class ConversationService {
|
|
|
39
35
|
* @param conversationData Payload object for group creation
|
|
40
36
|
* @returns Resolves when the conversation was created
|
|
41
37
|
*/
|
|
42
|
-
createProteusConversation(conversationData: NewConversation): Promise<
|
|
38
|
+
createProteusConversation(conversationData: NewConversation): Promise<import("./ConversationService.types").BaseCreateConversationResponse>;
|
|
43
39
|
getConversation(conversationId: QualifiedId): Promise<Conversation>;
|
|
44
40
|
getConversations(conversationIds?: QualifiedId[]): Promise<RemoteConversations>;
|
|
45
41
|
getAsset({ assetId, assetToken, otrKey, sha256 }: RemoteData): Promise<Uint8Array>;
|
|
46
42
|
getUnencryptedAsset(assetId: string, assetToken?: string): Promise<ArrayBuffer>;
|
|
47
|
-
addUsersToProteusConversation(params: AddUsersToProteusConversationParams): Promise<
|
|
48
|
-
event?: import("@wireapp/api-client/lib/event").ConversationMemberJoinEvent | undefined;
|
|
49
|
-
failedToAdd?: {
|
|
50
|
-
reason: AddUsersFailureReasons;
|
|
51
|
-
users: QualifiedId[];
|
|
52
|
-
} | undefined;
|
|
53
|
-
}>;
|
|
43
|
+
addUsersToProteusConversation(params: AddUsersToProteusConversationParams): Promise<import("./ConversationService.types").ProteusAddUsersResponse>;
|
|
54
44
|
removeUserFromConversation(conversationId: QualifiedId, userId: QualifiedId): Promise<ConversationMemberLeaveEvent>;
|
|
55
45
|
/**
|
|
56
46
|
* Sends a message to a conversation
|
|
@@ -75,7 +65,7 @@ export declare class ConversationService {
|
|
|
75
65
|
* Will create a conversation on backend and register it to CoreCrypto once created
|
|
76
66
|
* @param conversationData
|
|
77
67
|
*/
|
|
78
|
-
createMLSConversation(conversationData: NewConversation, selfUserId: QualifiedId, selfClientId: string): Promise<
|
|
68
|
+
createMLSConversation(conversationData: NewConversation, selfUserId: QualifiedId, selfClientId: string): Promise<MLSCreateConversationResponse>;
|
|
79
69
|
private sendMLSMessage;
|
|
80
70
|
/**
|
|
81
71
|
* Will add users to existing MLS group by claiming their key packages and passing them to CoreCrypto.addClientsToConversation
|
|
@@ -84,8 +74,8 @@ export declare class ConversationService {
|
|
|
84
74
|
* @param groupId Id of the group to which we want to add users
|
|
85
75
|
* @param conversationId Id of the conversation to which we want to add users
|
|
86
76
|
*/
|
|
87
|
-
addUsersToMLSConversation({ qualifiedUsers, groupId, conversationId, }: Required<AddUsersParams>): Promise<
|
|
88
|
-
removeUsersFromMLSConversation({ groupId, conversationId, qualifiedUserIds, }: RemoveUsersParams): Promise<
|
|
77
|
+
addUsersToMLSConversation({ qualifiedUsers, groupId, conversationId, }: Required<AddUsersParams>): Promise<MLSCreateConversationResponse>;
|
|
78
|
+
removeUsersFromMLSConversation({ groupId, conversationId, qualifiedUserIds, }: RemoveUsersParams): Promise<MLSCreateConversationResponse>;
|
|
89
79
|
joinByExternalCommit(conversationId: QualifiedId): Promise<PostMlsMessageResponse>;
|
|
90
80
|
/**
|
|
91
81
|
* Will send an external proposal for the current device to join a specific conversation.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConversationService.d.ts","sourceRoot":"","sources":["../../../src/conversation/ConversationService/ConversationService.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,YAAY,EACZ,2BAA2B,EAC3B,WAAW,EACX,eAAe,EACf,oBAAoB,EAEpB,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAC,4BAA4B,EAAC,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAIvD,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAI9C,OAAO,
|
|
1
|
+
{"version":3,"file":"ConversationService.d.ts","sourceRoot":"","sources":["../../../src/conversation/ConversationService/ConversationService.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,YAAY,EACZ,2BAA2B,EAC3B,WAAW,EACX,eAAe,EACf,oBAAoB,EAEpB,mBAAmB,EACnB,sBAAsB,EACvB,MAAM,sCAAsC,CAAC;AAE9C,OAAO,EAAC,4BAA4B,EAAC,MAAM,+BAA+B,CAAC;AAC3E,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AACzD,OAAO,EAAC,GAAG,EAAC,MAAM,oCAAoC,CAAC;AAIvD,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAI9C,OAAO,EAEL,cAAc,EACd,6BAA6B,EAC7B,oBAAoB,EACpB,UAAU,EACX,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAC,YAAY,EAAuB,iBAAiB,EAAC,MAAM,qBAAqB,CAAC;AAEzF,OAAO,EAAC,UAAU,EAAuB,MAAM,8BAA8B,CAAC;AAC9E,OAAO,EAAkC,cAAc,EAAC,MAAM,kCAAkC,CAAC;AACjG,OAAO,EACL,mCAAmC,EACnC,wBAAwB,EACzB,MAAM,sEAAsE,CAAC;AAG9E,OAAO,EAAC,UAAU,EAAC,MAAM,YAAY,CAAC;AAGtC,qBAAa,mBAAmB;IAK5B,OAAO,CAAC,QAAQ,CAAC,SAAS;IAC1B,OAAO,CAAC,QAAQ,CAAC,cAAc;IAC/B,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC;IAN/B,SAAgB,YAAY,EAAE,YAAY,CAAC;IAC3C,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAgD;gBAGpD,SAAS,EAAE,SAAS,EACpB,cAAc,EAAE,cAAc,EAC9B,WAAW,CAAC,wBAAY;IAK3C,IAAI,UAAU,IAAI,UAAU,CAK3B;IAED;;;;;OAKG;IACU,2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,EACtB,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,2BAA2B,GAAG,MAAM,GACrD,OAAO,CAAC,IAAI,CAAC;IAMhB;;;;OAIG;IAEH;;;OAGG;IACU,qBAAqB,CAChC,gBAAgB,EAAE,eAAe,EACjC,UAAU,EAAE,WAAW,EACvB,YAAY,EAAE,MAAM,GACnB,OAAO,CAAC,6BAA6B,CAAC;YAmC3B,cAAc;IAiC5B;;;;;;OAMG;IACU,yBAAyB,CAAC,EACrC,cAAc,EACd,OAAO,EACP,cAAc,GACf,EAAE,QAAQ,CAAC,cAAc,CAAC,GAAG,OAAO,CAAC,6BAA6B,CAAC;IAoBvD,8BAA8B,CAAC,EAC1C,OAAO,EACP,cAAc,EACd,gBAAgB,GACjB,EAAE,iBAAiB,GAAG,OAAO,CAAC,6BAA6B,CAAC;IAoBhD,oBAAoB,CAAC,cAAc,EAAE,WAAW;IAI7D;;;;;OAKG;IACU,wBAAwB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM;IAmBvD,4BAA4B,CAAC,OAAO,EAAE,MAAM;IAI5C,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;YAIlD,YAAY;IAYb,mBAAmB;IA4BhC;;;;;;;OAOG;IACH,SAAgB,4BAA4B,YACjC,MAAM,YACL;QAAC,IAAI,EAAE,WAAW,CAAC;QAAC,MAAM,EAAE,MAAM,CAAA;KAAC,eAChC,WAAW,KACvB,QAAQ,IAAI,CAAC,CA0Bd;CACH"}
|
|
@@ -21,13 +21,14 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
21
21
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
22
22
|
};
|
|
23
23
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
-
exports.ConversationService =
|
|
24
|
+
exports.ConversationService = void 0;
|
|
25
25
|
const conversation_1 = require("@wireapp/api-client/lib/conversation");
|
|
26
26
|
const data_1 = require("@wireapp/api-client/lib/conversation/data");
|
|
27
27
|
const bazinga64_1 = require("bazinga64");
|
|
28
28
|
const logdown_1 = __importDefault(require("logdown"));
|
|
29
29
|
const core_crypto_1 = require("@wireapp/core-crypto");
|
|
30
30
|
const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
31
|
+
const ConversationService_types_1 = require("./ConversationService.types");
|
|
31
32
|
const conversation_2 = require("../../conversation/");
|
|
32
33
|
const AssetCryptography_1 = require("../../cryptography/AssetCryptography");
|
|
33
34
|
const mls_1 = require("../../messagingProtocols/mls");
|
|
@@ -35,11 +36,6 @@ const proteus_1 = require("../../messagingProtocols/proteus");
|
|
|
35
36
|
const util_1 = require("../../util");
|
|
36
37
|
const fullyQualifiedClientIdUtils_1 = require("../../util/fullyQualifiedClientIdUtils");
|
|
37
38
|
const messageSender_1 = require("../message/messageSender");
|
|
38
|
-
var AddUsersFailureReasons;
|
|
39
|
-
(function (AddUsersFailureReasons) {
|
|
40
|
-
AddUsersFailureReasons["NON_FEDERATING_BACKENDS"] = "NON_FEDERATING_BACKENDS";
|
|
41
|
-
AddUsersFailureReasons["UNREACHABLE_BACKENDS"] = "UNREACHABLE_BACKENDS";
|
|
42
|
-
})(AddUsersFailureReasons || (exports.AddUsersFailureReasons = AddUsersFailureReasons = {}));
|
|
43
39
|
class ConversationService {
|
|
44
40
|
constructor(apiClient, proteusService, _mlsService) {
|
|
45
41
|
this.apiClient = apiClient;
|
|
@@ -216,13 +212,12 @@ class ConversationService {
|
|
|
216
212
|
});
|
|
217
213
|
// We fetch the fresh version of the conversation created on backend with the newly added users
|
|
218
214
|
const conversation = await this.apiClient.api.conversation.getConversation(qualifiedId);
|
|
219
|
-
/**
|
|
220
|
-
* @note Add users whom we could not fetch their keypackages to list of failed to add users.
|
|
221
|
-
*/
|
|
222
|
-
conversation.failed_to_add = response.failed || [];
|
|
223
215
|
return {
|
|
224
216
|
events: response.events,
|
|
225
217
|
conversation,
|
|
218
|
+
failedToAdd: response.failed
|
|
219
|
+
? { users: response.failed, reason: ConversationService_types_1.AddUsersFailureReasons.UNREACHABLE_BACKENDS }
|
|
220
|
+
: undefined,
|
|
226
221
|
};
|
|
227
222
|
}
|
|
228
223
|
async sendMLSMessage({ payload, groupId }) {
|
|
@@ -264,12 +259,14 @@ class ConversationService {
|
|
|
264
259
|
const { coreCryptoKeyPackagesPayload, failedToFetchKeyPackages } = await this.mlsService.getKeyPackagesPayload(qualifiedUsers);
|
|
265
260
|
const response = await this.mlsService.addUsersToExistingConversation(groupId, coreCryptoKeyPackagesPayload);
|
|
266
261
|
const conversation = await this.getConversation(conversationId);
|
|
267
|
-
conversation.failed_to_add = failedToFetchKeyPackages;
|
|
268
262
|
//We store the info when user was added (and key material was created), so we will know when to renew it
|
|
269
263
|
this.mlsService.resetKeyMaterialRenewal(groupId);
|
|
270
264
|
return {
|
|
271
265
|
events: response.events,
|
|
272
266
|
conversation,
|
|
267
|
+
failedToAdd: failedToFetchKeyPackages.length > 0
|
|
268
|
+
? { users: failedToFetchKeyPackages, reason: ConversationService_types_1.AddUsersFailureReasons.UNREACHABLE_BACKENDS }
|
|
269
|
+
: undefined,
|
|
273
270
|
};
|
|
274
271
|
}
|
|
275
272
|
async removeUsersFromMLSConversation({ groupId, conversationId, qualifiedUserIds, }) {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { QualifiedUserClients, ConversationProtocol, MessageSendingStatus, Conversation } from '@wireapp/api-client/lib/conversation';
|
|
2
2
|
import { ConversationEvent } from '@wireapp/api-client/lib/event';
|
|
3
|
+
import { ConversationMemberJoinEvent } from '@wireapp/api-client/lib/event';
|
|
3
4
|
import { QualifiedId } from '@wireapp/api-client/lib/user';
|
|
4
5
|
import { GenericMessage } from '@wireapp/protocol-messaging';
|
|
5
6
|
import { MessageSendingState } from '..';
|
|
@@ -76,10 +77,36 @@ export type RemoveUsersParams = {
|
|
|
76
77
|
qualifiedUserIds: QualifiedId[];
|
|
77
78
|
groupId: string;
|
|
78
79
|
};
|
|
79
|
-
export
|
|
80
|
-
|
|
80
|
+
export declare enum AddUsersFailureReasons {
|
|
81
|
+
NON_FEDERATING_BACKENDS = "NON_FEDERATING_BACKENDS",
|
|
82
|
+
UNREACHABLE_BACKENDS = "UNREACHABLE_BACKENDS"
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* List of users that were originaly requested to be in the conversation
|
|
86
|
+
* but could not be added due to their backend not being available
|
|
87
|
+
* @note Added since version 4: https://staging-nginz-https.z
|
|
88
|
+
ra.io/v4/api/swagger-ui/#/default/post_conversations
|
|
89
|
+
* @note Federation only
|
|
90
|
+
*/
|
|
91
|
+
export type AddUsersFailure = {
|
|
92
|
+
users: QualifiedId[];
|
|
93
|
+
reason: AddUsersFailureReasons;
|
|
94
|
+
};
|
|
95
|
+
/**
|
|
96
|
+
* The backend response of any method that will create (or add users to) a conversation
|
|
97
|
+
*/
|
|
98
|
+
export interface BaseCreateConversationResponse {
|
|
81
99
|
conversation: Conversation;
|
|
100
|
+
failedToAdd?: AddUsersFailure;
|
|
101
|
+
}
|
|
102
|
+
export type ProteusCreateConversationResponse = BaseCreateConversationResponse;
|
|
103
|
+
export type ProteusAddUsersResponse = {
|
|
104
|
+
event?: ConversationMemberJoinEvent;
|
|
105
|
+
failedToAdd?: AddUsersFailure;
|
|
82
106
|
};
|
|
107
|
+
export interface MLSCreateConversationResponse extends BaseCreateConversationResponse {
|
|
108
|
+
events: ConversationEvent[];
|
|
109
|
+
}
|
|
83
110
|
export type SendResult = {
|
|
84
111
|
/** The id of the message sent */
|
|
85
112
|
id: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ConversationService.types.d.ts","sourceRoot":"","sources":["../../../src/conversation/ConversationService/ConversationService.types.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,EACb,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAC,iBAAiB,EAAC,MAAM,+B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AmB,EAAE,CAAC;IACtC,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG;IAC9B,cAAc,EAAE,WAAW,CAAC;IAC5B,gBAAgB,EAAE,WAAW,EAAE,CAAC;IAChC,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,MAAM,MAAM,
|
|
1
|
+
{"version":3,"file":"ConversationService.types.d.ts","sourceRoot":"","sources":["../../../src/conversation/ConversationService/ConversationService.types.ts"],"names":[],"mappings":"AAmBA,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,oBAAoB,EACpB,YAAY,EACb,MAAM,sCAAsC,CAAC;AAC9C,OAAO,EAAC,iBAAiB,EAAC,MAAM,+BAA+B,CAAC;AAChE,OAAO,EAAC,2BAA2B,EAAC,MAAM,+BAA+B,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAEzD,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC;AAE3D,OAAO,EAAC,mBAAmB,EAAC,MAAM,IAAI,CAAC;AAEvC,oBAAY,iBAAiB;IAC3B,IAAI,IAAA;IACJ,KAAK,IAAA;IACL,aAAa,IAAA;CACd;AAED,MAAM,WAAW,qBAAqB;IACpC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,oBAAoB,CAAC;IAE/C,UAAU,CAAC,EAAE,OAAO,CAAC;IAErB;;OAEG;IACH,gBAAgB,CAAC,EAAE,uBAAuB,CAAC,kBAAkB,CAAC,CAAC;IAE/D;;;;;OAKG;IACH,UAAU,CAAC,EAAE,iBAAiB,CAAC;CAChC;AAED,MAAM,WAAW,uBAAuB;IACtC;;;;;;OAMG;IACH,gBAAgB,CAAC,EAAE,CAAC,MAAM,EAAE,oBAAoB,EAAE,OAAO,EAAE,OAAO,KAAK,IAAI,GAAG,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC1G;AAED;;;;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6BAA8B,SAAQ,8BAA8B;IACnF,MAAM,EAAE,iBAAiB,EAAE,CAAC;CAC7B;AAED,MAAM,MAAM,UAAU,GAAG;IACvB,iCAAiC;IACjC,EAAE,EAAE,MAAM,CAAC;IACX,8EAA8E;IAC9E,MAAM,EAAE,MAAM,CAAC;IACf,2FAA2F;IAC3F,KAAK,EAAE,mBAAmB,CAAC;IAC3B,4MAA4M;IAC5M,YAAY,CAAC,EAAE;QACb,gIAAgI;QAChI,MAAM,CAAC,EAAE,oBAAoB,GAAG,WAAW,EAAE,CAAC;QAC9C,oJAAoJ;QACpJ,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;KACxB,CAAC;CACH,CAAC"}
|
|
@@ -18,10 +18,15 @@
|
|
|
18
18
|
*
|
|
19
19
|
*/
|
|
20
20
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
-
exports.MessageTargetMode = void 0;
|
|
21
|
+
exports.AddUsersFailureReasons = exports.MessageTargetMode = void 0;
|
|
22
22
|
var MessageTargetMode;
|
|
23
23
|
(function (MessageTargetMode) {
|
|
24
24
|
MessageTargetMode[MessageTargetMode["NONE"] = 0] = "NONE";
|
|
25
25
|
MessageTargetMode[MessageTargetMode["USERS"] = 1] = "USERS";
|
|
26
26
|
MessageTargetMode[MessageTargetMode["USERS_CLIENTS"] = 2] = "USERS_CLIENTS";
|
|
27
27
|
})(MessageTargetMode || (exports.MessageTargetMode = MessageTargetMode = {}));
|
|
28
|
+
var AddUsersFailureReasons;
|
|
29
|
+
(function (AddUsersFailureReasons) {
|
|
30
|
+
AddUsersFailureReasons["NON_FEDERATING_BACKENDS"] = "NON_FEDERATING_BACKENDS";
|
|
31
|
+
AddUsersFailureReasons["UNREACHABLE_BACKENDS"] = "UNREACHABLE_BACKENDS";
|
|
32
|
+
})(AddUsersFailureReasons || (exports.AddUsersFailureReasons = AddUsersFailureReasons = {}));
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import type { APIClient } from '@wireapp/api-client/lib/APIClient';
|
|
2
2
|
import type { PreKey, Context } from '@wireapp/api-client/lib/auth';
|
|
3
|
-
import {
|
|
4
|
-
import type { ConversationMemberJoinEvent } from '@wireapp/api-client/lib/event';
|
|
3
|
+
import { NewConversation, QualifiedOTRRecipients, QualifiedUserClients } from '@wireapp/api-client/lib/conversation';
|
|
5
4
|
import type { QualifiedId, QualifiedUserPreKeyBundleMap } from '@wireapp/api-client/lib/user';
|
|
6
5
|
import { CRUDEngine } from '@wireapp/store-engine';
|
|
7
6
|
import { CryptoClient } from './CryptoClient';
|
|
8
7
|
import type { AddUsersToProteusConversationParams, ProteusServiceConfig, SendProteusMessageParams } from './ProteusService.types';
|
|
9
|
-
import {
|
|
8
|
+
import { ProteusCreateConversationResponse, SendResult, ProteusAddUsersResponse } from '../../../conversation';
|
|
10
9
|
import type { EventHandlerResult } from '../../common.types';
|
|
11
10
|
import { EventHandlerParams } from '../EventHandler';
|
|
12
11
|
export type EncryptionResult = {
|
|
@@ -40,18 +39,12 @@ export declare class ProteusService {
|
|
|
40
39
|
* If not provided and the session doesn't exists it will fetch a new prekey from the backend
|
|
41
40
|
*/
|
|
42
41
|
getRemoteFingerprint(userId: QualifiedId, clientId: string, prekey?: PreKey): Promise<string>;
|
|
43
|
-
createConversation(conversationData: NewConversation): Promise<
|
|
42
|
+
createConversation(conversationData: NewConversation): Promise<ProteusCreateConversationResponse>;
|
|
44
43
|
/**
|
|
45
44
|
* Tries to add all the given users to the given conversation.
|
|
46
45
|
* If some users are not reachable, it will try to add the remaining users and list them in the `failedToAdd` property of the response.
|
|
47
46
|
*/
|
|
48
|
-
addUsersToConversation({ conversationId, qualifiedUsers }: AddUsersToProteusConversationParams): Promise<
|
|
49
|
-
event?: ConversationMemberJoinEvent;
|
|
50
|
-
failedToAdd?: {
|
|
51
|
-
reason: AddUsersFailureReasons;
|
|
52
|
-
users: QualifiedId[];
|
|
53
|
-
};
|
|
54
|
-
}>;
|
|
47
|
+
addUsersToConversation({ conversationId, qualifiedUsers, }: AddUsersToProteusConversationParams): Promise<ProteusAddUsersResponse>;
|
|
55
48
|
sendMessage({ userIds, conversationId, nativePush, targetMode, payload, onClientMismatch, }: SendProteusMessageParams): Promise<SendResult>;
|
|
56
49
|
private decrypt;
|
|
57
50
|
deleteSession(userId: QualifiedId, clientId: string): Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProteusService.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,8BAA8B,CAAC;AAClE,OAAO,
|
|
1
|
+
{"version":3,"file":"ProteusService.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AACjE,OAAO,KAAK,EAAC,MAAM,EAAE,OAAO,EAAC,MAAM,8BAA8B,CAAC;AAClE,OAAO,EAGL,eAAe,EACf,sBAAsB,EACtB,oBAAoB,EACrB,MAAM,sCAAsC,CAAC;AAC9C,OAAO,KAAK,EAAC,WAAW,EAAE,4BAA4B,EAAC,MAAM,8BAA8B,CAAC;AAI5F,OAAO,EAAC,UAAU,EAAC,MAAM,uBAAuB,CAAC;AAEjD,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAI5C,OAAO,KAAK,EACV,mCAAmC,EACnC,oBAAoB,EACpB,wBAAwB,EACzB,MAAM,wBAAwB,CAAC;AAIhC,OAAO,EAEL,iCAAiC,EAGjC,UAAU,EACV,uBAAuB,EACxB,MAAM,uBAAuB,CAAC;AAG/B,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,oBAAoB,CAAC;AAC3D,OAAO,EAAC,kBAAkB,EAAqB,MAAM,iBAA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EAAE,wBAAwB,GAAG,OAAO,CAAC,UAAU,CAAC;YA6CnC,OAAO;IAuBd,aAAa,CAAC,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM;IAQ7C,OAAO,CAClB,SAAS,EAAE,UAAU,EACrB,UAAU,EAAE,4BAA4B,GAAG,oBAAoB,GAC9D,OAAO,CAAC,gBAAgB,CAAC;IAiBtB,IAAI,CAAC,WAAW,CAAC,EAAE,UAAU;CAMpC"}
|
|
@@ -110,7 +110,8 @@ class ProteusService {
|
|
|
110
110
|
async createConversation(conversationData) {
|
|
111
111
|
var _a;
|
|
112
112
|
try {
|
|
113
|
-
|
|
113
|
+
const conversation = await this.apiClient.api.conversation.postConversation(conversationData);
|
|
114
|
+
return { conversation };
|
|
114
115
|
}
|
|
115
116
|
catch (error) {
|
|
116
117
|
if ((0, conversation_1.isFederatedBackendsError)(error)) {
|
|
@@ -126,10 +127,15 @@ class ProteusService {
|
|
|
126
127
|
// If conversation creation returns an error because a backend is offline,
|
|
127
128
|
// we try creating the conversation again with users from available backends
|
|
128
129
|
const response = await this.apiClient.api.conversation.postConversation(conversationData);
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
130
|
+
return {
|
|
131
|
+
conversation: response,
|
|
132
|
+
failedToAdd:
|
|
133
|
+
// on a succesfull conversation creation with the available users,
|
|
134
|
+
// we append the users from an unreachable backend to the response
|
|
135
|
+
unreachableUsers.length > 0
|
|
136
|
+
? { reason: conversation_2.AddUsersFailureReasons.UNREACHABLE_BACKENDS, users: unreachableUsers }
|
|
137
|
+
: undefined,
|
|
138
|
+
};
|
|
133
139
|
}
|
|
134
140
|
}
|
|
135
141
|
}
|
|
@@ -140,7 +146,7 @@ class ProteusService {
|
|
|
140
146
|
* Tries to add all the given users to the given conversation.
|
|
141
147
|
* If some users are not reachable, it will try to add the remaining users and list them in the `failedToAdd` property of the response.
|
|
142
148
|
*/
|
|
143
|
-
async addUsersToConversation({ conversationId, qualifiedUsers }) {
|
|
149
|
+
async addUsersToConversation({ conversationId, qualifiedUsers, }) {
|
|
144
150
|
try {
|
|
145
151
|
return { event: await this.apiClient.api.conversation.postMembers(conversationId, qualifiedUsers) };
|
|
146
152
|
}
|
|
@@ -52,6 +52,7 @@ const notification_1 = require("../../../notification");
|
|
|
52
52
|
const event_1 = require("@wireapp/api-client/lib/event");
|
|
53
53
|
const protocol_messaging_1 = require("@wireapp/protocol-messaging");
|
|
54
54
|
const errors_1 = require("../../../errors");
|
|
55
|
+
const testUtils_1 = require("../../../testUtils");
|
|
55
56
|
jest.mock('./CryptoClient/CoreCryptoWrapper/PrekeysTracker', () => {
|
|
56
57
|
return {
|
|
57
58
|
PrekeyTracker: jest.fn().mockImplementation(() => {
|
|
@@ -123,11 +124,17 @@ const prepareDataForEncryption = async () => {
|
|
|
123
124
|
};
|
|
124
125
|
};
|
|
125
126
|
describe('ProteusService', () => {
|
|
127
|
+
const domain1 = 'domain1';
|
|
128
|
+
const domain2 = 'domain2';
|
|
129
|
+
const domain3 = 'domain3';
|
|
130
|
+
const usersDomain1 = (0, testUtils_1.generateQualifiedIds)(3, domain1);
|
|
131
|
+
const usersDomain2 = (0, testUtils_1.generateQualifiedIds)(3, domain2);
|
|
132
|
+
const usersDomain3 = (0, testUtils_1.generateQualifiedIds)(3, domain3);
|
|
126
133
|
describe('getRemoteFingerprint', () => {
|
|
127
134
|
it('create a session if session does not exists', async () => {
|
|
128
135
|
const [proteusService, { apiClient, cryptoClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
129
136
|
const expectedFingerprint = 'fingerprint-client1';
|
|
130
|
-
const userId =
|
|
137
|
+
const userId = (0, testUtils_1.generateQualifiedId)('domain');
|
|
131
138
|
const clientId = 'client1';
|
|
132
139
|
jest.spyOn(apiClient.api.user, 'postMultiPreKeyBundles').mockResolvedValue({
|
|
133
140
|
qualified_user_client_prekeys: {
|
|
@@ -156,7 +163,7 @@ describe('ProteusService', () => {
|
|
|
156
163
|
const saveSessionSpy = jest.spyOn(cryptoClient, 'sessionFromPrekey').mockResolvedValue(undefined);
|
|
157
164
|
jest.spyOn(cryptoClient, 'saveSession').mockResolvedValue(undefined);
|
|
158
165
|
jest.spyOn(cryptoClient, 'sessionExists').mockResolvedValue(false);
|
|
159
|
-
const userId =
|
|
166
|
+
const userId = (0, testUtils_1.generateQualifiedId)('domain');
|
|
160
167
|
const clientId = 'client1';
|
|
161
168
|
const result = await proteusService.getRemoteFingerprint(userId, clientId, {
|
|
162
169
|
key: 'pQABARhIAqEAWCCaJpFa9c626ORmjj1aV6OnOYgmTjfoiE3ynOfNfGAOmgOhAKEAWCD60VMzRrLfO+1GSjgyhnVp2N7L58DM+eeJhZJi1tBLfQT2',
|
|
@@ -173,7 +180,7 @@ describe('ProteusService', () => {
|
|
|
173
180
|
const sessionFromPrekeyMock = jest.spyOn(cryptoClient, 'sessionFromPrekey');
|
|
174
181
|
jest.spyOn(cryptoClient, 'getRemoteFingerprint').mockResolvedValue(expectedFingerprint);
|
|
175
182
|
jest.spyOn(cryptoClient, 'sessionExists').mockResolvedValue(true);
|
|
176
|
-
const userId =
|
|
183
|
+
const userId = (0, testUtils_1.generateQualifiedId)('domain');
|
|
177
184
|
const clientId = 'client1';
|
|
178
185
|
const result = await proteusService.getRemoteFingerprint(userId, clientId);
|
|
179
186
|
expect(getPrekeyMock).not.toHaveBeenCalled();
|
|
@@ -185,7 +192,7 @@ describe('ProteusService', () => {
|
|
|
185
192
|
const eventPayload = {
|
|
186
193
|
event: {
|
|
187
194
|
type: event_1.CONVERSATION_EVENT.OTR_MESSAGE_ADD,
|
|
188
|
-
qualified_from:
|
|
195
|
+
qualified_from: (0, testUtils_1.generateQualifiedId)('domain'),
|
|
189
196
|
data: { sender: 'client1', text: '' },
|
|
190
197
|
},
|
|
191
198
|
source: notification_1.NotificationSource.WEBSOCKET,
|
|
@@ -334,7 +341,7 @@ describe('ProteusService', () => {
|
|
|
334
341
|
const [proteusService] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
335
342
|
let errorMessage;
|
|
336
343
|
const params = {
|
|
337
|
-
conversationId:
|
|
344
|
+
conversationId: (0, testUtils_1.generateQualifiedId)('domain'),
|
|
338
345
|
payload: message,
|
|
339
346
|
protocol: conversation_1.ConversationProtocol.PROTEUS,
|
|
340
347
|
targetMode: conversation_2.MessageTargetMode.USERS,
|
|
@@ -465,7 +472,7 @@ describe('ProteusService', () => {
|
|
|
465
472
|
});
|
|
466
473
|
const result = await proteusService.sendMessage({
|
|
467
474
|
protocol: conversation_1.ConversationProtocol.PROTEUS,
|
|
468
|
-
conversationId:
|
|
475
|
+
conversationId: (0, testUtils_1.generateQualifiedId)('domain'),
|
|
469
476
|
payload: message,
|
|
470
477
|
targetMode: conversation_2.MessageTargetMode.USERS_CLIENTS,
|
|
471
478
|
userIds: recipients,
|
|
@@ -485,17 +492,13 @@ describe('ProteusService', () => {
|
|
|
485
492
|
type: event_1.CONVERSATION_EVENT.MEMBER_JOIN,
|
|
486
493
|
},
|
|
487
494
|
};
|
|
488
|
-
const conversationId =
|
|
489
|
-
const userDomain1 = { id: 'user-1-1', domain: 'domain1' };
|
|
490
|
-
const user2Domain1 = { id: 'user-2-1', domain: 'domain1' };
|
|
491
|
-
const userDomain2 = { id: 'user-1-2', domain: 'domain2' };
|
|
492
|
-
const userDomain3 = { id: 'user-1-3', domain: 'domain3' };
|
|
495
|
+
const conversationId = (0, testUtils_1.generateQualifiedId)('domain');
|
|
493
496
|
it('adds all requested users to an existing conversation', async () => {
|
|
494
497
|
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
495
498
|
jest.spyOn(apiClient.api.conversation, 'postMembers').mockResolvedValueOnce(baseResponse.event);
|
|
496
499
|
const event = await proteusService.addUsersToConversation({
|
|
497
500
|
conversationId,
|
|
498
|
-
qualifiedUsers: [
|
|
501
|
+
qualifiedUsers: [...usersDomain1, ...usersDomain2],
|
|
499
502
|
});
|
|
500
503
|
expect(event).toEqual(baseResponse);
|
|
501
504
|
});
|
|
@@ -504,37 +507,34 @@ describe('ProteusService', () => {
|
|
|
504
507
|
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
505
508
|
const postMembersSpy = jest
|
|
506
509
|
.spyOn(apiClient.api.conversation, 'postMembers')
|
|
507
|
-
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS, [
|
|
510
|
+
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS, [domain1]))
|
|
508
511
|
.mockResolvedValueOnce(baseResponse.event);
|
|
509
512
|
const result = await proteusService.addUsersToConversation({
|
|
510
513
|
conversationId,
|
|
511
|
-
qualifiedUsers: [
|
|
514
|
+
qualifiedUsers: [...usersDomain1, ...usersDomain2],
|
|
512
515
|
});
|
|
513
516
|
expect(postMembersSpy).toHaveBeenCalledTimes(2);
|
|
514
|
-
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining([
|
|
515
|
-
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining(
|
|
517
|
+
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining([...usersDomain1, ...usersDomain2]));
|
|
518
|
+
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining(usersDomain2));
|
|
516
519
|
expect((_a = result.failedToAdd) === null || _a === void 0 ? void 0 : _a.reason).toBe(conversation_2.AddUsersFailureReasons.UNREACHABLE_BACKENDS);
|
|
517
|
-
expect((_b = result.failedToAdd) === null || _b === void 0 ? void 0 : _b.users).toEqual([
|
|
520
|
+
expect((_b = result.failedToAdd) === null || _b === void 0 ? void 0 : _b.users).toEqual([...usersDomain1]);
|
|
518
521
|
});
|
|
519
522
|
it('partially add users if some users are part of not-connected backends', async () => {
|
|
520
523
|
var _a, _b;
|
|
521
524
|
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
522
525
|
const postMembersSpy = jest
|
|
523
526
|
.spyOn(apiClient.api.conversation, 'postMembers')
|
|
524
|
-
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.NON_FEDERATING_BACKENDS, [
|
|
525
|
-
userDomain2.domain,
|
|
526
|
-
userDomain3.domain,
|
|
527
|
-
]))
|
|
527
|
+
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.NON_FEDERATING_BACKENDS, [domain2, domain3]))
|
|
528
528
|
.mockResolvedValueOnce(baseResponse.event);
|
|
529
529
|
const result = await proteusService.addUsersToConversation({
|
|
530
530
|
conversationId,
|
|
531
|
-
qualifiedUsers: [
|
|
531
|
+
qualifiedUsers: [...usersDomain1, ...usersDomain2, ...usersDomain3],
|
|
532
532
|
});
|
|
533
533
|
expect(postMembersSpy).toHaveBeenCalledTimes(2);
|
|
534
|
-
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining([
|
|
535
|
-
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining(
|
|
534
|
+
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining([...usersDomain1, ...usersDomain2]));
|
|
535
|
+
expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining(usersDomain1));
|
|
536
536
|
expect((_a = result.failedToAdd) === null || _a === void 0 ? void 0 : _a.reason).toBe(conversation_2.AddUsersFailureReasons.NON_FEDERATING_BACKENDS);
|
|
537
|
-
expect((_b = result.failedToAdd) === null || _b === void 0 ? void 0 : _b.users).toEqual([
|
|
537
|
+
expect((_b = result.failedToAdd) === null || _b === void 0 ? void 0 : _b.users).toEqual([...usersDomain2, ...usersDomain3]);
|
|
538
538
|
});
|
|
539
539
|
});
|
|
540
540
|
describe('createConversation', () => {
|
|
@@ -559,65 +559,62 @@ describe('ProteusService', () => {
|
|
|
559
559
|
status_time: '',
|
|
560
560
|
},
|
|
561
561
|
},
|
|
562
|
-
failed_to_add: [],
|
|
563
562
|
protocol: conversation_1.ConversationProtocol.PROTEUS,
|
|
564
563
|
};
|
|
565
|
-
const userDomain1 = { id: 'user-1-1', domain: 'domain1' };
|
|
566
|
-
const user2Domain1 = { id: 'user-2-1', domain: 'domain1' };
|
|
567
|
-
const userDomain2 = { id: 'user-2-2', domain: 'domain2' };
|
|
568
564
|
it('adds all requested users to a new conversation', async () => {
|
|
569
565
|
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
570
566
|
jest.spyOn(apiClient.api.conversation, 'postConversation').mockResolvedValueOnce(Object.assign({}, newConversation));
|
|
571
567
|
const result = await proteusService.createConversation({
|
|
572
568
|
receipt_mode: null,
|
|
573
|
-
qualified_users: [
|
|
569
|
+
qualified_users: [...usersDomain1, ...usersDomain2, ...usersDomain3],
|
|
574
570
|
});
|
|
575
|
-
expect(result).toEqual(newConversation);
|
|
571
|
+
expect(result.conversation).toEqual(newConversation);
|
|
572
|
+
expect(result.failedToAdd).toBeUndefined();
|
|
576
573
|
});
|
|
577
574
|
it('partially add users if some backends are unreachable', async () => {
|
|
578
575
|
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
579
576
|
const postConversationSpy = jest
|
|
580
577
|
.spyOn(apiClient.api.conversation, 'postConversation')
|
|
581
|
-
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS, [
|
|
578
|
+
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS, [domain1]))
|
|
582
579
|
.mockResolvedValueOnce(newConversation);
|
|
583
|
-
const
|
|
580
|
+
const { failedToAdd } = await proteusService.createConversation({
|
|
584
581
|
receipt_mode: null,
|
|
585
|
-
qualified_users: [
|
|
582
|
+
qualified_users: [...usersDomain1, ...usersDomain2],
|
|
586
583
|
});
|
|
587
584
|
expect(postConversationSpy).toHaveBeenCalledTimes(2);
|
|
588
|
-
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: [
|
|
589
|
-
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users:
|
|
590
|
-
expect(
|
|
585
|
+
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: [...usersDomain1, ...usersDomain2] }));
|
|
586
|
+
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: usersDomain2 }));
|
|
587
|
+
expect(failedToAdd).toEqual({
|
|
588
|
+
reason: conversation_2.AddUsersFailureReasons.UNREACHABLE_BACKENDS,
|
|
589
|
+
users: expect.arrayContaining([...usersDomain1, ...usersDomain1]),
|
|
590
|
+
});
|
|
591
591
|
});
|
|
592
592
|
it('creates an empty conversation if no backend is reachable', async () => {
|
|
593
593
|
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
594
594
|
const postConversationSpy = jest
|
|
595
595
|
.spyOn(apiClient.api.conversation, 'postConversation')
|
|
596
|
-
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS, [
|
|
597
|
-
userDomain1.domain,
|
|
598
|
-
userDomain2.domain,
|
|
599
|
-
]))
|
|
596
|
+
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS, [domain1, domain2]))
|
|
600
597
|
.mockResolvedValueOnce({});
|
|
601
|
-
const
|
|
598
|
+
const { failedToAdd } = await proteusService.createConversation({
|
|
602
599
|
receipt_mode: null,
|
|
603
|
-
qualified_users: [
|
|
600
|
+
qualified_users: [...usersDomain1, ...usersDomain2],
|
|
604
601
|
});
|
|
605
602
|
expect(postConversationSpy).toHaveBeenCalledTimes(2);
|
|
606
|
-
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: [
|
|
603
|
+
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: [...usersDomain1, ...usersDomain2] }));
|
|
607
604
|
expect(postConversationSpy).toHaveBeenCalledWith(expect.objectContaining({ qualified_users: [] }));
|
|
608
|
-
expect(
|
|
605
|
+
expect(failedToAdd).toEqual({
|
|
606
|
+
reason: conversation_2.AddUsersFailureReasons.UNREACHABLE_BACKENDS,
|
|
607
|
+
users: expect.arrayContaining([...usersDomain1, ...usersDomain1]),
|
|
608
|
+
});
|
|
609
609
|
});
|
|
610
610
|
it('fails to create a conversation if there are users from non-connected backends', async () => {
|
|
611
611
|
const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
|
|
612
612
|
jest
|
|
613
613
|
.spyOn(apiClient.api.conversation, 'postConversation')
|
|
614
|
-
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.NON_FEDERATING_BACKENDS, [
|
|
615
|
-
userDomain1.domain,
|
|
616
|
-
userDomain2.domain,
|
|
617
|
-
]));
|
|
614
|
+
.mockRejectedValueOnce(new conversation_1.FederatedBackendsError(conversation_1.FederatedBackendsErrorLabel.NON_FEDERATING_BACKENDS, [domain1, domain2]));
|
|
618
615
|
await expect(() => proteusService.createConversation({
|
|
619
616
|
receipt_mode: null,
|
|
620
|
-
qualified_users: [
|
|
617
|
+
qualified_users: [...usersDomain1, ...usersDomain2],
|
|
621
618
|
})).rejects.toThrow(errors_1.NonFederatingBackendsError);
|
|
622
619
|
});
|
|
623
620
|
});
|
|
@@ -103,13 +103,13 @@ describe('createConversation', () => {
|
|
|
103
103
|
const proteusService = await prepareProteusService();
|
|
104
104
|
const conversationData = createConversationResult;
|
|
105
105
|
const returnData = await proteusService.createConversation(conversationData);
|
|
106
|
-
expect(returnData).toStrictEqual(createConversationResult);
|
|
106
|
+
expect(returnData.conversation).toStrictEqual(createConversationResult);
|
|
107
107
|
});
|
|
108
108
|
it('create a new conversation with no name', async () => {
|
|
109
109
|
const proteusService = await prepareProteusService();
|
|
110
110
|
const conversationData = { users: ['user1', 'user2'], receipt_mode: null };
|
|
111
111
|
const returnData = await proteusService.createConversation(conversationData);
|
|
112
|
-
expect(returnData).toStrictEqual(conversationData);
|
|
112
|
+
expect(returnData.conversation).toStrictEqual(conversationData);
|
|
113
113
|
});
|
|
114
114
|
});
|
|
115
115
|
});
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { QualifiedId } from '@wireapp/api-client/lib/user';
|
|
2
|
+
export declare function generateQualifiedId(domain: string): {
|
|
3
|
+
id: `${string}-${string}-${string}-${string}-${string}`;
|
|
4
|
+
domain: string;
|
|
5
|
+
};
|
|
6
|
+
export declare function generateQualifiedIds(nbUsers: number, domain: string): QualifiedId[];
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/testUtils/index.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAIzD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM;;;EAEjD;AAED,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,iBAMnE"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Wire
|
|
4
|
+
* Copyright (C) 2023 Wire Swiss GmbH
|
|
5
|
+
*
|
|
6
|
+
* This program is free software: you can redistribute it and/or modify
|
|
7
|
+
* it under the terms of the GNU General Public License as published by
|
|
8
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
9
|
+
* (at your option) any later version.
|
|
10
|
+
*
|
|
11
|
+
* This program is distributed in the hope that it will be useful,
|
|
12
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
13
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
14
|
+
* GNU General Public License for more details.
|
|
15
|
+
*
|
|
16
|
+
* You should have received a copy of the GNU General Public License
|
|
17
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
21
|
+
exports.generateQualifiedIds = exports.generateQualifiedId = void 0;
|
|
22
|
+
const crypto_1 = require("crypto");
|
|
23
|
+
function generateQualifiedId(domain) {
|
|
24
|
+
return { id: (0, crypto_1.randomUUID)(), domain };
|
|
25
|
+
}
|
|
26
|
+
exports.generateQualifiedId = generateQualifiedId;
|
|
27
|
+
function generateQualifiedIds(nbUsers, domain) {
|
|
28
|
+
const users = [];
|
|
29
|
+
for (let i = 0; i < nbUsers; i++) {
|
|
30
|
+
users.push(generateQualifiedId(domain));
|
|
31
|
+
}
|
|
32
|
+
return users;
|
|
33
|
+
}
|
|
34
|
+
exports.generateQualifiedIds = generateQualifiedIds;
|
package/package.json
CHANGED
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
"./lib/cryptography/AssetCryptography/crypto.node": "./lib/cryptography/AssetCryptography/crypto.browser.js"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@wireapp/api-client": "^25.2.
|
|
14
|
+
"@wireapp/api-client": "^25.2.2",
|
|
15
15
|
"@wireapp/commons": "^5.1.0",
|
|
16
16
|
"@wireapp/core-crypto": "1.0.0-rc.6",
|
|
17
17
|
"@wireapp/cryptobox": "12.8.0",
|
|
18
|
-
"@wireapp/promise-queue": "^2.2.
|
|
18
|
+
"@wireapp/promise-queue": "^2.2.1",
|
|
19
19
|
"@wireapp/protocol-messaging": "1.44.0",
|
|
20
20
|
"@wireapp/store-engine": "5.1.1",
|
|
21
21
|
"@wireapp/store-engine-dexie": "^2.1.3",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"fake-indexeddb": "^4.0.0",
|
|
44
44
|
"jest": "^29.2.1",
|
|
45
45
|
"jest-websocket-mock": "2.4.1",
|
|
46
|
-
"nock": "13.3.
|
|
46
|
+
"nock": "13.3.3",
|
|
47
47
|
"rimraf": "^3.0.2",
|
|
48
48
|
"typescript": "^5.0.4"
|
|
49
49
|
},
|
|
@@ -60,6 +60,6 @@
|
|
|
60
60
|
"test:coverage": "jest --coverage",
|
|
61
61
|
"watch": "tsc --watch"
|
|
62
62
|
},
|
|
63
|
-
"version": "41.2.
|
|
64
|
-
"gitHead": "
|
|
63
|
+
"version": "41.2.2",
|
|
64
|
+
"gitHead": "3697cef010797726548c209abc6a0376245b7d7a"
|
|
65
65
|
}
|