Skip to content

Commit

Permalink
feat: boilerplate to support development version api v5 (WPB-1124) (#…
Browse files Browse the repository at this point in the history
…2016)

* feat: boilerplate to support development version api v5 pt.1 (WPB-1124) (#2001)

* feat: add v5 boilerplate code apis

* feat: pr comments

* feat: move mls specific endpoints to v5 and enable dev support pt.2 (WPB-1124) (#2011)

* feat: move conversation mls endpoints

* feat: move conversation mls endpoints

* chore: move tests

* chore: move tests

* chore: move tests

* chore: detekt

* chore: support v5 as dev

* chore: move e2e endpoints

* chore: move e2e endpoints

* feat: pr comments

* Empty-Commit

* chore: detekt

* chore: detekt

* chore: detekt

---------

Co-authored-by: Yamil Medina <yamilmedina@users.noreply.github.com>
  • Loading branch information
github-actions[bot] and yamilmedina authored Aug 29, 2023
1 parent ba5c7bf commit 05d4b38
Show file tree
Hide file tree
Showing 50 changed files with 1,258 additions and 365 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,5 @@ class FeatureSupportImpl(
apiVersion: Int
) : FeatureSupport {

override val isMLSSupported: Boolean = kaliumConfigs.isMLSSupportEnabled && apiVersion >= 4
override val isMLSSupported: Boolean = kaliumConfigs.isMLSSupportEnabled && apiVersion >= 5
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import com.wire.kalium.network.tools.ApiVersionDTO
import com.wire.kalium.network.tools.ServerConfigDTO

val SupportedApiVersions = setOf(0, 1, 2, 3)
val DevelopmentApiVersions = setOf(4)
val DevelopmentApiVersions = setOf(4, 5)

interface BackendMetaDataUtil {
fun calculateApiVersion(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ interface E2EIApi {
suspend fun getWireNonce(clientId: String): NetworkResponse<String>

companion object {
fun getApiNotSupportError(apiName: String, apiVersion: String = "4") = NetworkResponse.Error(
fun getApiNotSupportError(apiName: String, apiVersion: String = "5") = NetworkResponse.Error(
APINotSupported("${this::class.simpleName}: $apiName api is only available on API V$apiVersion")
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ internal open class ConversationApiV0 internal constructor(

override suspend fun fetchGroupInfo(conversationId: QualifiedID): NetworkResponse<ByteArray> =
NetworkResponse.Error(
APINotSupported("MLS: fetchGroupInfo api is only available on API V3")
APINotSupported("MLS: fetchGroupInfo api is only available on API V5")
)

override suspend fun joinConversation(
Expand Down Expand Up @@ -269,15 +269,15 @@ internal open class ConversationApiV0 internal constructor(
subconversationId: SubconversationId
): NetworkResponse<SubconversationResponse> =
NetworkResponse.Error(
APINotSupported("MLS: fetchSubconversationDetails api is only available on API V3")
APINotSupported("MLS: fetchSubconversationDetails api is only available on API V5")
)

override suspend fun fetchSubconversationGroupInfo(
conversationId: ConversationId,
subconversationId: SubconversationId
): NetworkResponse<ByteArray> =
NetworkResponse.Error(
APINotSupported("MLS: fetchSubconversationGroupInfo api is only available on API V3")
APINotSupported("MLS: fetchSubconversationGroupInfo api is only available on API V5")
)

override suspend fun deleteSubconversation(
Expand All @@ -286,15 +286,15 @@ internal open class ConversationApiV0 internal constructor(
deleteRequest: SubconversationDeleteRequest
): NetworkResponse<Unit> =
NetworkResponse.Error(
APINotSupported("MLS: deleteSubconversation api is only available on API V3")
APINotSupported("MLS: deleteSubconversation api is only available on API V5")
)

override suspend fun leaveSubconversation(
conversationId: ConversationId,
subconversationId: SubconversationId
): NetworkResponse<Unit> =
NetworkResponse.Error(
APINotSupported("MLS: leaveSubconversation api is only available on API V3")
APINotSupported("MLS: leaveSubconversation api is only available on API V5")
)

protected suspend fun handleConversationMemberAddedResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,18 @@ internal open class KeyPackageApiV0 internal constructor() : KeyPackageApi {
override suspend fun claimKeyPackages(
param: KeyPackageApi.Param
): NetworkResponse<ClaimedKeyPackageList> = NetworkResponse.Error(
APINotSupported("MLS: claimKeyPackages api is only available on API V4")
APINotSupported("MLS: claimKeyPackages api is only available on API V5")
)

override suspend fun uploadKeyPackages(
clientId: String,
keyPackages: List<KeyPackage>
): NetworkResponse<Unit> = NetworkResponse.Error(
APINotSupported("MLS: uploadKeyPackages api is only available on API V4")
APINotSupported("MLS: uploadKeyPackages api is only available on API V5")
)

override suspend fun getAvailableKeyPackageCount(clientId: String): NetworkResponse<KeyPackageCountDTO> =
NetworkResponse.Error(
APINotSupported("MLS: getAvailableKeyPackageCount api is only available on API V4")
APINotSupported("MLS: getAvailableKeyPackageCount api is only available on API V5")
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import com.wire.kalium.network.utils.NetworkResponse
internal open class MLSMessageApiV0 internal constructor() : MLSMessageApi {

override suspend fun sendMessage(message: MLSMessageApi.Message): NetworkResponse<SendMLSMessageResponse> = NetworkResponse.Error(
APINotSupported("MLS: sendMessage api is only available on API V4")
APINotSupported("MLS: sendMessage api is only available on API V5")
)

override suspend fun sendCommitBundle(bundle: MLSMessageApi.CommitBundle): NetworkResponse<SendMLSMessageResponse> =
NetworkResponse.Error(
APINotSupported("MLS: sendCommitBundle api is only available on API V4")
APINotSupported("MLS: sendCommitBundle api is only available on API V5")
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ import com.wire.kalium.network.utils.NetworkResponse

open class MLSPublicKeyApiV0 internal constructor() : MLSPublicKeyApi {
override suspend fun getMLSPublicKeys(): NetworkResponse<MLSPublicKeysDTO> = NetworkResponse.Error(
APINotSupported("MLS: getMLSPublicKeys api is only available on API V4")
APINotSupported("MLS: getMLSPublicKeys api is only available on API V5")
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ package com.wire.kalium.network.api.v4.authenticated
import com.wire.kalium.network.api.v3.authenticated.AccessTokenApiV3
import io.ktor.client.HttpClient

internal class AccessTokenApiV4 internal constructor(
internal open class AccessTokenApiV4 internal constructor(
private val httpClient: HttpClient
) : AccessTokenApiV3(httpClient)
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,20 @@ import com.wire.kalium.network.api.base.authenticated.conversation.AddConversati
import com.wire.kalium.network.api.base.authenticated.conversation.ConversationMemberAddedResponse
import com.wire.kalium.network.api.base.authenticated.conversation.ConversationResponseV3
import com.wire.kalium.network.api.base.authenticated.conversation.CreateConversationRequest
import com.wire.kalium.network.api.base.authenticated.conversation.SubconversationDeleteRequest
import com.wire.kalium.network.api.base.authenticated.conversation.SubconversationResponse
import com.wire.kalium.network.api.base.authenticated.conversation.model.ConversationCodeInfo
import com.wire.kalium.network.api.base.authenticated.notification.EventContentDTO
import com.wire.kalium.network.api.base.model.ApiModelMapper
import com.wire.kalium.network.api.base.model.ApiModelMapperImpl
import com.wire.kalium.network.api.base.model.ConversationId
import com.wire.kalium.network.api.base.model.GenerateGuestLinkRequest
import com.wire.kalium.network.api.base.model.JoinConversationRequestV4
import com.wire.kalium.network.api.base.model.QualifiedID
import com.wire.kalium.network.api.base.model.SubconversationId
import com.wire.kalium.network.api.v3.authenticated.ConversationApiV3
import com.wire.kalium.network.exceptions.KaliumException
import com.wire.kalium.network.utils.NetworkResponse
import com.wire.kalium.network.utils.handleUnsuccessfulResponse
import com.wire.kalium.network.utils.mapSuccess
import com.wire.kalium.network.utils.wrapFederationResponse
import com.wire.kalium.network.utils.wrapKaliumResponse
import io.ktor.client.request.delete
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import io.ktor.client.request.post
Expand All @@ -65,58 +60,6 @@ internal open class ConversationApiV4 internal constructor(
apiModelMapper.fromApiV3(conversationResponseV4)
}

override suspend fun fetchGroupInfo(conversationId: QualifiedID): NetworkResponse<ByteArray> =
wrapKaliumResponse {
httpClient.get(
"$PATH_CONVERSATIONS/${conversationId.domain}/${conversationId.value}/$PATH_GROUP_INFO"
)
}

override suspend fun fetchSubconversationDetails(
conversationId: ConversationId,
subconversationId: SubconversationId
): NetworkResponse<SubconversationResponse> =
wrapKaliumResponse {
httpClient.get(
"$PATH_CONVERSATIONS/${conversationId.domain}/${conversationId.value}" +
"/$PATH_SUBCONVERSATIONS/$subconversationId"
)
}

override suspend fun fetchSubconversationGroupInfo(
conversationId: ConversationId,
subconversationId: SubconversationId
): NetworkResponse<ByteArray> =
wrapKaliumResponse {
httpClient.get(
"$PATH_CONVERSATIONS/${conversationId.domain}/${conversationId.value}/" +
"$PATH_SUBCONVERSATIONS/$subconversationId/$PATH_GROUP_INFO"
)
}

override suspend fun deleteSubconversation(
conversationId: ConversationId,
subconversationId: SubconversationId,
deleteRequest: SubconversationDeleteRequest
): NetworkResponse<Unit> =
wrapKaliumResponse {
httpClient.delete(
"$PATH_CONVERSATIONS/${conversationId.domain}/${conversationId.value}/$PATH_SUBCONVERSATIONS/$subconversationId"
) {
setBody(deleteRequest)
}
}

override suspend fun leaveSubconversation(
conversationId: ConversationId,
subconversationId: SubconversationId
): NetworkResponse<Unit> =
wrapKaliumResponse {
httpClient.delete(
"$PATH_CONVERSATIONS/${conversationId.domain}/${conversationId.value}/$PATH_SUBCONVERSATIONS/$subconversationId/self"
)
}

override suspend fun joinConversation(
code: String,
key: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,6 @@
*/
package com.wire.kalium.network.api.v4.authenticated

import com.wire.kalium.network.AuthenticatedNetworkClient
import com.wire.kalium.network.api.base.authenticated.e2ei.AccessTokenResponse
import com.wire.kalium.network.api.base.authenticated.e2ei.E2EIApi
import com.wire.kalium.network.serialization.JoseJson
import com.wire.kalium.network.utils.CustomErrors
import com.wire.kalium.network.utils.NetworkResponse
import com.wire.kalium.network.utils.handleUnsuccessfulResponse
import com.wire.kalium.network.utils.wrapKaliumResponse
import io.ktor.client.request.post
import io.ktor.client.request.prepareHead
import io.ktor.client.statement.HttpResponse
import io.ktor.http.ContentType
import io.ktor.http.contentType
import io.ktor.http.isSuccess
import com.wire.kalium.network.api.v3.authenticated.E2EIApiV3

internal open class E2EIApiV4 internal constructor(private val authenticatedNetworkClient: AuthenticatedNetworkClient) : E2EIApi {

private val httpClient get() = authenticatedNetworkClient.httpClient

override suspend fun getWireNonce(clientId: String): NetworkResponse<String> =
httpClient.prepareHead("$PATH_CLIENTS/$clientId/$PATH_NONCE") {
contentType(ContentType.Application.JoseJson)
}.execute { httpResponse ->
handleNonceResponse(httpResponse)
}

private suspend fun handleNonceResponse(
httpResponse: HttpResponse
): NetworkResponse<String> = if (httpResponse.status.isSuccess())
httpResponse.headers[NONCE_HEADER_KEY]?.let { nonce ->
NetworkResponse.Success(nonce, httpResponse)
} ?: run {
CustomErrors.MISSING_NONCE
}
else {
handleUnsuccessfulResponse(httpResponse)
}

override suspend fun getAccessToken(clientId: String, dpopToken: String): NetworkResponse<AccessTokenResponse> = wrapKaliumResponse {
httpClient.post("$PATH_CLIENTS/$clientId/$PATH_ACCESS_TOKEN") {
headers.append(DPOP_HEADER_KEY, dpopToken)
}
}

private companion object {
const val PATH_CLIENTS = "clients"
const val PATH_NONCE = "nonce"
const val PATH_ACCESS_TOKEN = "access-token"

const val DPOP_HEADER_KEY = "dpop"
const val NONCE_HEADER_KEY = "Replay-Nonce"
}
}
internal open class E2EIApiV4 internal constructor() : E2EIApiV3()
Original file line number Diff line number Diff line change
Expand Up @@ -18,56 +18,6 @@

package com.wire.kalium.network.api.v4.authenticated

import com.wire.kalium.network.AuthenticatedNetworkClient
import com.wire.kalium.network.api.base.authenticated.keypackage.ClaimedKeyPackageList
import com.wire.kalium.network.api.base.authenticated.keypackage.KeyPackage
import com.wire.kalium.network.api.base.authenticated.keypackage.KeyPackageApi
import com.wire.kalium.network.api.base.authenticated.keypackage.KeyPackageCountDTO
import com.wire.kalium.network.api.base.authenticated.keypackage.KeyPackageList
import com.wire.kalium.network.api.v3.authenticated.KeyPackageApiV3
import com.wire.kalium.network.kaliumLogger
import com.wire.kalium.network.utils.NetworkResponse
import com.wire.kalium.network.utils.wrapKaliumResponse
import io.ktor.client.request.get
import io.ktor.client.request.parameter
import io.ktor.client.request.post
import io.ktor.client.request.setBody

internal open class KeyPackageApiV4 internal constructor(
private val authenticatedNetworkClient: AuthenticatedNetworkClient
) : KeyPackageApiV3() {

private val httpClient get() = authenticatedNetworkClient.httpClient

override suspend fun claimKeyPackages(
param: KeyPackageApi.Param
): NetworkResponse<ClaimedKeyPackageList> = wrapKaliumResponse {
httpClient.post("$PATH_KEY_PACKAGES/$PATH_CLAIM/${param.user.domain}/${param.user.value}") {
if (param is KeyPackageApi.Param.SkipOwnClient) {
parameter(QUERY_SKIP_OWN, param.selfClientId)
}
}
}

override suspend fun uploadKeyPackages(
clientId: String,
keyPackages: List<KeyPackage>
): NetworkResponse<Unit> =
wrapKaliumResponse {
kaliumLogger.v("Keypackages Count: ${keyPackages.size}")
httpClient.post("$PATH_KEY_PACKAGES/$PATH_SELF/$clientId") {
setBody(KeyPackageList(keyPackages))
}
}

override suspend fun getAvailableKeyPackageCount(clientId: String): NetworkResponse<KeyPackageCountDTO> =
wrapKaliumResponse { httpClient.get("$PATH_KEY_PACKAGES/$PATH_SELF/$clientId/$PATH_COUNT") }

private companion object {
const val PATH_KEY_PACKAGES = "mls/key-packages"
const val PATH_CLAIM = "claim"
const val PATH_SELF = "self"
const val PATH_COUNT = "count"
const val QUERY_SKIP_OWN = "skip_own"
}
}
internal open class KeyPackageApiV4 internal constructor() : KeyPackageApiV3()
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,6 @@

package com.wire.kalium.network.api.v4.authenticated

import com.wire.kalium.network.AuthenticatedNetworkClient
import com.wire.kalium.network.api.base.authenticated.message.MLSMessageApi
import com.wire.kalium.network.api.base.authenticated.message.SendMLSMessageResponse
import com.wire.kalium.network.api.v3.authenticated.MLSMessageApiV3
import com.wire.kalium.network.serialization.Mls
import com.wire.kalium.network.utils.NetworkResponse
import com.wire.kalium.network.utils.wrapKaliumResponse
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.contentType

internal open class MLSMessageApiV4 internal constructor(
private val authenticatedNetworkClient: AuthenticatedNetworkClient
) : MLSMessageApiV3() {

private val httpClient get() = authenticatedNetworkClient.httpClient

override suspend fun sendMessage(message: MLSMessageApi.Message): NetworkResponse<SendMLSMessageResponse> =
wrapKaliumResponse {
httpClient.post(PATH_MESSAGE) {
setBody(message.value)
contentType(ContentType.Message.Mls)
}
}

override suspend fun sendCommitBundle(bundle: MLSMessageApi.CommitBundle): NetworkResponse<SendMLSMessageResponse> =
wrapKaliumResponse {
httpClient.post(PATH_COMMIT_BUNDLES) {
setBody(bundle.value)
contentType(ContentType.Message.Mls)
}
}

private companion object {
const val PATH_COMMIT_BUNDLES = "mls/commit-bundles"
const val PATH_MESSAGE = "mls/messages"
}
}
internal open class MLSMessageApiV4 internal constructor() : MLSMessageApiV3()
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,6 @@

package com.wire.kalium.network.api.v4.authenticated

import com.wire.kalium.network.AuthenticatedNetworkClient
import com.wire.kalium.network.api.base.authenticated.serverpublickey.MLSPublicKeysDTO
import com.wire.kalium.network.api.v3.authenticated.MLSPublicKeyApiV3
import com.wire.kalium.network.utils.NetworkResponse
import com.wire.kalium.network.utils.wrapKaliumResponse
import io.ktor.client.request.get

internal open class MLSPublicKeyApiV4 internal constructor(
private val authenticatedNetworkClient: AuthenticatedNetworkClient
) : MLSPublicKeyApiV3() {

private val httpClient get() = authenticatedNetworkClient.httpClient

override suspend fun getMLSPublicKeys(): NetworkResponse<MLSPublicKeysDTO> =
wrapKaliumResponse { httpClient.get("$PATH_MLS/$PATH_PUBLIC_KEYS") }

private companion object {
const val PATH_PUBLIC_KEYS = "public-keys"
const val PATH_MLS = "mls"
}
}
internal open class MLSPublicKeyApiV4 internal constructor() : MLSPublicKeyApiV3()
Loading

0 comments on commit 05d4b38

Please sign in to comment.