@wireapp/core 32.0.6 → 32.0.8

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/package.json CHANGED
@@ -43,13 +43,14 @@
43
43
  "jest": "29.0.3",
44
44
  "jest-babel": "1.0.1",
45
45
  "jest-jasmine2": "29.0.3",
46
+ "jest-websocket-mock": "2.4.0",
46
47
  "karma": "6.4.1",
47
48
  "karma-chrome-launcher": "3.1.1",
48
49
  "karma-jasmine": "4.0.2",
49
50
  "karma-jasmine-diff-reporter": "2.0.1",
50
51
  "karma-sourcemap-loader": "0.3.8",
51
52
  "karma-spec-reporter": "0.0.34",
52
- "mock-socket": "9.0.3",
53
+ "mock-socket": "9.1.5",
53
54
  "nock": "13.1.1",
54
55
  "nyc": "15.1.0",
55
56
  "rimraf": "3.0.2",
@@ -81,6 +82,6 @@
81
82
  "test": "jest",
82
83
  "watch": "tsc ---watch"
83
84
  },
84
- "version": "32.0.6",
85
- "gitHead": "b7e78c5c3923cd10386056cdeff94c74a56030a2"
85
+ "version": "32.0.8",
86
+ "gitHead": "9b39965aa991efec2376de9b40118be153d803f6"
86
87
  }
@@ -211,7 +211,7 @@ export declare class Account<T = any> extends EventEmitter {
211
211
  * 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
212
212
  */
213
213
  dryRun?: boolean;
214
- }): Promise<() => void>;
214
+ }): () => void;
215
215
  private generateDbName;
216
216
  private generateSecretsDbName;
217
217
  private initEngine;
@@ -377,7 +377,7 @@ class Account extends events_1.EventEmitter {
377
377
  * @param callbacks callbacks that will be called to handle different events
378
378
  * @returns close a function that will disconnect from the websocket
379
379
  */
380
- async listen({ onEvent = () => { }, onConnectionStateChanged = () => { }, onNotificationStreamProgress = () => { }, onMissedNotifications = () => { }, dryRun = false, } = {}) {
380
+ listen({ onEvent = () => { }, onConnectionStateChanged = () => { }, onNotificationStreamProgress = () => { }, onMissedNotifications = () => { }, dryRun = false, } = {}) {
381
381
  if (!this.apiClient.context) {
382
382
  throw new Error('Context is not set - please login first');
383
383
  }
@@ -432,19 +432,24 @@ class Account extends events_1.EventEmitter {
432
432
  });
433
433
  const processNotificationStream = async (abortHandler) => {
434
434
  // Lock websocket in order to buffer any message that arrives while we handle the notification stream
435
- onConnectionStateChanged(ConnectionState.PROCESSING_NOTIFICATIONS);
436
435
  this.apiClient.transport.ws.lock();
437
- await this.service.notification.handleNotificationStream(async (notification, source, progress) => {
436
+ onConnectionStateChanged(ConnectionState.PROCESSING_NOTIFICATIONS);
437
+ const results = await this.service.notification.processNotificationStream(async (notification, source, progress) => {
438
438
  await handleNotification(notification, source);
439
439
  onNotificationStreamProgress(progress);
440
440
  }, onMissedNotifications, abortHandler);
441
+ this.logger.log(`Finished processing notifications ${JSON.stringify(results)}`, results);
442
+ if (abortHandler.isAborted()) {
443
+ this.logger.warn('Ending connection process as websocket was closed');
444
+ return;
445
+ }
446
+ onConnectionStateChanged(ConnectionState.LIVE);
441
447
  // We can now unlock the websocket and let the new messages being handled and decrypted
442
448
  this.apiClient.transport.ws.unlock();
443
449
  // We need to wait for the notification stream to be fully handled before releasing the message sending queue.
444
450
  // This is due to the nature of how message are encrypted, any change in mls epoch needs to happen before we start encrypting any kind of messages
445
- this.logger.log(`resume message sending. ${(0, messageSender_1.getQueueLength)()} messages to be sent`);
451
+ this.logger.info(`Resuming message sending. ${(0, messageSender_1.getQueueLength)()} messages to be sent`);
446
452
  (0, messageSender_1.resumeMessageSending)();
447
- onConnectionStateChanged(ConnectionState.LIVE);
448
453
  };
449
454
  this.apiClient.connect(processNotificationStream);
450
455
  return () => {
@@ -38,7 +38,7 @@ class CryptographyService {
38
38
  this.config = config;
39
39
  this.cryptobox = new cryptobox_1.Cryptobox(this.storeEngine, config.nbPrekeys);
40
40
  this.database = new CryptographyDatabaseRepository_1.CryptographyDatabaseRepository(this.storeEngine);
41
- this.logger = (0, logdown_1.default)('@wireapp/core/cryptography/CryptographyService', {
41
+ this.logger = (0, logdown_1.default)('@wireapp/core/CryptographyService', {
42
42
  logger: console,
43
43
  markdown: false,
44
44
  });
@@ -153,7 +153,7 @@ class GenericMessageMapper {
153
153
  }
154
154
  }
155
155
  exports.GenericMessageMapper = GenericMessageMapper;
156
- GenericMessageMapper.logger = (0, logdown_1.default)('@wireapp/core/cryptography/GenericMessageMapper', {
156
+ GenericMessageMapper.logger = (0, logdown_1.default)('@wireapp/core/GenericMessageMapper', {
157
157
  logger: console,
158
158
  markdown: false,
159
159
  });
@@ -46,7 +46,11 @@ export declare class NotificationService extends EventEmitter {
46
46
  getNotificationEventList(): Promise<Events.BackendEvent[]>;
47
47
  setLastEventDate(eventDate: Date): Promise<Date>;
48
48
  setLastNotificationId(lastNotification: Notification): Promise<string>;
49
- handleNotificationStream(notificationHandler: NotificationHandler, onMissedNotifications: (notificationId: string) => void, abortHandler: AbortHandler): Promise<void>;
49
+ processNotificationStream(notificationHandler: NotificationHandler, onMissedNotifications: (notificationId: string) => void, abortHandler: AbortHandler): Promise<{
50
+ total: number;
51
+ error: number;
52
+ success: number;
53
+ }>;
50
54
  /**
51
55
  * Checks if an event should be ignored.
52
56
  * An event that has a date prior to that last event that we have parsed should be ignored
@@ -84,7 +84,7 @@ class NotificationService extends events_1.EventEmitter {
84
84
  constructor(apiClient, cryptographyService, mlsService, storeEngine) {
85
85
  super();
86
86
  this.mlsService = mlsService;
87
- this.logger = (0, logdown_1.default)('@wireapp/core/notification/NotificationService', {
87
+ this.logger = (0, logdown_1.default)('@wireapp/core/NotificationService', {
88
88
  logger: console,
89
89
  markdown: false,
90
90
  });
@@ -93,10 +93,9 @@ class NotificationService extends events_1.EventEmitter {
93
93
  this.backend = new NotificationBackendRepository_1.NotificationBackendRepository(this.apiClient);
94
94
  this.database = new NotificationDatabaseRepository_1.NotificationDatabaseRepository(storeEngine);
95
95
  }
96
- async getAllNotifications() {
96
+ async getAllNotifications(since) {
97
97
  const clientId = this.apiClient.clientId;
98
- const lastNotificationId = await this.database.getLastNotificationId();
99
- return this.backend.getAllNotifications(clientId, lastNotificationId);
98
+ return this.backend.getAllNotifications(clientId, since);
100
99
  }
101
100
  /** Should only be called with a completely new client. */
102
101
  async initializeNotificationStream() {
@@ -132,23 +131,39 @@ class NotificationService extends events_1.EventEmitter {
132
131
  async setLastNotificationId(lastNotification) {
133
132
  return this.database.updateLastNotificationId(lastNotification);
134
133
  }
135
- async handleNotificationStream(notificationHandler, onMissedNotifications, abortHandler) {
136
- const { notifications, missedNotification } = await this.getAllNotifications();
134
+ async processNotificationStream(notificationHandler, onMissedNotifications, abortHandler) {
135
+ const lastNotificationId = await this.database.getLastNotificationId();
136
+ const { notifications, missedNotification } = await this.getAllNotifications(lastNotificationId);
137
137
  if (missedNotification) {
138
138
  onMissedNotifications(missedNotification);
139
139
  }
140
+ const results = { total: notifications.length, error: 0, success: 0 };
141
+ const logMessage = notifications.length > 0
142
+ ? `Start processing ${notifications.length} notifications since notification id ${lastNotificationId}`
143
+ : `No notification to process from the stream`;
144
+ this.logger.log(logMessage);
140
145
  for (const [index, notification] of notifications.entries()) {
141
146
  if (abortHandler.isAborted()) {
142
147
  /* Stop handling notifications if the websocket has been disconnected.
143
148
  * Upon reconnecting we are going to restart handling the notification stream for where we left of
144
149
  */
145
- return;
150
+ this.logger.warn(`Stop processing notifications as connection to websocket was closed`);
151
+ return results;
152
+ }
153
+ try {
154
+ await notificationHandler(notification, conversation_1.PayloadBundleSource.NOTIFICATION_STREAM, {
155
+ done: index + 1,
156
+ total: notifications.length,
157
+ });
158
+ results.success++;
159
+ }
160
+ catch (error) {
161
+ const message = error instanceof Error ? error.message : error;
162
+ this.logger.error(`Error while processing notification ${notification.id}: ${message}`, error);
163
+ results.error++;
146
164
  }
147
- await notificationHandler(notification, conversation_1.PayloadBundleSource.NOTIFICATION_STREAM, {
148
- done: index + 1,
149
- total: notifications.length,
150
- }).catch(error => this.logger.error(error));
151
165
  }
166
+ return results;
152
167
  }
153
168
  /**
154
169
  * Checks if an event should be ignored.
@@ -23,7 +23,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
23
23
  Object.defineProperty(exports, "__esModule", { value: true });
24
24
  exports.TaskScheduler = void 0;
25
25
  const logdown_1 = __importDefault(require("logdown"));
26
- const logger = (0, logdown_1.default)('@wireapp/core/util/TaskScheduler/TaskScheduler', {
26
+ const logger = (0, logdown_1.default)('@wireapp/core/TaskScheduler', {
27
27
  logger: console,
28
28
  markdown: false,
29
29
  });