@wireapp/core 46.0.16 → 46.0.17

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.
Files changed (116) hide show
  1. package/lib/Account.js +43 -56
  2. package/lib/account/AccountService.js +1 -0
  3. package/lib/broadcast/BroadcastService.js +3 -0
  4. package/lib/client/ClientBackendRepository.js +1 -0
  5. package/lib/client/ClientDatabaseRepository.js +16 -7
  6. package/lib/client/ClientService.d.ts.map +1 -1
  7. package/lib/client/ClientService.js +14 -13
  8. package/lib/connection/ConnectionService.js +1 -0
  9. package/lib/conversation/AssetService/AssetService.d.ts +0 -1
  10. package/lib/conversation/AssetService/AssetService.d.ts.map +1 -1
  11. package/lib/conversation/AssetService/AssetService.js +13 -6
  12. package/lib/conversation/AssetService/AssetService.test.js +1 -1
  13. package/lib/conversation/ConversationService/ConversationService.d.ts.map +1 -1
  14. package/lib/conversation/ConversationService/ConversationService.js +90 -80
  15. package/lib/conversation/ConversationService/ConversationService.test.js +12 -5
  16. package/lib/conversation/ConversationService/Utility/getConversationQualifiedMembers.d.ts.map +1 -1
  17. package/lib/conversation/MessageTimer/MessageTimer.js +2 -0
  18. package/lib/conversation/SubconversationService/SubconversationService.d.ts.map +1 -1
  19. package/lib/conversation/SubconversationService/SubconversationService.js +23 -17
  20. package/lib/conversation/content/AssetContent.d.ts +0 -1
  21. package/lib/conversation/content/AssetContent.d.ts.map +1 -1
  22. package/lib/conversation/content/ContentType.js +18 -19
  23. package/lib/conversation/content/FileContent.d.ts +0 -1
  24. package/lib/conversation/content/FileContent.d.ts.map +1 -1
  25. package/lib/conversation/content/ImageContent.d.ts +0 -1
  26. package/lib/conversation/content/ImageContent.d.ts.map +1 -1
  27. package/lib/conversation/message/MessageBuilder.js +22 -23
  28. package/lib/conversation/message/MessageService.js +5 -4
  29. package/lib/conversation/message/MessageService.test.js +20 -9
  30. package/lib/conversation/message/MessageToProtoMapper.js +2 -2
  31. package/lib/conversation/message/RecipientsHelper.js +1 -2
  32. package/lib/conversation/message/TextContentBuilder.js +3 -2
  33. package/lib/conversation/message/UserClientsUtil.js +2 -3
  34. package/lib/conversation/message/messageSender.js +5 -6
  35. package/lib/cryptography/AssetCryptography/AssetCryptography.d.ts.map +1 -1
  36. package/lib/cryptography/GenericMessageMapper.js +74 -22
  37. package/lib/cryptography/MessageHashService.d.ts +0 -1
  38. package/lib/cryptography/MessageHashService.d.ts.map +1 -1
  39. package/lib/cryptography/MessageHashService.js +2 -0
  40. package/lib/errors/DecryptionError.js +2 -0
  41. package/lib/errors/FederatedBackendsError.js +3 -2
  42. package/lib/giphy/GiphyService.js +1 -0
  43. package/lib/linkPreview/LinkPreviewService.js +2 -12
  44. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/AcmeService.d.ts +4 -4
  45. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/AcmeService.js +9 -8
  46. package/lib/messagingProtocols/mls/E2EIdentityService/Connection/AcmeServer/schema.d.ts +8 -8
  47. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.js +33 -3
  48. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceExternal.test.js +11 -11
  49. package/lib/messagingProtocols/mls/E2EIdentityService/E2EIServiceInternal.js +15 -5
  50. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Account.d.ts.map +1 -1
  51. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Account.js +1 -1
  52. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Authorization.d.ts +1 -1
  53. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Authorization.d.ts.map +1 -1
  54. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Authorization.js +2 -3
  55. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Certificate.js +1 -1
  56. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Order.d.ts.map +1 -1
  57. package/lib/messagingProtocols/mls/E2EIdentityService/Steps/Order.js +2 -2
  58. package/lib/messagingProtocols/mls/E2EIdentityService/Storage/E2EIStorage.d.ts.map +1 -1
  59. package/lib/messagingProtocols/mls/E2EIdentityService/Storage/E2EIStorage.js +1 -2
  60. package/lib/messagingProtocols/mls/E2EIdentityService/Storage/E2EIStorage.schema.d.ts +4 -4
  61. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/IncomingMessagesQueue/IncomingMesssagesQueue.d.ts.map +1 -1
  62. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.d.ts.map +1 -1
  63. package/lib/messagingProtocols/mls/EventHandler/events/messageAdd/messageAdd.js +1 -1
  64. package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.d.ts.map +1 -1
  65. package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.js +1 -1
  66. package/lib/messagingProtocols/mls/EventHandler/events/welcomeMessage/welcomeMessage.test.js +7 -3
  67. package/lib/messagingProtocols/mls/MLSService/ClientMLSError.js +1 -0
  68. package/lib/messagingProtocols/mls/MLSService/CoreCryptoMLSError.d.ts.map +1 -1
  69. package/lib/messagingProtocols/mls/MLSService/MLSService.d.ts.map +1 -1
  70. package/lib/messagingProtocols/mls/MLSService/MLSService.js +109 -114
  71. package/lib/messagingProtocols/mls/MLSService/MLSService.test.js +28 -9
  72. package/lib/messagingProtocols/mls/MLSService/commitBundleUtil.js +1 -2
  73. package/lib/messagingProtocols/mls/conversationRejoinQueue.js +3 -4
  74. package/lib/messagingProtocols/mls/utils/MLSId.js +2 -3
  75. package/lib/messagingProtocols/proteus/EventHandler/events/otrMessageAdd/otrMessageAdd.d.ts.map +1 -1
  76. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/CoreCryptoWrapper.js +6 -2
  77. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.js +3 -0
  78. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CoreCryptoWrapper/PrekeysTracker/PrekeysTracker.store.js +1 -1
  79. package/lib/messagingProtocols/proteus/ProteusService/CryptoClient/CryptoboxWrapper.js +5 -4
  80. package/lib/messagingProtocols/proteus/ProteusService/DecryptionErrorGenerator/DecryptionErrorGenerator.js +1 -2
  81. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.js +17 -14
  82. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts +4 -7
  83. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.mocks.d.ts.map +1 -1
  84. package/lib/messagingProtocols/proteus/ProteusService/ProteusService.test.js +15 -15
  85. package/lib/messagingProtocols/proteus/ProteusService/cryptoMigrationStateStore.js +1 -1
  86. package/lib/messagingProtocols/proteus/ProteusService/identityClearer.js +1 -2
  87. package/lib/messagingProtocols/proteus/ProteusService/sessionIdMigrator.js +2 -3
  88. package/lib/messagingProtocols/proteus/ProteusService/userDomainFilters.js +1 -2
  89. package/lib/messagingProtocols/proteus/Utility/Recipients.d.ts.map +1 -1
  90. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.d.ts.map +1 -1
  91. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.js +14 -14
  92. package/lib/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.test.js +5 -2
  93. package/lib/messagingProtocols/proteus/Utility/getGenericMessageParams.d.ts.map +1 -1
  94. package/lib/notification/NotificationBackendRepository.d.ts +1 -1
  95. package/lib/notification/NotificationBackendRepository.js +1 -0
  96. package/lib/notification/NotificationDatabaseRepository.js +1 -0
  97. package/lib/notification/NotificationService.js +38 -49
  98. package/lib/secretStore/encryptedStore.js +10 -22
  99. package/lib/secretStore/secretKeyGenerator.js +2 -2
  100. package/lib/secretStore/secretKeyGenerator.test.js +1 -1
  101. package/lib/self/SelfService.js +2 -1
  102. package/lib/storage/CoreDB.js +2 -3
  103. package/lib/team/TeamService.js +1 -0
  104. package/lib/test/PayloadHelper.js +3 -4
  105. package/lib/testUtils/index.js +2 -3
  106. package/lib/user/UserService.d.ts +2 -2
  107. package/lib/user/UserService.js +1 -0
  108. package/lib/util/LocalStorageStore/index.d.ts.map +1 -1
  109. package/lib/util/LowPrecisionTaskScheduler/LowPrecisionTaskScheduler.js +4 -6
  110. package/lib/util/RecurringTaskScheduler/RecurringTaskScheduler.d.ts.map +1 -1
  111. package/lib/util/RecurringTaskScheduler/RecurringTaskScheduler.js +34 -33
  112. package/lib/util/TaskScheduler/TaskScheduler.d.ts +1 -1
  113. package/lib/util/TaskScheduler/TaskScheduler.d.ts.map +1 -1
  114. package/lib/util/TypePredicateUtil.js +7 -10
  115. package/lib/util/fullyQualifiedClientIdUtils.js +1 -2
  116. package/package.json +3 -3
@@ -37,11 +37,15 @@ const getGenericMessageParams_1 = require("../Utility/getGenericMessageParams");
37
37
  const isClearFromMismatch_1 = require("../Utility/isClearFromMismatch");
38
38
  const SessionHandler_1 = require("../Utility/SessionHandler");
39
39
  class ProteusService {
40
+ apiClient;
41
+ cryptoClient;
42
+ config;
43
+ messageService;
44
+ logger = (0, logdown_1.default)('@wireapp/core/ProteusService');
40
45
  constructor(apiClient, cryptoClient, config) {
41
46
  this.apiClient = apiClient;
42
47
  this.cryptoClient = cryptoClient;
43
48
  this.config = config;
44
- this.logger = (0, logdown_1.default)('@wireapp/core/ProteusService');
45
49
  this.messageService = new MessageService_1.MessageService(this.apiClient, this);
46
50
  }
47
51
  async handleOtrMessageAddEvent(event) {
@@ -51,7 +55,6 @@ class ProteusService {
51
55
  });
52
56
  }
53
57
  async initClient(storeEngine, context) {
54
- var _a;
55
58
  const dbName = storeEngine.storeName;
56
59
  if (context.domain) {
57
60
  // We want sessions to be fully qualified from now on
@@ -73,7 +76,7 @@ class ProteusService {
73
76
  this.logger.error('Client was not able to perform DB migration: ', error);
74
77
  }
75
78
  }
76
- const backendPrekeys = await this.apiClient.api.client.getClientPreKeys((_a = context.clientId) !== null && _a !== void 0 ? _a : '');
79
+ const backendPrekeys = await this.apiClient.api.client.getClientPreKeys(context.clientId ?? '');
77
80
  const totalUsableBackedPrekeys = backendPrekeys.length - 1; // we remove the last resort prekey from the total number of available prekeys
78
81
  return this.cryptoClient.init(totalUsableBackedPrekeys);
79
82
  }
@@ -101,7 +104,6 @@ class ProteusService {
101
104
  return this.cryptoClient.getRemoteFingerprint(sessionId);
102
105
  }
103
106
  async createConversation(conversationData) {
104
- var _a;
105
107
  try {
106
108
  const conversation = await this.apiClient.api.conversation.postConversation(conversationData);
107
109
  return { conversation };
@@ -115,8 +117,8 @@ class ProteusService {
115
117
  }
116
118
  case conversation_1.FederatedBackendsErrorLabel.UNREACHABLE_BACKENDS: {
117
119
  const { backends } = error;
118
- const { excludedUsers: unreachableUsers, includedUsers: availableUsers } = (0, userDomainFilters_1.filterUsersFromDomains)((_a = conversationData.qualified_users) !== null && _a !== void 0 ? _a : [], backends);
119
- conversationData = Object.assign(Object.assign({}, conversationData), { qualified_users: availableUsers });
120
+ const { excludedUsers: unreachableUsers, includedUsers: availableUsers } = (0, userDomainFilters_1.filterUsersFromDomains)(conversationData.qualified_users ?? [], backends);
121
+ conversationData = { ...conversationData, qualified_users: availableUsers };
120
122
  // If conversation creation returns an error because a backend is offline,
121
123
  // we try creating the conversation again with users from available backends
122
124
  const response = await this.apiClient.api.conversation.postConversation(conversationData);
@@ -188,7 +190,6 @@ class ProteusService {
188
190
  }
189
191
  }
190
192
  async sendMessage({ userIds, conversationId, nativePush, targetMode, payload, onClientMismatch, }) {
191
- var _a;
192
193
  const messageParams = await (0, getGenericMessageParams_1.getGenericMessageParams)({
193
194
  apiClient: this.apiClient,
194
195
  sendingClientId: this.apiClient.validatedClientId,
@@ -201,16 +202,19 @@ class ProteusService {
201
202
  },
202
203
  });
203
204
  const { sendingClientId, recipients, plainText, options } = messageParams;
204
- const response = await this.messageService.sendMessage(sendingClientId, recipients, plainText, Object.assign(Object.assign({}, options), { onClientMismatch: mismatch => onClientMismatch === null || onClientMismatch === void 0 ? void 0 : onClientMismatch(mismatch, false) }));
205
+ const response = await this.messageService.sendMessage(sendingClientId, recipients, plainText, {
206
+ ...options,
207
+ onClientMismatch: mismatch => onClientMismatch?.(mismatch, false),
208
+ });
205
209
  if (!response.canceled) {
206
210
  if (!(0, isClearFromMismatch_1.isClearFromMismatch)(response)) {
207
211
  // We warn the consumer that there is a mismatch that did not prevent message sending
208
- await (onClientMismatch === null || onClientMismatch === void 0 ? void 0 : onClientMismatch(response, true));
212
+ await onClientMismatch?.(response, true);
209
213
  }
210
214
  this.logger.log(`Successfully sent Proteus message to conversation '${conversationId.id}'`);
211
215
  }
212
216
  const sendingState = response.canceled ? conversation_2.MessageSendingState.CANCELED : conversation_2.MessageSendingState.OUTGOING_SENT;
213
- const failedToSend = response.failed || Object.keys((_a = response.failed_to_confirm_clients) !== null && _a !== void 0 ? _a : {}).length > 0
217
+ const failedToSend = response.failed || Object.keys(response.failed_to_confirm_clients ?? {}).length > 0
214
218
  ? {
215
219
  queued: response.failed_to_confirm_clients,
216
220
  failed: response.failed,
@@ -224,7 +228,6 @@ class ProteusService {
224
228
  };
225
229
  }
226
230
  async decrypt(encryptedText, userId, clientId) {
227
- var _a, _b;
228
231
  const sessionId = this.constructSessionId(userId, clientId);
229
232
  const sessionExists = await this.cryptoClient.sessionExists(sessionId);
230
233
  try {
@@ -233,11 +236,11 @@ class ProteusService {
233
236
  : await this.cryptoClient.decrypt(sessionId, encryptedText);
234
237
  if (!sessionExists) {
235
238
  await this.cryptoClient.saveSession(sessionId);
236
- (_b = (_a = this.config).onNewClient) === null || _b === void 0 ? void 0 : _b.call(_a, { userId, clientId });
237
- this.logger.info(`Created a new session from message for session ID "${sessionId}" and decrypted the message`);
239
+ this.config.onNewClient?.({ userId, clientId });
240
+ this.logger.debug(`Created a new session from message for session ID "${sessionId}" and decrypted the message`);
238
241
  }
239
242
  else {
240
- this.logger.info(`Decrypted message for session ID "${sessionId}"`);
243
+ this.logger.debug(`Decrypted message for session ID "${sessionId}"`);
241
244
  }
242
245
  return decryptedMessage;
243
246
  }
@@ -1,11 +1,8 @@
1
1
  import { APIClient } from '@wireapp/api-client';
2
2
  import { CryptoClient } from './CryptoClient';
3
3
  import { ProteusService } from './ProteusService';
4
- export declare const buildProteusService: () => Promise<[
5
- ProteusService,
6
- {
7
- apiClient: APIClient;
8
- cryptoClient: CryptoClient;
9
- }
10
- ]>;
4
+ export declare const buildProteusService: () => Promise<[ProteusService, {
5
+ apiClient: APIClient;
6
+ cryptoClient: CryptoClient;
7
+ }]>;
11
8
  //# sourceMappingURL=ProteusService.mocks.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"ProteusService.mocks.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.mocks.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAIhD,eAAO,MAAM,mBAAmB,QAAa,QAC3C;IAAC,cAAc;IAAE;QAAC,SAAS,EAAE,SAAS,CAAC;QAAC,YAAY,EAAE,YAAY,CAAA;KAAC;CAAC,CAgBrE,CAAC"}
1
+ {"version":3,"file":"ProteusService.mocks.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/ProteusService/ProteusService.mocks.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAE9C,OAAO,EAAC,YAAY,EAAC,MAAM,gBAAgB,CAAC;AAE5C,OAAO,EAAC,cAAc,EAAC,MAAM,kBAAkB,CAAC;AAIhD,eAAO,MAAM,mBAAmB,QAAa,OAAO,CAClD,CAAC,cAAc,EAAE;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,YAAY,CAAA;CAAC,CAAC,CAgBrE,CAAC"}
@@ -63,7 +63,11 @@ jest.mock('./CryptoClient/CoreCryptoWrapper/PrekeysTracker', () => {
63
63
  }),
64
64
  };
65
65
  });
66
- jest.mock('../Utility/Recipients', () => (Object.assign(Object.assign({}, jest.requireActual('../Utility/Recipients')), { getRecipientsForConversation: jest.fn(), getQualifiedRecipientsForConversation: jest.fn() })));
66
+ jest.mock('../Utility/Recipients', () => ({
67
+ ...jest.requireActual('../Utility/Recipients'),
68
+ getRecipientsForConversation: jest.fn(),
69
+ getQualifiedRecipientsForConversation: jest.fn(),
70
+ }));
67
71
  const MockedRecipients = Recipients;
68
72
  const prepareDataForEncryption = async () => {
69
73
  const [proteusService, { cryptoClient, apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
@@ -206,7 +210,7 @@ describe('ProteusService', () => {
206
210
  const result = await proteusService.handleOtrMessageAddEvent(eventPayload);
207
211
  expect(result).toBeDefined();
208
212
  expect(createSessionSpy).not.toHaveBeenCalled();
209
- expect(result === null || result === void 0 ? void 0 : result.decryptedData).toBe(decryptedMessage);
213
+ expect(result?.decryptedData).toBe(decryptedMessage);
210
214
  });
211
215
  it('decrypts incoming proteus encrypted and creates session if not already existing', async () => {
212
216
  const [proteusService, { cryptoClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
@@ -219,7 +223,7 @@ describe('ProteusService', () => {
219
223
  expect(result).toBeDefined();
220
224
  expect(createSessionSpy).toHaveBeenCalled();
221
225
  expect(decryptSpy).not.toHaveBeenCalled();
222
- expect(result === null || result === void 0 ? void 0 : result.decryptedData).toBe(decryptedMessage);
226
+ expect(result?.decryptedData).toBe(decryptedMessage);
223
227
  });
224
228
  });
225
229
  describe('"encrypt"', () => {
@@ -455,7 +459,6 @@ describe('ProteusService', () => {
455
459
  });
456
460
  });
457
461
  it(`returns the recipients that will receive the message later`, async () => {
458
- var _a;
459
462
  const [proteusService] = await (0, ProteusService_mocks_1.buildProteusService)();
460
463
  const recipients = {
461
464
  domain1: { user1: ['client1'], user2: ['client11', 'client12'] },
@@ -477,7 +480,7 @@ describe('ProteusService', () => {
477
480
  userIds: recipients,
478
481
  });
479
482
  expect(result.state).toBe(conversation_2.MessageSendingState.OUTGOING_SENT);
480
- expect((_a = result.failedToSend) === null || _a === void 0 ? void 0 : _a.queued).toEqual({ domain2: recipients.domain2 });
483
+ expect(result.failedToSend?.queued).toEqual({ domain2: recipients.domain2 });
481
484
  });
482
485
  });
483
486
  });
@@ -502,7 +505,6 @@ describe('ProteusService', () => {
502
505
  expect(event).toEqual(baseResponse);
503
506
  });
504
507
  it('partially add users if some backends are unreachable', async () => {
505
- var _a, _b, _c, _d;
506
508
  const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
507
509
  const postMembersSpy = jest
508
510
  .spyOn(apiClient.api.conversation, 'postMembers')
@@ -515,11 +517,10 @@ describe('ProteusService', () => {
515
517
  expect(postMembersSpy).toHaveBeenCalledTimes(2);
516
518
  expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining([...usersDomain1, ...usersDomain2]));
517
519
  expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining(usersDomain2));
518
- expect((_b = (_a = result.failedToAdd) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.reason).toBe(conversation_2.AddUsersFailureReasons.UNREACHABLE_BACKENDS);
519
- expect((_d = (_c = result.failedToAdd) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.users).toEqual([...usersDomain1]);
520
+ expect(result.failedToAdd?.[0]?.reason).toBe(conversation_2.AddUsersFailureReasons.UNREACHABLE_BACKENDS);
521
+ expect(result.failedToAdd?.[0]?.users).toEqual([...usersDomain1]);
520
522
  });
521
523
  it('completely fails to add users if some backends are unreachable', async () => {
522
- var _a, _b, _c, _d;
523
524
  const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
524
525
  const allUsers = [...usersDomain1, ...usersDomain2];
525
526
  const postMembersSpy = jest
@@ -532,11 +533,10 @@ describe('ProteusService', () => {
532
533
  expect(postMembersSpy).toHaveBeenCalledTimes(2);
533
534
  expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining(allUsers));
534
535
  expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining(usersDomain2));
535
- expect((_b = (_a = result.failedToAdd) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.reason).toBe(conversation_2.AddUsersFailureReasons.UNREACHABLE_BACKENDS);
536
- expect((_d = (_c = result.failedToAdd) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.users).toEqual(allUsers);
536
+ expect(result.failedToAdd?.[0]?.reason).toBe(conversation_2.AddUsersFailureReasons.UNREACHABLE_BACKENDS);
537
+ expect(result.failedToAdd?.[0]?.users).toEqual(allUsers);
537
538
  });
538
539
  it('partially add users if some users are part of not-connected backends', async () => {
539
- var _a, _b, _c, _d;
540
540
  const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
541
541
  const postMembersSpy = jest
542
542
  .spyOn(apiClient.api.conversation, 'postMembers')
@@ -549,8 +549,8 @@ describe('ProteusService', () => {
549
549
  expect(postMembersSpy).toHaveBeenCalledTimes(2);
550
550
  expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining([...usersDomain1, ...usersDomain2]));
551
551
  expect(postMembersSpy).toHaveBeenCalledWith(conversationId, expect.arrayContaining(usersDomain1));
552
- expect((_b = (_a = result.failedToAdd) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.reason).toBe(conversation_2.AddUsersFailureReasons.NON_FEDERATING_BACKENDS);
553
- expect((_d = (_c = result.failedToAdd) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.users).toEqual([...usersDomain2, ...usersDomain3]);
552
+ expect(result.failedToAdd?.[0]?.reason).toBe(conversation_2.AddUsersFailureReasons.NON_FEDERATING_BACKENDS);
553
+ expect(result.failedToAdd?.[0]?.users).toEqual([...usersDomain2, ...usersDomain3]);
554
554
  });
555
555
  });
556
556
  describe('createConversation', () => {
@@ -579,7 +579,7 @@ describe('ProteusService', () => {
579
579
  };
580
580
  it('adds all requested users to a new conversation', async () => {
581
581
  const [proteusService, { apiClient }] = await (0, ProteusService_mocks_1.buildProteusService)();
582
- jest.spyOn(apiClient.api.conversation, 'postConversation').mockResolvedValueOnce(Object.assign({}, newConversation));
582
+ jest.spyOn(apiClient.api.conversation, 'postConversation').mockResolvedValueOnce({ ...newConversation });
583
583
  const result = await proteusService.createConversation({
584
584
  receipt_mode: null,
585
585
  qualified_users: [...usersDomain1, ...usersDomain2, ...usersDomain3],
@@ -23,7 +23,7 @@ function getLocalStorage() {
23
23
  try {
24
24
  return window.localStorage;
25
25
  }
26
- catch (_a) {
26
+ catch {
27
27
  return { setItem: () => { }, getItem: () => { }, removeItem: () => { } };
28
28
  }
29
29
  }
@@ -18,7 +18,7 @@
18
18
  *
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.deleteIdentity = void 0;
21
+ exports.deleteIdentity = deleteIdentity;
22
22
  /** all the tables in the database that stores information relative to the client identity */
23
23
  const IDENTITY_STORES = ['amplify', 'clients', 'keys', 'prekeys', 'sessions', 'group_ids'];
24
24
  /**
@@ -30,4 +30,3 @@ function deleteIdentity(storeEngine) {
30
30
  //make sure we use enum's lowercase values, not uppercase keys
31
31
  IDENTITY_STORES.map(store => storeEngine.deleteAll(store)));
32
32
  }
33
- exports.deleteIdentity = deleteIdentity;
@@ -18,7 +18,7 @@
18
18
  *
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.migrateToQualifiedSessionIds = void 0;
21
+ exports.migrateToQualifiedSessionIds = migrateToQualifiedSessionIds;
22
22
  const sessionTableName = 'sessions';
23
23
  /**
24
24
  * Will migrate all the session ids in the database to fully qualified ids (from 'user-id@device-id` to `domain@user-id@device-id`)
@@ -34,7 +34,7 @@ async function migrateToQualifiedSessionIds(storeEngine, defaultDomain) {
34
34
  .reduce((acc, session) => {
35
35
  return acc.concat({
36
36
  oldId: session.id,
37
- newSession: Object.assign(Object.assign({}, session), { id: `${defaultDomain}@${session.id}` }),
37
+ newSession: { ...session, id: `${defaultDomain}@${session.id}` },
38
38
  });
39
39
  }, []);
40
40
  for (const { oldId, newSession } of updatedSessions) {
@@ -43,4 +43,3 @@ async function migrateToQualifiedSessionIds(storeEngine, defaultDomain) {
43
43
  await storeEngine.create(sessionTableName, newSession.id, newSession);
44
44
  }
45
45
  }
46
- exports.migrateToQualifiedSessionIds = migrateToQualifiedSessionIds;
@@ -18,7 +18,7 @@
18
18
  *
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.filterUsersFromDomains = void 0;
21
+ exports.filterUsersFromDomains = filterUsersFromDomains;
22
22
  function filterUsersFromDomains(userIds, domainsToExclude) {
23
23
  const excludedUsers = [];
24
24
  const includedUsers = [];
@@ -28,4 +28,3 @@ function filterUsersFromDomains(userIds, domainsToExclude) {
28
28
  includedUsers,
29
29
  };
30
30
  }
31
- exports.filterUsersFromDomains = filterUsersFromDomains;
@@ -1 +1 @@
1
- {"version":3,"file":"Recipients.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/Utility/Recipients.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAE5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAczD,UAAU,2CAA2C;IACnD,SAAS,EAAE,SAAS,CAAC;IACrB,cAAc,EAAE,WAAW,CAAC;IAC5B,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,oBAAoB,CAAC;CAChD;AAED,QAAA,MAAM,4BAA4B,4CAI/B,2CAA2C,KAAG,QAAQ,oBAAoB,CAW5E,CAAC;AAEF,OAAO,EAAC,4BAA4B,EAAC,CAAC"}
1
+ {"version":3,"file":"Recipients.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/Utility/Recipients.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAE5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAC,MAAM,8BAA8B,CAAC;AAczD,UAAU,2CAA2C;IACnD,SAAS,EAAE,SAAS,CAAC;IACrB,cAAc,EAAE,WAAW,CAAC;IAC5B,OAAO,CAAC,EAAE,WAAW,EAAE,GAAG,oBAAoB,CAAC;CAChD;AAED,QAAA,MAAM,4BAA4B,4CAI/B,2CAA2C,KAAG,OAAO,CAAC,oBAAoB,CAW5E,CAAC;AAEF,OAAO,EAAC,4BAA4B,EAAC,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SessionHandler.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAE,4BAA4B,EAAC,MAAM,8BAA8B,CAAC;AAEvF,OAAO,EAAC,MAAM,EAAC,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAK9C,OAAO,EAAC,YAAY,EAAC,MAAM,mCAAmC,CAAC;AAE/D,UAAU,wBAAwB;IAChC,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,KAAK,kBAAkB,GAAG;IACxB,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,8GAA8G;IAC9G,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,6EAA6E;IAC7E,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;CACxB,CAAC;AAEF,QAAA,MAAM,kBAAkB,yBAAwB,wBAAwB,KAAG,MAI1E,CAAC;AA6BF;;;GAGG;AACH,QAAA,MAAM,WAAW,wCACoB;IAAC,MAAM,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAC,+BACvE;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,YAAY,CAAA;CAAC,KAC5E,QAAQ,MAAM,CAUhB,CAAC;AAqBF,UAAU,wCAAwC;IAChD,UAAU,EAAE,oBAAoB,GAAG,4BAA4B,CAAC;IAChE,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,QAAA,MAAM,YAAY,qDAKf,wCAAwC,KAAG,QAAQ,kBAAkB,CAwDvE,CAAC;AAEF,UAAU,mBAAmB;IAC3B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;CAC5B;AACD,iBAAe,aAAa,CAAC,MAAM,EAAE,mBAAmB,iBAGvD;AA4CD,KAAK,iBAAiB,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9E;;GAEG;AACH,QAAA,MAAM,sBAAsB,gBAAiB,IAAI,MAAM,EAAE,CAAC,CAAC,KAAG,kBAAkB,CAAC,CAYhF,CAAC;AAEF,OAAO,EAAC,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAC,CAAC"}
1
+ {"version":3,"file":"SessionHandler.d.ts","sourceRoot":"","sources":["../../../../../src/messagingProtocols/proteus/Utility/SessionHandler/SessionHandler.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,MAAM,EAAC,MAAM,8BAA8B,CAAC;AACpD,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAE,4BAA4B,EAAC,MAAM,8BAA8B,CAAC;AAEvF,OAAO,EAAC,MAAM,EAAC,MAAM,SAAS,CAAC;AAE/B,OAAO,EAAC,SAAS,EAAC,MAAM,qBAAqB,CAAC;AAK9C,OAAO,EAAC,YAAY,EAAC,MAAM,mCAAmC,CAAC;AAE/D,UAAU,wBAAwB;IAChC,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,KAAK,kBAAkB,GAAG;IACxB,8EAA8E;IAC9E,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,8GAA8G;IAC9G,QAAQ,CAAC,EAAE,oBAAoB,CAAC;IAChC,6EAA6E;IAC7E,MAAM,CAAC,EAAE,WAAW,EAAE,CAAC;CACxB,CAAC;AAEF,QAAA,MAAM,kBAAkB,yBAAwB,wBAAwB,KAAG,MAI1E,CAAC;AA6BF;;;GAGG;AACH,QAAA,MAAM,WAAW,wCACoB;IAAC,MAAM,EAAE,WAAW,CAAC;IAAC,QAAQ,EAAE,MAAM,CAAC;IAAC,aAAa,CAAC,EAAE,MAAM,CAAA;CAAC,+BACvE;IAAC,SAAS,EAAE,SAAS,CAAC;IAAC,YAAY,EAAE,YAAY,CAAA;CAAC,KAC5E,OAAO,CAAC,MAAM,CAUhB,CAAC;AAqBF,UAAU,wCAAwC;IAChD,UAAU,EAAE,oBAAoB,GAAG,4BAA4B,CAAC;IAChE,SAAS,EAAE,SAAS,CAAC;IACrB,YAAY,EAAE,YAAY,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;GAEG;AACH,QAAA,MAAM,YAAY,qDAKf,wCAAwC,KAAG,OAAO,CAAC,kBAAkB,CAwDvE,CAAC;AAEF,UAAU,mBAAmB;IAC3B,MAAM,EAAE,WAAW,CAAC;IACpB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,YAAY,CAAC;CAC5B;AACD,iBAAe,aAAa,CAAC,MAAM,EAAE,mBAAmB,iBAGvD;AA4CD,KAAK,iBAAiB,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAC9E;;GAEG;AACH,QAAA,MAAM,sBAAsB,GAAI,CAAC,YAAY,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,KAAG,iBAAiB,CAAC,CAAC,CAYhF,CAAC;AAEF,OAAO,EAAC,kBAAkB,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,EAAE,sBAAsB,EAAC,CAAC"}
@@ -18,7 +18,8 @@
18
18
  *
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
- exports.buildEncryptedPayloads = exports.deleteSession = exports.initSessions = exports.initSession = exports.constructSessionId = void 0;
21
+ exports.buildEncryptedPayloads = exports.initSessions = exports.initSession = exports.constructSessionId = void 0;
22
+ exports.deleteSession = deleteSession;
22
23
  const bazinga64_1 = require("bazinga64");
23
24
  const UserClientsUtil_1 = require("../../../../conversation/message/UserClientsUtil");
24
25
  const constructSessionId = ({ userId, clientId }) => {
@@ -68,13 +69,15 @@ const createSessions = async ({ recipients, apiClient, cryptoClient }) => {
68
69
  recipients: prekeysBundle,
69
70
  cryptoClient,
70
71
  });
71
- return Object.assign(Object.assign({}, result), { failed: (failed === null || failed === void 0 ? void 0 : failed.length) ? failed : undefined });
72
+ return {
73
+ ...result,
74
+ failed: failed?.length ? failed : undefined,
75
+ };
72
76
  };
73
77
  /**
74
78
  * Will make sure all the sessions need to encrypt for those user/clients pair are set
75
79
  */
76
80
  const initSessions = async ({ recipients, apiClient, cryptoClient, logger, }) => {
77
- var _a, _b, _c;
78
81
  const missingClients = {};
79
82
  const missingClientsWithPrekeys = {};
80
83
  const existingSessions = [];
@@ -89,13 +92,13 @@ const initSessions = async ({ recipients, apiClient, cryptoClient, logger, }) =>
89
92
  continue;
90
93
  }
91
94
  if (!Array.isArray(data)) {
92
- const domainMissingWithPrekey = (_a = missingClientsWithPrekeys[userId.domain]) !== null && _a !== void 0 ? _a : {};
93
- domainMissingWithPrekey[userId.id] = (_b = domainMissingWithPrekey[userId.id]) !== null && _b !== void 0 ? _b : {};
95
+ const domainMissingWithPrekey = missingClientsWithPrekeys[userId.domain] ?? {};
96
+ domainMissingWithPrekey[userId.id] = domainMissingWithPrekey[userId.id] ?? {};
94
97
  domainMissingWithPrekey[userId.id][clientId] = data[clientId];
95
98
  missingClientsWithPrekeys[userId.domain] = domainMissingWithPrekey;
96
99
  continue;
97
100
  }
98
- const domainMissing = (_c = missingClients[userId.domain]) !== null && _c !== void 0 ? _c : {};
101
+ const domainMissing = missingClients[userId.domain] ?? {};
99
102
  domainMissing[userId.id] = domainMissing[userId.id] || [];
100
103
  domainMissing[userId.id].push(clientId);
101
104
  missingClients[userId.domain] = domainMissing;
@@ -115,7 +118,7 @@ const initSessions = async ({ recipients, apiClient, cryptoClient, logger, }) =>
115
118
  logger,
116
119
  })
117
120
  : { sessions: [], failed: undefined, unknowns: undefined };
118
- const allUnknowns = Object.assign(Object.assign({}, prekeyUnknows), unknowns);
121
+ const allUnknowns = { ...prekeyUnknows, ...unknowns };
119
122
  return {
120
123
  sessions: [...existingSessions, ...prekeyCreated, ...created],
121
124
  failed,
@@ -127,9 +130,7 @@ async function deleteSession(params) {
127
130
  const sessionId = constructSessionId(params);
128
131
  await params.cryptoClient.deleteSession(sessionId);
129
132
  }
130
- exports.deleteSession = deleteSession;
131
133
  const createSessionsFromPreKeys = async ({ recipients, cryptoClient, }) => {
132
- var _a, _b;
133
134
  const sessions = [];
134
135
  const unknowns = {};
135
136
  for (const domain in recipients) {
@@ -139,8 +140,8 @@ const createSessionsFromPreKeys = async ({ recipients, cryptoClient, }) => {
139
140
  const sessionId = constructSessionId({ userId: { id: userId, domain }, clientId });
140
141
  const prekey = userClients[clientId];
141
142
  if (!prekey) {
142
- const domainUnknowns = (_a = unknowns[domain]) !== null && _a !== void 0 ? _a : {};
143
- domainUnknowns[userId] = (_b = domainUnknowns[userId]) !== null && _b !== void 0 ? _b : [];
143
+ const domainUnknowns = unknowns[domain] ?? {};
144
+ domainUnknowns[userId] = domainUnknowns[userId] ?? [];
144
145
  domainUnknowns[userId].push(clientId);
145
146
  unknowns[domain] = domainUnknowns;
146
147
  continue;
@@ -159,13 +160,12 @@ const createSessionsFromPreKeys = async ({ recipients, cryptoClient, }) => {
159
160
  */
160
161
  const buildEncryptedPayloads = (payloads) => {
161
162
  return [...payloads].reduce((acc, [sessionId, payload]) => {
162
- var _a, _b;
163
163
  const { userId, domain, clientId } = parseSessionId(sessionId);
164
164
  if (!domain) {
165
165
  throw new Error('Invalid session ID');
166
166
  }
167
- const domainPayloads = (_a = acc[domain]) !== null && _a !== void 0 ? _a : {};
168
- domainPayloads[userId] = (_b = domainPayloads[userId]) !== null && _b !== void 0 ? _b : {};
167
+ const domainPayloads = acc[domain] ?? {};
168
+ domainPayloads[userId] = domainPayloads[userId] ?? {};
169
169
  domainPayloads[userId][clientId] = payload;
170
170
  acc[domain] = domainPayloads;
171
171
  return acc;
@@ -37,7 +37,10 @@ function generatePrekeys(recipients) {
37
37
  id: index,
38
38
  key: 'pQABARn//wKhAFggJ1Fbpg5l6wnzKOJE+vXpRnkqUYhIvVnR5lNXEbO2o/0DoQChAFggHxZvgvtDktY/vqBcpjjo6rQnXvcNQhfwmy8AJQJKlD0E9g==',
39
39
  };
40
- return Object.assign(Object.assign({}, acc), { [clientId]: payload });
40
+ return {
41
+ ...acc,
42
+ [clientId]: payload,
43
+ };
41
44
  }, {});
42
45
  prekeys[domain] = domainUsers;
43
46
  });
@@ -111,7 +114,7 @@ describe('SessionHandler', () => {
111
114
  .mockImplementation(sessionId => Promise.resolve(sessionId.includes('missing')));
112
115
  const sessionFromPrekeySpy = jest.spyOn(cryptoClient, 'sessionFromPrekey');
113
116
  const { sessions } = await (0, SessionHandler_1.initSessions)({
114
- recipients: { domain: Object.assign(Object.assign({}, existingUserClients), missingUserClients) },
117
+ recipients: { domain: { ...existingUserClients, ...missingUserClients } },
115
118
  apiClient,
116
119
  cryptoClient,
117
120
  });
@@ -1 +1 @@
1
- {"version":3,"file":"getGenericMessageParams.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/Utility/getGenericMessageParams.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAE,4BAA4B,EAAC,MAAM,8BAA8B,CAAC;AAEvF,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC;AAK3D,OAAO,EAAoB,qBAAqB,EAAC,MAAM,uBAAuB,CAAC;AAG/E,MAAM,MAAM,aAAa,GAAG;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,oBAAoB,GAAG,4BAA4B,CAAC;IAChE,SAAS,EAAE,UAAU,CAAC;IACtB,OAAO,EAAE;QACP,cAAc,EAAE,WAAW,CAAC;QAC5B,UAAU,EAAE,OAAO,GAAG,SAAS,CAAC;QAChC,aAAa,EAAE,OAAO,GAAG,WAAW,EAAE,GAAG,SAAS,CAAC;KACpD,CAAC;CACH,CAAC;AACF,UAAU,6BAA6B;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,WAAW,CAAC;IAC5B,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,qBAAqB,CAAC;IAC/B,SAAS,EAAE,SAAS,CAAC;CACtB;AACD,KAAK,iCAAiC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAEhE,QAAA,MAAM,uBAAuB,kHAM1B,6BAA6B,sCA0B/B,CAAC;AAEF,OAAO,EAAC,uBAAuB,EAAC,CAAC"}
1
+ {"version":3,"file":"getGenericMessageParams.d.ts","sourceRoot":"","sources":["../../../../src/messagingProtocols/proteus/Utility/getGenericMessageParams.ts"],"names":[],"mappings":"AAmBA,OAAO,EAAC,SAAS,EAAC,MAAM,mCAAmC,CAAC;AAC5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,sCAAsC,CAAC;AAC1E,OAAO,EAAC,WAAW,EAAE,4BAA4B,EAAC,MAAM,8BAA8B,CAAC;AAEvF,OAAO,EAAC,cAAc,EAAC,MAAM,6BAA6B,CAAC;AAK3D,OAAO,EAAoB,qBAAqB,EAAC,MAAM,uBAAuB,CAAC;AAG/E,MAAM,MAAM,aAAa,GAAG;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,UAAU,EAAE,oBAAoB,GAAG,4BAA4B,CAAC;IAChE,SAAS,EAAE,UAAU,CAAC;IACtB,OAAO,EAAE;QACP,cAAc,EAAE,WAAW,CAAC;QAC5B,UAAU,EAAE,OAAO,GAAG,SAAS,CAAC;QAChC,aAAa,EAAE,OAAO,GAAG,WAAW,EAAE,GAAG,SAAS,CAAC;KACpD,CAAC;CACH,CAAC;AACF,UAAU,6BAA6B;IACrC,eAAe,EAAE,MAAM,CAAC;IACxB,cAAc,EAAE,WAAW,CAAC;IAC5B,cAAc,EAAE,cAAc,CAAC;IAC/B,OAAO,EAAE,qBAAqB,CAAC;IAC/B,SAAS,EAAE,SAAS,CAAC;CACtB;AACD,KAAK,iCAAiC,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;AAEhE,QAAA,MAAM,uBAAuB,kHAM1B,6BAA6B,KAAG,iCA0BlC,CAAC;AAEF,OAAO,EAAC,uBAAuB,EAAC,CAAC"}
@@ -5,7 +5,7 @@ export declare class NotificationBackendRepository {
5
5
  constructor(apiClient: APIClient);
6
6
  getAllNotifications(clientId?: string, lastNotificationId?: string): Promise<{
7
7
  notifications: Notification[];
8
- missedNotification?: string | undefined;
8
+ missedNotification?: string;
9
9
  }>;
10
10
  getLastNotification(clientId?: string): Promise<Notification>;
11
11
  }
@@ -20,6 +20,7 @@
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.NotificationBackendRepository = void 0;
22
22
  class NotificationBackendRepository {
23
+ apiClient;
23
24
  constructor(apiClient) {
24
25
  this.apiClient = apiClient;
25
26
  }
@@ -32,6 +32,7 @@ const STORES = {
32
32
  AMPLIFY: 'amplify',
33
33
  };
34
34
  class NotificationDatabaseRepository {
35
+ storeEngine;
35
36
  constructor(storeEngine) {
36
37
  this.storeEngine = storeEngine;
37
38
  }
@@ -17,19 +17,6 @@
17
17
  * along with this program. If not, see http://www.gnu.org/licenses/.
18
18
  *
19
19
  */
20
- var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
21
- var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
22
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
23
- var g = generator.apply(thisArg, _arguments || []), i, q = [];
24
- return i = {}, verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
25
- function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
26
- function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
27
- function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
28
- function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
29
- function fulfill(value) { resume("next", value); }
30
- function reject(value) { resume("throw", value); }
31
- function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
32
- };
33
20
  var __importDefault = (this && this.__importDefault) || function (mod) {
34
21
  return (mod && mod.__esModule) ? mod : { "default": mod };
35
22
  };
@@ -47,13 +34,18 @@ var TOPIC;
47
34
  TOPIC["NOTIFICATION_ERROR"] = "NotificationService.TOPIC.NOTIFICATION_ERROR";
48
35
  })(TOPIC || (TOPIC = {}));
49
36
  class NotificationService extends commons_1.TypedEventEmitter {
37
+ conversationService;
38
+ apiClient;
39
+ backend;
40
+ database;
41
+ logger = (0, logdown_1.default)('@wireapp/core/NotificationService', {
42
+ logger: console,
43
+ markdown: false,
44
+ });
45
+ static TOPIC = TOPIC;
50
46
  constructor(apiClient, storeEngine, conversationService) {
51
47
  super();
52
48
  this.conversationService = conversationService;
53
- this.logger = (0, logdown_1.default)('@wireapp/core/NotificationService', {
54
- logger: console,
55
- markdown: false,
56
- });
57
49
  this.apiClient = apiClient;
58
50
  this.backend = new NotificationBackendRepository_1.NotificationBackendRepository(this.apiClient);
59
51
  this.database = new NotificationDatabaseRepository_1.NotificationDatabaseRepository(storeEngine);
@@ -147,40 +139,38 @@ class NotificationService extends commons_1.TypedEventEmitter {
147
139
  }
148
140
  return false;
149
141
  }
150
- handleNotification(notification_1, source_1) {
151
- return __asyncGenerator(this, arguments, function* handleNotification_1(notification, source, dryRun = false) {
152
- for (const event of notification.payload) {
153
- this.logger.log(`Handling event of type "${event.type}" for notification with ID "${notification.id}"`, event);
154
- let lastEventDate = undefined;
155
- try {
156
- lastEventDate = yield __await(this.database.getLastEventDate());
157
- }
158
- catch (_a) { }
159
- if ('time' in event && this.isOutdatedEvent(event, source, lastEventDate)) {
160
- this.logger.info(`Ignored outdated event type: '${event.type}'`);
161
- continue;
162
- }
163
- try {
164
- const handledEventResult = yield __await(this.handleEvent(event, dryRun));
165
- if (handledEventResult.status === 'handled' && handledEventResult.payload) {
166
- yield yield __await(handledEventResult.payload);
167
- }
168
- }
169
- catch (error) {
170
- this.logger.error(`There was an error with notification ID "${notification.id}": ${error.message}`, error);
171
- const notificationError = {
172
- error: error,
173
- notification,
174
- type: CoreError_1.CoreError.NOTIFICATION_ERROR,
175
- };
176
- this.emit(NotificationService.TOPIC.NOTIFICATION_ERROR, notificationError);
142
+ async *handleNotification(notification, source, dryRun = false) {
143
+ for (const event of notification.payload) {
144
+ this.logger.debug(`Handling event of type "${event.type}"`, event);
145
+ let lastEventDate = undefined;
146
+ try {
147
+ lastEventDate = await this.database.getLastEventDate();
148
+ }
149
+ catch { }
150
+ if ('time' in event && this.isOutdatedEvent(event, source, lastEventDate)) {
151
+ this.logger.info(`Ignored outdated event type: '${event.type}'`);
152
+ continue;
153
+ }
154
+ try {
155
+ const handledEventResult = await this.handleEvent(event, dryRun);
156
+ if (handledEventResult.status === 'handled' && handledEventResult.payload) {
157
+ yield handledEventResult.payload;
177
158
  }
178
159
  }
179
- if (!dryRun && !notification.transient) {
180
- // keep track of the last handled notification for next time we fetch the notification stream
181
- yield __await(this.setLastNotificationId(notification));
160
+ catch (error) {
161
+ this.logger.error(`There was an error with notification ID "${notification.id}": ${error.message}`, error);
162
+ const notificationError = {
163
+ error: error,
164
+ notification,
165
+ type: CoreError_1.CoreError.NOTIFICATION_ERROR,
166
+ };
167
+ this.emit(NotificationService.TOPIC.NOTIFICATION_ERROR, notificationError);
182
168
  }
183
- });
169
+ }
170
+ if (!dryRun && !notification.transient) {
171
+ // keep track of the last handled notification for next time we fetch the notification stream
172
+ await this.setLastNotificationId(notification);
173
+ }
184
174
  }
185
175
  /**
186
176
  * Will process one event
@@ -202,4 +192,3 @@ class NotificationService extends commons_1.TypedEventEmitter {
202
192
  }
203
193
  }
204
194
  exports.NotificationService = NotificationService;
205
- NotificationService.TOPIC = TOPIC;