@wireapp/core 46.31.0 → 46.31.1
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/Account.d.ts +25 -19
- package/lib/Account.d.ts.map +1 -1
- package/lib/Account.js +100 -84
- package/package.json +2 -2
package/lib/Account.d.ts
CHANGED
|
@@ -122,9 +122,9 @@ export declare class Account extends TypedEventEmitter<Events> {
|
|
|
122
122
|
* - useVersion(0, 1, true) > version 1 is used
|
|
123
123
|
* @return The highest version that is both supported by client and backend
|
|
124
124
|
*/
|
|
125
|
-
useAPIVersion(min: number, max: number, allowDev?: boolean)
|
|
125
|
+
useAPIVersion: (min: number, max: number, allowDev?: boolean) => Promise<BackendFeatures>;
|
|
126
126
|
private persistCookie;
|
|
127
|
-
enrollE2EI({ displayName, handle, teamId, discoveryUrl, getOAuthToken, getAllConversations, certificateTtl, }: {
|
|
127
|
+
enrollE2EI: ({ displayName, handle, teamId, discoveryUrl, getOAuthToken, getAllConversations, certificateTtl, }: {
|
|
128
128
|
/** display name of the user (should match the identity provider) */
|
|
129
129
|
displayName: string;
|
|
130
130
|
/** handle of the user (should match the identity provider) */
|
|
@@ -138,7 +138,7 @@ export declare class Account extends TypedEventEmitter<Events> {
|
|
|
138
138
|
getAllConversations: getAllConversationsCallback;
|
|
139
139
|
/** number of seconds the certificate should be valid (default 90 days) */
|
|
140
140
|
certificateTtl?: number;
|
|
141
|
-
})
|
|
141
|
+
}) => Promise<void>;
|
|
142
142
|
get clientId(): string;
|
|
143
143
|
get userId(): string;
|
|
144
144
|
/**
|
|
@@ -147,33 +147,31 @@ export declare class Account extends TypedEventEmitter<Events> {
|
|
|
147
147
|
* @param registration The user's data
|
|
148
148
|
* @param clientType Type of client to create (temporary or permanent)
|
|
149
149
|
*/
|
|
150
|
-
register(registration: RegisterData, clientType: ClientType)
|
|
150
|
+
register: (registration: RegisterData, clientType: ClientType) => Promise<Context>;
|
|
151
151
|
/**
|
|
152
152
|
* Will init the core with an already logged in user
|
|
153
153
|
*
|
|
154
154
|
* @param clientType The type of client the user is using (temporary or permanent)
|
|
155
155
|
*/
|
|
156
|
-
init(clientType: ClientType, { cookie }?: InitOptions)
|
|
156
|
+
init: (clientType: ClientType, { cookie }?: InitOptions) => Promise<Context>;
|
|
157
157
|
/**
|
|
158
158
|
* Will log the user in with the given credential.
|
|
159
159
|
*
|
|
160
160
|
* @param loginData The credentials of the user
|
|
161
161
|
* @param clientInfo Info about the client to create (name, type...)
|
|
162
162
|
*/
|
|
163
|
-
login(loginData: LoginData)
|
|
163
|
+
login: (loginData: LoginData) => Promise<Context>;
|
|
164
164
|
/**
|
|
165
165
|
* Will register a new client for the current user
|
|
166
166
|
*/
|
|
167
|
-
|
|
168
|
-
/** will add extra manual entropy to the client's identity being created */
|
|
169
|
-
entropyData?: Uint8Array): Promise<RegisteredClient>;
|
|
167
|
+
regsterClient: (loginData: LoginData, clientInfo?: ClientInfo, entropyData?: Uint8Array) => Promise<RegisteredClient>;
|
|
170
168
|
getLocalClient(): Promise<import("./client/ClientService").MetaClient | undefined> | undefined;
|
|
171
169
|
/**
|
|
172
170
|
* Will initiate all the cryptographic material of the given registered device and setup all the background tasks.
|
|
173
171
|
*
|
|
174
172
|
* @returns The local existing client or undefined if the client does not exist or is not valid (non existing on backend)
|
|
175
173
|
*/
|
|
176
|
-
initClient(client: RegisteredClient, mlsConfig?: InitClientOptions)
|
|
174
|
+
initClient: (client: RegisteredClient, mlsConfig?: InitClientOptions) => Promise<RegisteredClient>;
|
|
177
175
|
private buildCryptoClient;
|
|
178
176
|
/**
|
|
179
177
|
* In order to be able to send MLS messages, the core needs a few information from the consumer.
|
|
@@ -182,17 +180,17 @@ export declare class Account extends TypedEventEmitter<Events> {
|
|
|
182
180
|
* - what is the groupId of a conversation
|
|
183
181
|
* @param coreCallbacks
|
|
184
182
|
*/
|
|
185
|
-
configureCoreCallbacks(coreCallbacks: CoreCallbacks)
|
|
183
|
+
configureCoreCallbacks: (coreCallbacks: CoreCallbacks) => void;
|
|
186
184
|
private initServices;
|
|
187
185
|
private resetContext;
|
|
188
186
|
/**
|
|
189
187
|
* Will logout the current user
|
|
190
188
|
* @param clearData if set to `true` will completely wipe any database that was created by the Account
|
|
191
189
|
*/
|
|
192
|
-
logout(data?: {
|
|
190
|
+
logout: (data?: {
|
|
193
191
|
clearAllData?: boolean;
|
|
194
192
|
clearCryptoData?: boolean;
|
|
195
|
-
})
|
|
193
|
+
}) => Promise<void>;
|
|
196
194
|
private wipeCommonData;
|
|
197
195
|
/**
|
|
198
196
|
* Will delete the identity and history of the current user
|
|
@@ -214,7 +212,7 @@ export declare class Account extends TypedEventEmitter<Events> {
|
|
|
214
212
|
* @param callbacks callbacks that will be called to handle different events
|
|
215
213
|
* @returns close a function that will disconnect from the websocket
|
|
216
214
|
*/
|
|
217
|
-
listen({ onEvent, onConnectionStateChanged: onConnectionStateChangedCallBack, onNotificationStreamProgress, onMissedNotifications, dryRun, }?: {
|
|
215
|
+
listen: ({ onEvent, onConnectionStateChanged: onConnectionStateChangedCallBack, onNotificationStreamProgress, onMissedNotifications, dryRun, }?: {
|
|
218
216
|
/**
|
|
219
217
|
* Called when a new event arrives from backend
|
|
220
218
|
* @param payload the payload of the event. Contains the raw event received and the decrypted data (if event was encrypted)
|
|
@@ -241,7 +239,7 @@ export declare class Account extends TypedEventEmitter<Events> {
|
|
|
241
239
|
* When set will not decrypt and not store the last notification ID. This is useful if you only want to subscribe to unencrypted backend events
|
|
242
240
|
*/
|
|
243
241
|
dryRun?: boolean;
|
|
244
|
-
})
|
|
242
|
+
}) => Promise<() => void>;
|
|
245
243
|
private createConnectionStateChangedHandler;
|
|
246
244
|
/**
|
|
247
245
|
* Creates the event handler that is invoked for each decrypted event from the backend.
|
|
@@ -257,10 +255,11 @@ export declare class Account extends TypedEventEmitter<Events> {
|
|
|
257
255
|
*/
|
|
258
256
|
private createLegacyNotificationHandler;
|
|
259
257
|
private createNotificationHandler;
|
|
258
|
+
private handleNotificationQueueError;
|
|
260
259
|
private acknowledgeSynchronizationNotification;
|
|
261
260
|
private handleSynchronizationNotification;
|
|
262
261
|
private decryptAckEmitNotification;
|
|
263
|
-
getNotificationEventTime(backendEvent: Events.BackendEvent)
|
|
262
|
+
getNotificationEventTime: (backendEvent: Events.BackendEvent) => string | null;
|
|
264
263
|
/**
|
|
265
264
|
* Returns a function to handle missed notifications — i.e., when the backend indicates
|
|
266
265
|
* that some notifications were lost due to age (typically >28 days).
|
|
@@ -283,6 +282,13 @@ export declare class Account extends TypedEventEmitter<Events> {
|
|
|
283
282
|
* @param handlers Various logic handlers wired to notification callbacks
|
|
284
283
|
*/
|
|
285
284
|
private createLegacyNotificationStreamProcessor;
|
|
285
|
+
/**
|
|
286
|
+
* In case of a closed connection, we flush the notification processing queue.
|
|
287
|
+
* As we are not acknowledging them before decryption is done
|
|
288
|
+
* they will be resent next time the connection is opened
|
|
289
|
+
* this is to avoid duplicate decryption of notifications
|
|
290
|
+
*/
|
|
291
|
+
private pauseAndFlushNotificationQueue;
|
|
286
292
|
/**
|
|
287
293
|
* Sets up WebSocket event listeners for:
|
|
288
294
|
* - Incoming backend messages
|
|
@@ -313,14 +319,14 @@ export declare class Account extends TypedEventEmitter<Events> {
|
|
|
313
319
|
* then we remove the flag.
|
|
314
320
|
*/
|
|
315
321
|
private reactToMissedNotification;
|
|
316
|
-
getClientCapabilities()
|
|
317
|
-
checkIsConsumable(notification: Notification | ConsumableNotification)
|
|
322
|
+
getClientCapabilities: () => ClientCapability[];
|
|
323
|
+
checkIsConsumable: (notification: Notification | ConsumableNotification) => notification is ConsumableNotification;
|
|
318
324
|
private generateDbName;
|
|
319
325
|
private generateCoreDbName;
|
|
320
326
|
private generateEncryptedDbName;
|
|
321
327
|
private initEngine;
|
|
322
328
|
private groupIdFromConversationId;
|
|
323
|
-
isMLSActiveForClient()
|
|
329
|
+
isMLSActiveForClient: () => Promise<boolean>;
|
|
324
330
|
}
|
|
325
331
|
export {};
|
|
326
332
|
//#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B,2BAE1B;IAEK,iBAAiB,iBACR,YAAY,GAAG,sBAAsB,KAClD,YAAY,IAAI,sBAAsB,CAEvC;IAEF,OAAO,CAAC,cAAc,CAGpB;IAEF,OAAO,CAAC,kBAAkB,CAExB;IAEF,OAAO,CAAC,uBAAuB,CAE7B;IAEF,OAAO,CAAC,UAAU,CAqBhB;IAEF,OAAO,CAAC,yBAAyB,CAS/B;IAEK,oBAAoB,QAAa,OAAO,CAAC,OAAO,CAAC,CActD;CACH"}
|
package/lib/Account.js
CHANGED
|
@@ -165,16 +165,16 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
165
165
|
* - useVersion(0, 1, true) > version 1 is used
|
|
166
166
|
* @return The highest version that is both supported by client and backend
|
|
167
167
|
*/
|
|
168
|
-
async
|
|
168
|
+
useAPIVersion = async (min, max, allowDev) => {
|
|
169
169
|
const features = await this.apiClient.useVersion(min, max, allowDev);
|
|
170
170
|
this.backendFeatures = features;
|
|
171
171
|
return features;
|
|
172
|
-
}
|
|
173
|
-
persistCookie(storeEngine, cookie) {
|
|
172
|
+
};
|
|
173
|
+
persistCookie = (storeEngine, cookie) => {
|
|
174
174
|
const entity = { expiration: cookie.expiration, zuid: cookie.zuid };
|
|
175
175
|
return storeEngine.updateOrCreate(auth_1.AUTH_TABLE_NAME, auth_1.AUTH_COOKIE_KEY, entity);
|
|
176
|
-
}
|
|
177
|
-
async
|
|
176
|
+
};
|
|
177
|
+
enrollE2EI = async ({ displayName, handle, teamId, discoveryUrl, getOAuthToken, getAllConversations, certificateTtl = 90 * (TimeUtil_1.TimeInMillis.DAY / 1000), }) => {
|
|
178
178
|
const context = this.apiClient.context;
|
|
179
179
|
const domain = context?.domain ?? '';
|
|
180
180
|
if (!this.currentClient) {
|
|
@@ -191,7 +191,7 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
191
191
|
id: this.userId,
|
|
192
192
|
};
|
|
193
193
|
return this.service.mls.enrollE2EI(discoveryUrl, user, this.currentClient, this.options.nbPrekeys, certificateTtl, getOAuthToken, getAllConversations);
|
|
194
|
-
}
|
|
194
|
+
};
|
|
195
195
|
get clientId() {
|
|
196
196
|
return this.apiClient.validatedClientId;
|
|
197
197
|
}
|
|
@@ -204,40 +204,40 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
204
204
|
* @param registration The user's data
|
|
205
205
|
* @param clientType Type of client to create (temporary or permanent)
|
|
206
206
|
*/
|
|
207
|
-
async
|
|
207
|
+
register = async (registration, clientType) => {
|
|
208
208
|
const context = await this.apiClient.register(registration, clientType);
|
|
209
209
|
await this.initServices(context);
|
|
210
210
|
return context;
|
|
211
|
-
}
|
|
211
|
+
};
|
|
212
212
|
/**
|
|
213
213
|
* Will init the core with an already logged in user
|
|
214
214
|
*
|
|
215
215
|
* @param clientType The type of client the user is using (temporary or permanent)
|
|
216
216
|
*/
|
|
217
|
-
async
|
|
217
|
+
init = async (clientType, { cookie } = {}) => {
|
|
218
218
|
const context = await this.apiClient.init(clientType, cookie);
|
|
219
219
|
await this.initServices(context);
|
|
220
220
|
return context;
|
|
221
|
-
}
|
|
221
|
+
};
|
|
222
222
|
/**
|
|
223
223
|
* Will log the user in with the given credential.
|
|
224
224
|
*
|
|
225
225
|
* @param loginData The credentials of the user
|
|
226
226
|
* @param clientInfo Info about the client to create (name, type...)
|
|
227
227
|
*/
|
|
228
|
-
async
|
|
228
|
+
login = async (loginData) => {
|
|
229
229
|
this.resetContext();
|
|
230
230
|
auth_2.LoginSanitizer.removeNonPrintableCharacters(loginData);
|
|
231
231
|
const context = await this.apiClient.login(loginData);
|
|
232
232
|
await this.initServices(context);
|
|
233
233
|
return context;
|
|
234
|
-
}
|
|
234
|
+
};
|
|
235
235
|
/**
|
|
236
236
|
* Will register a new client for the current user
|
|
237
237
|
*/
|
|
238
|
-
async
|
|
238
|
+
regsterClient = async (loginData, clientInfo = coreDefaultClient,
|
|
239
239
|
/** will add extra manual entropy to the client's identity being created */
|
|
240
|
-
entropyData) {
|
|
240
|
+
entropyData) => {
|
|
241
241
|
if (!this.service || !this.apiClient.context || !this.storeEngine) {
|
|
242
242
|
throw new Error('Services are not set or context not initialized.');
|
|
243
243
|
}
|
|
@@ -249,7 +249,7 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
249
249
|
await this.service.notification.initializeNotificationStream(clientId);
|
|
250
250
|
await this.service.client.synchronizeClients(clientId);
|
|
251
251
|
return client;
|
|
252
|
-
}
|
|
252
|
+
};
|
|
253
253
|
getLocalClient() {
|
|
254
254
|
return this.service?.client.loadClient();
|
|
255
255
|
}
|
|
@@ -258,7 +258,7 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
258
258
|
*
|
|
259
259
|
* @returns The local existing client or undefined if the client does not exist or is not valid (non existing on backend)
|
|
260
260
|
*/
|
|
261
|
-
async
|
|
261
|
+
initClient = async (client, mlsConfig) => {
|
|
262
262
|
if (!this.service || !this.apiClient.context || !this.storeEngine) {
|
|
263
263
|
throw new Error('Services are not set.');
|
|
264
264
|
}
|
|
@@ -278,8 +278,8 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
278
278
|
}
|
|
279
279
|
this.currentClient = client;
|
|
280
280
|
return client;
|
|
281
|
-
}
|
|
282
|
-
async
|
|
281
|
+
};
|
|
282
|
+
buildCryptoClient = async (context, storeEngine, encryptedStore) => {
|
|
283
283
|
const baseConfig = {
|
|
284
284
|
nbPrekeys: this.options.nbPrekeys,
|
|
285
285
|
onNewPrekeys: async (prekeys) => {
|
|
@@ -299,7 +299,7 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
299
299
|
const { buildClient } = await Promise.resolve().then(() => __importStar(require('./messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper')));
|
|
300
300
|
const client = buildClient(storeEngine, baseConfig);
|
|
301
301
|
return [CryptoClient_1.CryptoClientType.CRYPTOBOX, client];
|
|
302
|
-
}
|
|
302
|
+
};
|
|
303
303
|
/**
|
|
304
304
|
* In order to be able to send MLS messages, the core needs a few information from the consumer.
|
|
305
305
|
* Namely:
|
|
@@ -307,10 +307,10 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
307
307
|
* - what is the groupId of a conversation
|
|
308
308
|
* @param coreCallbacks
|
|
309
309
|
*/
|
|
310
|
-
configureCoreCallbacks(coreCallbacks) {
|
|
310
|
+
configureCoreCallbacks = (coreCallbacks) => {
|
|
311
311
|
this.coreCallbacks = coreCallbacks;
|
|
312
|
-
}
|
|
313
|
-
async
|
|
312
|
+
};
|
|
313
|
+
initServices = async (context) => {
|
|
314
314
|
const encryptedStoreName = this.generateEncryptedDbName(context);
|
|
315
315
|
this.encryptedDb = this.options.systemCrypto
|
|
316
316
|
? await (0, encryptedStore_1.createCustomEncryptedStore)(encryptedStoreName, this.options.systemCrypto)
|
|
@@ -360,17 +360,17 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
360
360
|
team: teamService,
|
|
361
361
|
user: userService,
|
|
362
362
|
};
|
|
363
|
-
}
|
|
364
|
-
resetContext() {
|
|
363
|
+
};
|
|
364
|
+
resetContext = () => {
|
|
365
365
|
this.currentClient = undefined;
|
|
366
366
|
delete this.apiClient.context;
|
|
367
367
|
delete this.service;
|
|
368
|
-
}
|
|
368
|
+
};
|
|
369
369
|
/**
|
|
370
370
|
* Will logout the current user
|
|
371
371
|
* @param clearData if set to `true` will completely wipe any database that was created by the Account
|
|
372
372
|
*/
|
|
373
|
-
async
|
|
373
|
+
logout = async (data) => {
|
|
374
374
|
this.db?.close();
|
|
375
375
|
this.encryptedDb?.close();
|
|
376
376
|
if (data?.clearAllData) {
|
|
@@ -381,19 +381,19 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
381
381
|
}
|
|
382
382
|
await this.apiClient.logout();
|
|
383
383
|
this.resetContext();
|
|
384
|
-
}
|
|
385
|
-
async
|
|
384
|
+
};
|
|
385
|
+
wipeCommonData = async () => {
|
|
386
386
|
await this.service?.client.deleteLocalClient();
|
|
387
387
|
if (this.storeEngine) {
|
|
388
388
|
await (0, CoreCryptoWrapper_1.wipeCoreCryptoDb)(this.storeEngine);
|
|
389
389
|
}
|
|
390
390
|
// needs to be wiped last
|
|
391
391
|
await this.encryptedDb?.wipe();
|
|
392
|
-
}
|
|
392
|
+
};
|
|
393
393
|
/**
|
|
394
394
|
* Will delete the identity and history of the current user
|
|
395
395
|
*/
|
|
396
|
-
async
|
|
396
|
+
wipeAllData = async () => {
|
|
397
397
|
if (this.storeEngine) {
|
|
398
398
|
await (0, identityClearer_1.deleteIdentity)(this.storeEngine, false);
|
|
399
399
|
}
|
|
@@ -401,17 +401,17 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
401
401
|
await (0, CoreDB_1.deleteDB)(this.db);
|
|
402
402
|
}
|
|
403
403
|
await this.wipeCommonData();
|
|
404
|
-
}
|
|
404
|
+
};
|
|
405
405
|
/**
|
|
406
406
|
* Will delete the cryptography and client of the current user
|
|
407
407
|
* Will keep the history intact
|
|
408
408
|
*/
|
|
409
|
-
async
|
|
409
|
+
wipeCryptoData = async () => {
|
|
410
410
|
if (this.storeEngine) {
|
|
411
411
|
await (0, identityClearer_1.deleteIdentity)(this.storeEngine, true);
|
|
412
412
|
}
|
|
413
413
|
await this.wipeCommonData();
|
|
414
|
-
}
|
|
414
|
+
};
|
|
415
415
|
/**
|
|
416
416
|
* return true if the current user has a MLS device that is initialized and ready to use
|
|
417
417
|
*/
|
|
@@ -425,7 +425,7 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
425
425
|
* @param callbacks callbacks that will be called to handle different events
|
|
426
426
|
* @returns close a function that will disconnect from the websocket
|
|
427
427
|
*/
|
|
428
|
-
async
|
|
428
|
+
listen = async ({ onEvent = () => { }, onConnectionStateChanged: onConnectionStateChangedCallBack = () => { }, onNotificationStreamProgress = () => { }, onMissedNotifications = () => { }, dryRun = false, } = {}) => {
|
|
429
429
|
if (!this.currentClient) {
|
|
430
430
|
throw new Error('Client has not been initialized - please login first');
|
|
431
431
|
}
|
|
@@ -476,25 +476,25 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
476
476
|
this.notificationProcessingQueue.pause(false);
|
|
477
477
|
});
|
|
478
478
|
return () => {
|
|
479
|
+
this.pauseAndFlushNotificationQueue();
|
|
479
480
|
this.apiClient.disconnect();
|
|
480
481
|
onConnectionStateChanged(ConnectionState.CLOSED);
|
|
481
482
|
this.apiClient.transport.ws.removeAllListeners();
|
|
482
483
|
};
|
|
483
|
-
}
|
|
484
|
-
createConnectionStateChangedHandler(onConnectionStateChanged) {
|
|
484
|
+
};
|
|
485
|
+
createConnectionStateChangedHandler = (onConnectionStateChanged) => {
|
|
485
486
|
return (state) => {
|
|
486
|
-
console.info(`Connection state changed to: ${state}`);
|
|
487
487
|
this.connectionState = state;
|
|
488
488
|
onConnectionStateChanged(state);
|
|
489
489
|
this.logger.info(`Connection state changed to: ${state}`);
|
|
490
490
|
};
|
|
491
|
-
}
|
|
491
|
+
};
|
|
492
492
|
/**
|
|
493
493
|
* Creates the event handler that is invoked for each decrypted event from the backend.
|
|
494
494
|
* Responsible for handling specific event types like `MESSAGE_TIMER_UPDATE`, and then
|
|
495
495
|
* forwarding the event to the consumer via the `onEvent` callback.
|
|
496
496
|
*/
|
|
497
|
-
createEventHandler(onEvent) {
|
|
497
|
+
createEventHandler = (onEvent) => {
|
|
498
498
|
return async (payload, source) => {
|
|
499
499
|
const { event } = payload;
|
|
500
500
|
switch (event?.type) {
|
|
@@ -508,14 +508,14 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
508
508
|
// Always forward the event to the consumer
|
|
509
509
|
onEvent(payload, source);
|
|
510
510
|
};
|
|
511
|
-
}
|
|
511
|
+
};
|
|
512
512
|
/**
|
|
513
513
|
* @deprecated This method is used to handle legacy notifications from the backend.
|
|
514
514
|
* It processes notifications from the legacy system, decrypts them, and emits events.
|
|
515
515
|
* It can be replaced with the new notification handling system using `ConsumableNotification`
|
|
516
516
|
* when all clients are capable of handling consumable notifications.
|
|
517
517
|
*/
|
|
518
|
-
createLegacyNotificationHandler(handleEvent, dryRun) {
|
|
518
|
+
createLegacyNotificationHandler = (handleEvent, dryRun) => {
|
|
519
519
|
return async (notification, source) => {
|
|
520
520
|
try {
|
|
521
521
|
const messages = this.service.notification.handleNotification(notification, source, dryRun);
|
|
@@ -527,8 +527,8 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
527
527
|
this.logger.error(`Failed to handle legacy notification "${notification.id}": ${error.message}`, error);
|
|
528
528
|
}
|
|
529
529
|
};
|
|
530
|
-
}
|
|
531
|
-
createNotificationHandler(handleEvent, onNotificationStreamProgress, onConnectionStateChanged, dryRun) {
|
|
530
|
+
};
|
|
531
|
+
createNotificationHandler = (handleEvent, onNotificationStreamProgress, onConnectionStateChanged, dryRun) => {
|
|
532
532
|
return async (notification, source) => {
|
|
533
533
|
try {
|
|
534
534
|
if (notification.type === ConsumableNotification_1.ConsumableEvent.MISSED) {
|
|
@@ -536,20 +536,32 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
536
536
|
return;
|
|
537
537
|
}
|
|
538
538
|
if (notification.type === ConsumableNotification_1.ConsumableEvent.SYNCHRONIZATION) {
|
|
539
|
-
void this.notificationProcessingQueue
|
|
539
|
+
void this.notificationProcessingQueue
|
|
540
|
+
.push(() => this.handleSynchronizationNotification(notification, onConnectionStateChanged))
|
|
541
|
+
.catch(this.handleNotificationQueueError);
|
|
540
542
|
return;
|
|
541
543
|
}
|
|
542
|
-
void this.notificationProcessingQueue
|
|
544
|
+
void this.notificationProcessingQueue
|
|
545
|
+
.push(() => this.decryptAckEmitNotification(notification, handleEvent, source, onNotificationStreamProgress, dryRun))
|
|
546
|
+
.catch(this.handleNotificationQueueError);
|
|
543
547
|
}
|
|
544
548
|
catch (error) {
|
|
545
549
|
this.logger.error(`Failed to handle notification "${notification.type}": ${error.message}`, error);
|
|
546
550
|
}
|
|
547
551
|
};
|
|
548
|
-
}
|
|
549
|
-
|
|
552
|
+
};
|
|
553
|
+
handleNotificationQueueError = (error) => {
|
|
554
|
+
if (error instanceof Error && error.message.includes('Queue was flushed')) {
|
|
555
|
+
// queue is flushed manually so we ignore the error
|
|
556
|
+
this.logger.info('Notification processing queue was flushed, ignoring error', error);
|
|
557
|
+
return;
|
|
558
|
+
}
|
|
559
|
+
throw error;
|
|
560
|
+
};
|
|
561
|
+
acknowledgeSynchronizationNotification = (notification) => {
|
|
550
562
|
this.apiClient.transport.ws.acknowledgeConsumableNotificationSynchronization(notification);
|
|
551
|
-
}
|
|
552
|
-
async
|
|
563
|
+
};
|
|
564
|
+
handleSynchronizationNotification = async (notification, onConnectionStateChanged) => {
|
|
553
565
|
this.acknowledgeSynchronizationNotification(notification);
|
|
554
566
|
const markerId = notification.data.marker_id;
|
|
555
567
|
const currentMarkerId = this.apiClient.transport.http.accessTokenStore.markerToken;
|
|
@@ -563,8 +575,8 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
563
575
|
(0, messageSender_1.resumeMessageSending)();
|
|
564
576
|
onConnectionStateChanged(ConnectionState.LIVE);
|
|
565
577
|
}
|
|
566
|
-
}
|
|
567
|
-
async
|
|
578
|
+
};
|
|
579
|
+
decryptAckEmitNotification = async (notification, handleEvent, source, onNotificationStreamProgress, dryRun) => {
|
|
568
580
|
try {
|
|
569
581
|
const payloads = this.service.notification.handleNotification(notification.data.event, source, dryRun);
|
|
570
582
|
const notificationTime = this.getNotificationEventTime(notification.data.event.payload[0]);
|
|
@@ -581,13 +593,13 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
581
593
|
catch (err) {
|
|
582
594
|
this.logger.error(`Failed to process notification ${notification.data.delivery_tag}`, err);
|
|
583
595
|
}
|
|
584
|
-
}
|
|
585
|
-
getNotificationEventTime(backendEvent) {
|
|
596
|
+
};
|
|
597
|
+
getNotificationEventTime = (backendEvent) => {
|
|
586
598
|
if ('time' in backendEvent && typeof backendEvent.time === 'string') {
|
|
587
599
|
return backendEvent.time;
|
|
588
600
|
}
|
|
589
601
|
return null;
|
|
590
|
-
}
|
|
602
|
+
};
|
|
591
603
|
/**
|
|
592
604
|
* Returns a function to handle missed notifications — i.e., when the backend indicates
|
|
593
605
|
* that some notifications were lost due to age (typically >28 days).
|
|
@@ -597,14 +609,14 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
597
609
|
* It should be replaced with the new notification handling system using `ConsumableNotification`.
|
|
598
610
|
* when all clients are capable of handling consumable notifications.
|
|
599
611
|
*/
|
|
600
|
-
createLegacyMissedNotificationsHandler(onMissedNotifications) {
|
|
612
|
+
createLegacyMissedNotificationsHandler = (onMissedNotifications) => {
|
|
601
613
|
return async (notificationId) => {
|
|
602
614
|
if (this.hasMLSDevice) {
|
|
603
615
|
(0, conversationRejoinQueue_1.queueConversationRejoin)('all-conversations', () => this.service.conversation.handleConversationsEpochMismatch());
|
|
604
616
|
}
|
|
605
617
|
return onMissedNotifications(notificationId);
|
|
606
618
|
};
|
|
607
|
-
}
|
|
619
|
+
};
|
|
608
620
|
/**
|
|
609
621
|
* Returns a processor function for the notification stream (legacy sync).
|
|
610
622
|
* It pauses message sending and MLS rejoining during stream handling to prevent race conditions,
|
|
@@ -616,7 +628,7 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
616
628
|
*
|
|
617
629
|
* @param handlers Various logic handlers wired to notification callbacks
|
|
618
630
|
*/
|
|
619
|
-
createLegacyNotificationStreamProcessor({ handleLegacyNotification, handleMissedNotifications, onNotificationStreamProgress, onConnectionStateChanged, }) {
|
|
631
|
+
createLegacyNotificationStreamProcessor = ({ handleLegacyNotification, handleMissedNotifications, onNotificationStreamProgress, onConnectionStateChanged, }) => {
|
|
620
632
|
return async () => {
|
|
621
633
|
(0, messageSender_1.pauseMessageSending)();
|
|
622
634
|
// We want to avoid triggering rejoins of out-of-sync MLS conversations while we are processing the notification stream
|
|
@@ -637,7 +649,18 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
637
649
|
(0, conversationRejoinQueue_1.resumeRejoiningMLSConversations)();
|
|
638
650
|
onConnectionStateChanged(ConnectionState.LIVE);
|
|
639
651
|
};
|
|
640
|
-
}
|
|
652
|
+
};
|
|
653
|
+
/**
|
|
654
|
+
* In case of a closed connection, we flush the notification processing queue.
|
|
655
|
+
* As we are not acknowledging them before decryption is done
|
|
656
|
+
* they will be resent next time the connection is opened
|
|
657
|
+
* this is to avoid duplicate decryption of notifications
|
|
658
|
+
*/
|
|
659
|
+
pauseAndFlushNotificationQueue = () => {
|
|
660
|
+
this.notificationProcessingQueue.pause();
|
|
661
|
+
this.notificationProcessingQueue.flush();
|
|
662
|
+
this.logger.info('Notification processing queue paused and flushed');
|
|
663
|
+
};
|
|
641
664
|
/**
|
|
642
665
|
* Sets up WebSocket event listeners for:
|
|
643
666
|
* - Incoming backend messages
|
|
@@ -645,7 +668,7 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
645
668
|
* On each new backend message, we pass it to the notification handler.
|
|
646
669
|
* On state changes, we map raw socket states to public connection states and emit them.
|
|
647
670
|
*/
|
|
648
|
-
setupWebSocketListeners(handleNotification, onConnectionStateChanged) {
|
|
671
|
+
setupWebSocketListeners = (handleNotification, onConnectionStateChanged) => {
|
|
649
672
|
this.apiClient.transport.ws.removeAllListeners(tcp_1.WebSocketClient.TOPIC.ON_MESSAGE);
|
|
650
673
|
this.apiClient.transport.ws.on(tcp_1.WebSocketClient.TOPIC.ON_MESSAGE, notification => handleNotification(notification, notification_1.NotificationSource.WEBSOCKET));
|
|
651
674
|
this.apiClient.transport.ws.on(tcp_1.WebSocketClient.TOPIC.ON_STATE_CHANGE, wsState => {
|
|
@@ -655,20 +678,13 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
655
678
|
};
|
|
656
679
|
const connectionState = mapping[wsState];
|
|
657
680
|
if (connectionState === ConnectionState.CLOSED) {
|
|
658
|
-
this.
|
|
659
|
-
/**
|
|
660
|
-
* In case of a closed connection, we flush the notification processing queue.
|
|
661
|
-
* As we are not acknowledging them before decryption is done
|
|
662
|
-
* they will be resent next time the connection is opened
|
|
663
|
-
* this is to avoid duplicate decryption of notifications
|
|
664
|
-
*/
|
|
665
|
-
this.notificationProcessingQueue.flush();
|
|
681
|
+
this.pauseAndFlushNotificationQueue();
|
|
666
682
|
}
|
|
667
683
|
if (connectionState) {
|
|
668
684
|
onConnectionStateChanged(connectionState);
|
|
669
685
|
}
|
|
670
686
|
});
|
|
671
|
-
}
|
|
687
|
+
};
|
|
672
688
|
/**
|
|
673
689
|
* Handles logic for reacting to a missed notification event.
|
|
674
690
|
*
|
|
@@ -690,7 +706,7 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
690
706
|
* the WebSocket transport, unblocking the backend so it resumes sending updates
|
|
691
707
|
* then we remove the flag.
|
|
692
708
|
*/
|
|
693
|
-
reactToMissedNotification() {
|
|
709
|
+
reactToMissedNotification = () => {
|
|
694
710
|
const localStorageKey = 'has_missing_notification';
|
|
695
711
|
// First-time handling: set flag and reload to trigger full re-fetch of state.
|
|
696
712
|
if (!exports.AccountLocalStorageStore.has(localStorageKey)) {
|
|
@@ -701,24 +717,24 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
701
717
|
// After reload: acknowledge the missed notification so backend resumes notifications.
|
|
702
718
|
this.apiClient.transport.ws.acknowledgeMissedNotification();
|
|
703
719
|
exports.AccountLocalStorageStore.remove(localStorageKey);
|
|
704
|
-
}
|
|
705
|
-
getClientCapabilities() {
|
|
720
|
+
};
|
|
721
|
+
getClientCapabilities = () => {
|
|
706
722
|
return this.currentClient?.capabilities || [];
|
|
707
|
-
}
|
|
708
|
-
checkIsConsumable(notification) {
|
|
723
|
+
};
|
|
724
|
+
checkIsConsumable = (notification) => {
|
|
709
725
|
return 'type' in notification;
|
|
710
|
-
}
|
|
711
|
-
generateDbName(context) {
|
|
726
|
+
};
|
|
727
|
+
generateDbName = (context) => {
|
|
712
728
|
const clientType = context.clientType === client_1.ClientType.NONE ? '' : `@${context.clientType}`;
|
|
713
729
|
return `wire@${this.apiClient.config.urls.name}@${context.userId}${clientType}`;
|
|
714
|
-
}
|
|
715
|
-
generateCoreDbName(context) {
|
|
730
|
+
};
|
|
731
|
+
generateCoreDbName = (context) => {
|
|
716
732
|
return `core-${this.generateDbName(context)}`;
|
|
717
|
-
}
|
|
718
|
-
generateEncryptedDbName(context) {
|
|
733
|
+
};
|
|
734
|
+
generateEncryptedDbName = (context) => {
|
|
719
735
|
return `secrets-${this.generateDbName(context)}`;
|
|
720
|
-
}
|
|
721
|
-
async
|
|
736
|
+
};
|
|
737
|
+
initEngine = async (context, encryptedStore) => {
|
|
722
738
|
const dbName = this.generateDbName(context);
|
|
723
739
|
this.logger.debug(`Initialising store with name "${dbName}"...`);
|
|
724
740
|
const openDb = async () => {
|
|
@@ -739,14 +755,14 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
739
755
|
await this.persistCookie(storeEngine, cookie);
|
|
740
756
|
}
|
|
741
757
|
return storeEngine;
|
|
742
|
-
}
|
|
758
|
+
};
|
|
743
759
|
groupIdFromConversationId = async (conversationId, subconversationId) => {
|
|
744
760
|
if (!subconversationId) {
|
|
745
761
|
return this.coreCallbacks?.groupIdFromConversationId(conversationId);
|
|
746
762
|
}
|
|
747
763
|
return this.service?.subconversation.getSubconversationGroupId(conversationId, subconversationId);
|
|
748
764
|
};
|
|
749
|
-
async
|
|
765
|
+
isMLSActiveForClient = async () => {
|
|
750
766
|
// Check for CoreCrypto library, it is required for MLS
|
|
751
767
|
if (!this.options.coreCryptoConfig?.enabled) {
|
|
752
768
|
return false;
|
|
@@ -758,6 +774,6 @@ class Account extends commons_1.TypedEventEmitter {
|
|
|
758
774
|
// Check if MLS is enabled for the public via backend feature flag
|
|
759
775
|
const commonConfig = (await this.service?.team.getCommonFeatureConfig()) ?? {};
|
|
760
776
|
return commonConfig[team_1.FEATURE_KEY.MLS]?.status === team_1.FeatureStatus.ENABLED;
|
|
761
|
-
}
|
|
777
|
+
};
|
|
762
778
|
}
|
|
763
779
|
exports.Account = Account;
|
package/package.json
CHANGED