@wireapp/wire-apps-js-sdk 0.1.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (138) hide show
  1. package/README.md +23 -3
  2. package/build/WireAppSdk.d.ts +22 -2
  3. package/build/WireAppSdk.d.ts.map +1 -1
  4. package/build/WireAppSdk.js +88 -27
  5. package/build/WireAppSdk.js.map +1 -1
  6. package/build/WireAppSdkOptions.d.ts +26 -0
  7. package/build/WireAppSdkOptions.d.ts.map +1 -0
  8. package/build/WireAppSdkOptions.js +17 -0
  9. package/build/WireAppSdkOptions.js.map +1 -0
  10. package/build/api/ConversationService.d.ts +3 -0
  11. package/build/api/ConversationService.d.ts.map +1 -1
  12. package/build/api/ConversationService.js +10 -0
  13. package/build/api/ConversationService.js.map +1 -1
  14. package/build/api/ConversationsApiClient.d.ts +2 -0
  15. package/build/api/ConversationsApiClient.d.ts.map +1 -1
  16. package/build/api/ConversationsApiClient.js +10 -0
  17. package/build/api/ConversationsApiClient.js.map +1 -1
  18. package/build/api/MlsApiClient.d.ts +2 -0
  19. package/build/api/MlsApiClient.d.ts.map +1 -1
  20. package/build/api/MlsApiClient.js +4 -0
  21. package/build/api/MlsApiClient.js.map +1 -1
  22. package/build/api/MlsService.d.ts +1 -0
  23. package/build/api/MlsService.d.ts.map +1 -1
  24. package/build/api/MlsService.js +3 -0
  25. package/build/api/MlsService.js.map +1 -1
  26. package/build/api/UserService.d.ts +0 -1
  27. package/build/api/UserService.d.ts.map +1 -1
  28. package/build/api/UserService.js +2 -4
  29. package/build/api/UserService.js.map +1 -1
  30. package/build/api/UsersApiClient.d.ts +0 -2
  31. package/build/api/UsersApiClient.d.ts.map +1 -1
  32. package/build/api/UsersApiClient.js +0 -4
  33. package/build/api/UsersApiClient.js.map +1 -1
  34. package/build/api/response/MlsKeyPackageCountResponse.d.ts +4 -0
  35. package/build/api/response/MlsKeyPackageCountResponse.d.ts.map +1 -0
  36. package/build/api/response/MlsKeyPackageCountResponse.js +17 -0
  37. package/build/api/response/MlsKeyPackageCountResponse.js.map +1 -0
  38. package/build/core/CoreCryptoClient.d.ts +4 -4
  39. package/build/core/CoreCryptoClient.d.ts.map +1 -1
  40. package/build/core/CoreCryptoClient.js +9 -10
  41. package/build/core/CoreCryptoClient.js.map +1 -1
  42. package/build/core/CoreCryptoService.d.ts +3 -1
  43. package/build/core/CoreCryptoService.d.ts.map +1 -1
  44. package/build/core/CoreCryptoService.js +21 -7
  45. package/build/core/CoreCryptoService.js.map +1 -1
  46. package/build/core/HttpClient.d.ts +1 -0
  47. package/build/core/HttpClient.d.ts.map +1 -1
  48. package/build/core/HttpClient.js +17 -7
  49. package/build/core/HttpClient.js.map +1 -1
  50. package/build/core/HttpRetryHelper.d.ts +3 -1
  51. package/build/core/HttpRetryHelper.d.ts.map +1 -1
  52. package/build/core/HttpRetryHelper.js +30 -2
  53. package/build/core/HttpRetryHelper.js.map +1 -1
  54. package/build/core/TypingIndicatorController.d.ts +15 -0
  55. package/build/core/TypingIndicatorController.d.ts.map +1 -0
  56. package/build/core/TypingIndicatorController.js +100 -0
  57. package/build/core/TypingIndicatorController.js.map +1 -0
  58. package/build/core/WebSocketClient.d.ts.map +1 -1
  59. package/build/core/WebSocketClient.js +3 -3
  60. package/build/core/WebSocketClient.js.map +1 -1
  61. package/build/core/WireApplicationManager.d.ts +8 -1
  62. package/build/core/WireApplicationManager.d.ts.map +1 -1
  63. package/build/core/WireApplicationManager.js +17 -4
  64. package/build/core/WireApplicationManager.js.map +1 -1
  65. package/build/core/WireEventsHandler.d.ts +8 -0
  66. package/build/core/WireEventsHandler.d.ts.map +1 -1
  67. package/build/core/WireEventsHandler.js +9 -0
  68. package/build/core/WireEventsHandler.js.map +1 -1
  69. package/build/core/event/MlsWelcomeEventProcessor.d.ts +2 -3
  70. package/build/core/event/MlsWelcomeEventProcessor.d.ts.map +1 -1
  71. package/build/core/event/MlsWelcomeEventProcessor.js +12 -10
  72. package/build/core/event/MlsWelcomeEventProcessor.js.map +1 -1
  73. package/build/core/event/TeamMemberJoinEventProcessor.d.ts +13 -0
  74. package/build/core/event/TeamMemberJoinEventProcessor.d.ts.map +1 -0
  75. package/build/core/event/TeamMemberJoinEventProcessor.js +60 -0
  76. package/build/core/event/TeamMemberJoinEventProcessor.js.map +1 -0
  77. package/build/core/event/processors.index.d.ts +1 -0
  78. package/build/core/event/processors.index.d.ts.map +1 -1
  79. package/build/core/event/processors.index.js +1 -0
  80. package/build/core/event/processors.index.js.map +1 -1
  81. package/build/db/DatabaseService.d.ts +2 -1
  82. package/build/db/DatabaseService.d.ts.map +1 -1
  83. package/build/db/DatabaseService.js +12 -5
  84. package/build/db/DatabaseService.js.map +1 -1
  85. package/build/index.d.ts +1 -0
  86. package/build/index.d.ts.map +1 -1
  87. package/build/index.js.map +1 -1
  88. package/build/model/EventContentDTO.d.ts +10 -1
  89. package/build/model/EventContentDTO.d.ts.map +1 -1
  90. package/build/model/conversation/TypingStatus.d.ts +5 -0
  91. package/build/model/conversation/TypingStatus.d.ts.map +1 -0
  92. package/build/model/conversation/TypingStatus.js +21 -0
  93. package/build/model/conversation/TypingStatus.js.map +1 -0
  94. package/build/service/KeyPackageReplenisher.d.ts +15 -0
  95. package/build/service/KeyPackageReplenisher.d.ts.map +1 -0
  96. package/build/service/KeyPackageReplenisher.js +82 -0
  97. package/build/service/KeyPackageReplenisher.js.map +1 -0
  98. package/build/utils/ApiDateReviver.d.ts +3 -0
  99. package/build/utils/ApiDateReviver.d.ts.map +1 -0
  100. package/build/utils/ApiDateReviver.js +26 -0
  101. package/build/utils/ApiDateReviver.js.map +1 -0
  102. package/build/utils/DependencyInjectionTokens.d.ts +1 -0
  103. package/build/utils/DependencyInjectionTokens.d.ts.map +1 -1
  104. package/build/utils/DependencyInjectionTokens.js +1 -0
  105. package/build/utils/DependencyInjectionTokens.js.map +1 -1
  106. package/build/utils/StoragePaths.d.ts +3 -3
  107. package/build/utils/StoragePaths.d.ts.map +1 -1
  108. package/build/utils/StoragePaths.js +10 -5
  109. package/build/utils/StoragePaths.js.map +1 -1
  110. package/package.json +2 -2
  111. package/src/WireAppSdk.ts +97 -28
  112. package/src/WireAppSdkOptions.ts +42 -0
  113. package/src/api/ConversationService.ts +15 -0
  114. package/src/api/ConversationsApiClient.ts +15 -0
  115. package/src/api/MlsApiClient.ts +6 -0
  116. package/src/api/MlsService.ts +4 -0
  117. package/src/api/UserService.ts +2 -5
  118. package/src/api/UsersApiClient.ts +0 -6
  119. package/src/api/response/MlsKeyPackageCountResponse.ts +19 -0
  120. package/src/core/CoreCryptoClient.ts +13 -10
  121. package/src/core/CoreCryptoService.ts +17 -3
  122. package/src/core/HttpClient.ts +31 -9
  123. package/src/core/HttpRetryHelper.ts +31 -2
  124. package/src/core/TypingIndicatorController.ts +108 -0
  125. package/src/core/WebSocketClient.ts +4 -4
  126. package/src/core/WireApplicationManager.ts +19 -5
  127. package/src/core/WireEventsHandler.ts +11 -0
  128. package/src/core/event/MlsWelcomeEventProcessor.ts +9 -6
  129. package/src/core/event/TeamMemberJoinEventProcessor.ts +48 -0
  130. package/src/core/event/processors.index.ts +1 -0
  131. package/src/db/DatabaseService.ts +5 -4
  132. package/src/index.ts +1 -0
  133. package/src/model/EventContentDTO.ts +12 -0
  134. package/src/model/conversation/TypingStatus.ts +20 -0
  135. package/src/service/KeyPackageReplenisher.ts +71 -0
  136. package/src/utils/ApiDateReviver.ts +27 -0
  137. package/src/utils/DependencyInjectionTokens.ts +1 -0
  138. package/src/utils/StoragePaths.ts +12 -5
@@ -14,6 +14,7 @@
14
14
  * along with this program. If not, see http://www.gnu.org/licenses/.
15
15
  */
16
16
 
17
+ import {apiDateReviver} from '../utils/ApiDateReviver.js'
17
18
  import {WIRE_API_HOST} from '../utils/DependencyInjectionTokens.js'
18
19
  import type {WireApiError} from '../exception/WireApiError.js'
19
20
  import {inject, singleton} from 'tsyringe'
@@ -28,7 +29,8 @@ import {
28
29
  isRetryableHttpStatus,
29
30
  RetryableHttpStatusError,
30
31
  RetryableNetworkError,
31
- waitForHttpRetry
32
+ waitForHttpRetry,
33
+ withAbortSignal
32
34
  } from './HttpRetryHelper.js'
33
35
  import {AuthenticationError, UnknownError} from '../exception/WireException.js'
34
36
 
@@ -131,9 +133,14 @@ export class HttpClient {
131
133
  includeApiVersion: boolean = true,
132
134
  shouldRetry: boolean = true
133
135
  ): Promise<{data: T; response: Response}> {
134
- return this.withRetry(
135
- (shouldRetryOnStatus) => this.requestOnce<T>(path, options, includeApiVersion, shouldRetry, shouldRetryOnStatus),
136
- path
136
+ return withAbortSignal(
137
+ this.withRetry(
138
+ (shouldRetryOnStatus) =>
139
+ this.requestOnce<T>(path, options, includeApiVersion, shouldRetry, shouldRetryOnStatus),
140
+ path,
141
+ options.signal
142
+ ),
143
+ options.signal
137
144
  )
138
145
  }
139
146
 
@@ -144,6 +151,7 @@ export class HttpClient {
144
151
  shouldRetryUnauthorized: boolean,
145
152
  shouldRetryOnStatus: boolean
146
153
  ): Promise<{data: T; response: Response}> {
154
+ options.signal?.throwIfAborted()
147
155
  const optionsAndHeaders = {
148
156
  ...options,
149
157
  headers: {
@@ -156,13 +164,17 @@ export class HttpClient {
156
164
  try {
157
165
  response = await fetch(url, optionsAndHeaders)
158
166
  } catch (exception) {
167
+ options.signal?.throwIfAborted()
159
168
  throw new RetryableNetworkError(path, exception)
160
169
  }
170
+ options.signal?.throwIfAborted()
161
171
 
162
172
  if (!response.ok) {
163
173
  if (response.status === 401 && shouldRetryUnauthorized) {
164
174
  this.logger.info('Access token not valid, getting a new one.')
165
- await this.refreshAccessToken()
175
+ // The refresh may be shared with other calls. Stop this caller's wait without cancelling
176
+ // their authentication request; the aborted typing request will never be replayed.
177
+ await withAbortSignal(this.refreshAccessToken(), options.signal)
166
178
  return this.requestOnce(path, options, includeApiVersion, false, shouldRetryOnStatus)
167
179
  }
168
180
 
@@ -194,7 +206,8 @@ export class HttpClient {
194
206
  const contentType = response.headers.get('content-type')
195
207
 
196
208
  if (contentType?.includes('application/json')) {
197
- const data = (await response.json()) as T
209
+ const body = await response.text()
210
+ const data = body.trim().length === 0 ? (undefined as T) : (JSON.parse(body, apiDateReviver) as T)
198
211
  return {data, response}
199
212
  }
200
213
 
@@ -207,16 +220,22 @@ export class HttpClient {
207
220
  return {data: undefined as unknown as T, response}
208
221
  }
209
222
 
210
- private async withRetry<T>(operation: (shouldRetryOnStatus: boolean) => Promise<T>, path: string): Promise<T> {
223
+ private async withRetry<T>(
224
+ operation: (shouldRetryOnStatus: boolean) => Promise<T>,
225
+ path: string,
226
+ signal?: AbortSignal | null
227
+ ): Promise<T> {
211
228
  const retryPolicy = HTTP_RETRY_POLICY
212
229
  const maxAttempts = retryPolicy.maxAttempts
213
230
 
214
231
  for (let attemptIndex = 0; attemptIndex < maxAttempts; attemptIndex++) {
232
+ signal?.throwIfAborted()
215
233
  const shouldRetryOnStatus = attemptIndex < maxAttempts - 1
216
234
 
217
235
  try {
218
236
  return await operation(shouldRetryOnStatus)
219
237
  } catch (exception) {
238
+ signal?.throwIfAborted()
220
239
  if (attemptIndex >= maxAttempts - 1 || !isRetryableHttpError(exception)) {
221
240
  throw exception
222
241
  }
@@ -225,7 +244,7 @@ export class HttpClient {
225
244
  this.logger.warn(
226
245
  `Retrying HTTP request for ${path} in ${delayMs}ms ` + `(attempt ${attemptIndex + 2}/${maxAttempts})`
227
246
  )
228
- await waitForHttpRetry(delayMs)
247
+ await waitForHttpRetry(delayMs, signal)
229
248
  }
230
249
  }
231
250
 
@@ -267,12 +286,14 @@ export class HttpClient {
267
286
  headerContentType?: string
268
287
  headerAccept?: string
269
288
  includeApiVersion?: boolean
289
+ signal?: AbortSignal
270
290
  }
271
291
  ): Promise<T> {
272
292
  const {
273
293
  headerContentType = this.HEADER_DEFAULT_CONTENT_TYPE,
274
294
  headerAccept = this.HEADER_DEFAULT_ACCEPT,
275
- includeApiVersion = true
295
+ includeApiVersion = true,
296
+ signal
276
297
  } = options ?? {}
277
298
 
278
299
  const isBinary = body instanceof Uint8Array || body instanceof ArrayBuffer
@@ -281,6 +302,7 @@ export class HttpClient {
281
302
  const requestConfig = {
282
303
  method: 'POST',
283
304
  body: requestBody,
305
+ ...(signal ? {signal} : {}),
284
306
  headers: {
285
307
  'Content-Type': headerContentType,
286
308
  Accept: headerAccept
@@ -49,6 +49,35 @@ export function isRetryableHttpError(exception: unknown): boolean {
49
49
  return exception instanceof RetryableHttpStatusError || exception instanceof RetryableNetworkError
50
50
  }
51
51
 
52
- export async function waitForHttpRetry(delayMs: number): Promise<void> {
53
- await new Promise<void>((resolve) => setTimeout(resolve, delayMs))
52
+ /** Stops waiting when aborted; the operation itself must also observe the signal. */
53
+ export function withAbortSignal<T>(operation: Promise<T>, signal?: AbortSignal | null): Promise<T> {
54
+ if (!signal) return operation
55
+ return new Promise<T>((resolve, reject) => {
56
+ const onAbort = () => {
57
+ signal.removeEventListener('abort', onAbort)
58
+ reject(signal.reason)
59
+ }
60
+ signal.addEventListener('abort', onAbort, {once: true})
61
+ operation.then(
62
+ (value) => {
63
+ signal.removeEventListener('abort', onAbort)
64
+ resolve(value)
65
+ },
66
+ (error: unknown) => {
67
+ signal.removeEventListener('abort', onAbort)
68
+ reject(error)
69
+ }
70
+ )
71
+ if (signal.aborted) onAbort()
72
+ })
73
+ }
74
+
75
+ export async function waitForHttpRetry(delayMs: number, signal?: AbortSignal | null): Promise<void> {
76
+ signal?.throwIfAborted()
77
+ let timer: ReturnType<typeof setTimeout> | undefined
78
+ try {
79
+ await withAbortSignal(new Promise<void>((resolve) => (timer = setTimeout(resolve, delayMs))), signal)
80
+ } finally {
81
+ clearTimeout(timer)
82
+ }
54
83
  }
@@ -0,0 +1,108 @@
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
+ import {QualifiedId} from '../model/QualifiedId.js'
18
+ import {TypingStatus} from '../model/conversation/TypingStatus.js'
19
+ import {LoggerFactory} from '../utils/logger/LoggerFactory.js'
20
+
21
+ const REFRESH_INTERVAL_MS = 30_000
22
+ const MAX_DURATION_MS = 300_000
23
+
24
+ interface TypingSession {
25
+ references: number
26
+ closed: boolean
27
+ pending: Promise<void>
28
+ refreshTimer?: ReturnType<typeof setTimeout>
29
+ maximumTimer?: ReturnType<typeof setTimeout>
30
+ }
31
+
32
+ /** Coordinates one ordered typing session per conversation within an application manager. */
33
+ export class TypingIndicatorController {
34
+ private readonly sessions = new Map<string, TypingSession>()
35
+ private readonly logger = LoggerFactory.getLogger(this.constructor.name)
36
+
37
+ constructor(private readonly send: (conversationId: QualifiedId, status: TypingStatus) => Promise<void>) {}
38
+
39
+ acquire(conversationId: QualifiedId): () => void {
40
+ const key = QualifiedId.toKey(conversationId)
41
+ let session = this.sessions.get(key)
42
+ if (!session || session.references === 0) {
43
+ // A new session waits for the preceding session's STOPPED, even though its work starts immediately.
44
+ session = {references: 0, closed: false, pending: session?.pending ?? Promise.resolve()}
45
+ this.sessions.set(key, session)
46
+ const current = session
47
+ this.enqueue(conversationId, current, TypingStatus.STARTED)
48
+ this.scheduleRefresh(conversationId, current)
49
+ current.maximumTimer = setTimeout(() => this.close(conversationId, current), MAX_DURATION_MS)
50
+ current.maximumTimer.unref()
51
+ }
52
+ session.references++
53
+ const current = session
54
+ let released = false
55
+ return () => {
56
+ if (released) return
57
+ released = true
58
+ current.references--
59
+ if (current.references === 0) {
60
+ this.close(conversationId, current)
61
+ // Expired sessions already have a completed or pending STOPPED.
62
+ void current.pending.then(() => this.removeIdle(key, current))
63
+ }
64
+ }
65
+ }
66
+
67
+ private scheduleRefresh(conversationId: QualifiedId, session: TypingSession): void {
68
+ session.refreshTimer = setTimeout(() => {
69
+ if (session.closed) return
70
+ this.enqueue(conversationId, session, TypingStatus.STARTED)
71
+ this.scheduleRefresh(conversationId, session)
72
+ }, REFRESH_INTERVAL_MS)
73
+ session.refreshTimer.unref()
74
+ }
75
+
76
+ private close(conversationId: QualifiedId, session: TypingSession): void {
77
+ if (session.closed) return
78
+ session.closed = true
79
+ clearTimeout(session.refreshTimer)
80
+ clearTimeout(session.maximumTimer)
81
+ this.enqueue(conversationId, session, TypingStatus.STOPPED)
82
+ }
83
+
84
+ private enqueue(conversationId: QualifiedId, session: TypingSession, status: TypingStatus): void {
85
+ session.pending = session.pending.then(async () => {
86
+ // Do not send a queued refresh after the session ends or reaches its upper bound.
87
+ if (status === TypingStatus.STARTED && session.closed) return
88
+ try {
89
+ await this.send(conversationId, status)
90
+ } catch (error) {
91
+ this.logger.warn(`Could not send typing status ${status} in conversation ${conversationId}`, error)
92
+ }
93
+ })
94
+ void session.pending.then(() => this.removeIdle(QualifiedId.toKey(conversationId), session))
95
+ }
96
+
97
+ private removeIdle(key: string, session: TypingSession): void {
98
+ if (session.references === 0 && session.closed && this.sessions.get(key) === session) {
99
+ // The current tail may include STOPPED; keep it available to a new session until it settles.
100
+ const pending = session.pending
101
+ void pending.then(() => {
102
+ if (session.pending === pending && session.references === 0 && this.sessions.get(key) === session) {
103
+ this.sessions.delete(key)
104
+ }
105
+ })
106
+ }
107
+ }
108
+ }
@@ -21,6 +21,7 @@ import {EventRouter} from './event/EventRouter.js'
21
21
  import {inject, singleton} from 'tsyringe'
22
22
  import {LoggerFactory} from '../utils/logger/LoggerFactory.js'
23
23
  import type {EventResponse} from '../api/response/EventResponse.js'
24
+ import {apiDateReviver} from '../utils/ApiDateReviver.js'
24
25
  import {NotificationsService} from '../service/NotificationsService.js'
25
26
  import {AppProperties} from '../service/AppProperties.js'
26
27
  import type {BackendConnectionListener} from './BackendConnectionListener.js'
@@ -230,10 +231,9 @@ export class WebSocketClient {
230
231
  }
231
232
 
232
233
  private async handleEvent(data: Buffer) {
233
- const jsonString = data.toString('utf-8')
234
- const event = JSON.parse(jsonString) as EventResponse
235
-
236
234
  try {
235
+ const event = JSON.parse(data.toString('utf-8'), apiDateReviver) as EventResponse
236
+
237
237
  if (!event.transient && !this.processedEventIds.has(event.id)) {
238
238
  this.processedEventIds.clear()
239
239
  await this.eventRouter.route(event)
@@ -242,7 +242,7 @@ export class WebSocketClient {
242
242
  // TODO: Send back ACK event (To be done when we have Async notifications again)
243
243
  }
244
244
  } catch (exception) {
245
- this.logger.error(`Error processing event: ${event}`, exception)
245
+ this.logger.error('Error processing event:', exception)
246
246
  }
247
247
  }
248
248
 
@@ -36,11 +36,15 @@ import type {WireUser} from '../model/WireUser.js'
36
36
  import {AppProperties} from '../service/AppProperties.js'
37
37
  import type {ConversationEntity} from '../db/model/ConversationEntity.js'
38
38
  import type {TeamId} from '../model/TeamId.js'
39
+ import {TypingIndicatorController} from './TypingIndicatorController.js'
39
40
 
40
41
  @singleton()
41
42
  export class WireApplicationManager {
42
43
  private logger = LoggerFactory.getLogger(this.constructor.name)
43
44
  private appQualifiedId?: QualifiedId
45
+ private readonly typingIndicator = new TypingIndicatorController((conversationId, status) =>
46
+ this.conversationService.sendTypingStatus(conversationId, status)
47
+ )
44
48
 
45
49
  constructor(
46
50
  private coreCryptoService: CoreCryptoService,
@@ -65,6 +69,21 @@ export class WireApplicationManager {
65
69
  return preparedMessage.id
66
70
  }
67
71
 
72
+ /**
73
+ * Runs work immediately while typing is sent in the background. Overlapping work in this
74
+ * conversation shares one indicator, refreshed every 30 seconds for at most five minutes.
75
+ * The last operation schedules STOPPED after any pending request. Delivery failures are logged;
76
+ * typing requests (including cleanup) never delay or replace the operation's result.
77
+ */
78
+ async processWithTypingIndicator<T>(conversationId: QualifiedId, process: () => Promise<T>): Promise<T> {
79
+ const release = this.typingIndicator.acquire(conversationId)
80
+ try {
81
+ return await process()
82
+ } finally {
83
+ release()
84
+ }
85
+ }
86
+
68
87
  private prepareMessageForSending(conversation: ConversationEntity, originalMessage: WireMessage): WireMessage {
69
88
  // If the conversation has a message timer set, we override the ephemeral type message's expiration duration to match it.
70
89
  if (conversation.messageTimer == null || !('expiresAfterMillis' in originalMessage)) {
@@ -188,11 +207,6 @@ export class WireApplicationManager {
188
207
  this.logger.debug("Member's role is updated in the conversation with id: " + obfuscateId(conversationId.id))
189
208
  }
190
209
 
191
- async getUser(userQualifiedId: QualifiedId): Promise<WireUser> {
192
- this.logger.debug('App requested to get user info: ' + obfuscateId(userQualifiedId.id))
193
- return await this.userService.getUser(userQualifiedId)
194
- }
195
-
196
210
  async getUsers(userIds: QualifiedId[]): Promise<WireUser[]> {
197
211
  this.logger.debug(`App requested to get info for ${userIds.length} users`)
198
212
  return await this.userService.getUsers(userIds)
@@ -32,6 +32,7 @@ import {obfuscateId} from '../utils/ObfuscateUtil.js'
32
32
  import {container} from 'tsyringe'
33
33
  import {LoggerFactory} from '../utils/logger/LoggerFactory.js'
34
34
  import type {QualifiedId} from '../model/QualifiedId.js'
35
+ import type {TeamId} from '../model/TeamId.js'
35
36
 
36
37
  /**
37
38
  * Abstract class exposed by the SDK to handle events.
@@ -106,4 +107,14 @@ export abstract class WireEventsHandler {
106
107
  `Received onUserLeftConversation, ID: ${obfuscateId(conversationId.id)} - length: ${members.length}`
107
108
  )
108
109
  }
110
+
111
+ /**
112
+ * A user has joined the team.
113
+ *
114
+ * @param userId the user ID of the user who joined
115
+ * @param teamId the ID of the team
116
+ */
117
+ public async onTeamMemberJoined(userId: QualifiedId, teamId: TeamId): Promise<void> {
118
+ this.logger.info(`Received onTeamMemberJoined, userId: ${userId}, teamId: ${teamId}`)
119
+ }
109
120
  }
@@ -25,17 +25,17 @@ import {WireEventsHandler} from './../WireEventsHandler.js'
25
25
  import {WIRE_EVENTS_HANDLER, EVENT_PROCESSOR} from '../../utils/DependencyInjectionTokens.js'
26
26
  import {ConversationMapper} from '../../mappers/conversation/ConversationMapper.js'
27
27
  import {QualifiedId} from '../../model/QualifiedId.js'
28
- import {AppProperties} from '../../service/AppProperties.js'
28
+ import {LoggerFactory} from '../../utils/logger/LoggerFactory.js'
29
29
 
30
30
  @injectable({token: EVENT_PROCESSOR})
31
31
  export class MlsWelcomeEventProcessor implements EventProcessor<MLSWelcomeDTO> {
32
32
  readonly eventType = 'conversation.mls-welcome' as const
33
+ private logger = LoggerFactory.getLogger(this.constructor.name)
33
34
 
34
35
  constructor(
35
36
  private coreCryptoService: CoreCryptoService,
36
37
  private conversationService: ConversationService,
37
38
  private mlsService: MlsService,
38
- private appProperties: AppProperties,
39
39
  @inject(WIRE_EVENTS_HANDLER) private wireEventsHandler: WireEventsHandler
40
40
  ) {}
41
41
 
@@ -52,10 +52,13 @@ export class MlsWelcomeEventProcessor implements EventProcessor<MLSWelcomeDTO> {
52
52
  conversationResponse
53
53
  )
54
54
 
55
- const storedDeviceId = this.appProperties.getDeviceId()
56
- if ((await this.coreCryptoService.hasTooFewKeyPackageCount()) && storedDeviceId) {
57
- const keyPackages = await this.coreCryptoService.mlsGenerateKeyPackages()
58
- await this.mlsService.uploadMlsKeyPackages(keyPackages)
55
+ try {
56
+ if (await this.coreCryptoService.hasTooFewKeyPackageCount()) {
57
+ const keyPackages = await this.coreCryptoService.mlsGenerateKeyPackages()
58
+ await this.mlsService.uploadMlsKeyPackages(keyPackages)
59
+ }
60
+ } catch (exception) {
61
+ this.logger.error('Failed to replenish MLS key packages after joining conversation', exception)
59
62
  }
60
63
 
61
64
  await this.wireEventsHandler.onAppAddedToConversation(ConversationMapper.fromEntity(conversation), members)
@@ -0,0 +1,48 @@
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
+ import {inject, injectable} from 'tsyringe'
18
+ import type {EventProcessor} from './EventProcessor.js'
19
+ import type {TeamMemberJoinDTO} from '../../model/EventContentDTO.js'
20
+ import {WireEventsHandler} from '../WireEventsHandler.js'
21
+ import {EVENT_PROCESSOR, WIRE_EVENTS_HANDLER} from '../../utils/DependencyInjectionTokens.js'
22
+ import {LoggerFactory} from '../../utils/logger/LoggerFactory.js'
23
+ import {QualifiedId} from '../../model/QualifiedId.js'
24
+ import {TeamId} from '../../model/TeamId.js'
25
+ import {AppProperties} from '../../service/AppProperties.js'
26
+
27
+ @injectable({token: EVENT_PROCESSOR})
28
+ export class TeamMemberJoinEventProcessor implements EventProcessor<TeamMemberJoinDTO> {
29
+ private logger = LoggerFactory.getLogger(this.constructor.name)
30
+
31
+ readonly eventType = 'team.member-join' as const
32
+
33
+ constructor(
34
+ private appProperties: AppProperties,
35
+ @inject(WIRE_EVENTS_HANDLER) private wireEventsHandler: WireEventsHandler
36
+ ) {}
37
+
38
+ async process(event: TeamMemberJoinDTO): Promise<void> {
39
+ // The event only carries a non-qualified user id, team members share the application's domain
40
+ const userId = new QualifiedId(event.data.user, this.appProperties.getApplicationQualifiedId().domain)
41
+ const teamId = new TeamId(event.team)
42
+ this.logger.info(`Processing TeamMemberJoin event for teamId: ${teamId}, userId: ${userId}`)
43
+
44
+ await this.wireEventsHandler.onTeamMemberJoined(userId, teamId)
45
+
46
+ this.logger.info(`Processed TeamMemberJoin event for teamId: ${teamId}`)
47
+ }
48
+ }
@@ -23,3 +23,4 @@ import './MlsMessageEventProcessor.js'
23
23
  import './MlsResetEventProcessor.js'
24
24
  import './MlsWelcomeEventProcessor.js'
25
25
  import './NewConversationEventProcessor.js'
26
+ import './TeamMemberJoinEventProcessor.js'
@@ -15,11 +15,12 @@
15
15
  */
16
16
 
17
17
  import Database, {type Database as DB} from 'better-sqlite3'
18
- import {singleton} from 'tsyringe'
18
+ import {inject, singleton} from 'tsyringe'
19
19
  import {LoggerFactory} from '../utils/logger/LoggerFactory.js'
20
20
  import {BetterSQLite3Database, drizzle} from 'drizzle-orm/better-sqlite3'
21
21
  import {migrate} from 'drizzle-orm/better-sqlite3/migrator'
22
- import {DATABASE_PATH} from '../utils/StoragePaths.js'
22
+ import {getDatabasePath} from '../utils/StoragePaths.js'
23
+ import {WIRE_STORAGE_PATH} from '../utils/DependencyInjectionTokens.js'
23
24
  import {dirname, join} from 'node:path'
24
25
  import {fileURLToPath} from 'node:url'
25
26
  import {DatabaseError} from '../exception/WireException.js'
@@ -30,7 +31,7 @@ export class DatabaseService {
30
31
  private readonly sqliteClient: DB
31
32
  public readonly db: BetterSQLite3Database
32
33
 
33
- constructor() {
34
+ constructor(@inject(WIRE_STORAGE_PATH) private readonly storagePath: string) {
34
35
  this.logger.info('DatabaseService being created')
35
36
  this.sqliteClient = new Database(this.getDatabasePath())
36
37
  this.sqliteClient.pragma('foreign_keys = ON')
@@ -40,7 +41,7 @@ export class DatabaseService {
40
41
  }
41
42
 
42
43
  protected getDatabasePath(): string {
43
- return DATABASE_PATH
44
+ return getDatabasePath(this.storagePath)
44
45
  }
45
46
 
46
47
  protected getMigrationsFolder(): string {
package/src/index.ts CHANGED
@@ -18,6 +18,7 @@
18
18
  // Main SDK Class
19
19
  // ============================================
20
20
  export {WireAppSdk} from './WireAppSdk.js'
21
+ export type {WireAppSdkOptions} from './WireAppSdkOptions.js'
21
22
 
22
23
  // ============================================
23
24
  // Core Components
@@ -122,6 +122,17 @@ interface MessageTimerUpdateEventData {
122
122
  message_timer: number | null
123
123
  }
124
124
 
125
+ export interface TeamMemberJoinDTO {
126
+ type: string
127
+ team: string
128
+ time: Date
129
+ data: TeamMemberIdData
130
+ }
131
+
132
+ interface TeamMemberIdData {
133
+ user: string
134
+ }
135
+
125
136
  export type EventContentDTO =
126
137
  | MLSWelcomeDTO
127
138
  | NewMLSMessageDTO
@@ -133,3 +144,4 @@ export type EventContentDTO =
133
144
  | MemberUpdateDTO
134
145
  | MlsResetDTO
135
146
  | MessageTimerUpdateDTO
147
+ | TeamMemberJoinDTO
@@ -0,0 +1,20 @@
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 enum TypingStatus {
18
+ STARTED = 'started',
19
+ STOPPED = 'stopped'
20
+ }
@@ -0,0 +1,71 @@
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
+ import {singleton} from 'tsyringe'
18
+ import {MlsService} from '../api/MlsService.js'
19
+ import {MLS_DEFAULT_KEY_PACKAGE_COUNT} from '../core/CoreCryptoClient.js'
20
+ import {CoreCryptoService} from '../core/CoreCryptoService.js'
21
+ import {LoggerFactory} from '../utils/logger/LoggerFactory.js'
22
+
23
+ @singleton()
24
+ export class KeyPackageReplenisher {
25
+ private static readonly CHECK_INTERVAL_MS = 24 * 60 * 60 * 1_000
26
+ private logger = LoggerFactory.getLogger(this.constructor.name)
27
+ private activeRun: object | undefined
28
+ private timer: ReturnType<typeof setTimeout> | undefined
29
+
30
+ constructor(
31
+ private mlsService: MlsService,
32
+ private coreCryptoService: CoreCryptoService
33
+ ) {}
34
+
35
+ start(): void {
36
+ if (this.activeRun) return
37
+
38
+ const run = {}
39
+ this.activeRun = run
40
+ void this.checkAndSchedule(run)
41
+ }
42
+
43
+ stop(): void {
44
+ this.activeRun = undefined
45
+ if (this.timer) clearTimeout(this.timer)
46
+ this.timer = undefined
47
+ }
48
+
49
+ private async checkAndSchedule(run: object): Promise<void> {
50
+ try {
51
+ const count = await this.mlsService.getAvailableKeyPackageCount(
52
+ this.coreCryptoService.getDefaultCiphersuiteCode()
53
+ )
54
+ if (count < MLS_DEFAULT_KEY_PACKAGE_COUNT / 2) {
55
+ this.logger.info(
56
+ `Found ${count} available MLS key packages, replenishing with ${MLS_DEFAULT_KEY_PACKAGE_COUNT} new packages`
57
+ )
58
+ const keyPackages = await this.coreCryptoService.mlsGenerateKeyPackages()
59
+ await this.mlsService.uploadMlsKeyPackages(keyPackages)
60
+ } else {
61
+ this.logger.info(`Found ${count} available MLS key packages, replenishment is not needed`)
62
+ }
63
+ } catch (exception) {
64
+ this.logger.error('Failed to check or replenish MLS key packages', exception)
65
+ }
66
+
67
+ if (run === this.activeRun) {
68
+ this.timer = setTimeout(() => void this.checkAndSchedule(run), KeyPackageReplenisher.CHECK_INTERVAL_MS)
69
+ }
70
+ }
71
+ }
@@ -0,0 +1,27 @@
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
+ /** Converts API `time` fields during JSON.parse, preserving unparseable strings. */
18
+ export function apiDateReviver(key: string, value: unknown): unknown {
19
+ if (key !== 'time') return value
20
+
21
+ if (typeof value !== 'string') {
22
+ throw new TypeError('API timestamp must be a string')
23
+ }
24
+
25
+ const time = new Date(value)
26
+ return Number.isNaN(time.getTime()) ? value : time
27
+ }
@@ -17,6 +17,7 @@
17
17
  export const WIRE_API_HOST = 'WIRE_API_HOST'
18
18
  export const WIRE_SDK_API_TOKEN = 'WIRE_SDK_API_TOKEN'
19
19
  export const WIRE_CRYPTOGRAPHY_STORAGE_KEY = 'WIRE_CRYPTOGRAPHY_STORAGE_KEY'
20
+ export const WIRE_STORAGE_PATH = 'WIRE_STORAGE_PATH'
20
21
 
21
22
  export const WIRE_EVENTS_HANDLER = 'WIRE_EVENTS_HANDLER'
22
23