@wireapp/wire-apps-js-sdk 0.1.0 → 0.2.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/README.md +23 -3
- package/build/WireAppSdk.d.ts +22 -2
- package/build/WireAppSdk.d.ts.map +1 -1
- package/build/WireAppSdk.js +88 -27
- package/build/WireAppSdk.js.map +1 -1
- package/build/WireAppSdkOptions.d.ts +26 -0
- package/build/WireAppSdkOptions.d.ts.map +1 -0
- package/build/WireAppSdkOptions.js +17 -0
- package/build/WireAppSdkOptions.js.map +1 -0
- package/build/api/ConversationService.d.ts +1 -0
- package/build/api/ConversationService.d.ts.map +1 -1
- package/build/api/ConversationService.js +7 -0
- package/build/api/ConversationService.js.map +1 -1
- package/build/api/MlsApiClient.d.ts +2 -0
- package/build/api/MlsApiClient.d.ts.map +1 -1
- package/build/api/MlsApiClient.js +4 -0
- package/build/api/MlsApiClient.js.map +1 -1
- package/build/api/MlsService.d.ts +1 -0
- package/build/api/MlsService.d.ts.map +1 -1
- package/build/api/MlsService.js +3 -0
- package/build/api/MlsService.js.map +1 -1
- package/build/api/UserService.d.ts +0 -1
- package/build/api/UserService.d.ts.map +1 -1
- package/build/api/UserService.js +2 -4
- package/build/api/UserService.js.map +1 -1
- package/build/api/UsersApiClient.d.ts +0 -2
- package/build/api/UsersApiClient.d.ts.map +1 -1
- package/build/api/UsersApiClient.js +0 -4
- package/build/api/UsersApiClient.js.map +1 -1
- package/build/api/response/MlsKeyPackageCountResponse.d.ts +4 -0
- package/build/api/response/MlsKeyPackageCountResponse.d.ts.map +1 -0
- package/build/api/response/MlsKeyPackageCountResponse.js +17 -0
- package/build/api/response/MlsKeyPackageCountResponse.js.map +1 -0
- package/build/core/CoreCryptoClient.d.ts +4 -4
- package/build/core/CoreCryptoClient.d.ts.map +1 -1
- package/build/core/CoreCryptoClient.js +9 -10
- package/build/core/CoreCryptoClient.js.map +1 -1
- package/build/core/CoreCryptoService.d.ts +3 -1
- package/build/core/CoreCryptoService.d.ts.map +1 -1
- package/build/core/CoreCryptoService.js +21 -7
- package/build/core/CoreCryptoService.js.map +1 -1
- package/build/core/HttpClient.d.ts.map +1 -1
- package/build/core/HttpClient.js +2 -1
- package/build/core/HttpClient.js.map +1 -1
- package/build/core/WebSocketClient.d.ts.map +1 -1
- package/build/core/WebSocketClient.js +3 -3
- package/build/core/WebSocketClient.js.map +1 -1
- package/build/core/WireApplicationManager.d.ts +0 -1
- package/build/core/WireApplicationManager.d.ts.map +1 -1
- package/build/core/WireApplicationManager.js +0 -4
- package/build/core/WireApplicationManager.js.map +1 -1
- package/build/core/WireEventsHandler.d.ts +8 -0
- package/build/core/WireEventsHandler.d.ts.map +1 -1
- package/build/core/WireEventsHandler.js +9 -0
- package/build/core/WireEventsHandler.js.map +1 -1
- package/build/core/event/MlsWelcomeEventProcessor.d.ts +2 -3
- package/build/core/event/MlsWelcomeEventProcessor.d.ts.map +1 -1
- package/build/core/event/MlsWelcomeEventProcessor.js +12 -10
- package/build/core/event/MlsWelcomeEventProcessor.js.map +1 -1
- package/build/core/event/TeamMemberJoinEventProcessor.d.ts +13 -0
- package/build/core/event/TeamMemberJoinEventProcessor.d.ts.map +1 -0
- package/build/core/event/TeamMemberJoinEventProcessor.js +60 -0
- package/build/core/event/TeamMemberJoinEventProcessor.js.map +1 -0
- package/build/core/event/processors.index.d.ts +1 -0
- package/build/core/event/processors.index.d.ts.map +1 -1
- package/build/core/event/processors.index.js +1 -0
- package/build/core/event/processors.index.js.map +1 -1
- package/build/db/DatabaseService.d.ts +2 -1
- package/build/db/DatabaseService.d.ts.map +1 -1
- package/build/db/DatabaseService.js +12 -5
- package/build/db/DatabaseService.js.map +1 -1
- package/build/index.d.ts +1 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js.map +1 -1
- package/build/model/EventContentDTO.d.ts +10 -1
- package/build/model/EventContentDTO.d.ts.map +1 -1
- package/build/service/KeyPackageReplenisher.d.ts +15 -0
- package/build/service/KeyPackageReplenisher.d.ts.map +1 -0
- package/build/service/KeyPackageReplenisher.js +82 -0
- package/build/service/KeyPackageReplenisher.js.map +1 -0
- package/build/utils/ApiDateReviver.d.ts +3 -0
- package/build/utils/ApiDateReviver.d.ts.map +1 -0
- package/build/utils/ApiDateReviver.js +26 -0
- package/build/utils/ApiDateReviver.js.map +1 -0
- package/build/utils/DependencyInjectionTokens.d.ts +1 -0
- package/build/utils/DependencyInjectionTokens.d.ts.map +1 -1
- package/build/utils/DependencyInjectionTokens.js +1 -0
- package/build/utils/DependencyInjectionTokens.js.map +1 -1
- package/build/utils/StoragePaths.d.ts +3 -3
- package/build/utils/StoragePaths.d.ts.map +1 -1
- package/build/utils/StoragePaths.js +10 -5
- package/build/utils/StoragePaths.js.map +1 -1
- package/package.json +2 -2
- package/src/WireAppSdk.ts +97 -28
- package/src/WireAppSdkOptions.ts +42 -0
- package/src/api/ConversationService.ts +10 -0
- package/src/api/MlsApiClient.ts +6 -0
- package/src/api/MlsService.ts +4 -0
- package/src/api/UserService.ts +2 -5
- package/src/api/UsersApiClient.ts +0 -6
- package/src/api/response/MlsKeyPackageCountResponse.ts +19 -0
- package/src/core/CoreCryptoClient.ts +13 -10
- package/src/core/CoreCryptoService.ts +17 -3
- package/src/core/HttpClient.ts +2 -1
- package/src/core/WebSocketClient.ts +4 -4
- package/src/core/WireApplicationManager.ts +0 -5
- package/src/core/WireEventsHandler.ts +11 -0
- package/src/core/event/MlsWelcomeEventProcessor.ts +9 -6
- package/src/core/event/TeamMemberJoinEventProcessor.ts +48 -0
- package/src/core/event/processors.index.ts +1 -0
- package/src/db/DatabaseService.ts +5 -4
- package/src/index.ts +1 -0
- package/src/model/EventContentDTO.ts +12 -0
- package/src/service/KeyPackageReplenisher.ts +71 -0
- package/src/utils/ApiDateReviver.ts +27 -0
- package/src/utils/DependencyInjectionTokens.ts +1 -0
- package/src/utils/StoragePaths.ts +12 -5
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Wire
|
|
3
|
+
* Copyright (C) 2026 Wire Swiss GmbH
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
* You should have received a copy of the GNU General Public License
|
|
14
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
15
|
+
*/
|
|
16
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
17
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
18
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
19
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
20
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
21
|
+
};
|
|
22
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
23
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
24
|
+
};
|
|
25
|
+
var KeyPackageReplenisher_1;
|
|
26
|
+
import { singleton } from 'tsyringe';
|
|
27
|
+
import { MlsService } from '../api/MlsService.js';
|
|
28
|
+
import { MLS_DEFAULT_KEY_PACKAGE_COUNT } from '../core/CoreCryptoClient.js';
|
|
29
|
+
import { CoreCryptoService } from '../core/CoreCryptoService.js';
|
|
30
|
+
import { LoggerFactory } from '../utils/logger/LoggerFactory.js';
|
|
31
|
+
let KeyPackageReplenisher = class KeyPackageReplenisher {
|
|
32
|
+
static { KeyPackageReplenisher_1 = this; }
|
|
33
|
+
mlsService;
|
|
34
|
+
coreCryptoService;
|
|
35
|
+
static CHECK_INTERVAL_MS = 24 * 60 * 60 * 1_000;
|
|
36
|
+
logger = LoggerFactory.getLogger(this.constructor.name);
|
|
37
|
+
activeRun;
|
|
38
|
+
timer;
|
|
39
|
+
constructor(mlsService, coreCryptoService) {
|
|
40
|
+
this.mlsService = mlsService;
|
|
41
|
+
this.coreCryptoService = coreCryptoService;
|
|
42
|
+
}
|
|
43
|
+
start() {
|
|
44
|
+
if (this.activeRun)
|
|
45
|
+
return;
|
|
46
|
+
const run = {};
|
|
47
|
+
this.activeRun = run;
|
|
48
|
+
void this.checkAndSchedule(run);
|
|
49
|
+
}
|
|
50
|
+
stop() {
|
|
51
|
+
this.activeRun = undefined;
|
|
52
|
+
if (this.timer)
|
|
53
|
+
clearTimeout(this.timer);
|
|
54
|
+
this.timer = undefined;
|
|
55
|
+
}
|
|
56
|
+
async checkAndSchedule(run) {
|
|
57
|
+
try {
|
|
58
|
+
const count = await this.mlsService.getAvailableKeyPackageCount(this.coreCryptoService.getDefaultCiphersuiteCode());
|
|
59
|
+
if (count < MLS_DEFAULT_KEY_PACKAGE_COUNT / 2) {
|
|
60
|
+
this.logger.info(`Found ${count} available MLS key packages, replenishing with ${MLS_DEFAULT_KEY_PACKAGE_COUNT} new packages`);
|
|
61
|
+
const keyPackages = await this.coreCryptoService.mlsGenerateKeyPackages();
|
|
62
|
+
await this.mlsService.uploadMlsKeyPackages(keyPackages);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
this.logger.info(`Found ${count} available MLS key packages, replenishment is not needed`);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
catch (exception) {
|
|
69
|
+
this.logger.error('Failed to check or replenish MLS key packages', exception);
|
|
70
|
+
}
|
|
71
|
+
if (run === this.activeRun) {
|
|
72
|
+
this.timer = setTimeout(() => void this.checkAndSchedule(run), KeyPackageReplenisher_1.CHECK_INTERVAL_MS);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
KeyPackageReplenisher = KeyPackageReplenisher_1 = __decorate([
|
|
77
|
+
singleton(),
|
|
78
|
+
__metadata("design:paramtypes", [MlsService,
|
|
79
|
+
CoreCryptoService])
|
|
80
|
+
], KeyPackageReplenisher);
|
|
81
|
+
export { KeyPackageReplenisher };
|
|
82
|
+
//# sourceMappingURL=KeyPackageReplenisher.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyPackageReplenisher.js","sourceRoot":"","sources":["../../src/service/KeyPackageReplenisher.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;;;;;;;;;;;AAEH,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAA;AAClC,OAAO,EAAC,UAAU,EAAC,MAAM,sBAAsB,CAAA;AAC/C,OAAO,EAAC,6BAA6B,EAAC,MAAM,6BAA6B,CAAA;AACzE,OAAO,EAAC,iBAAiB,EAAC,MAAM,8BAA8B,CAAA;AAC9D,OAAO,EAAC,aAAa,EAAC,MAAM,kCAAkC,CAAA;AAGvD,IAAM,qBAAqB,GAA3B,MAAM,qBAAqB;;IAOtB;IACA;IAPF,MAAM,CAAU,iBAAiB,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,KAAK,CAAA;IACxD,MAAM,GAAG,aAAa,CAAC,SAAS,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAA;IACvD,SAAS,CAAoB;IAC7B,KAAK,CAA2C;IAExD,YACU,UAAsB,EACtB,iBAAoC;QADpC,eAAU,GAAV,UAAU,CAAY;QACtB,sBAAiB,GAAjB,iBAAiB,CAAmB;IAC3C,CAAC;IAEJ,KAAK;QACH,IAAI,IAAI,CAAC,SAAS;YAAE,OAAM;QAE1B,MAAM,GAAG,GAAG,EAAE,CAAA;QACd,IAAI,CAAC,SAAS,GAAG,GAAG,CAAA;QACpB,KAAK,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;IACjC,CAAC;IAED,IAAI;QACF,IAAI,CAAC,SAAS,GAAG,SAAS,CAAA;QAC1B,IAAI,IAAI,CAAC,KAAK;YAAE,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC,CAAA;QACxC,IAAI,CAAC,KAAK,GAAG,SAAS,CAAA;IACxB,CAAC;IAEO,KAAK,CAAC,gBAAgB,CAAC,GAAW;QACxC,IAAI,CAAC;YACH,MAAM,KAAK,GAAG,MAAM,IAAI,CAAC,UAAU,CAAC,2BAA2B,CAC7D,IAAI,CAAC,iBAAiB,CAAC,yBAAyB,EAAE,CACnD,CAAA;YACD,IAAI,KAAK,GAAG,6BAA6B,GAAG,CAAC,EAAE,CAAC;gBAC9C,IAAI,CAAC,MAAM,CAAC,IAAI,CACd,SAAS,KAAK,kDAAkD,6BAA6B,eAAe,CAC7G,CAAA;gBACD,MAAM,WAAW,GAAG,MAAM,IAAI,CAAC,iBAAiB,CAAC,sBAAsB,EAAE,CAAA;gBACzE,MAAM,IAAI,CAAC,UAAU,CAAC,oBAAoB,CAAC,WAAW,CAAC,CAAA;YACzD,CAAC;iBAAM,CAAC;gBACN,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,SAAS,KAAK,0DAA0D,CAAC,CAAA;YAC5F,CAAC;QACH,CAAC;QAAC,OAAO,SAAS,EAAE,CAAC;YACnB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,+CAA+C,EAAE,SAAS,CAAC,CAAA;QAC/E,CAAC;QAED,IAAI,GAAG,KAAK,IAAI,CAAC,SAAS,EAAE,CAAC;YAC3B,IAAI,CAAC,KAAK,GAAG,UAAU,CAAC,GAAG,EAAE,CAAC,KAAK,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,EAAE,uBAAqB,CAAC,iBAAiB,CAAC,CAAA;QACzG,CAAC;IACH,CAAC;;AA9CU,qBAAqB;IADjC,SAAS,EAAE;qCAQY,UAAU;QACH,iBAAiB;GARnC,qBAAqB,CA+CjC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiDateReviver.d.ts","sourceRoot":"","sources":["../../src/utils/ApiDateReviver.ts"],"names":[],"mappings":"AAgBA,oFAAoF;AACpF,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CASnE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Wire
|
|
3
|
+
* Copyright (C) 2026 Wire Swiss GmbH
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
* You should have received a copy of the GNU General Public License
|
|
14
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
15
|
+
*/
|
|
16
|
+
/** Converts API `time` fields during JSON.parse, preserving unparseable strings. */
|
|
17
|
+
export function apiDateReviver(key, value) {
|
|
18
|
+
if (key !== 'time')
|
|
19
|
+
return value;
|
|
20
|
+
if (typeof value !== 'string') {
|
|
21
|
+
throw new TypeError('API timestamp must be a string');
|
|
22
|
+
}
|
|
23
|
+
const time = new Date(value);
|
|
24
|
+
return Number.isNaN(time.getTime()) ? value : time;
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=ApiDateReviver.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ApiDateReviver.js","sourceRoot":"","sources":["../../src/utils/ApiDateReviver.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,oFAAoF;AACpF,MAAM,UAAU,cAAc,CAAC,GAAW,EAAE,KAAc;IACxD,IAAI,GAAG,KAAK,MAAM;QAAE,OAAO,KAAK,CAAA;IAEhC,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,IAAI,SAAS,CAAC,gCAAgC,CAAC,CAAA;IACvD,CAAC;IAED,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,KAAK,CAAC,CAAA;IAC5B,OAAO,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAA;AACpD,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
export declare const WIRE_API_HOST = "WIRE_API_HOST";
|
|
2
2
|
export declare const WIRE_SDK_API_TOKEN = "WIRE_SDK_API_TOKEN";
|
|
3
3
|
export declare const WIRE_CRYPTOGRAPHY_STORAGE_KEY = "WIRE_CRYPTOGRAPHY_STORAGE_KEY";
|
|
4
|
+
export declare const WIRE_STORAGE_PATH = "WIRE_STORAGE_PATH";
|
|
4
5
|
export declare const WIRE_EVENTS_HANDLER = "WIRE_EVENTS_HANDLER";
|
|
5
6
|
export declare const EVENT_PROCESSOR = "EVENT_PROCESSOR";
|
|
6
7
|
//# sourceMappingURL=DependencyInjectionTokens.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependencyInjectionTokens.d.ts","sourceRoot":"","sources":["../../src/utils/DependencyInjectionTokens.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,aAAa,kBAAkB,CAAA;AAC5C,eAAO,MAAM,kBAAkB,uBAAuB,CAAA;AACtD,eAAO,MAAM,6BAA6B,kCAAkC,CAAA;
|
|
1
|
+
{"version":3,"file":"DependencyInjectionTokens.d.ts","sourceRoot":"","sources":["../../src/utils/DependencyInjectionTokens.ts"],"names":[],"mappings":"AAgBA,eAAO,MAAM,aAAa,kBAAkB,CAAA;AAC5C,eAAO,MAAM,kBAAkB,uBAAuB,CAAA;AACtD,eAAO,MAAM,6BAA6B,kCAAkC,CAAA;AAC5E,eAAO,MAAM,iBAAiB,sBAAsB,CAAA;AAEpD,eAAO,MAAM,mBAAmB,wBAAwB,CAAA;AAExD,eAAO,MAAM,eAAe,oBAAoB,CAAA"}
|
|
@@ -16,6 +16,7 @@
|
|
|
16
16
|
export const WIRE_API_HOST = 'WIRE_API_HOST';
|
|
17
17
|
export const WIRE_SDK_API_TOKEN = 'WIRE_SDK_API_TOKEN';
|
|
18
18
|
export const WIRE_CRYPTOGRAPHY_STORAGE_KEY = 'WIRE_CRYPTOGRAPHY_STORAGE_KEY';
|
|
19
|
+
export const WIRE_STORAGE_PATH = 'WIRE_STORAGE_PATH';
|
|
19
20
|
export const WIRE_EVENTS_HANDLER = 'WIRE_EVENTS_HANDLER';
|
|
20
21
|
export const EVENT_PROCESSOR = 'EVENT_PROCESSOR';
|
|
21
22
|
//# sourceMappingURL=DependencyInjectionTokens.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DependencyInjectionTokens.js","sourceRoot":"","sources":["../../src/utils/DependencyInjectionTokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAA;AAC5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAA;AACtD,MAAM,CAAC,MAAM,6BAA6B,GAAG,+BAA+B,CAAA;
|
|
1
|
+
{"version":3,"file":"DependencyInjectionTokens.js","sourceRoot":"","sources":["../../src/utils/DependencyInjectionTokens.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,MAAM,CAAC,MAAM,aAAa,GAAG,eAAe,CAAA;AAC5C,MAAM,CAAC,MAAM,kBAAkB,GAAG,oBAAoB,CAAA;AACtD,MAAM,CAAC,MAAM,6BAA6B,GAAG,+BAA+B,CAAA;AAC5E,MAAM,CAAC,MAAM,iBAAiB,GAAG,mBAAmB,CAAA;AAEpD,MAAM,CAAC,MAAM,mBAAmB,GAAG,qBAAqB,CAAA;AAExD,MAAM,CAAC,MAAM,eAAe,GAAG,iBAAiB,CAAA"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
2
|
-
export declare
|
|
3
|
-
export declare
|
|
1
|
+
export declare const DEFAULT_STORAGE_PATH = "./storage";
|
|
2
|
+
export declare function getDatabasePath(storagePath: string): string;
|
|
3
|
+
export declare function getCryptographyStoragePath(storagePath: string): string;
|
|
4
4
|
//# sourceMappingURL=StoragePaths.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoragePaths.d.ts","sourceRoot":"","sources":["../../src/utils/StoragePaths.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"StoragePaths.d.ts","sourceRoot":"","sources":["../../src/utils/StoragePaths.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,oBAAoB,cAAc,CAAA;AAE/C,wBAAgB,eAAe,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAE3D;AAED,wBAAgB,0BAA0B,CAAC,WAAW,EAAE,MAAM,GAAG,MAAM,CAEtE"}
|
|
@@ -14,9 +14,14 @@
|
|
|
14
14
|
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
15
15
|
*/
|
|
16
16
|
import { join } from 'node:path';
|
|
17
|
-
//
|
|
18
|
-
// the SDK-managed storage folder in the directory where
|
|
19
|
-
|
|
20
|
-
export const
|
|
21
|
-
export
|
|
17
|
+
// Relative paths are resolved against process.cwd() when the SDK is created, so
|
|
18
|
+
// by default host apps get the SDK-managed storage folder in the directory where
|
|
19
|
+
// the process starts. Host apps can override it with `WireAppSdkOptions.storagePath`.
|
|
20
|
+
export const DEFAULT_STORAGE_PATH = './storage';
|
|
21
|
+
export function getDatabasePath(storagePath) {
|
|
22
|
+
return join(storagePath, 'apps.db');
|
|
23
|
+
}
|
|
24
|
+
export function getCryptographyStoragePath(storagePath) {
|
|
25
|
+
return join(storagePath, 'cryptography');
|
|
26
|
+
}
|
|
22
27
|
//# sourceMappingURL=StoragePaths.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"StoragePaths.js","sourceRoot":"","sources":["../../src/utils/StoragePaths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAE9B,
|
|
1
|
+
{"version":3,"file":"StoragePaths.js","sourceRoot":"","sources":["../../src/utils/StoragePaths.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAC,IAAI,EAAC,MAAM,WAAW,CAAA;AAE9B,gFAAgF;AAChF,iFAAiF;AACjF,sFAAsF;AACtF,MAAM,CAAC,MAAM,oBAAoB,GAAG,WAAW,CAAA;AAE/C,MAAM,UAAU,eAAe,CAAC,WAAmB;IACjD,OAAO,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,CAAA;AACrC,CAAC;AAED,MAAM,UAAU,0BAA0B,CAAC,WAAmB;IAC5D,OAAO,IAAI,CAAC,WAAW,EAAE,cAAc,CAAC,CAAA;AAC1C,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wireapp/wire-apps-js-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "SDK for Wire third-party applications written in Typescript.",
|
|
5
5
|
"license": "GPL-3.0",
|
|
6
6
|
"keywords": [
|
|
@@ -89,7 +89,7 @@
|
|
|
89
89
|
"@types/ws": "^8.18.1",
|
|
90
90
|
"@vitest/coverage-v8": "^4.1.9",
|
|
91
91
|
"cpy-cli": "^7.0.0",
|
|
92
|
-
"dotenv": "^
|
|
92
|
+
"dotenv": "^18.0.1",
|
|
93
93
|
"drizzle-kit": "^0.31.9",
|
|
94
94
|
"eslint": "^10.7.0",
|
|
95
95
|
"eslint-config-prettier": "^10.1.8",
|
package/src/WireAppSdk.ts
CHANGED
|
@@ -17,12 +17,14 @@
|
|
|
17
17
|
import 'reflect-metadata'
|
|
18
18
|
import './core/event/processors.index.js'
|
|
19
19
|
import {mkdirSync} from 'node:fs'
|
|
20
|
+
import {resolve} from 'node:path'
|
|
20
21
|
import {CoreCryptoService} from './core/CoreCryptoService.js'
|
|
21
22
|
import {
|
|
22
23
|
WIRE_API_HOST,
|
|
23
24
|
WIRE_CRYPTOGRAPHY_STORAGE_KEY,
|
|
24
25
|
WIRE_EVENTS_HANDLER,
|
|
25
|
-
WIRE_SDK_API_TOKEN
|
|
26
|
+
WIRE_SDK_API_TOKEN,
|
|
27
|
+
WIRE_STORAGE_PATH
|
|
26
28
|
} from './utils/DependencyInjectionTokens.js'
|
|
27
29
|
import {WebSocketClient} from './core/WebSocketClient.js'
|
|
28
30
|
import {WireEventsHandler} from './core/WireEventsHandler.js'
|
|
@@ -33,24 +35,47 @@ import {LoggerFactory} from './utils/logger/LoggerFactory.js'
|
|
|
33
35
|
import {ConsoleLogger} from './utils/logger/ConsoleLogger.js'
|
|
34
36
|
import {ConversationService} from './api/ConversationService.js'
|
|
35
37
|
import {AppProperties} from './service/AppProperties.js'
|
|
36
|
-
import {
|
|
38
|
+
import {DEFAULT_STORAGE_PATH, getCryptographyStoragePath} from './utils/StoragePaths.js'
|
|
39
|
+
import type {WireAppSdkOptions} from './WireAppSdkOptions.js'
|
|
37
40
|
import type {BackendConnectionListener} from './core/BackendConnectionListener.js'
|
|
38
41
|
import {InvalidParameterError, UnknownError} from './exception/WireException.js'
|
|
39
42
|
import {SelfService} from './api/SelfService.js'
|
|
40
43
|
import {WireApplicationManager} from './core/WireApplicationManager.js'
|
|
44
|
+
import {KeyPackageReplenisher} from './service/KeyPackageReplenisher.js'
|
|
41
45
|
|
|
42
46
|
export class WireAppSdk {
|
|
43
47
|
private readonly CRYPTOGRAPHY_STORAGE_KEY_BYTES = 32
|
|
44
48
|
private apiToken: string
|
|
45
49
|
private apiHost: string
|
|
46
50
|
private cryptographyStorageKey: Uint8Array
|
|
51
|
+
private storagePath: string
|
|
47
52
|
|
|
48
53
|
private isShuttingDown = false
|
|
54
|
+
private readonly shouldRegisterExitHandlers: boolean
|
|
55
|
+
|
|
56
|
+
// SIGINT: Ctrl+C in terminal
|
|
57
|
+
private readonly onSigint = () => this.handleExit('SIGINT', 0)
|
|
58
|
+
|
|
59
|
+
// SIGTERM: Termination signal (e.g., from Docker, Kubernetes)
|
|
60
|
+
private readonly onSigterm = () => this.handleExit('SIGTERM', 0)
|
|
61
|
+
|
|
62
|
+
// Errors always exit with a failure code, so supervisors restart the process
|
|
63
|
+
private readonly onUncaughtException = (error: Error) => {
|
|
64
|
+
this.logger.error('Uncaught exception:', error)
|
|
65
|
+
this.handleExit('uncaughtException', 1)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
private readonly onUnhandledRejection = (reason: unknown) => {
|
|
69
|
+
this.logger.error('Unhandled rejection:', reason)
|
|
70
|
+
this.handleExit('unhandledRejection', 1)
|
|
71
|
+
}
|
|
49
72
|
|
|
50
|
-
private isWebSocketRunning: boolean = false
|
|
51
73
|
private webSocketClient?: WebSocketClient
|
|
52
74
|
private conversationService?: ConversationService
|
|
53
75
|
private appProperties?: AppProperties
|
|
76
|
+
private keyPackageReplenisher?: KeyPackageReplenisher
|
|
77
|
+
private isWebSocketRunning = false
|
|
78
|
+
private webSocketLoop: Promise<void> | undefined
|
|
54
79
|
|
|
55
80
|
private wireEventsHandler: WireEventsHandler
|
|
56
81
|
private logger: Logger
|
|
@@ -60,7 +85,8 @@ export class WireAppSdk {
|
|
|
60
85
|
apiHost: string,
|
|
61
86
|
cryptographyStorageKey: Uint8Array,
|
|
62
87
|
wireEventsHandler: WireEventsHandler,
|
|
63
|
-
logger?: Logger
|
|
88
|
+
logger?: Logger,
|
|
89
|
+
options: WireAppSdkOptions = {}
|
|
64
90
|
) {
|
|
65
91
|
if (cryptographyStorageKey.length !== this.CRYPTOGRAPHY_STORAGE_KEY_BYTES) {
|
|
66
92
|
throw new InvalidParameterError(
|
|
@@ -68,25 +94,48 @@ export class WireAppSdk {
|
|
|
68
94
|
)
|
|
69
95
|
}
|
|
70
96
|
|
|
97
|
+
if (options.storagePath !== undefined && options.storagePath.trim() === '') {
|
|
98
|
+
throw new InvalidParameterError('storagePath must not be empty; omit it to use the default ./storage')
|
|
99
|
+
}
|
|
100
|
+
|
|
71
101
|
this.apiToken = apiToken
|
|
72
102
|
this.apiHost = apiHost
|
|
73
103
|
this.cryptographyStorageKey = cryptographyStorageKey
|
|
104
|
+
// Resolve once, so a later process.chdir() cannot move the storage while the SDK is running.
|
|
105
|
+
this.storagePath = resolve(options.storagePath ?? DEFAULT_STORAGE_PATH)
|
|
74
106
|
this.wireEventsHandler = wireEventsHandler
|
|
107
|
+
this.shouldRegisterExitHandlers = options.registerExitHandlers ?? true
|
|
75
108
|
LoggerFactory.setRootLogger(logger ?? new ConsoleLogger())
|
|
76
109
|
this.logger = LoggerFactory.getLogger(this.constructor.name)
|
|
77
110
|
}
|
|
78
111
|
|
|
112
|
+
/**
|
|
113
|
+
* Creates and initializes the SDK.
|
|
114
|
+
*
|
|
115
|
+
* @param apiToken API token of the Wire application
|
|
116
|
+
* @param apiHost Base URL of the Wire backend API
|
|
117
|
+
* @param cryptographyStorageKey 32-byte key used to encrypt the local cryptographic storage
|
|
118
|
+
* @param wireEventsHandler Handler receiving the events of the application
|
|
119
|
+
* @param logger Optional logger, defaults to {@link ConsoleLogger}
|
|
120
|
+
* @param options Optional settings, see {@link WireAppSdkOptions}
|
|
121
|
+
*/
|
|
79
122
|
static async create(
|
|
80
123
|
apiToken: string,
|
|
81
124
|
apiHost: string,
|
|
82
125
|
cryptographyStorageKey: Uint8Array,
|
|
83
126
|
wireEventsHandler: WireEventsHandler,
|
|
84
|
-
logger?: Logger
|
|
127
|
+
logger?: Logger,
|
|
128
|
+
options?: WireAppSdkOptions
|
|
85
129
|
): Promise<WireAppSdk> {
|
|
86
|
-
const wireAppSdk = new WireAppSdk(apiToken, apiHost, cryptographyStorageKey, wireEventsHandler, logger)
|
|
130
|
+
const wireAppSdk = new WireAppSdk(apiToken, apiHost, cryptographyStorageKey, wireEventsHandler, logger, options)
|
|
87
131
|
|
|
88
132
|
wireAppSdk.registerExitHandlers()
|
|
89
|
-
|
|
133
|
+
try {
|
|
134
|
+
await wireAppSdk.init()
|
|
135
|
+
} catch (error) {
|
|
136
|
+
wireAppSdk.removeExitHandlers()
|
|
137
|
+
throw error
|
|
138
|
+
}
|
|
90
139
|
return wireAppSdk
|
|
91
140
|
}
|
|
92
141
|
|
|
@@ -106,14 +155,15 @@ export class WireAppSdk {
|
|
|
106
155
|
}
|
|
107
156
|
|
|
108
157
|
private prepareStorage() {
|
|
109
|
-
mkdirSync(
|
|
110
|
-
mkdirSync(
|
|
158
|
+
mkdirSync(this.storagePath, {recursive: true})
|
|
159
|
+
mkdirSync(getCryptographyStoragePath(this.storagePath), {recursive: true})
|
|
111
160
|
}
|
|
112
161
|
|
|
113
162
|
private configureDependencyTokens() {
|
|
114
163
|
container.registerInstance(WIRE_API_HOST, this.apiHost)
|
|
115
164
|
container.registerInstance(WIRE_SDK_API_TOKEN, this.apiToken)
|
|
116
165
|
container.registerInstance(WIRE_CRYPTOGRAPHY_STORAGE_KEY, this.cryptographyStorageKey)
|
|
166
|
+
container.registerInstance(WIRE_STORAGE_PATH, this.storagePath)
|
|
117
167
|
|
|
118
168
|
container.registerInstance(WIRE_EVENTS_HANDLER, this.wireEventsHandler)
|
|
119
169
|
}
|
|
@@ -121,6 +171,7 @@ export class WireAppSdk {
|
|
|
121
171
|
private resolveRuntimeDependencies() {
|
|
122
172
|
this.webSocketClient = container.resolve(WebSocketClient)
|
|
123
173
|
this.conversationService = container.resolve(ConversationService)
|
|
174
|
+
this.keyPackageReplenisher = container.resolve(KeyPackageReplenisher)
|
|
124
175
|
}
|
|
125
176
|
|
|
126
177
|
private async configureApplicationIdentity() {
|
|
@@ -141,13 +192,26 @@ export class WireAppSdk {
|
|
|
141
192
|
this.logger.info('Wire Apps SDK is already running.')
|
|
142
193
|
return
|
|
143
194
|
}
|
|
144
|
-
this.isWebSocketRunning = true
|
|
145
195
|
|
|
146
|
-
if (!this.webSocketClient || !this.conversationService) {
|
|
196
|
+
if (!this.webSocketClient || !this.conversationService || !this.keyPackageReplenisher) {
|
|
147
197
|
throw new UnknownError('Wire Apps SDK dependencies are not initialized.')
|
|
148
198
|
}
|
|
149
199
|
|
|
150
|
-
this.
|
|
200
|
+
await this.webSocketLoop
|
|
201
|
+
if (this.isWebSocketRunning) return
|
|
202
|
+
|
|
203
|
+
this.keyPackageReplenisher.start()
|
|
204
|
+
this.isWebSocketRunning = true
|
|
205
|
+
|
|
206
|
+
const webSocketLoop = this.webSocketClient
|
|
207
|
+
.connect()
|
|
208
|
+
.catch((exception) => this.logger.error('WebSocket connection loop failed', exception))
|
|
209
|
+
this.webSocketLoop = webSocketLoop
|
|
210
|
+
void webSocketLoop.finally(() => {
|
|
211
|
+
if (this.webSocketLoop !== webSocketLoop) return
|
|
212
|
+
|
|
213
|
+
this.webSocketLoop = undefined
|
|
214
|
+
this.keyPackageReplenisher?.stop()
|
|
151
215
|
this.isWebSocketRunning = false
|
|
152
216
|
})
|
|
153
217
|
|
|
@@ -157,14 +221,18 @@ export class WireAppSdk {
|
|
|
157
221
|
stopListening() {
|
|
158
222
|
if (!this.isWebSocketRunning) {
|
|
159
223
|
this.logger.info('Wire Apps SDK is not running.')
|
|
224
|
+
} else {
|
|
225
|
+
this.logger.info('Wire Apps SDK shutting down.')
|
|
160
226
|
}
|
|
161
|
-
this.logger.info('Wire Apps SDK shutting down.')
|
|
162
227
|
this.isWebSocketRunning = false
|
|
163
228
|
|
|
229
|
+
this.keyPackageReplenisher?.stop()
|
|
164
230
|
this.webSocketClient?.close()
|
|
165
231
|
}
|
|
166
232
|
|
|
167
233
|
async close() {
|
|
234
|
+
this.removeExitHandlers()
|
|
235
|
+
|
|
168
236
|
this.logger.debug('Closing Websocket connections.')
|
|
169
237
|
this.stopListening()
|
|
170
238
|
|
|
@@ -200,24 +268,25 @@ export class WireAppSdk {
|
|
|
200
268
|
}
|
|
201
269
|
|
|
202
270
|
private registerExitHandlers(): void {
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
// SIGTERM: Termination signal (e.g., from Docker, Kubernetes)
|
|
207
|
-
process.on('SIGTERM', () => this.handleExit('SIGTERM'))
|
|
271
|
+
if (!this.shouldRegisterExitHandlers) {
|
|
272
|
+
return
|
|
273
|
+
}
|
|
208
274
|
|
|
209
|
-
process.on('
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
275
|
+
process.on('SIGINT', this.onSigint)
|
|
276
|
+
process.on('SIGTERM', this.onSigterm)
|
|
277
|
+
process.on('uncaughtException', this.onUncaughtException)
|
|
278
|
+
process.on('unhandledRejection', this.onUnhandledRejection)
|
|
279
|
+
}
|
|
213
280
|
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
281
|
+
// Removing a listener that was never added is a no-op, so this is safe to call at any time
|
|
282
|
+
private removeExitHandlers(): void {
|
|
283
|
+
process.off('SIGINT', this.onSigint)
|
|
284
|
+
process.off('SIGTERM', this.onSigterm)
|
|
285
|
+
process.off('uncaughtException', this.onUncaughtException)
|
|
286
|
+
process.off('unhandledRejection', this.onUnhandledRejection)
|
|
218
287
|
}
|
|
219
288
|
|
|
220
|
-
private async handleExit(signal: string): Promise<void> {
|
|
289
|
+
private async handleExit(signal: string, exitCode: number): Promise<void> {
|
|
221
290
|
if (this.isShuttingDown) {
|
|
222
291
|
return
|
|
223
292
|
}
|
|
@@ -228,7 +297,7 @@ export class WireAppSdk {
|
|
|
228
297
|
try {
|
|
229
298
|
await this.close()
|
|
230
299
|
this.logger.info('Cleanup completed successfully')
|
|
231
|
-
process.exit(
|
|
300
|
+
process.exit(exitCode)
|
|
232
301
|
} catch (exception) {
|
|
233
302
|
this.logger.error('Error during cleanup:', exception)
|
|
234
303
|
process.exit(1)
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Wire
|
|
3
|
+
* Copyright (C) 2026 Wire Swiss GmbH
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
* You should have received a copy of the GNU General Public License
|
|
14
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Optional settings for {@link WireAppSdk.create}.
|
|
19
|
+
*/
|
|
20
|
+
export interface WireAppSdkOptions {
|
|
21
|
+
/**
|
|
22
|
+
* Directory where the SDK keeps its local state: the `apps.db` SQLite database and the
|
|
23
|
+
* `cryptography` folder with the app's MLS keys and device state.
|
|
24
|
+
*
|
|
25
|
+
* Relative paths are resolved against `process.cwd()` once, when the SDK is created.
|
|
26
|
+
* The directory is created if it does not exist. Each app needs its own directory, and it must
|
|
27
|
+
* persist across restarts: if it is lost, the app comes back as a new device.
|
|
28
|
+
*
|
|
29
|
+
* @default './storage'
|
|
30
|
+
*/
|
|
31
|
+
storagePath?: string
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Whether the SDK handles `SIGINT`, `SIGTERM`, `uncaughtException` and `unhandledRejection` by
|
|
35
|
+
* calling {@link WireAppSdk.close} and exiting the process: with code 0 after a signal, and with
|
|
36
|
+
* code 1 after an error or a failed close. Set it to `false` when the host application manages the
|
|
37
|
+
* process lifecycle; it must then call {@link WireAppSdk.close} itself on shutdown.
|
|
38
|
+
*
|
|
39
|
+
* @default true
|
|
40
|
+
*/
|
|
41
|
+
registerExitHandlers?: boolean
|
|
42
|
+
}
|
|
@@ -478,6 +478,7 @@ export class ConversationService {
|
|
|
478
478
|
`Updating member in conversation. conversationId: ${conversationId}, userId: ${userId}, newRole: ${newRole}`
|
|
479
479
|
)
|
|
480
480
|
|
|
481
|
+
this.requireAssignableRole(newRole)
|
|
481
482
|
const conversation = await this.getConversationById(conversationId)
|
|
482
483
|
this.requireConversationIsGroupOrChannel(conversationId, conversation.type)
|
|
483
484
|
this.requireAppIsAdminInConversation(conversationId)
|
|
@@ -678,6 +679,15 @@ export class ConversationService {
|
|
|
678
679
|
this.logger.info(`Conversation is deleted. teamId: ${teamId}, conversationId: ${conversationId}`)
|
|
679
680
|
}
|
|
680
681
|
|
|
682
|
+
private requireAssignableRole(role: ConversationRole): void {
|
|
683
|
+
if (role !== ConversationRole.MEMBER && role !== ConversationRole.ADMIN) {
|
|
684
|
+
this.logger.warn(`Skipping operation, role is not assignable. role: ${role}`)
|
|
685
|
+
throw new InvalidParameterError(
|
|
686
|
+
`Invalid conversation role: ${role}. Accepted roles: ${ConversationRole.MEMBER}, ${ConversationRole.ADMIN}`
|
|
687
|
+
)
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
|
|
681
691
|
private requireConversationIsGroupOrChannel(conversationId: QualifiedId, conversationType: ConversationType): void {
|
|
682
692
|
if (conversationType !== ConversationType.GROUP) {
|
|
683
693
|
this.logger.warn(
|
package/src/api/MlsApiClient.ts
CHANGED
|
@@ -21,6 +21,7 @@ import {singleton} from 'tsyringe'
|
|
|
21
21
|
import type {MlsPublicKeysResponse} from './response/MlsPublicKeysResponse.js'
|
|
22
22
|
import type {ClaimedKeyPackageList} from './response/ClaimedKeyPackageList.js'
|
|
23
23
|
import {AppProperties} from '../service/AppProperties.js'
|
|
24
|
+
import type {MlsKeyPackageCountResponse} from './response/MlsKeyPackageCountResponse.js'
|
|
24
25
|
|
|
25
26
|
@singleton()
|
|
26
27
|
export class MlsApiClient {
|
|
@@ -62,6 +63,11 @@ export class MlsApiClient {
|
|
|
62
63
|
await this.httpClient.postRequest<void>(path, requestPayload)
|
|
63
64
|
}
|
|
64
65
|
|
|
66
|
+
async getAvailableKeyPackageCount(ciphersuite: string): Promise<MlsKeyPackageCountResponse> {
|
|
67
|
+
const path = `${this.uploadMlsKeyPackagesPath}${this.appProperties.getDeviceId()}/count?${this.CIPHERSUITE_QUERY_PARAM}=${ciphersuite}`
|
|
68
|
+
return await this.httpClient.getRequest<MlsKeyPackageCountResponse>(path)
|
|
69
|
+
}
|
|
70
|
+
|
|
65
71
|
async getPublicKeys(): Promise<MlsPublicKeysResponse> {
|
|
66
72
|
return await this.httpClient.getRequest<MlsPublicKeysResponse>(this.getPublicKeysPath)
|
|
67
73
|
}
|
package/src/api/MlsService.ts
CHANGED
|
@@ -43,6 +43,10 @@ export class MlsService {
|
|
|
43
43
|
await this.mlsApiClient.uploadMlsKeyPackages(mlsKeyPackages)
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
+
async getAvailableKeyPackageCount(ciphersuite: number): Promise<number> {
|
|
47
|
+
return (await this.mlsApiClient.getAvailableKeyPackageCount(this.toHexString(ciphersuite))).count
|
|
48
|
+
}
|
|
49
|
+
|
|
46
50
|
async getRemovalKey(
|
|
47
51
|
cipherSuite: CipherSuite,
|
|
48
52
|
existingPublicKeysResponse?: MlsPublicKeysResponse
|
package/src/api/UserService.ts
CHANGED
|
@@ -35,13 +35,10 @@ export class UserService {
|
|
|
35
35
|
private searchApiClient: SearchApiClient
|
|
36
36
|
) {}
|
|
37
37
|
|
|
38
|
-
async getUser(userQualifiedId: QualifiedId): Promise<WireUser> {
|
|
39
|
-
const response = await this.usersApiClient.getUser(userQualifiedId.id, userQualifiedId.domain)
|
|
40
|
-
return this.mapUserResponseToWireUser(response)
|
|
41
|
-
}
|
|
42
|
-
|
|
43
38
|
async getUsers(userIds: QualifiedId[]): Promise<WireUser[]> {
|
|
44
39
|
this.logger.info(`Fetching ${userIds.length} users by qualified IDs`)
|
|
40
|
+
if (userIds.length === 0) return []
|
|
41
|
+
|
|
45
42
|
const response = await this.usersApiClient.listUsers(userIds)
|
|
46
43
|
if (response.failed?.length) {
|
|
47
44
|
response.failed.forEach((id) => this.logger.warn(`Failed to fetch user: ${obfuscateId(id.id)}@${id.domain}`))
|
|
@@ -15,7 +15,6 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
import {HttpClient} from '../core/HttpClient.js'
|
|
18
|
-
import type {UserResponse} from './model/UserResponse.js'
|
|
19
18
|
import {singleton} from 'tsyringe'
|
|
20
19
|
import type {UserClientResponse} from './model/UserClientResponse.js'
|
|
21
20
|
import {QualifiedId} from '../model/QualifiedId.js'
|
|
@@ -28,11 +27,6 @@ export class UsersApiClient {
|
|
|
28
27
|
private readonly basePathUsers = 'users'
|
|
29
28
|
private readonly basePathListUsers = 'list-users'
|
|
30
29
|
|
|
31
|
-
async getUser(userId: string, userDomain: string): Promise<UserResponse> {
|
|
32
|
-
const path = `${this.basePathUsers}/${userDomain}/${userId}`
|
|
33
|
-
return await this.httpClient.getRequest<UserResponse>(path)
|
|
34
|
-
}
|
|
35
|
-
|
|
36
30
|
async getClientsByUserIds(userIds: QualifiedId[]): Promise<Map<string, UserClientResponse[]>> {
|
|
37
31
|
const path = `${this.basePathUsers}/list-clients`
|
|
38
32
|
const response = await this.httpClient.postRequest<{
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Wire
|
|
3
|
+
* Copyright (C) 2026 Wire Swiss GmbH
|
|
4
|
+
*
|
|
5
|
+
* This program is free software: you can redistribute it and/or modify
|
|
6
|
+
* it under the terms of the GNU General Public License as published by
|
|
7
|
+
* the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
* (at your option) any later version.
|
|
9
|
+
* This program is distributed in the hope that it will be useful,
|
|
10
|
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12
|
+
* GNU General Public License for more details.
|
|
13
|
+
* You should have received a copy of the GNU General Public License
|
|
14
|
+
* along with this program. If not, see http://www.gnu.org/licenses/.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export interface MlsKeyPackageCountResponse {
|
|
18
|
+
count: number
|
|
19
|
+
}
|