@wireapp/core 17.31.0 → 17.31.4
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/CHANGELOG.md +35 -0
- package/package.json +9 -9
- package/src/main/Account.js.map +0 -1
- package/src/main/Account.test.browser.js +0 -114
- package/src/main/Account.test.node.d.ts +0 -1
- package/src/main/Account.test.node.js +0 -214
- package/src/main/Account.test.node.js.map +0 -1
- package/src/main/Account.test.node.ts +0 -236
- package/src/main/Account.ts +0 -401
- package/src/main/CoreError.js.map +0 -1
- package/src/main/CoreError.ts +0 -30
- package/src/main/auth/LoginSanitizer.js.map +0 -1
- package/src/main/auth/LoginSanitizer.test.node.d.ts +0 -1
- package/src/main/auth/LoginSanitizer.test.node.js +0 -56
- package/src/main/auth/LoginSanitizer.test.node.js.map +0 -1
- package/src/main/auth/LoginSanitizer.test.node.ts +0 -68
- package/src/main/auth/LoginSanitizer.ts +0 -44
- package/src/main/auth/index.js.map +0 -1
- package/src/main/auth/index.ts +0 -20
- package/src/main/broadcast/AvailabilityType.js.map +0 -1
- package/src/main/broadcast/AvailabilityType.ts +0 -22
- package/src/main/broadcast/BroadcastService.js.map +0 -1
- package/src/main/broadcast/BroadcastService.ts +0 -66
- package/src/main/broadcast/index.js.map +0 -1
- package/src/main/broadcast/index.ts +0 -21
- package/src/main/client/ClientBackendRepository.js.map +0 -1
- package/src/main/client/ClientBackendRepository.ts +0 -33
- package/src/main/client/ClientDatabaseRepository.js.map +0 -1
- package/src/main/client/ClientDatabaseRepository.ts +0 -130
- package/src/main/client/ClientInfo.js.map +0 -1
- package/src/main/client/ClientInfo.ts +0 -28
- package/src/main/client/ClientService.js.map +0 -1
- package/src/main/client/ClientService.ts +0 -116
- package/src/main/client/index.js.map +0 -1
- package/src/main/client/index.ts +0 -23
- package/src/main/connection/ConnectionService.js.map +0 -1
- package/src/main/connection/ConnectionService.ts +0 -49
- package/src/main/connection/index.js.map +0 -1
- package/src/main/connection/index.ts +0 -20
- package/src/main/conversation/AbortReason.js.map +0 -1
- package/src/main/conversation/AbortReason.ts +0 -22
- package/src/main/conversation/AssetService.js.map +0 -1
- package/src/main/conversation/AssetService.test.node.d.ts +0 -1
- package/src/main/conversation/AssetService.test.node.js +0 -61
- package/src/main/conversation/AssetService.test.node.js.map +0 -1
- package/src/main/conversation/AssetService.test.node.ts +0 -65
- package/src/main/conversation/AssetService.ts +0 -60
- package/src/main/conversation/AssetTransferState.js.map +0 -1
- package/src/main/conversation/AssetTransferState.ts +0 -23
- package/src/main/conversation/ClientActionType.js.map +0 -1
- package/src/main/conversation/ClientActionType.ts +0 -20
- package/src/main/conversation/ConversationMapper.js.map +0 -1
- package/src/main/conversation/ConversationMapper.test.node.d.ts +0 -1
- package/src/main/conversation/ConversationMapper.test.node.js +0 -111
- package/src/main/conversation/ConversationMapper.test.node.js.map +0 -1
- package/src/main/conversation/ConversationMapper.test.node.ts +0 -154
- package/src/main/conversation/ConversationMapper.ts +0 -56
- package/src/main/conversation/ConversationService.js.map +0 -1
- package/src/main/conversation/ConversationService.test.node.d.ts +0 -1
- package/src/main/conversation/ConversationService.test.node.js +0 -344
- package/src/main/conversation/ConversationService.test.node.js.map +0 -1
- package/src/main/conversation/ConversationService.test.node.ts +0 -416
- package/src/main/conversation/ConversationService.ts +0 -1024
- package/src/main/conversation/GenericMessageType.js.map +0 -1
- package/src/main/conversation/GenericMessageType.ts +0 -44
- package/src/main/conversation/MessageTimer.js.map +0 -1
- package/src/main/conversation/MessageTimer.test.node.d.ts +0 -1
- package/src/main/conversation/MessageTimer.test.node.js +0 -88
- package/src/main/conversation/MessageTimer.test.node.js.map +0 -1
- package/src/main/conversation/MessageTimer.test.node.ts +0 -103
- package/src/main/conversation/MessageTimer.ts +0 -56
- package/src/main/conversation/ReactionType.js.map +0 -1
- package/src/main/conversation/ReactionType.ts +0 -23
- package/src/main/conversation/content/AssetContent.js.map +0 -1
- package/src/main/conversation/content/AssetContent.ts +0 -71
- package/src/main/conversation/content/ButtonActionConfirmationContent.js.map +0 -1
- package/src/main/conversation/content/ButtonActionConfirmationContent.ts +0 -21
- package/src/main/conversation/content/ButtonActionContent.js.map +0 -1
- package/src/main/conversation/content/ButtonActionContent.ts +0 -21
- package/src/main/conversation/content/CallingContent.js.map +0 -1
- package/src/main/conversation/content/CallingContent.ts +0 -20
- package/src/main/conversation/content/ClearedContent.js.map +0 -1
- package/src/main/conversation/content/ClearedContent.ts +0 -21
- package/src/main/conversation/content/ClientActionContent.js.map +0 -1
- package/src/main/conversation/content/ClientActionContent.ts +0 -22
- package/src/main/conversation/content/ClientAddContent.js.map +0 -1
- package/src/main/conversation/content/ClientAddContent.ts +0 -24
- package/src/main/conversation/content/ClientRemoveContent.js.map +0 -1
- package/src/main/conversation/content/ClientRemoveContent.ts +0 -25
- package/src/main/conversation/content/CompositeContent.js.map +0 -1
- package/src/main/conversation/content/CompositeContent.ts +0 -21
- package/src/main/conversation/content/ConfirmationContent.js.map +0 -1
- package/src/main/conversation/content/ConfirmationContent.ts +0 -21
- package/src/main/conversation/content/ContentType.js.map +0 -1
- package/src/main/conversation/content/ContentType.ts +0 -112
- package/src/main/conversation/content/ConversationContent.js.map +0 -1
- package/src/main/conversation/content/ConversationContent.ts +0 -71
- package/src/main/conversation/content/DeletedContent.js.map +0 -1
- package/src/main/conversation/content/DeletedContent.ts +0 -21
- package/src/main/conversation/content/EditedTextContent.js.map +0 -1
- package/src/main/conversation/content/EditedTextContent.ts +0 -31
- package/src/main/conversation/content/FileContent.js.map +0 -1
- package/src/main/conversation/content/FileContent.ts +0 -32
- package/src/main/conversation/content/HiddenContent.js.map +0 -1
- package/src/main/conversation/content/HiddenContent.ts +0 -21
- package/src/main/conversation/content/ImageContent.js.map +0 -1
- package/src/main/conversation/content/ImageContent.ts +0 -25
- package/src/main/conversation/content/KnockContent.js.map +0 -1
- package/src/main/conversation/content/KnockContent.ts +0 -21
- package/src/main/conversation/content/LinkPreviewContent.js.map +0 -1
- package/src/main/conversation/content/LinkPreviewContent.ts +0 -32
- package/src/main/conversation/content/LocationContent.js.map +0 -1
- package/src/main/conversation/content/LocationContent.ts +0 -29
- package/src/main/conversation/content/MentionContent.js.map +0 -1
- package/src/main/conversation/content/MentionContent.ts +0 -21
- package/src/main/conversation/content/QuoteContent.js.map +0 -1
- package/src/main/conversation/content/QuoteContent.ts +0 -29
- package/src/main/conversation/content/ReactionContent.js.map +0 -1
- package/src/main/conversation/content/ReactionContent.ts +0 -27
- package/src/main/conversation/content/TextContent.js.map +0 -1
- package/src/main/conversation/content/TextContent.ts +0 -29
- package/src/main/conversation/content/TweetContent.js.map +0 -1
- package/src/main/conversation/content/TweetContent.ts +0 -21
- package/src/main/conversation/content/index.js.map +0 -1
- package/src/main/conversation/content/index.ts +0 -49
- package/src/main/conversation/index.js.map +0 -1
- package/src/main/conversation/index.ts +0 -28
- package/src/main/conversation/message/CompositeContentBuilder.js.map +0 -1
- package/src/main/conversation/message/CompositeContentBuilder.ts +0 -60
- package/src/main/conversation/message/Message.js.map +0 -1
- package/src/main/conversation/message/Message.ts +0 -24
- package/src/main/conversation/message/MessageBuilder.js.map +0 -1
- package/src/main/conversation/message/MessageBuilder.test.browser.js +0 -27
- package/src/main/conversation/message/MessageBuilder.ts +0 -488
- package/src/main/conversation/message/MessageService.js.map +0 -1
- package/src/main/conversation/message/MessageService.test.node.d.ts +0 -1
- package/src/main/conversation/message/MessageService.test.node.js +0 -308
- package/src/main/conversation/message/MessageService.test.node.js.map +0 -1
- package/src/main/conversation/message/MessageService.test.node.ts +0 -398
- package/src/main/conversation/message/MessageService.ts +0 -383
- package/src/main/conversation/message/MessageToProtoMapper.js.map +0 -1
- package/src/main/conversation/message/MessageToProtoMapper.ts +0 -114
- package/src/main/conversation/message/OtrMessage.js.map +0 -1
- package/src/main/conversation/message/OtrMessage.ts +0 -160
- package/src/main/conversation/message/PayloadBundle.js.map +0 -1
- package/src/main/conversation/message/PayloadBundle.ts +0 -101
- package/src/main/conversation/message/TeamMessage.js.map +0 -1
- package/src/main/conversation/message/TeamMessage.ts +0 -72
- package/src/main/conversation/message/TextContentBuilder.js.map +0 -1
- package/src/main/conversation/message/TextContentBuilder.ts +0 -88
- package/src/main/conversation/message/UserClientsUtil.js.map +0 -1
- package/src/main/conversation/message/UserClientsUtil.ts +0 -44
- package/src/main/conversation/message/UserClientsUtils.test.node.d.ts +0 -1
- package/src/main/conversation/message/UserClientsUtils.test.node.js +0 -42
- package/src/main/conversation/message/UserClientsUtils.test.node.js.map +0 -1
- package/src/main/conversation/message/UserClientsUtils.test.node.ts +0 -44
- package/src/main/conversation/message/UserMessage.js.map +0 -1
- package/src/main/conversation/message/UserMessage.ts +0 -95
- package/src/main/cryptography/AssetCryptography.browser.js.map +0 -1
- package/src/main/cryptography/AssetCryptography.browser.ts +0 -76
- package/src/main/cryptography/AssetCryptography.node.js.map +0 -1
- package/src/main/cryptography/AssetCryptography.node.ts +0 -85
- package/src/main/cryptography/CryptographyDatabaseRepository.js.map +0 -1
- package/src/main/cryptography/CryptographyDatabaseRepository.ts +0 -44
- package/src/main/cryptography/CryptographyService.js.map +0 -1
- package/src/main/cryptography/CryptographyService.test.browser.js +0 -195
- package/src/main/cryptography/CryptographyService.test.node.d.ts +0 -1
- package/src/main/cryptography/CryptographyService.test.node.js +0 -228
- package/src/main/cryptography/CryptographyService.test.node.js.map +0 -1
- package/src/main/cryptography/CryptographyService.test.node.ts +0 -246
- package/src/main/cryptography/CryptographyService.ts +0 -246
- package/src/main/cryptography/EncryptedAsset.js.map +0 -1
- package/src/main/cryptography/EncryptedAsset.ts +0 -30
- package/src/main/cryptography/GenericMessageMapper.js.map +0 -1
- package/src/main/cryptography/GenericMessageMapper.ts +0 -274
- package/src/main/cryptography/MessageHashService.js.map +0 -1
- package/src/main/cryptography/MessageHashService.test.browser.js +0 -176
- package/src/main/cryptography/MessageHashService.test.node.d.ts +0 -1
- package/src/main/cryptography/MessageHashService.test.node.js +0 -138
- package/src/main/cryptography/MessageHashService.test.node.js.map +0 -1
- package/src/main/cryptography/MessageHashService.test.node.ts +0 -176
- package/src/main/cryptography/MessageHashService.ts +0 -109
- package/src/main/cryptography/SessionPayloadBundle.js.map +0 -1
- package/src/main/cryptography/SessionPayloadBundle.ts +0 -23
- package/src/main/cryptography/index.js.map +0 -1
- package/src/main/cryptography/index.ts +0 -23
- package/src/main/giphy/GiphyService.js.map +0 -1
- package/src/main/giphy/GiphyService.ts +0 -37
- package/src/main/giphy/index.js.map +0 -1
- package/src/main/giphy/index.ts +0 -20
- package/src/main/index.js.map +0 -1
- package/src/main/index.test.browser.js +0 -22
- package/src/main/index.ts +0 -34
- package/src/main/notification/NotificationBackendRepository.js.map +0 -1
- package/src/main/notification/NotificationBackendRepository.ts +0 -33
- package/src/main/notification/NotificationDatabaseRepository.js.map +0 -1
- package/src/main/notification/NotificationDatabaseRepository.ts +0 -74
- package/src/main/notification/NotificationService.js.map +0 -1
- package/src/main/notification/NotificationService.test.browser.js +0 -179
- package/src/main/notification/NotificationService.test.node.d.ts +0 -1
- package/src/main/notification/NotificationService.test.node.js +0 -99
- package/src/main/notification/NotificationService.test.node.js.map +0 -1
- package/src/main/notification/NotificationService.test.node.ts +0 -124
- package/src/main/notification/NotificationService.ts +0 -260
- package/src/main/notification/index.js.map +0 -1
- package/src/main/notification/index.ts +0 -20
- package/src/main/self/SelfService.js.map +0 -1
- package/src/main/self/SelfService.ts +0 -59
- package/src/main/self/index.js.map +0 -1
- package/src/main/self/index.ts +0 -20
- package/src/main/team/TeamService.js.map +0 -1
- package/src/main/team/TeamService.ts +0 -68
- package/src/main/team/index.js.map +0 -1
- package/src/main/team/index.ts +0 -20
- package/src/main/test/CryptographyHelper.js.map +0 -1
- package/src/main/test/CryptographyHelper.ts +0 -57
- package/src/main/test/PayloadHelper.js.map +0 -1
- package/src/main/test/PayloadHelper.ts +0 -60
- package/src/main/user/UserMapper.js.map +0 -1
- package/src/main/user/UserMapper.test.node.d.ts +0 -1
- package/src/main/user/UserMapper.test.node.js +0 -55
- package/src/main/user/UserMapper.test.node.js.map +0 -1
- package/src/main/user/UserMapper.test.node.ts +0 -63
- package/src/main/user/UserMapper.ts +0 -92
- package/src/main/user/UserService.js.map +0 -1
- package/src/main/user/UserService.test.node.js +0 -141
- package/src/main/user/UserService.ts +0 -98
- package/src/main/user/index.js.map +0 -1
- package/src/main/user/index.ts +0 -20
- package/src/main/util/TypePredicateUtil.js.map +0 -1
- package/src/main/util/TypePredicateUtil.test.node.d.ts +0 -1
- package/src/main/util/TypePredicateUtil.test.node.js +0 -42
- package/src/main/util/TypePredicateUtil.test.node.js.map +0 -1
- package/src/main/util/TypePredicateUtil.test.node.ts +0 -44
- package/src/main/util/TypePredicateUtil.ts +0 -52
- package/src/main/util/index.js.map +0 -1
- package/src/main/util/index.ts +0 -20
|
@@ -1,236 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Wire
|
|
3
|
-
* Copyright (C) 2018 Wire Swiss GmbH
|
|
4
|
-
*
|
|
5
|
-
* This program is free software: you can redistribute it and/or modify
|
|
6
|
-
* it under the terms of the GNU General Public License as published by
|
|
7
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
* (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This program is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
* GNU General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU General Public License
|
|
16
|
-
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import {StatusCodes as HTTP_STATUS} from 'http-status-codes';
|
|
21
|
-
import {APIClient} from '@wireapp/api-client';
|
|
22
|
-
import {AuthAPI} from '@wireapp/api-client/src/auth';
|
|
23
|
-
import {ClientAPI, ClientType, RegisteredClient} from '@wireapp/api-client/src/client';
|
|
24
|
-
import {Self, SelfAPI} from '@wireapp/api-client/src/self';
|
|
25
|
-
import {ConversationAPI} from '@wireapp/api-client/src/conversation';
|
|
26
|
-
import {BackendError, BackendErrorLabel} from '@wireapp/api-client/src/http';
|
|
27
|
-
import {Notification, NotificationAPI} from '@wireapp/api-client/src/notification';
|
|
28
|
-
import {AccentColor, ValidationUtil} from '@wireapp/commons';
|
|
29
|
-
import {GenericMessage, Text} from '@wireapp/protocol-messaging';
|
|
30
|
-
import * as Proteus from '@wireapp/proteus';
|
|
31
|
-
import {MemoryEngine} from '@wireapp/store-engine';
|
|
32
|
-
import nock = require('nock');
|
|
33
|
-
import {Account} from './Account';
|
|
34
|
-
import {PayloadBundleSource, PayloadBundleType} from './conversation';
|
|
35
|
-
|
|
36
|
-
const BASE_URL = 'mock-backend.wire.com';
|
|
37
|
-
const MOCK_BACKEND = {
|
|
38
|
-
name: 'mock',
|
|
39
|
-
rest: `https://${BASE_URL}`,
|
|
40
|
-
ws: `wss://${BASE_URL}`,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
async function createAccount(storageName = `test-${Date.now()}`): Promise<Account> {
|
|
44
|
-
const apiClient = new APIClient({urls: MOCK_BACKEND});
|
|
45
|
-
const account = new Account(apiClient);
|
|
46
|
-
await account.initServices(new MemoryEngine());
|
|
47
|
-
return account;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
describe('Account', () => {
|
|
51
|
-
const CLIENT_ID = '4e37b32f57f6da55';
|
|
52
|
-
|
|
53
|
-
const accessTokenData = {
|
|
54
|
-
access_token:
|
|
55
|
-
'iJCRCjc8oROO-dkrkqCXOade997oa8Jhbz6awMUQPBQo80VenWqp_oNvfY6AnU5BxEsdDPOBfBP-uz_b0gAKBQ==.v=1.k=1.d=1498600993.t=a.l=.u=aaf9a833-ef30-4c22-86a0-9adc8a15b3b4.c=15037015562284012115',
|
|
56
|
-
expires_in: 900,
|
|
57
|
-
token_type: 'Bearer',
|
|
58
|
-
user: 'aaf9a833-ef30-4c22-86a0-9adc8a15b3b4',
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
beforeAll(async () => {
|
|
62
|
-
await Proteus.init();
|
|
63
|
-
});
|
|
64
|
-
|
|
65
|
-
beforeEach(() => {
|
|
66
|
-
nock(MOCK_BACKEND.rest)
|
|
67
|
-
.post(AuthAPI.URL.LOGIN, body => body.email && body.password)
|
|
68
|
-
.query(() => true)
|
|
69
|
-
.reply((uri, body: any) => {
|
|
70
|
-
if (body.password === 'wrong') {
|
|
71
|
-
return [
|
|
72
|
-
HTTP_STATUS.FORBIDDEN,
|
|
73
|
-
JSON.stringify({
|
|
74
|
-
code: HTTP_STATUS.FORBIDDEN,
|
|
75
|
-
label: 'invalid-credentials',
|
|
76
|
-
message: 'Authentication failed.',
|
|
77
|
-
}),
|
|
78
|
-
];
|
|
79
|
-
}
|
|
80
|
-
return [HTTP_STATUS.OK, JSON.stringify(accessTokenData)];
|
|
81
|
-
});
|
|
82
|
-
|
|
83
|
-
nock(MOCK_BACKEND.rest).post(`${AuthAPI.URL.ACCESS}/${AuthAPI.URL.LOGOUT}`).reply(HTTP_STATUS.OK, undefined);
|
|
84
|
-
|
|
85
|
-
nock(MOCK_BACKEND.rest).post(AuthAPI.URL.ACCESS).reply(HTTP_STATUS.OK, accessTokenData);
|
|
86
|
-
|
|
87
|
-
nock(MOCK_BACKEND.rest).post(ClientAPI.URL.CLIENTS).reply(HTTP_STATUS.OK, {id: CLIENT_ID});
|
|
88
|
-
|
|
89
|
-
nock(MOCK_BACKEND.rest)
|
|
90
|
-
.post(
|
|
91
|
-
new RegExp(
|
|
92
|
-
`${ConversationAPI.URL.CONVERSATIONS}/.*/${ConversationAPI.URL.OTR}/${ConversationAPI.URL.MESSAGES}`,
|
|
93
|
-
),
|
|
94
|
-
)
|
|
95
|
-
.query({ignore_missing: false})
|
|
96
|
-
.reply(HTTP_STATUS.OK)
|
|
97
|
-
.persist();
|
|
98
|
-
|
|
99
|
-
nock(MOCK_BACKEND.rest)
|
|
100
|
-
.get(`${NotificationAPI.URL.NOTIFICATION}/${NotificationAPI.URL.LAST}`)
|
|
101
|
-
.query({client: CLIENT_ID})
|
|
102
|
-
.reply(HTTP_STATUS.OK, {});
|
|
103
|
-
|
|
104
|
-
nock(MOCK_BACKEND.rest)
|
|
105
|
-
.get(NotificationAPI.URL.NOTIFICATION)
|
|
106
|
-
.query({client: CLIENT_ID, size: 10000})
|
|
107
|
-
.reply(HTTP_STATUS.OK, {has_more: false, notifications: []})
|
|
108
|
-
.persist();
|
|
109
|
-
|
|
110
|
-
nock(MOCK_BACKEND.rest)
|
|
111
|
-
.get(ClientAPI.URL.CLIENTS)
|
|
112
|
-
.reply(HTTP_STATUS.OK, [{id: CLIENT_ID}] as RegisteredClient[]);
|
|
113
|
-
|
|
114
|
-
nock(MOCK_BACKEND.rest)
|
|
115
|
-
.get(SelfAPI.URL.SELF)
|
|
116
|
-
.reply(HTTP_STATUS.OK, {
|
|
117
|
-
email: 'email@example.com',
|
|
118
|
-
handle: 'exampleuser',
|
|
119
|
-
locale: 'en',
|
|
120
|
-
qualified_id: {
|
|
121
|
-
domain: 'example.com',
|
|
122
|
-
id: '024174ec-c098-4104-9424-3849804acb78',
|
|
123
|
-
},
|
|
124
|
-
accent_id: AccentColor.AccentColorID.BRIGHT_ORANGE,
|
|
125
|
-
picture: [],
|
|
126
|
-
name: 'Example User',
|
|
127
|
-
id: '024174ec-c098-4104-9424-3849804acb78',
|
|
128
|
-
assets: [],
|
|
129
|
-
} as Self);
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
describe('"createText"', () => {
|
|
133
|
-
it('creates a text payload', async () => {
|
|
134
|
-
const account = await createAccount();
|
|
135
|
-
|
|
136
|
-
await account.login({
|
|
137
|
-
clientType: ClientType.TEMPORARY,
|
|
138
|
-
email: 'hello@example.com',
|
|
139
|
-
password: 'my-secret',
|
|
140
|
-
});
|
|
141
|
-
|
|
142
|
-
expect(account['apiClient'].context!.userId).toBeDefined();
|
|
143
|
-
|
|
144
|
-
const text = 'FIFA World Cup';
|
|
145
|
-
const payload = account.service!.conversation.messageBuilder.createText({conversationId: '', text}).build();
|
|
146
|
-
|
|
147
|
-
expect(payload.timestamp).toBeGreaterThan(0);
|
|
148
|
-
});
|
|
149
|
-
});
|
|
150
|
-
|
|
151
|
-
describe('"init"', () => {
|
|
152
|
-
it('initializes the Protocol buffers', async () => {
|
|
153
|
-
const account = new Account();
|
|
154
|
-
|
|
155
|
-
await account.initServices(new MemoryEngine());
|
|
156
|
-
|
|
157
|
-
expect(account.service!.conversation).toBeDefined();
|
|
158
|
-
expect(account.service!.cryptography).toBeDefined();
|
|
159
|
-
|
|
160
|
-
const message = GenericMessage.create({
|
|
161
|
-
messageId: '2d7cb6d8-118f-11e8-b642-0ed5f89f718b',
|
|
162
|
-
text: Text.create({content: 'Hello, World!'}),
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
expect(message.content).toBe('text');
|
|
166
|
-
});
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
describe('"login"', () => {
|
|
170
|
-
it('logs in with correct credentials', async () => {
|
|
171
|
-
const apiClient = new APIClient({urls: MOCK_BACKEND});
|
|
172
|
-
const account = new Account(apiClient);
|
|
173
|
-
|
|
174
|
-
await account.initServices(new MemoryEngine());
|
|
175
|
-
const {clientId, clientType, userId} = await account.login({
|
|
176
|
-
clientType: ClientType.TEMPORARY,
|
|
177
|
-
email: 'hello@example.com',
|
|
178
|
-
password: 'my-secret',
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
expect(clientId).toBe(CLIENT_ID);
|
|
182
|
-
expect(ValidationUtil.isUUIDv4(userId)).toBe(true);
|
|
183
|
-
expect(clientType).toBe(ClientType.TEMPORARY);
|
|
184
|
-
});
|
|
185
|
-
|
|
186
|
-
it('does not log in with incorrect credentials', async () => {
|
|
187
|
-
const apiClient = new APIClient({urls: MOCK_BACKEND});
|
|
188
|
-
const account = new Account(apiClient);
|
|
189
|
-
|
|
190
|
-
await account.initServices(new MemoryEngine());
|
|
191
|
-
|
|
192
|
-
try {
|
|
193
|
-
await account.login({
|
|
194
|
-
clientType: ClientType.TEMPORARY,
|
|
195
|
-
email: 'hello@example.com',
|
|
196
|
-
password: 'wrong',
|
|
197
|
-
});
|
|
198
|
-
|
|
199
|
-
fail('Should not be logged in');
|
|
200
|
-
} catch (error) {
|
|
201
|
-
const backendError = error as BackendError;
|
|
202
|
-
expect(backendError.code).toBe(HTTP_STATUS.FORBIDDEN);
|
|
203
|
-
expect(backendError.label).toBe(BackendErrorLabel.INVALID_CREDENTIALS);
|
|
204
|
-
}
|
|
205
|
-
});
|
|
206
|
-
});
|
|
207
|
-
|
|
208
|
-
it('emits text messages', async done => {
|
|
209
|
-
const account = await createAccount();
|
|
210
|
-
|
|
211
|
-
await account.login({
|
|
212
|
-
clientType: ClientType.TEMPORARY,
|
|
213
|
-
email: 'hello@example.com',
|
|
214
|
-
password: 'my-secret',
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
await account.listen();
|
|
218
|
-
|
|
219
|
-
spyOn<any>(account.service!.notification, 'handleEvent').and.returnValue({type: PayloadBundleType.TEXT});
|
|
220
|
-
account.service!.notification.on(PayloadBundleType.TEXT, message => {
|
|
221
|
-
expect(message.type).toBe(PayloadBundleType.TEXT);
|
|
222
|
-
});
|
|
223
|
-
account.on(PayloadBundleType.TEXT, message => {
|
|
224
|
-
expect(message.type).toBe(PayloadBundleType.TEXT);
|
|
225
|
-
done();
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
await account.service!.notification.handleNotification(
|
|
229
|
-
{
|
|
230
|
-
payload: [{}],
|
|
231
|
-
transient: true,
|
|
232
|
-
} as unknown as Notification,
|
|
233
|
-
PayloadBundleSource.WEBSOCKET,
|
|
234
|
-
);
|
|
235
|
-
});
|
|
236
|
-
});
|
package/src/main/Account.ts
DELETED
|
@@ -1,401 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Wire
|
|
3
|
-
* Copyright (C) 2018 Wire Swiss GmbH
|
|
4
|
-
*
|
|
5
|
-
* This program is free software: you can redistribute it and/or modify
|
|
6
|
-
* it under the terms of the GNU General Public License as published by
|
|
7
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
* (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This program is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
* GNU General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU General Public License
|
|
16
|
-
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import type {AxiosError} from 'axios';
|
|
21
|
-
import {StatusCodes as HTTP_STATUS} from 'http-status-codes';
|
|
22
|
-
import {APIClient} from '@wireapp/api-client';
|
|
23
|
-
import type {RegisterData} from '@wireapp/api-client/src/auth';
|
|
24
|
-
import {AUTH_COOKIE_KEY, AUTH_TABLE_NAME, Context, Cookie, CookieStore, LoginData} from '@wireapp/api-client/src/auth/';
|
|
25
|
-
import {ClientType, RegisteredClient} from '@wireapp/api-client/src/client/';
|
|
26
|
-
import * as Events from '@wireapp/api-client/src/event';
|
|
27
|
-
import {WebSocketClient} from '@wireapp/api-client/src/tcp/';
|
|
28
|
-
import * as cryptobox from '@wireapp/cryptobox';
|
|
29
|
-
import {CRUDEngine, MemoryEngine, error as StoreEngineError} from '@wireapp/store-engine';
|
|
30
|
-
import {EventEmitter} from 'events';
|
|
31
|
-
import logdown from 'logdown';
|
|
32
|
-
|
|
33
|
-
import {LoginSanitizer} from './auth/';
|
|
34
|
-
import {BroadcastService} from './broadcast/';
|
|
35
|
-
import {ClientInfo, ClientService} from './client/';
|
|
36
|
-
import {ConnectionService} from './connection/';
|
|
37
|
-
import {
|
|
38
|
-
AssetService,
|
|
39
|
-
ConversationService,
|
|
40
|
-
PayloadBundle,
|
|
41
|
-
PayloadBundleSource,
|
|
42
|
-
PayloadBundleType,
|
|
43
|
-
} from './conversation/';
|
|
44
|
-
import * as OtrMessage from './conversation/message/OtrMessage';
|
|
45
|
-
import * as UserMessage from './conversation/message/UserMessage';
|
|
46
|
-
import type {CoreError, NotificationError} from './CoreError';
|
|
47
|
-
import {CryptographyService} from './cryptography/';
|
|
48
|
-
import {GiphyService} from './giphy/';
|
|
49
|
-
import {NotificationHandler, NotificationService} from './notification/';
|
|
50
|
-
import {SelfService} from './self/';
|
|
51
|
-
import {TeamService} from './team/';
|
|
52
|
-
import {UserService} from './user/';
|
|
53
|
-
import {AccountService} from './account/';
|
|
54
|
-
|
|
55
|
-
enum TOPIC {
|
|
56
|
-
ERROR = 'Account.TOPIC.ERROR',
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export interface Account {
|
|
60
|
-
on(
|
|
61
|
-
event: PayloadBundleType.ASSET,
|
|
62
|
-
listener: (payload: OtrMessage.FileAssetMessage | OtrMessage.ImageAssetMessage) => void,
|
|
63
|
-
): this;
|
|
64
|
-
on(event: PayloadBundleType.BUTTON_ACTION, listener: (payload: OtrMessage.ButtonActionMessage) => void): this;
|
|
65
|
-
on(event: PayloadBundleType.ASSET_ABORT, listener: (payload: OtrMessage.FileAssetAbortMessage) => void): this;
|
|
66
|
-
on(event: PayloadBundleType.ASSET_IMAGE, listener: (payload: OtrMessage.ImageAssetMessage) => void): this;
|
|
67
|
-
on(event: PayloadBundleType.ASSET_META, listener: (payload: OtrMessage.FileAssetMetaDataMessage) => void): this;
|
|
68
|
-
on(event: PayloadBundleType.CALL, listener: (payload: OtrMessage.CallMessage) => void): this;
|
|
69
|
-
on(event: PayloadBundleType.CLIENT_ACTION, listener: (payload: OtrMessage.ResetSessionMessage) => void): this;
|
|
70
|
-
on(event: PayloadBundleType.CLIENT_ADD, listener: (payload: UserMessage.UserClientAddMessage) => void): this;
|
|
71
|
-
on(event: PayloadBundleType.CLIENT_REMOVE, listener: (payload: UserMessage.UserClientRemoveMessage) => void): this;
|
|
72
|
-
on(event: PayloadBundleType.CONFIRMATION, listener: (payload: OtrMessage.ConfirmationMessage) => void): this;
|
|
73
|
-
on(event: PayloadBundleType.CONNECTION_REQUEST, listener: (payload: UserMessage.UserConnectionMessage) => void): this;
|
|
74
|
-
on(event: PayloadBundleType.USER_UPDATE, listener: (payload: UserMessage.UserUpdateMessage) => void): this;
|
|
75
|
-
on(
|
|
76
|
-
event: PayloadBundleType.CONVERSATION_CLEAR,
|
|
77
|
-
listener: (payload: OtrMessage.ClearConversationMessage) => void,
|
|
78
|
-
): this;
|
|
79
|
-
on(event: PayloadBundleType.CONVERSATION_RENAME, listener: (payload: Events.ConversationRenameEvent) => void): this;
|
|
80
|
-
on(event: PayloadBundleType.LOCATION, listener: (payload: OtrMessage.LocationMessage) => void): this;
|
|
81
|
-
on(event: PayloadBundleType.MEMBER_JOIN, listener: (payload: Events.TeamMemberJoinEvent) => void): this;
|
|
82
|
-
on(event: PayloadBundleType.MESSAGE_DELETE, listener: (payload: OtrMessage.DeleteMessage) => void): this;
|
|
83
|
-
on(event: PayloadBundleType.MESSAGE_EDIT, listener: (payload: OtrMessage.EditedTextMessage) => void): this;
|
|
84
|
-
on(event: PayloadBundleType.MESSAGE_HIDE, listener: (payload: OtrMessage.HideMessage) => void): this;
|
|
85
|
-
on(event: PayloadBundleType.PING, listener: (payload: OtrMessage.PingMessage) => void): this;
|
|
86
|
-
on(event: PayloadBundleType.REACTION, listener: (payload: OtrMessage.ReactionMessage) => void): this;
|
|
87
|
-
on(event: PayloadBundleType.TEXT, listener: (payload: OtrMessage.TextMessage) => void): this;
|
|
88
|
-
on(
|
|
89
|
-
event: PayloadBundleType.TIMER_UPDATE,
|
|
90
|
-
listener: (payload: Events.ConversationMessageTimerUpdateEvent) => void,
|
|
91
|
-
): this;
|
|
92
|
-
on(event: PayloadBundleType.TYPING, listener: (payload: Events.ConversationTypingEvent) => void): this;
|
|
93
|
-
on(event: PayloadBundleType.UNKNOWN, listener: (payload: any) => void): this;
|
|
94
|
-
on(event: TOPIC.ERROR, listener: (payload: CoreError) => void): this;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export type StoreEngineProvider = (storeName: string) => Promise<CRUDEngine>;
|
|
98
|
-
|
|
99
|
-
type AccountConfig = {
|
|
100
|
-
federationDomain?: string;
|
|
101
|
-
};
|
|
102
|
-
|
|
103
|
-
export class Account extends EventEmitter {
|
|
104
|
-
private readonly apiClient: APIClient;
|
|
105
|
-
private readonly logger: logdown.Logger;
|
|
106
|
-
private readonly storeEngineProvider: StoreEngineProvider;
|
|
107
|
-
private storeEngine?: CRUDEngine;
|
|
108
|
-
|
|
109
|
-
public static readonly TOPIC = TOPIC;
|
|
110
|
-
public service?: {
|
|
111
|
-
account: AccountService;
|
|
112
|
-
asset: AssetService;
|
|
113
|
-
broadcast: BroadcastService;
|
|
114
|
-
client: ClientService;
|
|
115
|
-
connection: ConnectionService;
|
|
116
|
-
conversation: ConversationService;
|
|
117
|
-
cryptography: CryptographyService;
|
|
118
|
-
giphy: GiphyService;
|
|
119
|
-
notification: NotificationService;
|
|
120
|
-
self: SelfService;
|
|
121
|
-
team: TeamService;
|
|
122
|
-
user: UserService;
|
|
123
|
-
};
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
|
|
127
|
-
* @param storeEngineProvider Used to store info in the database (will create a inMemory engine if undefined)
|
|
128
|
-
* @param config.federationDomain If using a federated backend this will set the default domain for qualified ids. Do not set if using a regular backend
|
|
129
|
-
*/
|
|
130
|
-
constructor(
|
|
131
|
-
apiClient: APIClient = new APIClient(),
|
|
132
|
-
storeEngineProvider?: StoreEngineProvider,
|
|
133
|
-
private readonly config?: AccountConfig,
|
|
134
|
-
) {
|
|
135
|
-
super();
|
|
136
|
-
this.apiClient = apiClient;
|
|
137
|
-
if (storeEngineProvider) {
|
|
138
|
-
this.storeEngineProvider = storeEngineProvider;
|
|
139
|
-
} else {
|
|
140
|
-
this.storeEngineProvider = async (storeName: string) => {
|
|
141
|
-
const engine = new MemoryEngine();
|
|
142
|
-
await engine.init(storeName);
|
|
143
|
-
return engine;
|
|
144
|
-
};
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
apiClient.on(APIClient.TOPIC.COOKIE_REFRESH, async (cookie?: Cookie) => {
|
|
148
|
-
if (cookie && this.storeEngine) {
|
|
149
|
-
try {
|
|
150
|
-
await this.persistCookie(this.storeEngine, cookie);
|
|
151
|
-
} catch (error) {
|
|
152
|
-
this.logger.error(`Failed to save cookie: ${(error as Error).message}`, error);
|
|
153
|
-
}
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
this.logger = logdown('@wireapp/core/Account', {
|
|
158
|
-
logger: console,
|
|
159
|
-
markdown: false,
|
|
160
|
-
});
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
private persistCookie(storeEngine: CRUDEngine, cookie: Cookie): Promise<string> {
|
|
164
|
-
const entity = {expiration: cookie.expiration, zuid: cookie.zuid};
|
|
165
|
-
return storeEngine.updateOrCreate(AUTH_TABLE_NAME, AUTH_COOKIE_KEY, entity);
|
|
166
|
-
}
|
|
167
|
-
|
|
168
|
-
get clientId(): string {
|
|
169
|
-
return this.apiClient.validatedClientId;
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
get userId(): string {
|
|
173
|
-
return this.apiClient.validatedUserId;
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
public async register(registration: RegisterData, clientType: ClientType): Promise<Context> {
|
|
177
|
-
const context = await this.apiClient.register(registration, clientType);
|
|
178
|
-
const storeEngine = await this.initEngine(context);
|
|
179
|
-
await this.initServices(storeEngine);
|
|
180
|
-
return context;
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
public async init(clientType: ClientType, cookie?: Cookie, initializedStoreEngine?: CRUDEngine): Promise<Context> {
|
|
184
|
-
const context = await this.apiClient.init(clientType, cookie);
|
|
185
|
-
if (initializedStoreEngine) {
|
|
186
|
-
this.storeEngine = initializedStoreEngine;
|
|
187
|
-
this.logger.log(`Initialized store with existing engine "${this.storeEngine.storeName}".`);
|
|
188
|
-
} else {
|
|
189
|
-
this.storeEngine = await this.initEngine(context);
|
|
190
|
-
}
|
|
191
|
-
await this.initServices(this.storeEngine);
|
|
192
|
-
if (initializedStoreEngine) {
|
|
193
|
-
await this.initClient({
|
|
194
|
-
clientType,
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
return context;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
public async initServices(storeEngine: CRUDEngine): Promise<void> {
|
|
201
|
-
const accountService = new AccountService(this.apiClient);
|
|
202
|
-
const assetService = new AssetService(this.apiClient);
|
|
203
|
-
const cryptographyService = new CryptographyService(this.apiClient, storeEngine, this.config);
|
|
204
|
-
|
|
205
|
-
const clientService = new ClientService(this.apiClient, storeEngine, cryptographyService);
|
|
206
|
-
const connectionService = new ConnectionService(this.apiClient);
|
|
207
|
-
const giphyService = new GiphyService(this.apiClient);
|
|
208
|
-
const conversationService = new ConversationService(this.apiClient, cryptographyService, assetService);
|
|
209
|
-
const notificationService = new NotificationService(this.apiClient, cryptographyService, storeEngine);
|
|
210
|
-
const selfService = new SelfService(this.apiClient);
|
|
211
|
-
const teamService = new TeamService(this.apiClient);
|
|
212
|
-
|
|
213
|
-
const broadcastService = new BroadcastService(this.apiClient, cryptographyService);
|
|
214
|
-
const userService = new UserService(this.apiClient, broadcastService, conversationService, connectionService);
|
|
215
|
-
|
|
216
|
-
this.service = {
|
|
217
|
-
account: accountService,
|
|
218
|
-
asset: assetService,
|
|
219
|
-
broadcast: broadcastService,
|
|
220
|
-
client: clientService,
|
|
221
|
-
connection: connectionService,
|
|
222
|
-
conversation: conversationService,
|
|
223
|
-
cryptography: cryptographyService,
|
|
224
|
-
giphy: giphyService,
|
|
225
|
-
notification: notificationService,
|
|
226
|
-
self: selfService,
|
|
227
|
-
team: teamService,
|
|
228
|
-
user: userService,
|
|
229
|
-
};
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
public async login(
|
|
233
|
-
loginData: LoginData,
|
|
234
|
-
initClient: boolean = true,
|
|
235
|
-
clientInfo?: ClientInfo,
|
|
236
|
-
initializedStoreEngine?: CRUDEngine,
|
|
237
|
-
): Promise<Context> {
|
|
238
|
-
this.resetContext();
|
|
239
|
-
LoginSanitizer.removeNonPrintableCharacters(loginData);
|
|
240
|
-
|
|
241
|
-
const context = await this.apiClient.login(loginData);
|
|
242
|
-
if (initializedStoreEngine) {
|
|
243
|
-
this.storeEngine = initializedStoreEngine;
|
|
244
|
-
this.logger.log(`Initialized store with existing engine "${this.storeEngine.storeName}".`);
|
|
245
|
-
} else {
|
|
246
|
-
this.storeEngine = await this.initEngine(context);
|
|
247
|
-
}
|
|
248
|
-
await this.initServices(this.storeEngine);
|
|
249
|
-
|
|
250
|
-
if (initClient) {
|
|
251
|
-
await this.initClient(loginData, clientInfo);
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
return context;
|
|
255
|
-
}
|
|
256
|
-
|
|
257
|
-
public async initClient(
|
|
258
|
-
loginData: LoginData,
|
|
259
|
-
clientInfo?: ClientInfo,
|
|
260
|
-
): Promise<{isNewClient: boolean; localClient: RegisteredClient}> {
|
|
261
|
-
if (!this.service) {
|
|
262
|
-
throw new Error('Services are not set.');
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
try {
|
|
266
|
-
const localClient = await this.loadAndValidateLocalClient();
|
|
267
|
-
return {isNewClient: false, localClient};
|
|
268
|
-
} catch (error) {
|
|
269
|
-
// There was no client so we need to "create" and "register" a client
|
|
270
|
-
const notFoundInDatabase =
|
|
271
|
-
error instanceof cryptobox.error.CryptoboxError ||
|
|
272
|
-
(error as Error).constructor.name === 'CryptoboxError' ||
|
|
273
|
-
error instanceof StoreEngineError.RecordNotFoundError ||
|
|
274
|
-
(error as Error).constructor.name === StoreEngineError.RecordNotFoundError.name;
|
|
275
|
-
const notFoundOnBackend = (error as AxiosError).response?.status === HTTP_STATUS.NOT_FOUND;
|
|
276
|
-
|
|
277
|
-
if (notFoundInDatabase) {
|
|
278
|
-
this.logger.log(`Could not find valid client in database "${this.storeEngine?.storeName}".`);
|
|
279
|
-
return this.registerClient(loginData, clientInfo);
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
if (notFoundOnBackend) {
|
|
283
|
-
this.logger.log('Could not find valid client on backend');
|
|
284
|
-
const client = await this.service!.client.getLocalClient();
|
|
285
|
-
const shouldDeleteWholeDatabase = client.type === ClientType.TEMPORARY;
|
|
286
|
-
if (shouldDeleteWholeDatabase) {
|
|
287
|
-
this.logger.log('Last client was temporary - Deleting database');
|
|
288
|
-
|
|
289
|
-
if (this.storeEngine) {
|
|
290
|
-
await this.storeEngine.clearTables();
|
|
291
|
-
}
|
|
292
|
-
const context = await this.apiClient.init(loginData.clientType);
|
|
293
|
-
await this.initEngine(context);
|
|
294
|
-
|
|
295
|
-
return this.registerClient(loginData, clientInfo);
|
|
296
|
-
}
|
|
297
|
-
|
|
298
|
-
this.logger.log('Last client was permanent - Deleting cryptography stores');
|
|
299
|
-
await this.service!.cryptography.deleteCryptographyStores();
|
|
300
|
-
return this.registerClient(loginData, clientInfo);
|
|
301
|
-
}
|
|
302
|
-
|
|
303
|
-
throw error;
|
|
304
|
-
}
|
|
305
|
-
}
|
|
306
|
-
|
|
307
|
-
public async loadAndValidateLocalClient(): Promise<RegisteredClient> {
|
|
308
|
-
await this.service!.cryptography.initCryptobox();
|
|
309
|
-
|
|
310
|
-
const loadedClient = await this.service!.client.getLocalClient();
|
|
311
|
-
await this.apiClient.client.api.getClient(loadedClient.id);
|
|
312
|
-
this.apiClient.context!.clientId = loadedClient.id;
|
|
313
|
-
|
|
314
|
-
return loadedClient;
|
|
315
|
-
}
|
|
316
|
-
|
|
317
|
-
private async registerClient(
|
|
318
|
-
loginData: LoginData,
|
|
319
|
-
clientInfo?: ClientInfo,
|
|
320
|
-
): Promise<{isNewClient: boolean; localClient: RegisteredClient}> {
|
|
321
|
-
if (!this.service) {
|
|
322
|
-
throw new Error('Services are not set.');
|
|
323
|
-
}
|
|
324
|
-
const registeredClient = await this.service.client.register(loginData, clientInfo);
|
|
325
|
-
this.apiClient.context!.clientId = registeredClient.id;
|
|
326
|
-
this.logger.log('Client is created');
|
|
327
|
-
|
|
328
|
-
await this.service!.notification.initializeNotificationStream();
|
|
329
|
-
await this.service!.client.synchronizeClients();
|
|
330
|
-
|
|
331
|
-
return {isNewClient: true, localClient: registeredClient};
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
private resetContext(): void {
|
|
335
|
-
delete this.apiClient.context;
|
|
336
|
-
delete this.service;
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
public async logout(): Promise<void> {
|
|
340
|
-
await this.apiClient.logout();
|
|
341
|
-
this.resetContext();
|
|
342
|
-
}
|
|
343
|
-
|
|
344
|
-
public async listen(
|
|
345
|
-
notificationHandler: NotificationHandler = this.service!.notification.handleNotification,
|
|
346
|
-
): Promise<Account> {
|
|
347
|
-
if (!this.apiClient.context) {
|
|
348
|
-
throw new Error('Context is not set - please login first');
|
|
349
|
-
}
|
|
350
|
-
|
|
351
|
-
this.apiClient.transport.ws.removeAllListeners(WebSocketClient.TOPIC.ON_MESSAGE);
|
|
352
|
-
this.apiClient.transport.ws.on(WebSocketClient.TOPIC.ON_MESSAGE, notification => {
|
|
353
|
-
notificationHandler(notification, PayloadBundleSource.WEBSOCKET).catch(error => {
|
|
354
|
-
this.logger.error(`Failed to handle notification ID "${notification.id}": ${error.message}`, error);
|
|
355
|
-
});
|
|
356
|
-
});
|
|
357
|
-
|
|
358
|
-
this.service!.notification.removeAllListeners(NotificationService.TOPIC.NOTIFICATION_ERROR);
|
|
359
|
-
this.service!.notification.on(NotificationService.TOPIC.NOTIFICATION_ERROR, this.handleError);
|
|
360
|
-
|
|
361
|
-
for (const payloadType of Object.values(PayloadBundleType)) {
|
|
362
|
-
this.service!.notification.removeAllListeners(payloadType);
|
|
363
|
-
this.service!.notification.on(payloadType as any, this.handlePayload);
|
|
364
|
-
}
|
|
365
|
-
|
|
366
|
-
const onBeforeConnect = async () => this.service!.notification.handleNotificationStream(notificationHandler);
|
|
367
|
-
await this.apiClient.connect(onBeforeConnect);
|
|
368
|
-
return this;
|
|
369
|
-
}
|
|
370
|
-
|
|
371
|
-
private readonly handlePayload = async (payload: PayloadBundle): Promise<void> => {
|
|
372
|
-
switch (payload.type) {
|
|
373
|
-
case PayloadBundleType.TIMER_UPDATE: {
|
|
374
|
-
const {
|
|
375
|
-
data: {message_timer},
|
|
376
|
-
conversation,
|
|
377
|
-
} = payload as unknown as Events.ConversationMessageTimerUpdateEvent;
|
|
378
|
-
const expireAfterMillis = Number(message_timer);
|
|
379
|
-
this.service!.conversation.messageTimer.setConversationLevelTimer(conversation, expireAfterMillis);
|
|
380
|
-
break;
|
|
381
|
-
}
|
|
382
|
-
}
|
|
383
|
-
this.emit(payload.type, payload);
|
|
384
|
-
};
|
|
385
|
-
|
|
386
|
-
private readonly handleError = (accountError: NotificationError): void => {
|
|
387
|
-
this.emit(Account.TOPIC.ERROR, accountError);
|
|
388
|
-
};
|
|
389
|
-
|
|
390
|
-
private async initEngine(context: Context): Promise<CRUDEngine> {
|
|
391
|
-
const clientType = context.clientType === ClientType.NONE ? '' : `@${context.clientType}`;
|
|
392
|
-
const dbName = `wire@${this.apiClient.config.urls.name}@${context.userId}${clientType}`;
|
|
393
|
-
this.logger.log(`Initialising store with name "${dbName}"...`);
|
|
394
|
-
this.storeEngine = await this.storeEngineProvider(dbName);
|
|
395
|
-
const cookie = CookieStore.getCookie();
|
|
396
|
-
if (cookie) {
|
|
397
|
-
await this.persistCookie(this.storeEngine, cookie);
|
|
398
|
-
}
|
|
399
|
-
return this.storeEngine;
|
|
400
|
-
}
|
|
401
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"CoreError.js","sourceRoot":"","sources":["CoreError.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAIH,IAAY,SAEX;AAFD,WAAY,SAAS;IACnB,gEAAmD,CAAA;AACrD,CAAC,EAFW,SAAS,GAAT,iBAAS,KAAT,iBAAS,QAEpB"}
|
package/src/main/CoreError.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Wire
|
|
3
|
-
* Copyright (C) 2019 Wire Swiss GmbH
|
|
4
|
-
*
|
|
5
|
-
* This program is free software: you can redistribute it and/or modify
|
|
6
|
-
* it under the terms of the GNU General Public License as published by
|
|
7
|
-
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
-
* (at your option) any later version.
|
|
9
|
-
*
|
|
10
|
-
* This program is distributed in the hope that it will be useful,
|
|
11
|
-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
-
* GNU General Public License for more details.
|
|
14
|
-
*
|
|
15
|
-
* You should have received a copy of the GNU General Public License
|
|
16
|
-
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
17
|
-
*
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
import type {Notification} from '@wireapp/api-client/src/notification';
|
|
21
|
-
|
|
22
|
-
export enum CoreError {
|
|
23
|
-
NOTIFICATION_ERROR = 'CoreError.NOTIFICATION_ERROR',
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface NotificationError {
|
|
27
|
-
error: Error;
|
|
28
|
-
notification: Notification;
|
|
29
|
-
type: CoreError.NOTIFICATION_ERROR;
|
|
30
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LoginSanitizer.js","sourceRoot":"","sources":["LoginSanitizer.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;;;AAIH,MAAa,cAAc;IACzB,gBAAe,CAAC;IAET,MAAM,CAAC,4BAA4B,CAAC,SAAoB;QAC7D,MAAM,sBAAsB,GAAG,MAAM,CAAC;QAEtC,IAAI,SAAS,CAAC,KAAK,EAAE;YACnB,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;SACvE;QAED,IAAI,SAAS,CAAC,MAAM,EAAE;YACpB,SAAS,CAAC,MAAM,GAAG,SAAS,CAAC,MAAM,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;SACzE;QAED,IAAI,SAAS,CAAC,QAAQ,EAAE;YACtB,SAAS,CAAC,QAAQ,GAAG,SAAS,CAAC,QAAQ,CAAC,QAAQ,EAAE,CAAC;SACpD;QAED,IAAI,SAAS,CAAC,KAAK,EAAE;YACnB,SAAS,CAAC,KAAK,GAAG,SAAS,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC;SAClF;IACH,CAAC;CACF;AAtBD,wCAsBC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|