@wireapp/core 26.1.0 → 27.0.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/CHANGELOG.md +32 -0
- package/package.json +3 -3
- package/src/main/Account.d.ts +32 -1
- package/src/main/Account.js +80 -40
- package/src/main/client/ClientService.d.ts +1 -1
- package/src/main/client/ClientService.js +1 -5
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,38 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [27.0.2](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@27.0.1...@wireapp/core@27.0.2) (2022-05-19)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @wireapp/core
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## [27.0.1](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@27.0.0...@wireapp/core@27.0.1) (2022-05-18)
|
|
15
|
+
|
|
16
|
+
**Note:** Version bump only for package @wireapp/core
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
# [27.0.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@26.1.0...@wireapp/core@27.0.0) (2022-05-17)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
### Bug Fixes
|
|
26
|
+
|
|
27
|
+
* Avoid silently creating client when initializing core ([#4264](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4264)) ([65a843a](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/65a843a2052dad2543e6cf046aca55ce85cc7c5e))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
### BREAKING CHANGES
|
|
31
|
+
|
|
32
|
+
* if you were relying on account.init() to also create a new client, this behavior now change and will throw an error instead. If you also want to create a device (if it doesn't exist already), you should use the account.login() or account.initClient() methods instead
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
|
|
6
38
|
# [26.1.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@26.0.0...@wireapp/core@26.1.0) (2022-05-16)
|
|
7
39
|
|
|
8
40
|
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
"dependencies": {
|
|
6
6
|
"@types/long": "4.0.1",
|
|
7
7
|
"@types/node": "~14",
|
|
8
|
-
"@wireapp/api-client": "19.2.
|
|
8
|
+
"@wireapp/api-client": "19.2.2",
|
|
9
9
|
"@wireapp/cryptobox": "12.8.0",
|
|
10
10
|
"bazinga64": "5.10.0",
|
|
11
11
|
"hash.js": "1.1.7",
|
|
@@ -69,6 +69,6 @@
|
|
|
69
69
|
"test:project": "yarn dist && yarn test",
|
|
70
70
|
"test:node": "nyc jasmine --config=jasmine.json"
|
|
71
71
|
},
|
|
72
|
-
"version": "
|
|
73
|
-
"gitHead": "
|
|
72
|
+
"version": "27.0.2",
|
|
73
|
+
"gitHead": "e6c73564a2d4d848a5796a92a74e37720791be27"
|
|
74
74
|
}
|
package/src/main/Account.d.ts
CHANGED
|
@@ -98,14 +98,45 @@ export declare class Account extends EventEmitter {
|
|
|
98
98
|
private persistCookie;
|
|
99
99
|
get clientId(): string;
|
|
100
100
|
get userId(): string;
|
|
101
|
+
/**
|
|
102
|
+
* Will register a new user to the backend
|
|
103
|
+
*
|
|
104
|
+
* @param registration The user's data
|
|
105
|
+
* @param clientType Type of client to create (temporary or permanent)
|
|
106
|
+
*/
|
|
101
107
|
register(registration: RegisterData, clientType: ClientType): Promise<Context>;
|
|
108
|
+
/**
|
|
109
|
+
* Will init the core with an aleady existing client (both on backend and local)
|
|
110
|
+
* Will fail if local client cannot be found
|
|
111
|
+
*
|
|
112
|
+
* @param clientType The type of client the user is using (temporary or permanent)
|
|
113
|
+
* @param cookie The cookie to identify the user against backend (will use the browser's one if not given)
|
|
114
|
+
*/
|
|
102
115
|
init(clientType: ClientType, cookie?: Cookie, initClient?: boolean): Promise<Context>;
|
|
103
|
-
|
|
116
|
+
/**
|
|
117
|
+
* Will log the user in with the given credential.
|
|
118
|
+
* Will also create the local client and store it in DB
|
|
119
|
+
*
|
|
120
|
+
* @param loginData The credentials of the user
|
|
121
|
+
* @param initClient Should the call also create the local client
|
|
122
|
+
* @param clientInfo Info about the client to create (name, type...)
|
|
123
|
+
*/
|
|
104
124
|
login(loginData: LoginData, initClient?: boolean, clientInfo?: ClientInfo): Promise<Context>;
|
|
125
|
+
/**
|
|
126
|
+
* Will try to get the load the local client from local DB.
|
|
127
|
+
* If clientInfo are provided, will also create the client on backend and DB
|
|
128
|
+
* If clientInfo are not provideo, the method will fail if local client cannot be found
|
|
129
|
+
*
|
|
130
|
+
* @param loginData User's credentials
|
|
131
|
+
* @param clientInfo Will allow creating the client if the local client cannot be found (else will fail if local client is not found)
|
|
132
|
+
* @param entropyData Additional entropy data
|
|
133
|
+
* @returns The local existing client or newly created client
|
|
134
|
+
*/
|
|
105
135
|
initClient(loginData: LoginData, clientInfo?: ClientInfo, entropyData?: Uint8Array): Promise<{
|
|
106
136
|
isNewClient: boolean;
|
|
107
137
|
localClient: RegisteredClient;
|
|
108
138
|
}>;
|
|
139
|
+
initServices(context: Context): Promise<void>;
|
|
109
140
|
loadAndValidateLocalClient(): Promise<RegisteredClient>;
|
|
110
141
|
private registerClient;
|
|
111
142
|
private resetContext;
|
package/src/main/Account.js
CHANGED
|
@@ -67,6 +67,11 @@ var TOPIC;
|
|
|
67
67
|
(function (TOPIC) {
|
|
68
68
|
TOPIC["ERROR"] = "Account.TOPIC.ERROR";
|
|
69
69
|
})(TOPIC || (TOPIC = {}));
|
|
70
|
+
const coreDefaultClient = {
|
|
71
|
+
classification: client_1.ClientClassification.DESKTOP,
|
|
72
|
+
cookieLabel: 'default',
|
|
73
|
+
model: '@wireapp/core',
|
|
74
|
+
};
|
|
70
75
|
class Account extends events_1.EventEmitter {
|
|
71
76
|
/**
|
|
72
77
|
* @param apiClient The apiClient instance to use in the core (will create a new new one if undefined)
|
|
@@ -117,11 +122,24 @@ class Account extends events_1.EventEmitter {
|
|
|
117
122
|
get userId() {
|
|
118
123
|
return this.apiClient.validatedUserId;
|
|
119
124
|
}
|
|
125
|
+
/**
|
|
126
|
+
* Will register a new user to the backend
|
|
127
|
+
*
|
|
128
|
+
* @param registration The user's data
|
|
129
|
+
* @param clientType Type of client to create (temporary or permanent)
|
|
130
|
+
*/
|
|
120
131
|
async register(registration, clientType) {
|
|
121
132
|
const context = await this.apiClient.register(registration, clientType);
|
|
122
133
|
await this.initServices(context);
|
|
123
134
|
return context;
|
|
124
135
|
}
|
|
136
|
+
/**
|
|
137
|
+
* Will init the core with an aleady existing client (both on backend and local)
|
|
138
|
+
* Will fail if local client cannot be found
|
|
139
|
+
*
|
|
140
|
+
* @param clientType The type of client the user is using (temporary or permanent)
|
|
141
|
+
* @param cookie The cookie to identify the user against backend (will use the browser's one if not given)
|
|
142
|
+
*/
|
|
125
143
|
async init(clientType, cookie, initClient = true) {
|
|
126
144
|
const context = await this.apiClient.init(clientType, cookie);
|
|
127
145
|
await this.initServices(context);
|
|
@@ -130,45 +148,15 @@ class Account extends events_1.EventEmitter {
|
|
|
130
148
|
}
|
|
131
149
|
return context;
|
|
132
150
|
}
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
const clientService = new client_2.ClientService(this.apiClient, this.storeEngine, cryptographyService);
|
|
143
|
-
const connectionService = new connection_1.ConnectionService(this.apiClient);
|
|
144
|
-
const giphyService = new giphy_1.GiphyService(this.apiClient);
|
|
145
|
-
const linkPreviewService = new linkPreview_1.LinkPreviewService(assetService);
|
|
146
|
-
const conversationService = new conversation_1.ConversationService(this.apiClient, cryptographyService, {
|
|
147
|
-
// We can use qualified ids to send messages as long as the backend supports federated endpoints
|
|
148
|
-
useQualifiedIds: this.backendFeatures.federationEndpoints,
|
|
149
|
-
});
|
|
150
|
-
const notificationService = new notification_1.NotificationService(this.apiClient, cryptographyService, this.storeEngine);
|
|
151
|
-
const selfService = new self_1.SelfService(this.apiClient);
|
|
152
|
-
const teamService = new team_1.TeamService(this.apiClient);
|
|
153
|
-
const broadcastService = new broadcast_1.BroadcastService(this.apiClient, cryptographyService);
|
|
154
|
-
const userService = new user_1.UserService(this.apiClient, broadcastService, conversationService, connectionService);
|
|
155
|
-
this.service = {
|
|
156
|
-
account: accountService,
|
|
157
|
-
asset: assetService,
|
|
158
|
-
broadcast: broadcastService,
|
|
159
|
-
client: clientService,
|
|
160
|
-
connection: connectionService,
|
|
161
|
-
conversation: conversationService,
|
|
162
|
-
cryptography: cryptographyService,
|
|
163
|
-
giphy: giphyService,
|
|
164
|
-
linkPreview: linkPreviewService,
|
|
165
|
-
notification: notificationService,
|
|
166
|
-
self: selfService,
|
|
167
|
-
team: teamService,
|
|
168
|
-
user: userService,
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
async login(loginData, initClient = true, clientInfo) {
|
|
151
|
+
/**
|
|
152
|
+
* Will log the user in with the given credential.
|
|
153
|
+
* Will also create the local client and store it in DB
|
|
154
|
+
*
|
|
155
|
+
* @param loginData The credentials of the user
|
|
156
|
+
* @param initClient Should the call also create the local client
|
|
157
|
+
* @param clientInfo Info about the client to create (name, type...)
|
|
158
|
+
*/
|
|
159
|
+
async login(loginData, initClient = true, clientInfo = coreDefaultClient) {
|
|
172
160
|
this.resetContext();
|
|
173
161
|
auth_2.LoginSanitizer.removeNonPrintableCharacters(loginData);
|
|
174
162
|
const context = await this.apiClient.login(loginData);
|
|
@@ -178,6 +166,16 @@ class Account extends events_1.EventEmitter {
|
|
|
178
166
|
}
|
|
179
167
|
return context;
|
|
180
168
|
}
|
|
169
|
+
/**
|
|
170
|
+
* Will try to get the load the local client from local DB.
|
|
171
|
+
* If clientInfo are provided, will also create the client on backend and DB
|
|
172
|
+
* If clientInfo are not provideo, the method will fail if local client cannot be found
|
|
173
|
+
*
|
|
174
|
+
* @param loginData User's credentials
|
|
175
|
+
* @param clientInfo Will allow creating the client if the local client cannot be found (else will fail if local client is not found)
|
|
176
|
+
* @param entropyData Additional entropy data
|
|
177
|
+
* @returns The local existing client or newly created client
|
|
178
|
+
*/
|
|
181
179
|
async initClient(loginData, clientInfo, entropyData) {
|
|
182
180
|
var _a, _b;
|
|
183
181
|
if (!this.service) {
|
|
@@ -188,6 +186,10 @@ class Account extends events_1.EventEmitter {
|
|
|
188
186
|
return { isNewClient: false, localClient };
|
|
189
187
|
}
|
|
190
188
|
catch (error) {
|
|
189
|
+
if (!clientInfo) {
|
|
190
|
+
// If no client info provided, the client should not be created
|
|
191
|
+
throw error;
|
|
192
|
+
}
|
|
191
193
|
// There was no client so we need to "create" and "register" a client
|
|
192
194
|
const notFoundInDatabase = error instanceof cryptobox.error.CryptoboxError ||
|
|
193
195
|
error.constructor.name === 'CryptoboxError' ||
|
|
@@ -218,6 +220,44 @@ class Account extends events_1.EventEmitter {
|
|
|
218
220
|
throw error;
|
|
219
221
|
}
|
|
220
222
|
}
|
|
223
|
+
async initServices(context) {
|
|
224
|
+
this.storeEngine = await this.initEngine(context);
|
|
225
|
+
const accountService = new account_1.AccountService(this.apiClient);
|
|
226
|
+
const assetService = new conversation_1.AssetService(this.apiClient);
|
|
227
|
+
const cryptographyService = new cryptography_1.CryptographyService(this.apiClient, this.storeEngine, {
|
|
228
|
+
// We want to encrypt with fully qualified session ids, only if the backend is federated with other backends
|
|
229
|
+
useQualifiedIds: this.backendFeatures.isFederated,
|
|
230
|
+
nbPrekeys: this.nbPrekeys,
|
|
231
|
+
});
|
|
232
|
+
const clientService = new client_2.ClientService(this.apiClient, this.storeEngine, cryptographyService);
|
|
233
|
+
const connectionService = new connection_1.ConnectionService(this.apiClient);
|
|
234
|
+
const giphyService = new giphy_1.GiphyService(this.apiClient);
|
|
235
|
+
const linkPreviewService = new linkPreview_1.LinkPreviewService(assetService);
|
|
236
|
+
const conversationService = new conversation_1.ConversationService(this.apiClient, cryptographyService, {
|
|
237
|
+
// We can use qualified ids to send messages as long as the backend supports federated endpoints
|
|
238
|
+
useQualifiedIds: this.backendFeatures.federationEndpoints,
|
|
239
|
+
});
|
|
240
|
+
const notificationService = new notification_1.NotificationService(this.apiClient, cryptographyService, this.storeEngine);
|
|
241
|
+
const selfService = new self_1.SelfService(this.apiClient);
|
|
242
|
+
const teamService = new team_1.TeamService(this.apiClient);
|
|
243
|
+
const broadcastService = new broadcast_1.BroadcastService(this.apiClient, cryptographyService);
|
|
244
|
+
const userService = new user_1.UserService(this.apiClient, broadcastService, conversationService, connectionService);
|
|
245
|
+
this.service = {
|
|
246
|
+
account: accountService,
|
|
247
|
+
asset: assetService,
|
|
248
|
+
broadcast: broadcastService,
|
|
249
|
+
client: clientService,
|
|
250
|
+
connection: connectionService,
|
|
251
|
+
conversation: conversationService,
|
|
252
|
+
cryptography: cryptographyService,
|
|
253
|
+
giphy: giphyService,
|
|
254
|
+
linkPreview: linkPreviewService,
|
|
255
|
+
notification: notificationService,
|
|
256
|
+
self: selfService,
|
|
257
|
+
team: teamService,
|
|
258
|
+
user: userService,
|
|
259
|
+
};
|
|
260
|
+
}
|
|
221
261
|
async loadAndValidateLocalClient() {
|
|
222
262
|
await this.service.cryptography.initCryptobox();
|
|
223
263
|
const loadedClient = await this.service.client.getLocalClient();
|
|
@@ -225,7 +265,7 @@ class Account extends events_1.EventEmitter {
|
|
|
225
265
|
this.apiClient.context.clientId = loadedClient.id;
|
|
226
266
|
return loadedClient;
|
|
227
267
|
}
|
|
228
|
-
async registerClient(loginData, clientInfo, entropyData) {
|
|
268
|
+
async registerClient(loginData, clientInfo = coreDefaultClient, entropyData) {
|
|
229
269
|
if (!this.service) {
|
|
230
270
|
throw new Error('Services are not set.');
|
|
231
271
|
}
|
|
@@ -36,5 +36,5 @@ export declare class ClientService {
|
|
|
36
36
|
getLocalClient(): Promise<MetaClient>;
|
|
37
37
|
createLocalClient(client: RegisteredClient, domain?: string): Promise<MetaClient>;
|
|
38
38
|
synchronizeClients(): Promise<MetaClient[]>;
|
|
39
|
-
register(loginData: LoginData, clientInfo
|
|
39
|
+
register(loginData: LoginData, clientInfo: ClientInfo, entropyData?: Uint8Array): Promise<RegisteredClient>;
|
|
40
40
|
}
|
|
@@ -71,11 +71,7 @@ class ClientService {
|
|
|
71
71
|
return this.database.createClientList(this.apiClient.context.userId, filteredClients, (_a = this.apiClient.context) === null || _a === void 0 ? void 0 : _a.domain);
|
|
72
72
|
}
|
|
73
73
|
// TODO: Split functionality into "create" and "register" client
|
|
74
|
-
async register(loginData, clientInfo
|
|
75
|
-
classification: client_1.ClientClassification.DESKTOP,
|
|
76
|
-
cookieLabel: 'default',
|
|
77
|
-
model: '@wireapp/core',
|
|
78
|
-
}, entropyData) {
|
|
74
|
+
async register(loginData, clientInfo, entropyData) {
|
|
79
75
|
if (!this.apiClient.context) {
|
|
80
76
|
throw new Error('Context is not set.');
|
|
81
77
|
}
|