@wireapp/core 20.2.0 → 20.5.0

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 CHANGED
@@ -3,6 +3,47 @@
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
+ # [20.5.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@20.4.1...@wireapp/core@20.5.0) (2022-01-10)
7
+
8
+
9
+ ### Features
10
+
11
+ * **core:** Add method to download v4 assets ([#4206](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4206)) ([41ab95a](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/41ab95ab1d70e2f5bee4e0b4f7d81f058a381792))
12
+
13
+
14
+
15
+
16
+
17
+ ## [20.4.1](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@20.4.0...@wireapp/core@20.4.1) (2022-01-06)
18
+
19
+ **Note:** Version bump only for package @wireapp/core
20
+
21
+
22
+
23
+
24
+
25
+ # [20.4.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@20.3.0...@wireapp/core@20.4.0) (2021-12-17)
26
+
27
+
28
+ ### Features
29
+
30
+ * **core:** Allow broadcasting to a limited set of users ([99dca26](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/99dca265bc38e84b6279ca5ac9a928e6ef7e3239))
31
+
32
+
33
+
34
+
35
+
36
+ # [20.3.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@20.2.0...@wireapp/core@20.3.0) (2021-12-17)
37
+
38
+
39
+ ### Features
40
+
41
+ * **core:** Add lastRead and Countly message to the core ([#4204](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/issues/4204)) ([64a2336](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/commit/64a2336f9de1f7ada34bd88652c624e28ac8169d))
42
+
43
+
44
+
45
+
46
+
6
47
  # [20.2.0](https://github.com/wireapp/wire-web-packages/tree/main/packages/core/compare/@wireapp/core@20.1.3...@wireapp/core@20.2.0) (2021-12-16)
7
48
 
8
49
 
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": "16.2.0",
8
+ "@wireapp/api-client": "16.4.0",
9
9
  "@wireapp/cryptobox": "12.7.1",
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": "20.2.0",
73
- "gitHead": "5ff57f8efd8713ae9767f12c103ea918acbbaa3b"
72
+ "version": "20.5.0",
73
+ "gitHead": "951a884827988fb5d805cc16da6f96fb7352c555"
74
74
  }
@@ -1,5 +1,5 @@
1
1
  import type { APIClient } from '@wireapp/api-client';
2
- import { ClientMismatch } from '@wireapp/api-client/src/conversation';
2
+ import { ClientMismatch, UserClients } from '@wireapp/api-client/src/conversation';
3
3
  import type { UserPreKeyBundleMap } from '@wireapp/api-client/src/user/';
4
4
  import { GenericMessage } from '@wireapp/protocol-messaging';
5
5
  import type { CryptographyService } from '../cryptography/';
@@ -9,5 +9,5 @@ export declare class BroadcastService {
9
9
  private readonly messageService;
10
10
  constructor(apiClient: APIClient, cryptographyService: CryptographyService);
11
11
  getPreKeyBundlesFromTeam(teamId: string, skipOwnClients?: boolean): Promise<UserPreKeyBundleMap>;
12
- broadcastGenericMessage(genericMessage: GenericMessage, preKeyBundles: UserPreKeyBundleMap, sendAsProtobuf?: boolean): Promise<ClientMismatch>;
12
+ broadcastGenericMessage(genericMessage: GenericMessage, recipients: UserPreKeyBundleMap | UserClients, sendAsProtobuf?: boolean): Promise<ClientMismatch>;
13
13
  }
@@ -43,10 +43,11 @@ class BroadcastService {
43
43
  return bundleMap;
44
44
  }, {});
45
45
  }
46
- async broadcastGenericMessage(genericMessage, preKeyBundles, sendAsProtobuf) {
46
+ async broadcastGenericMessage(genericMessage, recipients, sendAsProtobuf) {
47
47
  const plainTextArray = protocol_messaging_1.GenericMessage.encode(genericMessage).finish();
48
- return this.messageService.sendMessage(this.apiClient.validatedClientId, preKeyBundles, plainTextArray, {
48
+ return this.messageService.sendMessage(this.apiClient.validatedClientId, recipients, plainTextArray, {
49
49
  sendAsProtobuf,
50
+ reportMissing: Object.keys(recipients),
50
51
  });
51
52
  }
52
53
  }
@@ -3,9 +3,44 @@ import type { APIClient } from '@wireapp/api-client';
3
3
  import type { AssetOptions } from '@wireapp/api-client/src/asset';
4
4
  import type { ProgressCallback, RequestCancelable } from '@wireapp/api-client/src/http';
5
5
  import type { EncryptedAssetUploaded } from '../cryptography/';
6
+ export interface AssetDataV4 {
7
+ assetKey: string;
8
+ assetToken: string;
9
+ assetDomain: string;
10
+ forceCaching: boolean;
11
+ version: 4;
12
+ }
13
+ export interface AssetDataV3 {
14
+ assetKey: string;
15
+ assetToken: string;
16
+ forceCaching: boolean;
17
+ version: 3;
18
+ }
19
+ export interface AssetDataV2 {
20
+ assetId: string;
21
+ conversationId: string;
22
+ forceCaching: boolean;
23
+ version: 2;
24
+ }
25
+ export interface AssetDataV1 {
26
+ assetId: string;
27
+ conversationId: string;
28
+ forceCaching: boolean;
29
+ version: 1;
30
+ }
31
+ export declare type AssetUrlData = AssetDataV1 | AssetDataV2 | AssetDataV3 | AssetDataV4;
6
32
  export declare class AssetService {
7
33
  private readonly apiClient;
8
34
  constructor(apiClient: APIClient);
35
+ /**
36
+ * Will download an asset on the server.
37
+ * Will route the request to the right endpoint depending on the asset version
38
+ *
39
+ * @param assetData The versioned asset data
40
+ * @param progressCallback?
41
+ * @return Resolves when the asset has been uploaded
42
+ */
43
+ downloadAsset(assetData: AssetUrlData, progressCallback?: ProgressCallback): RequestCancelable<import("@wireapp/api-client/src/asset").AssetResponse>;
9
44
  /**
10
45
  * Uploads a raw asset to the backend without encrypting it
11
46
  *
@@ -24,6 +24,27 @@ class AssetService {
24
24
  constructor(apiClient) {
25
25
  this.apiClient = apiClient;
26
26
  }
27
+ /**
28
+ * Will download an asset on the server.
29
+ * Will route the request to the right endpoint depending on the asset version
30
+ *
31
+ * @param assetData The versioned asset data
32
+ * @param progressCallback?
33
+ * @return Resolves when the asset has been uploaded
34
+ */
35
+ downloadAsset(assetData, progressCallback) {
36
+ const { forceCaching } = assetData;
37
+ switch (assetData.version) {
38
+ case 1:
39
+ return this.apiClient.asset.api.getAssetV1(assetData.assetId, assetData.conversationId, forceCaching, progressCallback);
40
+ case 2:
41
+ return this.apiClient.asset.api.getAssetV2(assetData.assetId, assetData.conversationId, forceCaching, progressCallback);
42
+ case 3:
43
+ return this.apiClient.asset.api.getAssetV3(assetData.assetKey, assetData.assetToken, forceCaching, progressCallback);
44
+ case 4:
45
+ return this.apiClient.asset.api.getAssetV4(assetData.assetKey, assetData.assetToken, assetData.assetDomain, forceCaching, progressCallback);
46
+ }
47
+ }
27
48
  /**
28
49
  * Uploads a raw asset to the backend without encrypting it
29
50
  *
@@ -1,8 +1,8 @@
1
1
  /// <reference types="node" />
2
2
  import type { APIClient } from '@wireapp/api-client';
3
- import { MessageSendingStatus, Conversation, DefaultConversationRoleName, MutedStatus, QualifiedUserClients, UserClients, ClientMismatch } from '@wireapp/api-client/src/conversation/';
4
- import type { ConversationMemberLeaveEvent } from '@wireapp/api-client/src/event/';
5
- import type { QualifiedId, UserPreKeyBundleMap } from '@wireapp/api-client/src/user/';
3
+ import { MessageSendingStatus, Conversation, DefaultConversationRoleName, MutedStatus, QualifiedUserClients, UserClients, ClientMismatch } from '@wireapp/api-client/src/conversation';
4
+ import type { ConversationMemberLeaveEvent } from '@wireapp/api-client/src/event';
5
+ import type { QualifiedId, UserPreKeyBundleMap } from '@wireapp/api-client/src/user';
6
6
  import { GenericMessage } from '@wireapp/protocol-messaging';
7
7
  import { MessageTimer } from '../conversation/';
8
8
  import type { RemoteData } from '../conversation/content/';
@@ -63,6 +63,7 @@ export declare class ConversationService {
63
63
  private readonly apiClient;
64
64
  readonly messageTimer: MessageTimer;
65
65
  private readonly messageService;
66
+ private selfConversationId?;
66
67
  constructor(apiClient: APIClient, cryptographyService: CryptographyService);
67
68
  private createEphemeral;
68
69
  private getConversationQualifiedMembers;
@@ -76,7 +77,7 @@ export declare class ConversationService {
76
77
  */
77
78
  private getQualifiedPreKeyBundle;
78
79
  getPreKeyBundleMap(conversationId: string, userIds?: string[] | UserClients): Promise<UserPreKeyBundleMap>;
79
- private getSelfConversation;
80
+ private getSelfConversationId;
80
81
  private getQualifiedRecipientsForConversation;
81
82
  private getRecipientsForConversation;
82
83
  /**
@@ -105,7 +106,33 @@ export declare class ConversationService {
105
106
  private generateSessionResetGenericMessage;
106
107
  private generateCallGenericMessage;
107
108
  private generateTextGenericMessage;
108
- clearConversation(conversationId: string, timestamp?: number | Date, messageId?: string, sendAsProtobuf?: boolean, conversationDomain?: string): Promise<ClearConversationMessage>;
109
+ clearConversation(conversationId: string, timestamp?: number | Date, messageId?: string, sendAsProtobuf?: boolean): Promise<ClearConversationMessage>;
110
+ /**
111
+ * Sends a LastRead message to the current user's self conversation.
112
+ * This will allow all the user's devices to compute which messages are unread
113
+ *
114
+ * @param conversationId The conversation which has been read
115
+ * @param lastReadTimestamp The timestamp at which the conversation was read
116
+ * @param sendAsProtobuf?
117
+ * @return Resolves when the message has been sent
118
+ */
119
+ sendLastRead(conversationId: string, lastReadTimestamp: number, sendAsProtobuf?: boolean): Promise<(MessageSendingStatus & {
120
+ errored?: boolean | undefined;
121
+ }) | (ClientMismatch & {
122
+ errored?: boolean | undefined;
123
+ })>;
124
+ /**
125
+ * Syncs all self user's devices with the countly id
126
+ *
127
+ * @param countlyId The countly id of the current device
128
+ * @param sendAsProtobuf?
129
+ * @return Resolves when the message has been sent
130
+ */
131
+ sendCountlySync(countlyId: string, sendAsProtobuf?: boolean): Promise<(MessageSendingStatus & {
132
+ errored?: boolean | undefined;
133
+ }) | (ClientMismatch & {
134
+ errored?: boolean | undefined;
135
+ })>;
109
136
  /**
110
137
  * Get a fresh list from backend of clients for all the participants of the conversation.
111
138
  * This is a hacky way of getting all the clients for a conversation.
@@ -19,8 +19,8 @@
19
19
  */
20
20
  Object.defineProperty(exports, "__esModule", { value: true });
21
21
  exports.ConversationService = exports.MessageTargetMode = void 0;
22
- const conversation_1 = require("@wireapp/api-client/src/conversation/");
23
- const data_1 = require("@wireapp/api-client/src/conversation/data/");
22
+ const conversation_1 = require("@wireapp/api-client/src/conversation");
23
+ const data_1 = require("@wireapp/api-client/src/conversation/data");
24
24
  const protocol_messaging_1 = require("@wireapp/protocol-messaging");
25
25
  const conversation_2 = require("../conversation/");
26
26
  const AssetCryptography_1 = require("../cryptography/AssetCryptography");
@@ -134,9 +134,13 @@ class ConversationService {
134
134
  return bundleMap;
135
135
  }, {});
136
136
  }
137
- getSelfConversation() {
138
- const { userId } = this.apiClient.context;
139
- return this.apiClient.conversation.api.getConversation(userId);
137
+ async getSelfConversationId() {
138
+ if (!this.selfConversationId) {
139
+ const { userId } = this.apiClient.context;
140
+ const { qualified_id, id } = await this.apiClient.conversation.api.getConversation(userId);
141
+ this.selfConversationId = qualified_id || { id, domain: '' };
142
+ }
143
+ return this.selfConversationId;
140
144
  }
141
145
  async getQualifiedRecipientsForConversation(conversationId, userIds) {
142
146
  if ((0, TypePredicateUtil_1.isQualifiedUserClients)(userIds)) {
@@ -426,7 +430,7 @@ class ConversationService {
426
430
  const expireAfterMillis = this.messageTimer.getMessageTimer(payloadBundle.conversation);
427
431
  return expireAfterMillis > 0 ? this.createEphemeral(genericMessage, expireAfterMillis) : genericMessage;
428
432
  }
429
- async clearConversation(conversationId, timestamp = new Date(), messageId = MessageBuilder_1.MessageBuilder.createId(), sendAsProtobuf, conversationDomain) {
433
+ async clearConversation(conversationId, timestamp = new Date(), messageId = MessageBuilder_1.MessageBuilder.createId(), sendAsProtobuf) {
430
434
  if (timestamp instanceof Date) {
431
435
  timestamp = timestamp.getTime();
432
436
  }
@@ -439,9 +443,9 @@ class ConversationService {
439
443
  [conversation_2.GenericMessageType.CLEARED]: clearedMessage,
440
444
  messageId,
441
445
  });
442
- const { id: selfConversationId } = await this.getSelfConversation();
446
+ const { id: selfConversationId, domain } = await this.getSelfConversationId();
443
447
  await this.sendGenericMessage(this.apiClient.validatedClientId, selfConversationId, genericMessage, {
444
- conversationDomain,
448
+ conversationDomain: domain,
445
449
  sendAsProtobuf,
446
450
  });
447
451
  return {
@@ -456,6 +460,53 @@ class ConversationService {
456
460
  type: conversation_2.PayloadBundleType.CONVERSATION_CLEAR,
457
461
  };
458
462
  }
463
+ /**
464
+ * Sends a LastRead message to the current user's self conversation.
465
+ * This will allow all the user's devices to compute which messages are unread
466
+ *
467
+ * @param conversationId The conversation which has been read
468
+ * @param lastReadTimestamp The timestamp at which the conversation was read
469
+ * @param sendAsProtobuf?
470
+ * @return Resolves when the message has been sent
471
+ */
472
+ async sendLastRead(conversationId, lastReadTimestamp, sendAsProtobuf) {
473
+ const lastRead = new protocol_messaging_1.LastRead({
474
+ conversationId,
475
+ lastReadTimestamp,
476
+ });
477
+ const genericMessage = protocol_messaging_1.GenericMessage.create({
478
+ [conversation_2.GenericMessageType.LAST_READ]: lastRead,
479
+ messageId: MessageBuilder_1.MessageBuilder.createId(),
480
+ });
481
+ const { id: selfConversationId, domain: selfConversationDomain } = await this.getSelfConversationId();
482
+ return this.sendGenericMessage(this.apiClient.validatedClientId, selfConversationId, genericMessage, {
483
+ conversationDomain: selfConversationDomain,
484
+ sendAsProtobuf,
485
+ });
486
+ }
487
+ /**
488
+ * Syncs all self user's devices with the countly id
489
+ *
490
+ * @param countlyId The countly id of the current device
491
+ * @param sendAsProtobuf?
492
+ * @return Resolves when the message has been sent
493
+ */
494
+ async sendCountlySync(countlyId, sendAsProtobuf) {
495
+ const { id: selfConversationId, domain: selfConversationDomain } = await this.getSelfConversationId();
496
+ const dataTransfer = new protocol_messaging_1.DataTransfer({
497
+ trackingIdentifier: {
498
+ identifier: countlyId,
499
+ },
500
+ });
501
+ const genericMessage = new protocol_messaging_1.GenericMessage({
502
+ [conversation_2.GenericMessageType.DATA_TRANSFER]: dataTransfer,
503
+ messageId: MessageBuilder_1.MessageBuilder.createId(),
504
+ });
505
+ return this.sendGenericMessage(this.apiClient.validatedClientId, selfConversationId, genericMessage, {
506
+ conversationDomain: selfConversationDomain,
507
+ sendAsProtobuf,
508
+ });
509
+ }
459
510
  /**
460
511
  * Get a fresh list from backend of clients for all the participants of the conversation.
461
512
  * This is a hacky way of getting all the clients for a conversation.
@@ -500,7 +551,7 @@ class ConversationService {
500
551
  [conversation_2.GenericMessageType.HIDDEN]: content,
501
552
  messageId,
502
553
  });
503
- const { id: selfConversationId } = await this.getSelfConversation();
554
+ const { id: selfConversationId } = await this.getSelfConversationId();
504
555
  await this.sendGenericMessage(this.apiClient.validatedClientId, selfConversationId, genericMessage, {
505
556
  sendAsProtobuf,
506
557
  conversationDomain,
@@ -577,7 +628,7 @@ class ConversationService {
577
628
  return this.apiClient.conversation.api.getConversationsByIds(conversationIds);
578
629
  }
579
630
  async getAsset({ assetId, assetToken, otrKey, sha256 }) {
580
- const request = await this.apiClient.asset.api.getAssetV3(assetId, assetToken);
631
+ const request = this.apiClient.asset.api.getAssetV3(assetId, assetToken);
581
632
  const encryptedBuffer = (await request.response).buffer;
582
633
  return (0, AssetCryptography_1.decryptAsset)({
583
634
  cipherText: Buffer.from(encryptedBuffer),
@@ -10,6 +10,7 @@ export declare enum GenericMessageType {
10
10
  CLIENT_ACTION = "clientAction",
11
11
  COMPOSITE = "composite",
12
12
  CONFIRMATION = "confirmation",
13
+ DATA_TRANSFER = "dataTransfer",
13
14
  DELETED = "deleted",
14
15
  EDITED = "edited",
15
16
  EPHEMERAL = "ephemeral",
@@ -33,6 +33,7 @@ var GenericMessageType;
33
33
  GenericMessageType["CLIENT_ACTION"] = "clientAction";
34
34
  GenericMessageType["COMPOSITE"] = "composite";
35
35
  GenericMessageType["CONFIRMATION"] = "confirmation";
36
+ GenericMessageType["DATA_TRANSFER"] = "dataTransfer";
36
37
  GenericMessageType["DELETED"] = "deleted";
37
38
  GenericMessageType["EDITED"] = "edited";
38
39
  GenericMessageType["EPHEMERAL"] = "ephemeral";