From 6d0468c301f843a3d8f4be66d23ff7fbbaf10187 Mon Sep 17 00:00:00 2001 From: y9vad9 Date: Wed, 27 Sep 2023 20:32:24 +0200 Subject: [PATCH] refactor: `grpc-engine` removal --- grpc-engine/android/build.gradle.kts | 48 -- .../android/grpc/AndroidGrpcEngineBuilder.kt | 15 - grpc-engine/build.gradle.kts | 72 --- .../api/grpc/GrpcTimeMatesRequestsEngine.kt | 429 ------------------ .../grpc/factory/DefaultGrpcEngineBuilder.kt | 12 - .../api/grpc/factory/GrpcEngineBuilder.kt | 7 - .../timemates/api/grpc/internal/ResultExt.kt | 16 - .../api/grpc/mappers/AuthorizationsMapper.kt | 39 -- .../timemates/api/grpc/mappers/FilesMapper.kt | 13 - .../api/grpc/mappers/TimersMapper.kt | 115 ----- .../timemates/api/grpc/mappers/UsersMapper.kt | 23 - .../authorizations/AuthorizationService.proto | 49 -- .../options/OmitAuthorizationOption.proto | 13 - .../ConfirmAuthorizationRequest.proto | 15 - .../requests/CreateProfileRequest.proto | 22 - .../requests/GetAuthorizationsRequest.proto | 14 - .../requests/StartAuthorizationRequest.proto | 13 - .../authorizations/types/Authorization.proto | 40 -- .../io/timemates/api/files/FilesService.proto | 23 - .../files/requests/GetFileBytesRequest.proto | 14 - .../files/requests/UploadFileRequest.proto | 31 -- .../timemates/api/timers/TimersService.proto | 68 --- .../requests/CreateInviteRequest.proto | 13 - .../invites/requests/GetInvitesRequest.proto | 15 - .../requests/RemoveInviteRequest.proto | 8 - .../timers/members/invites/types/Invite.proto | 9 - .../members/requests/GetMembersRequest.proto | 14 - .../members/requests/KickMemberRequest.proto | 8 - .../timers/requests/CreateTimerRequest.proto | 24 - .../requests/EditTimerInfoRequest.proto | 23 - .../api/timers/requests/GetTimerRequest.proto | 7 - .../timers/requests/GetTimersRequest.proto | 13 - .../timers/requests/RemoveTimerRequest.proto | 9 - .../sessions/TimerSessionsService.proto | 71 --- .../requests/ConfirmTimerSessionRequest.proto | 7 - .../requests/GetTimerStateRequest.proto | 7 - .../GetUserCurrentSessionRequest.proto | 11 - .../requests/JoinTimerSessionRequest.proto | 7 - .../requests/StartTimerSessionRequest.proto | 7 - .../requests/StopTimerSessionRequest.proto | 7 - .../timers/sessions/types/TimerState.proto | 76 ---- .../io/timemates/api/timers/types/Timer.proto | 111 ----- .../io/timemates/api/users/UsersService.proto | 32 -- .../api/users/requests/EditEmailRequest.proto | 7 - .../api/users/requests/EditUserRequest.proto | 22 - .../api/users/requests/GetUsersRequest.proto | 7 - .../io/timemates/api/users/types/User.proto | 39 -- rsocket-engine/build.gradle.kts | 18 + .../exceptions/handler/SafeExceptionResult.kt | 225 --------- settings.gradle.kts | 2 - 50 files changed, 18 insertions(+), 1872 deletions(-) delete mode 100644 grpc-engine/android/build.gradle.kts delete mode 100644 grpc-engine/android/src/main/kotlin/io/timemates/android/grpc/AndroidGrpcEngineBuilder.kt delete mode 100644 grpc-engine/build.gradle.kts delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/GrpcTimeMatesRequestsEngine.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/DefaultGrpcEngineBuilder.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/GrpcEngineBuilder.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/internal/ResultExt.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/AuthorizationsMapper.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/FilesMapper.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/TimersMapper.kt delete mode 100644 grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/UsersMapper.kt delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/options/OmitAuthorizationOption.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/CreateProfileRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/files/FilesService.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/files/requests/GetFileBytesRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/files/requests/UploadFileRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/TimersService.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/types/Invite.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/GetMembersRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/KickMemberRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/requests/CreateTimerRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/requests/EditTimerInfoRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimerRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimersRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/requests/RemoveTimerRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/TimerSessionsService.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetUserCurrentSessionRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/sessions/types/TimerState.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/timers/types/Timer.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/users/UsersService.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/users/requests/EditEmailRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/users/requests/EditUserRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/users/requests/GetUsersRequest.proto delete mode 100644 grpc-engine/src/main/proto/io/timemates/api/users/types/User.proto delete mode 100644 sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/handler/SafeExceptionResult.kt diff --git a/grpc-engine/android/build.gradle.kts b/grpc-engine/android/build.gradle.kts deleted file mode 100644 index 27b1883..0000000 --- a/grpc-engine/android/build.gradle.kts +++ /dev/null @@ -1,48 +0,0 @@ -plugins { - alias(libs.plugins.android.library) - alias(libs.plugins.kotlin.android) - alias(libs.plugins.library.publish) -} - -android { - compileSdk = libs.versions.android.target.get().toInt() - - defaultConfig { - minSdk = libs.versions.android.min.get().toInt() - } - - compileOptions { - targetCompatibility = JavaVersion.VERSION_17 - sourceCompatibility = JavaVersion.VERSION_17 - } - - namespace = "io.timemates.android.grpc" -} - -dependencies { - implementation(projects.grpcEngine) - - implementation(libs.grpc.android) -} - -kotlin { - jvmToolchain(17) -} - -deployLibrary { - ssh(tag = "maven.timemates.io") { - host = System.getenv("TIMEMATES_SSH_HOST") - user = System.getenv("TIMEMATES_SSH_USER") - password = System.getenv("TIMEMATES_SSH_PASSWORD") - deployPath = System.getenv("TIMEMATES_SSH_DEPLOY_PATH") - - group = "io.timemates" - componentName = "release" - artifactId = "grpc-engine-android" - name = "grpc-engine-android" - - description = "TimeMates android grpc adapter for SDK" - - version = System.getenv("TIMEMATES_SDK_VERSION") - } -} \ No newline at end of file diff --git a/grpc-engine/android/src/main/kotlin/io/timemates/android/grpc/AndroidGrpcEngineBuilder.kt b/grpc-engine/android/src/main/kotlin/io/timemates/android/grpc/AndroidGrpcEngineBuilder.kt deleted file mode 100644 index 377b055..0000000 --- a/grpc-engine/android/src/main/kotlin/io/timemates/android/grpc/AndroidGrpcEngineBuilder.kt +++ /dev/null @@ -1,15 +0,0 @@ -package io.timemates.android.grpc - -import android.content.Context -import io.grpc.ManagedChannel -import io.grpc.android.AndroidChannelBuilder -import io.timemates.api.grpc.factory.GrpcEngineBuilder - -class AndroidGrpcEngineBuilder(private val context: Context) : GrpcEngineBuilder { - override fun createGrpcEngine(endpoint: String): ManagedChannel { - return AndroidChannelBuilder.forTarget(endpoint) - .useTransportSecurity() - .context(context) - .build() - } -} \ No newline at end of file diff --git a/grpc-engine/build.gradle.kts b/grpc-engine/build.gradle.kts deleted file mode 100644 index cae6d30..0000000 --- a/grpc-engine/build.gradle.kts +++ /dev/null @@ -1,72 +0,0 @@ -import org.gradle.kotlin.dsl.dependencies -import org.gradle.kotlin.dsl.implementation -import org.gradle.kotlin.dsl.projects -import com.google.protobuf.gradle.id - -plugins { - alias(libs.plugins.kotlin.jvm) - alias(libs.plugins.google.protobuf) - alias(libs.plugins.library.publish) -} - -dependencies { - implementation(libs.kotlinx.coroutines) - implementation(libs.grpc.kotlin.stub) - implementation(libs.grpc.protobuf) - implementation(libs.grpc.netty) - implementation(libs.protobuf.kotlin) - implementation(libs.protobuf.java) - - implementation(libs.kotlinx.datetime) - implementation(projects.sdk) -} - -kotlin { - explicitApi() - jvmToolchain(17) -} - -protobuf { - protoc { - artifact = "com.google.protobuf:protoc:3.22.2" - } - plugins { - id("grpc") { - artifact = "io.grpc:protoc-gen-grpc-java:1.54.0" - } - id("grpckt") { - artifact = "io.grpc:protoc-gen-grpc-kotlin:1.3.0:jdk8@jar" - } - } - generateProtoTasks { - all().forEach { - it.plugins { - id("grpc") - id("grpckt") - } - it.builtins { - id("kotlin") - } - } - } -} - -group = "io.timemates" - -deployLibrary { - ssh(tag = "maven.timemates.io") { - host = System.getenv("TIMEMATES_SSH_HOST") - user = System.getenv("TIMEMATES_SSH_USER") - password = System.getenv("TIMEMATES_SSH_PASSWORD") - deployPath = System.getenv("TIMEMATES_SSH_DEPLOY_PATH") - - group = "io.timemates" - componentName = "kotlin" - artifactId = "grpc-engine" - name = "grpc-engine" - - description = "TimeMates grpc adapter for SDK" - - version = System.getenv("TIMEMATES_SDK_VERSION") - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/GrpcTimeMatesRequestsEngine.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/GrpcTimeMatesRequestsEngine.kt deleted file mode 100644 index cdda75b..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/GrpcTimeMatesRequestsEngine.kt +++ /dev/null @@ -1,429 +0,0 @@ -@file:Suppress("UNCHECKED_CAST") - -package io.timemates.api.grpc - -import com.google.protobuf.Empty -import com.google.protobuf.kotlin.toByteString -import io.grpc.Metadata -import io.grpc.Status -import io.grpc.StatusException -import io.timemates.api.authorizations.AuthorizationServiceGrpcKt -import io.timemates.api.files.FilesServiceGrpcKt -import io.timemates.api.files.requests.UploadFileRequestKt.fileMetadata -import io.timemates.api.grpc.factory.GrpcEngineBuilder -import io.timemates.api.grpc.internal.mapException -import io.timemates.api.grpc.mappers.AuthorizationsMapper -import io.timemates.api.grpc.mappers.FilesMapper -import io.timemates.api.grpc.mappers.TimersMapper -import io.timemates.api.grpc.mappers.UsersMapper -import io.timemates.api.timers.TimerSessionsServiceGrpcKt -import io.timemates.api.timers.TimersServiceGrpcKt -import io.timemates.api.timers.sessions.requests.getTimerStateRequest -import io.timemates.api.users.UsersServiceGrpcKt -import io.timemates.sdk.authorization.email.requests.ConfigureNewAccountRequest -import io.timemates.sdk.authorization.email.requests.ConfirmAuthorizationRequest -import io.timemates.sdk.authorization.email.requests.StartAuthorizationRequest -import io.timemates.sdk.authorization.email.types.value.VerificationHash -import io.timemates.sdk.authorization.sessions.requests.GetAuthorizationSessionsRequest -import io.timemates.sdk.authorization.sessions.requests.TerminateCurrentAuthorizationSessionRequest -import io.timemates.sdk.authorization.types.value.AccessHash -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.common.engine.TimeMatesRequestsEngine -import io.timemates.sdk.common.exceptions.AlreadyExistsException -import io.timemates.sdk.common.exceptions.InternalServerError -import io.timemates.sdk.common.exceptions.InvalidArgumentException -import io.timemates.sdk.common.exceptions.NotFoundException -import io.timemates.sdk.common.exceptions.PermissionDeniedException -import io.timemates.sdk.common.exceptions.TooManyRequestsException -import io.timemates.sdk.common.exceptions.UnauthorizedException -import io.timemates.sdk.common.exceptions.UnavailableException -import io.timemates.sdk.common.exceptions.UnsupportedException -import io.timemates.sdk.common.pagination.Page -import io.timemates.sdk.common.pagination.PageToken -import io.timemates.sdk.common.types.TimeMatesEntity -import io.timemates.sdk.common.types.TimeMatesRequest -import io.timemates.sdk.common.types.value.Count -import io.timemates.sdk.files.requests.GetFileBytesRequest -import io.timemates.sdk.files.requests.UploadFileRequest -import io.timemates.sdk.files.types.value.FileId -import io.timemates.sdk.timers.members.invites.requests.CreateInviteRequest -import io.timemates.sdk.timers.members.invites.requests.GetInvitesRequest -import io.timemates.sdk.timers.members.invites.requests.RemoveInviteRequest -import io.timemates.sdk.timers.members.invites.types.value.InviteCode -import io.timemates.sdk.timers.members.requests.GetMembersRequest -import io.timemates.sdk.timers.members.requests.KickMemberRequest -import io.timemates.sdk.timers.requests.* -import io.timemates.sdk.timers.sessions.requests.ConfirmTimerRoundRequest -import io.timemates.sdk.timers.sessions.requests.GetTimerStateRequest -import io.timemates.sdk.timers.sessions.requests.GetUserCurrentSessionRequest -import io.timemates.sdk.timers.sessions.requests.JoinTimerSessionRequest -import io.timemates.sdk.timers.sessions.requests.LeaveTimerSessionRequest -import io.timemates.sdk.timers.sessions.requests.PingSessionRequest -import io.timemates.sdk.timers.sessions.requests.StartTimerRequest -import io.timemates.sdk.timers.sessions.requests.StopTimerRequest -import io.timemates.sdk.timers.types.value.TimerId -import io.timemates.sdk.users.profile.requests.EditProfileRequest -import io.timemates.sdk.users.profile.requests.GetUsersRequest -import io.timemates.sdk.users.profile.types.Avatar -import io.timemates.sdk.users.settings.requests.EditEmailRequest -import kotlinx.coroutines.flow.flow -import kotlinx.coroutines.flow.map -import kotlinx.datetime.Instant -import kotlin.reflect.KClass -import io.timemates.api.authorizations.requests.ConfirmAuthorizationRequestOuterClass.ConfirmAuthorizationRequest as GrpcConfirmAuthorizationRequest -import io.timemates.api.authorizations.requests.GetAuthorizationsRequestOuterClass.GetAuthorizationsRequest as GrpcGetAuthorizationsRequest -import io.timemates.api.authorizations.requests.StartAuthorizationRequestOuterClass.StartAuthorizationRequest as GrpcStartAuthorizationRequest -import io.timemates.api.files.requests.GetFileBytesRequestOuterClass.GetFileBytesRequest as GrpcGetFileBytesRequest -import io.timemates.api.files.requests.uploadFileRequest as buildUploadFileGrpcRequest -import io.timemates.api.timers.members.invites.requests.getInvitesRequest as buildGetInvitesGrpcRequest -import io.timemates.api.timers.members.invites.requests.inviteMemberRequest as buildCreateInviteGrpcRequest -import io.timemates.api.timers.members.invites.requests.removeInviteRequest as buildRemoveInviteGrpcRequest -import io.timemates.api.timers.members.requests.getMembersRequest as buildGetMembersGrpcRequest -import io.timemates.api.timers.members.requests.kickMemberRequest as buildKickMemberGrpcRequest -import io.timemates.api.timers.requests.CreateTimerRequestOuterClass.CreateTimerRequest as GrpcCreateTimerRequest -import io.timemates.api.timers.requests.EditTimerInfoRequest.EditTimerRequest as GrpcEditTimerRequest -import io.timemates.api.timers.requests.getTimerRequest as buildGetTimerGrpcRequest -import io.timemates.api.timers.requests.getTimersRequest as buildGetTimersGrpcRequest -import io.timemates.api.timers.requests.removeTimerRequest as buildRemoveTimerGrpcRequest -import io.timemates.api.timers.sessions.requests.joinTimerSessionRequest as buildJoinTimerSessionGrpcRequest -import io.timemates.api.timers.sessions.requests.startTimerRequest as buildStartTimerGrpcRequest -import io.timemates.api.timers.sessions.requests.stopTimerRequest as buildStopTimerGrpcRequest -import io.timemates.api.users.requests.CreateProfileRequestOuterClass.CreateProfileRequest as GrpcCreateProfileRequest -import io.timemates.api.users.requests.EditUserRequestOuterClass.EditUserRequest as GrpcEditUserRequest -import io.timemates.api.users.requests.GetUsersRequestOuterClass.GetUsersRequest as GrpcGetUsersRequest -import io.timemates.sdk.common.types.Empty as SdkEmpty - -/** - * gRPC-based implementation of the TimeMatesRequestsEngine interface. - * - * @param endpoint The endpoint URL for the gRPC API. Default value is "https://api.timemates.io". - */ -public class GrpcTimeMatesRequestsEngine( - endpoint: String = "api.timemates.io", - grpcEngineBuilder: GrpcEngineBuilder, -) : TimeMatesRequestsEngine { - private companion object { - val ACCESS_TOKEN: Metadata.Key = Metadata.Key.of("access-token", Metadata.ASCII_STRING_MARSHALLER) - } - - private val channel = grpcEngineBuilder.createGrpcEngine(endpoint) - - private val authorizationService = AuthorizationServiceGrpcKt.AuthorizationServiceCoroutineStub(channel) - private val authMapper = AuthorizationsMapper() - - private val filesService = FilesServiceGrpcKt.FilesServiceCoroutineStub(channel) - private val filesMapper = FilesMapper() - - private val usersService = UsersServiceGrpcKt.UsersServiceCoroutineStub(channel) - private val usersMapper = UsersMapper() - - private val timersService = TimersServiceGrpcKt.TimersServiceCoroutineStub(channel) - private val timerSessionsService = TimerSessionsServiceGrpcKt.TimerSessionsServiceCoroutineStub(channel) - private val timersMapper = TimersMapper() - - override suspend fun execute(request: TimeMatesRequest): Result = runCatching { - when (request) { - is StartAuthorizationRequest -> authorizationService.startAuthorization( - GrpcStartAuthorizationRequest - .newBuilder() - .setEmailAddress(request.emailAddress.string) - .build() - ).let { - StartAuthorizationRequest.Result( - verificationHash = VerificationHash.createOrThrow(it.verificationHash), - attempts = Count.createOrThrow(it.attempts), - expiresAt = Instant.fromEpochMilliseconds(it.expiresAt), - ) - } - - is ConfirmAuthorizationRequest -> authorizationService.confirmAuthorization( - GrpcConfirmAuthorizationRequest - .newBuilder() - .setConfirmationCode(request.confirmationCode.string) - .setVerificationHash(request.verificationHash.string) - .build() - ).let { response -> - ConfirmAuthorizationRequest.Result( - isNewAccount = response.isNewAccount, - authorization = response.authorization.takeIf { !response.isNewAccount } - ?.let(authMapper::grpcAuthorizationToSdkAuthorization), - ) - } - - is ConfigureNewAccountRequest -> authorizationService.createProfile( - GrpcCreateProfileRequest.newBuilder() - .setName(request.name.string) - .setDescription(request.description.string) - .setVerificationHash(request.verificationHash.string) - .build() - ).let { - ConfigureNewAccountRequest.Result( - authMapper.grpcAuthorizationToSdkAuthorization(it.authorization) - ) - } - - is GetAuthorizationSessionsRequest -> authorizationService.getAuthorizations( - GrpcGetAuthorizationsRequest.newBuilder() - .setPageToken(request.nextPageToken?.string) - .build(), - headers = authorizedMetadata(request.accessHash), - ).let { response -> - Page( - response.authorizationsList.map(authMapper::grpcAuthorizationToSdkAuthorization), - nextPageToken = response.nextPageToken.takeIf { it.isNotEmpty() } - ?.let(PageToken::createOrThrow), - ) - } - - is TerminateCurrentAuthorizationSessionRequest -> - authorizationService.terminateAuthorization(Empty.getDefaultInstance()) - .let { SdkEmpty } - - is GetFileBytesRequest -> - filesService.getFileBytes( - GrpcGetFileBytesRequest - .newBuilder() - .setFileId(request.fileId.string) - .build(), - ).map { it.chunk.toByteArray() }.let { GetFileBytesRequest.Result(it) } - - is UploadFileRequest -> filesService.uploadFile( - requests = flow { - emit(buildUploadFileGrpcRequest { - metadata = fileMetadata { - fileName = request.fileName.string - fileType = filesMapper.sdkFileTypeToGrpcFileType(request.fileType) - } - }) - - request.bytes.collect { - emit(buildUploadFileGrpcRequest { - chunk = it.toByteString() - }) - } - }, - headers = authorizedMetadata(request.accessHash), - ).let { UploadFileRequest.Result(FileId.createOrThrow(it.fileId)) } - - is EditProfileRequest -> usersService.setUser( - GrpcEditUserRequest.newBuilder() - .apply { - request.name?.let { name = it.string } - request.description?.let { description = it.string } - request.avatar?.let { - avatarId = (it as? Avatar.FileId)?.string - gravatarId = (it as? Avatar.GravatarId)?.string - } - }.build(), - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is GetUsersRequest -> usersService.getUsers( - GrpcGetUsersRequest.newBuilder() - .addAllUserId(request.users.map { it.long }) - .build(), - ).let { GetUsersRequest.Result(it.usersList.map { usersMapper.grpcUserToSdkUser(it) }) } - - is EditEmailRequest -> unsupported() - - is CreateTimerRequest -> timersService.createTimer( - GrpcCreateTimerRequest.newBuilder() - .setName(request.name.string) - .setDescription(request.description.string) - .setSettings(timersMapper.sdkSettingsToGrpcSettings(request.settings)) - .build(), - headers = authorizedMetadata(request.accessHash) - ).let { CreateTimerRequest.Result(TimerId.createOrThrow(it.timerId)) } - - is EditTimerRequest -> timersService.editTimer( - GrpcEditTimerRequest.newBuilder() - .setTimerId(request.timerId.long) - .apply { - request.name?.let { name = it.string } - request.description?.let { description = it.string } - request.settings?.let { - settings = timersMapper.sdkSettingsPatchToGrpcSettingsPatch(it) - } - }.build(), - headers = authorizedMetadata(request.accessHash) - ).let { SdkEmpty } - - is GetTimerRequest -> timersService.getTimer( - buildGetTimerGrpcRequest { - timerId = request.timerId.long - }, - headers = authorizedMetadata(request.accessHash) - ).let { timersMapper.grpcTimerToSdkTimer(it) } - - is GetUserTimersRequest -> timersService.getTimers( - buildGetTimersGrpcRequest { - request.pageToken?.let { nextPageToken = it.string } - }, - headers = authorizedMetadata(request.accessHash) - ).let { response -> - Page( - response.timersList.map { timersMapper.grpcTimerToSdkTimer(it) }, - nextPageToken = response.nextPageToken.takeIf { - response.hasNextPageToken() - }?.let { - PageToken.createOrThrow(it) - }, - ) - } - - is RemoveTimerRequest -> timersService.removeTimer( - buildRemoveTimerGrpcRequest { - timerId = request.timerId.long - }, - headers = authorizedMetadata(request.accessHash) - ).let { SdkEmpty } - - is GetMembersRequest -> timersService.getMembers( - buildGetMembersGrpcRequest { - timerId = request.timerId.long - request.pageToken?.let { nextPageToken = it.string } - }, - headers = authorizedMetadata(request.accessHash) - ).let { response -> - Page( - response.usersList.map { usersMapper.grpcUserToSdkUser(it) }, - nextPageToken = response.nextPageToken?.takeIf { it.isNotEmpty() } - ?.let { PageToken.createOrThrow(it) } - ) - } - - is KickMemberRequest -> timersService.kickMember( - buildKickMemberGrpcRequest { - timerId = request.timerId.long - userId = request.userId.long - }, - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is CreateInviteRequest -> timersService.createInvite( - buildCreateInviteGrpcRequest { - timerId = request.timerId.long - maxJoiners = request.maxJoinersCount.int - }, - headers = authorizedMetadata(request.accessHash), - ).let { CreateInviteRequest.Result(InviteCode.createOrThrow(it.inviteCode)) } - - is GetInvitesRequest -> timersService.getInvites( - buildGetInvitesGrpcRequest { - timerId = request.timerId.long - request.pageToken?.let { nextPageToken = it.string } - }, - headers = authorizedMetadata(request.accessHash), - ).let { response -> - Page( - results = response.invitesList.map { timersMapper.grpcInviteToSdkInvite(it) }, - nextPageToken = response.nextPageToken.takeIf { it.isNotEmpty() } - ?.let { PageToken.createOrThrow(it) } - ) - } - - is RemoveInviteRequest -> timersService.removeInvite( - buildRemoveInviteGrpcRequest { - timerId = request.timerId.long - inviteCode = request.inviteCode.string - }, - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is StartTimerRequest -> timerSessionsService.startTimer( - buildStartTimerGrpcRequest { - timerId = request.timerId.long - }, - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is StopTimerRequest -> timerSessionsService.stopTimer( - buildStopTimerGrpcRequest { - timerId = request.timerId.long - }, - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is JoinTimerSessionRequest -> timerSessionsService.joinSession( - buildJoinTimerSessionGrpcRequest { - timerId = request.timerId.long - }, - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is LeaveTimerSessionRequest -> timerSessionsService.leaveSession( - Empty.getDefaultInstance(), - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is ConfirmTimerRoundRequest -> timerSessionsService.pingSession( - Empty.getDefaultInstance(), - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is PingSessionRequest -> timerSessionsService.pingSession( - Empty.getDefaultInstance(), - headers = authorizedMetadata(request.accessHash), - ).let { SdkEmpty } - - is GetUserCurrentSessionRequest -> timerSessionsService.getUserCurrentSession( - request = Empty.getDefaultInstance(), - headers = authorizedMetadata(request.accessHash), - ).let { timersMapper.grpcTimerToSdkTimer(it) } - - is GetTimerStateRequest -> timerSessionsService.getState( - request = getTimerStateRequest { - - }, - headers = authorizedMetadata(request.accessHash) - ).let { states -> - GetTimerStateRequest.Result( - states.map { state -> timersMapper.grpcStateToSdkState(state) } - ) - } - - else -> unsupported(request::class) - } as T - }.mapException { - val exception = (it as? StatusException) ?: return@mapException it - val status = exception.status - - val message = exception.message ?: NO_MESSAGE - - when (status) { - Status.RESOURCE_EXHAUSTED -> - TooManyRequestsException("Too many requests.", exception) - - Status.INVALID_ARGUMENT, Status.FAILED_PRECONDITION -> - InvalidArgumentException(message, exception) - - Status.UNAUTHENTICATED -> - UnauthorizedException(message, exception) - - Status.INTERNAL -> - InternalServerError(message, exception) - - Status.NOT_FOUND -> - NotFoundException(message, exception) - - Status.ALREADY_EXISTS -> - AlreadyExistsException(message, exception) - - Status.PERMISSION_DENIED -> PermissionDeniedException(message, exception) - Status.UNAVAILABLE -> UnavailableException(message, exception) - - else -> InternalServerError(message, exception) - } - } - - private fun authorizedMetadata(accessHash: AccessHash) = Metadata().apply { - put(ACCESS_TOKEN, accessHash.string) - } - - private fun unsupported(kClass: KClass<*>): Nothing = - throw UnsupportedException("Request of type ${kClass.simpleName} is not supported") - - private inline fun unsupported(): Nothing = unsupported(T::class) -} - -private const val NO_MESSAGE = "No message is provided." \ No newline at end of file diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/DefaultGrpcEngineBuilder.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/DefaultGrpcEngineBuilder.kt deleted file mode 100644 index 5137877..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/DefaultGrpcEngineBuilder.kt +++ /dev/null @@ -1,12 +0,0 @@ -package io.timemates.api.grpc.factory - -import io.grpc.ManagedChannel -import io.grpc.ManagedChannelBuilder - -public class DefaultGrpcEngineBuilder : GrpcEngineBuilder { - override fun createGrpcEngine(endpoint: String): ManagedChannel { - return ManagedChannelBuilder.forTarget(endpoint) - .useTransportSecurity() - .build() - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/GrpcEngineBuilder.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/GrpcEngineBuilder.kt deleted file mode 100644 index c9318f8..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/factory/GrpcEngineBuilder.kt +++ /dev/null @@ -1,7 +0,0 @@ -package io.timemates.api.grpc.factory - -import io.grpc.ManagedChannel - -public interface GrpcEngineBuilder { - public fun createGrpcEngine(endpoint: String): ManagedChannel -} \ No newline at end of file diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/internal/ResultExt.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/internal/ResultExt.kt deleted file mode 100644 index 4564846..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/internal/ResultExt.kt +++ /dev/null @@ -1,16 +0,0 @@ -package io.timemates.api.grpc.internal - -/** - * Applies the given transformation function to the exception contained in the `Result` and returns a new `Result` - * with the transformed exception. If the `Result` does not contain an exception, - * it returns the original `Result` unchanged. - * - * @param transform The transformation function to apply to the exception. - * @return A new `Result` with the transformed exception, or the original `Result` if no exception is present. - */ -@JvmSynthetic -internal inline fun Result.mapException(transform: (Throwable) -> Throwable): Result { - val exception = exceptionOrNull() ?: return this - - return Result.failure(transform(exception)) -} diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/AuthorizationsMapper.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/AuthorizationsMapper.kt deleted file mode 100644 index a07e38a..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/AuthorizationsMapper.kt +++ /dev/null @@ -1,39 +0,0 @@ -package io.timemates.api.grpc.mappers - -import io.timemates.api.authorizations.types.AuthorizationOuterClass.Authorization -import io.timemates.sdk.authorization.sessions.types.value.ClientIpAddress -import io.timemates.sdk.authorization.sessions.types.value.ApplicationName -import io.timemates.sdk.authorization.sessions.types.value.ClientVersion -import io.timemates.sdk.authorization.types.value.HashValue -import io.timemates.sdk.common.constructor.createOrThrow -import kotlinx.datetime.Instant -import io.timemates.sdk.authorization.sessions.types.Authorization as SdkAuthorization - -internal class AuthorizationsMapper { - fun grpcAuthorizationToSdkAuthorization( - authorization: Authorization - ): SdkAuthorization = with(authorization) { - return@with SdkAuthorization( - accessHash = SdkAuthorization.Hash( - value = HashValue.createOrThrow(accessHash.value), - expiresAt = Instant.fromEpochMilliseconds(accessHash.expiresAt), - ), - refreshHash = SdkAuthorization.Hash( - value = HashValue.createOrThrow(refreshHash.value), - expiresAt = Instant.fromEpochMilliseconds(refreshHash.expiresAt), - ), - generationTime = Instant.fromEpochMilliseconds(generationTime), - metadata = grpcMetadataToSdkMetadata(metadata), - ) - } - - private fun grpcMetadataToSdkMetadata( - metadata: Authorization.Metadata, - ): SdkAuthorization.Metadata = with(metadata) { - return@with SdkAuthorization.Metadata( - applicationName = ApplicationName.createOrThrow(clientName), - clientVersion = ClientVersion.createOrThrow(clientVersion), - clientIpAddress = ClientIpAddress.createOrThrow(clientIpAddress), - ) - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/FilesMapper.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/FilesMapper.kt deleted file mode 100644 index e10877a..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/FilesMapper.kt +++ /dev/null @@ -1,13 +0,0 @@ -package io.timemates.api.grpc.mappers - -import io.timemates.api.files.requests.UploadFileRequestOuterClass -import io.timemates.sdk.files.types.FileType -import io.timemates.api.files.requests.UploadFileRequestOuterClass.UploadFileRequest.FileMetadata.FileType as GrpcFileType - -internal class FilesMapper { - fun sdkFileTypeToGrpcFileType(fileType: FileType): GrpcFileType { - return when (fileType) { - FileType.IMAGE -> GrpcFileType.IMAGE - } - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/TimersMapper.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/TimersMapper.kt deleted file mode 100644 index af0e2b7..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/TimersMapper.kt +++ /dev/null @@ -1,115 +0,0 @@ -package io.timemates.api.grpc.mappers - -import io.timemates.api.timers.members.invites.types.InviteOuterClass.Invite -import io.timemates.api.timers.sessions.types.TimerStateOuterClass.TimerState -import io.timemates.api.timers.types.TimerKt -import io.timemates.api.timers.types.TimerOuterClass.Timer -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.common.exceptions.UnsupportedException -import io.timemates.sdk.common.types.value.Count -import io.timemates.sdk.timers.members.invites.types.value.InviteCode -import io.timemates.sdk.timers.types.value.TimerDescription -import io.timemates.sdk.timers.types.value.TimerId -import io.timemates.sdk.timers.types.value.TimerName -import io.timemates.sdk.users.profile.types.value.UserId -import kotlinx.datetime.Instant -import kotlin.time.Duration.Companion.seconds -import kotlin.time.DurationUnit -import io.timemates.sdk.timers.members.invites.types.Invite as SdkInvite -import io.timemates.sdk.timers.types.Timer as SdkTimer -import io.timemates.sdk.timers.types.TimerSettings as SdkTimerSettings - -internal class TimersMapper { - fun grpcTimerToSdkTimer(timer: Timer): SdkTimer = with(timer) { - return SdkTimer( - timerId = TimerId.createOrThrow(id), - name = TimerName.createOrThrow(name), - description = TimerDescription.createOrThrow(description), - ownerId = UserId.createOrThrow(ownerId), - membersCount = Count.createOrThrow(membersCount), - settings = grpcSettingsToSdkSettings(settings), - ) - } - - fun grpcStateToSdkState(timerState: TimerState): SdkTimer.State = with(timerState) { - val publishTime = Instant.fromEpochMilliseconds(publishTime) - - return when { - hasPaused() -> SdkTimer.State.Paused(publishTime) - hasRunning() -> SdkTimer.State.Running( - publishTime = publishTime, - endsAt = Instant.fromEpochMilliseconds(running.endsAt), - ) - - hasConfirmationWaiting() -> SdkTimer.State.ConfirmationWaiting( - publishTime = publishTime, - endsAt = Instant.fromEpochMilliseconds(confirmationWaiting.endsAt), - ) - - hasRest() -> SdkTimer.State.Rest( - publishTime = publishTime, - endsAt = Instant.fromEpochMilliseconds(rest.endsAt), - ) - - hasInactive() -> SdkTimer.State.Inactive( - publishTime = publishTime, - ) - - else -> throw UnsupportedException("Unsupported timer state.") - } - } - - fun grpcSettingsToSdkSettings(settings: Timer.Settings): SdkTimerSettings = with(settings) { - return SdkTimerSettings( - workTime = workTime.seconds, - restTime = restTime.seconds, - bigRestTime = bigRestTime.seconds, - bigRestEnabled = bigRestEnabled, - bigRestPer = Count.createOrThrow(bigRestPer), - isEveryoneCanPause = isEveryoneCanPause, - isConfirmationRequired = isConfirmationRequired, - ) - } - fun sdkTimerToGrpcTimer(sdkTimer: SdkTimer): Timer = with(sdkTimer) { - return Timer.newBuilder() - .setId(timerId.long) - .setName(name.string) - .setDescription(description.string) - .setOwnerId(ownerId.long) - .setMembersCount(membersCount.int) - .setSettings(sdkSettingsToGrpcSettings(settings)) - .build() - } - - fun sdkSettingsToGrpcSettings(sdkSettings: SdkTimerSettings): Timer.Settings = with(sdkSettings) { - return Timer.Settings.newBuilder() - .setWorkTime(workTime.toInt(DurationUnit.MINUTES)) - .setRestTime(restTime.toInt(DurationUnit.MINUTES)) - .setBigRestTime(bigRestTime.toInt(DurationUnit.MINUTES)) - .setBigRestEnabled(bigRestEnabled) - .setBigRestPer(bigRestPer.int) - .setIsEveryoneCanPause(isEveryoneCanPause) - .setIsConfirmationRequired(isConfirmationRequired) - .build() - } - - fun sdkSettingsPatchToGrpcSettingsPatch( - sdkSettings: SdkTimerSettings.Patch - ): Timer.Settings.Patch = TimerKt.SettingsKt.patch { - sdkSettings.workTime?.let { workTime = it.toInt(DurationUnit.MINUTES) } - sdkSettings.restTime?.let { restTime = it.toInt(DurationUnit.MINUTES) } - sdkSettings.bigRestTime?.let { bigRestTime = it.toInt(DurationUnit.MINUTES) } - sdkSettings.bigRestPer?.let { bigRestPer = it.int } - sdkSettings.bigRestEnabled?.let { bigRestEnabled = it } - sdkSettings.isConfirmationRequired?.let { isConfirmationRequired = it } - sdkSettings.isEveryoneCanPause?.let { isEveryoneCanPause = it } - } - - fun grpcInviteToSdkInvite(invite: Invite): SdkInvite { - return SdkInvite( - inviteCode = InviteCode.createOrThrow(invite.code), - creationTime = Instant.fromEpochMilliseconds(invite.creationTime), - limit = Count.createOrThrow(invite.limit), - ) - } -} diff --git a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/UsersMapper.kt b/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/UsersMapper.kt deleted file mode 100644 index 4fc1a08..0000000 --- a/grpc-engine/src/main/kotlin/io/timemates/api/grpc/mappers/UsersMapper.kt +++ /dev/null @@ -1,23 +0,0 @@ -package io.timemates.api.grpc.mappers - -import io.timemates.api.users.types.UserOuterClass -import io.timemates.sdk.common.constructor.createOrThrow -import io.timemates.sdk.users.profile.types.Avatar -import io.timemates.sdk.users.profile.types.value.EmailAddress -import io.timemates.sdk.users.profile.types.value.UserDescription -import io.timemates.sdk.users.profile.types.value.UserId -import io.timemates.sdk.users.profile.types.value.UserName -import io.timemates.sdk.users.profile.types.User as SdkUser - -internal class UsersMapper { - fun grpcUserToSdkUser(user: UserOuterClass.User): SdkUser = with(user) { - return SdkUser( - id = UserId.createOrThrow(id), - name = UserName.createOrThrow(name), - description = UserDescription.createOrThrow(description), - emailAddress = email?.takeIf { it.isNotEmpty() }?.let { EmailAddress.createOrThrow(it) }, - avatar = gravatarId?.let { Avatar.GravatarId.createOrThrow(it) } ?: - avatarId?.let { Avatar.FileId.createOrThrow(it) } - ) - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto deleted file mode 100644 index 059cfea..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/AuthorizationService.proto +++ /dev/null @@ -1,49 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto"; -import "io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto"; -import "io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto"; -import "io/timemates/api/authorizations/options/OmitAuthorizationOption.proto"; -import "io/timemates/api/authorizations/requests/CreateProfileRequest.proto"; -import "io/timemates/api/authorizations/types/Authorization.proto"; -import "google/protobuf/empty.proto"; - -option java_package = "io.timemates.api.authorizations"; - -service AuthorizationService { - /** - * Starts authorization by sending corresponding email to email address. - * - * Has next restrictions: - * – 3 requests per email is max. - */ - rpc startAuthorization(StartAuthorizationRequest) returns (StartAuthorizationRequest.Result) { - option (omit_authorization) = true; - } - - /** - * Confirms authorization by sending authorization verification code. - * - * Has next restrictions: - * – 3 attempts per verification code. - */ - rpc confirmAuthorization(ConfirmAuthorizationRequest) returns (ConfirmAuthorizationRequest.Response) { - option (omit_authorization) = true; - } - - rpc createProfile(CreateProfileRequest) returns (CreateProfileRequest.Response) { - option (omit_authorization) = true; - } - - /** - * Gets all active authorizations. - */ - rpc getAuthorizations(GetAuthorizationsRequest) returns (GetAuthorizationsRequest.Response); - - /** - * Terminates authorization by given identifier. - * - * Returns [Status] - */ - rpc terminateAuthorization(google.protobuf.Empty) returns (google.protobuf.Empty); -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/options/OmitAuthorizationOption.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/options/OmitAuthorizationOption.proto deleted file mode 100644 index e1f69d3..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/options/OmitAuthorizationOption.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; - -import "google/protobuf/descriptor.proto"; - -option java_package = "io.timemates.api.authorizations.options"; - -extend google.protobuf.MethodOptions { - /** - * Some methods should not be checked on authorization as they provide - * registration / authentication features or just safe to be called by anyone. - */ - bool omit_authorization = 50001; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto deleted file mode 100644 index e34d950..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/ConfirmAuthorizationRequest.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; -import "io/timemates/api/authorizations/types/Authorization.proto"; - -option java_package = "io.timemates.api.authorizations.requests"; - -message ConfirmAuthorizationRequest { - string verificationHash = 1; - string confirmationCode = 2; - - message Response { - bool isNewAccount = 1; - // if it's a new account, there's no authorization returned - optional Authorization authorization = 2; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/CreateProfileRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/CreateProfileRequest.proto deleted file mode 100644 index b01a69a..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/CreateProfileRequest.proto +++ /dev/null @@ -1,22 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/authorizations/types/Authorization.proto"; - -option java_package = "io.timemates.api.users.requests"; - -message CreateProfileRequest { - string verificationHash = 1; - /** - * User's name - */ - string name = 2; - - /** - * User's description. - */ - optional string description = 3; - - message Response { - Authorization authorization = 1; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto deleted file mode 100644 index bb46c28..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/GetAuthorizationsRequest.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; -import "io/timemates/api/authorizations/types/Authorization.proto"; - -option java_package = "io.timemates.api.authorizations.requests"; - -message GetAuthorizationsRequest { - // null if it's start of pagination - optional string pageToken = 1; - - message Response { - repeated Authorization authorizations = 1; - string nextPageToken = 2; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto deleted file mode 100644 index 605b36e..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/requests/StartAuthorizationRequest.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.authorizations.requests"; - -message StartAuthorizationRequest { - string emailAddress = 1; - - message Result { - string verificationHash = 1; - int64 expiresAt = 2; - int32 attempts = 3; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto b/grpc-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto deleted file mode 100644 index db61522..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/authorizations/types/Authorization.proto +++ /dev/null @@ -1,40 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.authorizations.types"; - -message Authorization { - /** - * Hash that used to identify user. - * - * Has null if it's not new authorization. - */ - optional Hash accessHash = 2; - - /** - * Hash that used to identify user. - * - * Has null if it's not new authorization. - */ - optional Hash refreshHash = 3; - - /** - * Denotes when authorization was generated. - */ - int64 generationTime = 4; - - /** - * Additional information about authorization. - */ - optional Metadata metadata = 5; - - message Hash { - string value = 1; - int64 expiresAt = 2; - } - - message Metadata { - string clientName = 1; - string clientVersion = 2; - string clientIpAddress = 3; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/files/FilesService.proto b/grpc-engine/src/main/proto/io/timemates/api/files/FilesService.proto deleted file mode 100644 index 00f5cad..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/files/FilesService.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/files/requests/GetFileBytesRequest.proto"; -import "io/timemates/api/files/requests/UploadFileRequest.proto"; -import "io/timemates/api/authorizations/options/OmitAuthorizationOption.proto"; -import "google/protobuf/empty.proto"; - -option java_package = "io.timemates.api.files"; - -service FilesService { - /** - * Returns a sequence of bytes of the file's content. - */ - rpc getFileBytes(GetFileBytesRequest) returns (stream GetFileBytesRequest.Response) { - option (omit_authorization) = true; - } - - /* - * Uploads file to server. - * Returns status after upload file stream ends. - */ - rpc uploadFile(stream UploadFileRequest) returns (UploadFileRequest.Response); -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/files/requests/GetFileBytesRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/files/requests/GetFileBytesRequest.proto deleted file mode 100644 index 625ea0d..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/files/requests/GetFileBytesRequest.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.files.requests"; - -message GetFileBytesRequest { - string fileId = 1; - - message Response { - /** - * Chunked file content bytes. - */ - bytes chunk = 1; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/files/requests/UploadFileRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/files/requests/UploadFileRequest.proto deleted file mode 100644 index f32c786..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/files/requests/UploadFileRequest.proto +++ /dev/null @@ -1,31 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.files.requests"; - -message UploadFileRequest { - oneof request { - /** - * Should always be sent as first request. - * Should not be repeated. - */ - FileMetadata metadata = 1; - /** - * Bytes of file included into given chunk. - */ - bytes chunk = 2; - } - - message Response { - string fileId = 1; - } - - message FileMetadata { - FileType fileType = 1; - string fileName = 2; - - enum FileType { - BINARY = 0; // unsupported by default - IMAGE = 1; - } - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/TimersService.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/TimersService.proto deleted file mode 100644 index ff8cfc5..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/TimersService.proto +++ /dev/null @@ -1,68 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/requests/CreateTimerRequest.proto"; -import "io/timemates/api/timers/requests/EditTimerInfoRequest.proto"; -import "io/timemates/api/timers/requests/RemoveTimerRequest.proto"; -import "io/timemates/api/timers/requests/GetTimerRequest.proto"; -import "io/timemates/api/timers/requests/GetTimersRequest.proto"; -import "io/timemates/api/timers/members/requests/KickMemberRequest.proto"; -import "io/timemates/api/timers/members/requests/GetMembersRequest.proto"; -import "io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto"; -import "io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto"; -import "io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto"; -import "io/timemates/api/timers/types/Timer.proto"; -import "google/protobuf/empty.proto"; - -option java_package = "io.timemates.api.timers"; - -service TimersService { - /** - * Creates timer. - */ - rpc createTimer(CreateTimerRequest) returns (CreateTimerRequest.Response); - - /** - * Gets timer by id. - */ - rpc getTimer(GetTimerRequest) returns (Timer); - - /* - * Gets timers by page token. - */ - rpc getTimers(GetTimersRequest) returns (GetTimersRequest.Response); - - /** - * Edits timer information & settings (name, description). - */ - rpc editTimer(EditTimerRequest) returns (google.protobuf.Empty); - - /** - * Kicks member out of timer. - */ - rpc kickMember(KickMemberRequest) returns (google.protobuf.Empty); - - /* - * Gets members of a timer. - */ - rpc getMembers(GetMembersRequest) returns (GetMembersRequest.Response); - - /* - * Creates invite for joining a timer. - */ - rpc createInvite(InviteMemberRequest) returns (InviteMemberRequest.Response); - - /** - * Gets invites of a timer. - */ - rpc getInvites(GetInvitesRequest) returns (GetInvitesRequest.Response); - - /** - * Gets invites of a timer. - */ - rpc removeInvite(RemoveInviteRequest) returns (google.protobuf.Empty); - - /** - * Removes timer. - */ - rpc removeTimer(RemoveTimerRequest) returns (google.protobuf.Empty); -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto deleted file mode 100644 index bbeead2..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/CreateInviteRequest.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; -import "io/timemates/api/users/types/User.proto"; - -option java_package = "io.timemates.api.timers.members.invites.requests"; - -message InviteMemberRequest { - int64 timerId = 1; - int32 maxJoiners = 2; - - message Response { - string inviteCode = 1; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto deleted file mode 100644 index 3947777..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/GetInvitesRequest.proto +++ /dev/null @@ -1,15 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/members/invites/types/Invite.proto"; - -option java_package = "io.timemates.api.timers.members.invites.requests"; - -message GetInvitesRequest { - int64 timerId = 1; - optional string nextPageToken = 2; - - message Response { - repeated Invite invites = 1; - optional string nextPageToken = 3; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto deleted file mode 100644 index 82b3325..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/requests/RemoveInviteRequest.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.members.invites.requests"; - -message RemoveInviteRequest { - int64 timerId = 1; - string inviteCode = 2; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/types/Invite.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/types/Invite.proto deleted file mode 100644 index 7717238..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/members/invites/types/Invite.proto +++ /dev/null @@ -1,9 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.members.invites.types"; - -message Invite { - string code = 1; - int64 creationTime = 2; - int32 limit = 3; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/GetMembersRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/GetMembersRequest.proto deleted file mode 100644 index b9dee63..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/GetMembersRequest.proto +++ /dev/null @@ -1,14 +0,0 @@ -syntax = "proto3"; -import "io/timemates/api/users/types/User.proto"; - -option java_package = "io.timemates.api.timers.members.requests"; - -message GetMembersRequest { - int64 timerId = 1; - optional string nextPageToken = 2; - - message Response { - repeated User users = 1; - optional string nextPageToken = 2; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/KickMemberRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/KickMemberRequest.proto deleted file mode 100644 index 13918ef..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/members/requests/KickMemberRequest.proto +++ /dev/null @@ -1,8 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.members.requests"; - -message KickMemberRequest { - int64 timerId = 1; - int64 userId = 2; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/CreateTimerRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/requests/CreateTimerRequest.proto deleted file mode 100644 index 945ec05..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/CreateTimerRequest.proto +++ /dev/null @@ -1,24 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/types/Timer.proto"; - -option java_package = "io.timemates.api.timers.requests"; - -message CreateTimerRequest { - int64 timerId = 1; - /** - * Timer's name. Up to 50 symbols. - */ - string name = 2; - - /** - * Timer's name. Up to 500 symbols. - */ - optional string description = 3; - - optional Timer.Settings settings = 4; - - message Response { - int64 timerId = 1; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/EditTimerInfoRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/requests/EditTimerInfoRequest.proto deleted file mode 100644 index 2d266b7..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/EditTimerInfoRequest.proto +++ /dev/null @@ -1,23 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/types/Timer.proto"; - -option java_package = "io.timemates.api.timers.requests"; - -message EditTimerRequest { - int64 timerId = 1; - /** - * Timer's name. Up to 50 symbols. - */ - optional string name = 2; - - /** - * Timer's name. Up to 500 symbols. - */ - optional string description = 3; - - /** - * Timer's settings - */ - optional Timer.Settings.Patch settings = 4; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimerRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimerRequest.proto deleted file mode 100644 index 70143b6..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimerRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.requests"; - -message GetTimerRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimersRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimersRequest.proto deleted file mode 100644 index e409eeb..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/GetTimersRequest.proto +++ /dev/null @@ -1,13 +0,0 @@ -syntax = "proto3"; -import "io/timemates/api/timers/types/Timer.proto"; - -option java_package = "io.timemates.api.timers.requests"; - -message GetTimersRequest { - optional string nextPageToken = 1; - - message Response { - repeated Timer timers = 1; - optional string nextPageToken = 2; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/RemoveTimerRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/requests/RemoveTimerRequest.proto deleted file mode 100644 index 10684d5..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/requests/RemoveTimerRequest.proto +++ /dev/null @@ -1,9 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/types/Timer.proto"; - -option java_package = "io.timemates.api.timers.requests"; - -message RemoveTimerRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/TimerSessionsService.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/TimerSessionsService.proto deleted file mode 100644 index fcfe1ce..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/TimerSessionsService.proto +++ /dev/null @@ -1,71 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto"; -import "io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto"; -import "io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto"; -import "io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto"; -import "io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto"; -import "io/timemates/api/timers/sessions/requests/GetUserCurrentSessionRequest.proto"; -import "io/timemates/api/timers/sessions/types/TimerState.proto"; -import "io/timemates/api/timers/types/Timer.proto"; -import "google/protobuf/empty.proto"; - -option java_package = "io.timemates.api.timers"; - -/** - * The TimerSessionsService provides operations related to timer sessions. - */ -service TimerSessionsService { - - /** - * Starts the timer session. - * This RPC method starts the timer session. - */ - rpc startTimer(StartTimerRequest) returns (google.protobuf.Empty); - - /** - * Stops the timer session. - * This RPC method stops the timer session. - */ - rpc stopTimer(StopTimerRequest) returns (google.protobuf.Empty); - - /** - * Joins the timer session. - * This RPC method allows a user to join the timer session. - */ - rpc joinSession(JoinTimerSessionRequest) returns (google.protobuf.Empty); - - /** - * Leaves the timer session. - * This RPC method allows a user to leave the timer session. - */ - rpc leaveSession(google.protobuf.Empty) returns (google.protobuf.Empty); - - /** - * Confirms the user's attendance of the next round. - * This RPC method confirms the user's attendance of the next round. - * This is needed if the corresponding setting is enabled, usually you should - * just await for [TimerState.ConfirmationWaiting] state. - * - * Server will automatically determine your session. - */ - rpc confirmRound(google.protobuf.Empty) returns (google.protobuf.Empty); - - /** - * Sends a ping request that says that client currently online and active. - * Client should send such request once per 5 minutes. - */ - rpc pingSession(google.protobuf.Empty) returns (google.protobuf.Empty); - - /** - * Retrieves the current state of the timer. - * This RPC method always returns the current state of the timer and then updates of it. - * The state is returned as a stream of TimerState messages. - */ - rpc getState(GetTimerStateRequest) returns (stream TimerState); - - /** - * Gets current timer session - */ - rpc getUserCurrentSession(google.protobuf.Empty) returns (Timer); -} diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto deleted file mode 100644 index 6fad59a..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.sessions.requests"; - -message ConfirmTimerSessionRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto deleted file mode 100644 index ef4e16c..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.sessions.requests"; - -message GetTimerStateRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetUserCurrentSessionRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetUserCurrentSessionRequest.proto deleted file mode 100644 index c73a7eb..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/GetUserCurrentSessionRequest.proto +++ /dev/null @@ -1,11 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/types/Timer.proto"; - -option java_package = "io.timemates.api.timers.sessions.requests"; - -message GetUserCurrentSessionRequest { - message Response { - optional Timer timer = 1; - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto deleted file mode 100644 index 209cc2f..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.sessions.requests"; - -message JoinTimerSessionRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto deleted file mode 100644 index 168e5b6..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StartTimerSessionRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.sessions.requests"; - -message StartTimerRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto deleted file mode 100644 index 15dcba0..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.sessions.requests"; - -message StopTimerRequest { - int64 timerId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/types/TimerState.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/types/TimerState.proto deleted file mode 100644 index ebe39bf..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/sessions/types/TimerState.proto +++ /dev/null @@ -1,76 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.timers.sessions.types"; - -/** - * Represents the state of a timer. - */ -message TimerState { - - /** - * The publish time of the timer state. - * This field represents the time when the timer state was started. - */ - int64 publishTime = 1; - - /** - * The phase of the timer state. - * This field is a oneof field, indicating the current phase of the timer. - * Only one of the phase options can be set at a time. - */ - oneof phase { - Rest rest = 2; - Paused paused = 3; - Running running = 4; - ConfirmationWaiting confirmationWaiting = 5; - Inactive inactive = 6; - } - - /** - * Represents the inactive phase of the timer. - * This phase indicates that the timer is inactive. - */ - message Inactive {} - - /** - * Represents the rest phase of the timer. - * This phase indicates that the timer is in a resting state. - */ - message Rest { - /** - * The end time of the rest phase. - * This field represents the time when the rest phase ends. - */ - int64 endsAt = 1; - } - - /** - * Represents the paused phase of the timer. - * This phase indicates that the timer is paused. - */ - message Paused {} - - /** - * Represents the running phase of the timer. - * This phase indicates that the timer is currently running. - */ - message Running { - /** - * The end time of the running phase. - * This field represents the time when the running phase ends. - */ - int64 endsAt = 1; - } - - /** - * Represents the confirmation waiting phase of the timer. - * This phase indicates that the timer is waiting for confirmation. - */ - message ConfirmationWaiting { - /** - * The end time of the confirmation waiting phase. - * This field represents the time when the confirmation waiting phase ends. - */ - int64 endsAt = 1; - } -} diff --git a/grpc-engine/src/main/proto/io/timemates/api/timers/types/Timer.proto b/grpc-engine/src/main/proto/io/timemates/api/timers/types/Timer.proto deleted file mode 100644 index cf60797..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/timers/types/Timer.proto +++ /dev/null @@ -1,111 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/timers/sessions/types/TimerState.proto"; - -option java_package = "io.timemates.api.timers.types"; - -/** - * Represents a timer. - */ -message Timer { - - /** - * The ID of the timer. - */ - int64 id = 1; - - /** - * The name of the timer. - * This field represents the name of the timer and can contain up to 50 characters. - */ - string name = 2; - - /** - * The description of the timer. - * This field represents an optional description for the timer and can contain up to 500 characters. - */ - optional string description = 3; - - /** - * The ID of the owner of the timer. - * This field represents the ID of the user who owns the timer. - */ - int64 ownerId = 4; - - /** - * The settings of the timer. - * This field represents the settings for the timer. - */ - Settings settings = 5; - - /** - * The number of members in the timer. - * This field represents the count of members associated with the timer. - */ - int32 membersCount = 6; - - /** - * The current state of the timer. - * This field represents the current state of the timer. - */ - TimerState currentState = 7; - - /** - * Represents the settings of the timer. - */ - message Settings { - /** - * The work time duration in seconds. - * This field represents the duration of the work time in milliseconds. - */ - int32 workTime = 1; - - /** - * The rest time duration in seconds. - * This field represents the duration of the rest time in seconds. - */ - int32 restTime = 2; - - /** - * The big rest time duration in seconds. - * This field represents the duration of the big rest time in seconds. - */ - int32 bigRestTime = 3; - - /** - * Indicates if big rest is enabled. - * This field indicates whether the big rest is enabled or not. - */ - bool bigRestEnabled = 4; - - /** - * The number of work cycles before big rest. - * This field represents the number of work rounds before the big rest is triggered. - */ - int32 bigRestPer = 5; - - /** - * Indicates if everyone can pause the timer. - * This field indicates whether everyone can pause the timer or not. - * - * Also, it denotes whether all users can start the timer. - */ - bool isEveryoneCanPause = 6; - - /** - * Indicates if confirmation is required for timer round start. - * This field indicates whether confirmation is required for timer actions or not. - */ - bool isConfirmationRequired = 7; - - message Patch { - optional int32 workTime = 2; - optional int32 restTime = 3; - optional int32 bigRestTime = 4; - optional bool bigRestEnabled = 5; - optional int32 bigRestPer = 6; - optional bool isEveryoneCanPause = 7; - optional bool isConfirmationRequired = 8; - } - } -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/users/UsersService.proto b/grpc-engine/src/main/proto/io/timemates/api/users/UsersService.proto deleted file mode 100644 index 4f7fc7d..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/users/UsersService.proto +++ /dev/null @@ -1,32 +0,0 @@ -syntax = "proto3"; - -import "io/timemates/api/users/requests/GetUsersRequest.proto"; -import "io/timemates/api/users/requests/EditUserRequest.proto"; -import "io/timemates/api/users/requests/EditEmailRequest.proto"; -import "io/timemates/api/users/types/User.proto"; -import "google/protobuf/empty.proto"; - -option java_package = "io.timemates.api.users"; - -service UsersService { - /** - * Gets users by given identifiers. - * - * Returns [User] or null - */ - rpc getUsers(GetUsersRequest) returns (Users); - - /** - * Sets user information (name / description / avatar file id). - * - * Returns [Status] - */ - rpc setUser(EditUserRequest) returns (google.protobuf.Empty); - - /** - * Sets new email for current user. - * - * Returns [Status] - */ - rpc setEmail(EditEmailRequest) returns (google.protobuf.Empty); -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/users/requests/EditEmailRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/users/requests/EditEmailRequest.proto deleted file mode 100644 index d22dc87..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/users/requests/EditEmailRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.users.requests"; - -message EditEmailRequest { - string email = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/users/requests/EditUserRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/users/requests/EditUserRequest.proto deleted file mode 100644 index aa19215..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/users/requests/EditUserRequest.proto +++ /dev/null @@ -1,22 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.users.requests"; - -message EditUserRequest { - /** - * User's avatar id - */ - oneof avatar { - string avatarId = 1; - string gravatarId = 2; - } - /** - * User's name - */ - optional string name = 3; - - /** - * User's description. - */ - optional string description = 4; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/users/requests/GetUsersRequest.proto b/grpc-engine/src/main/proto/io/timemates/api/users/requests/GetUsersRequest.proto deleted file mode 100644 index 2ab5057..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/users/requests/GetUsersRequest.proto +++ /dev/null @@ -1,7 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.users.requests"; - -message GetUsersRequest { - repeated int64 userId = 1; -} \ No newline at end of file diff --git a/grpc-engine/src/main/proto/io/timemates/api/users/types/User.proto b/grpc-engine/src/main/proto/io/timemates/api/users/types/User.proto deleted file mode 100644 index b5b69c0..0000000 --- a/grpc-engine/src/main/proto/io/timemates/api/users/types/User.proto +++ /dev/null @@ -1,39 +0,0 @@ -syntax = "proto3"; - -option java_package = "io.timemates.api.users.types"; - -message User { - /** - * User's identifier - */ - int64 id = 1; - - /** - * String identifier of 128 length. Can be null - * if there is no avatar. - */ - oneof avatar { - string avatarId = 2; - string gravatarId = 3; - } - - /** - * User's name - */ - string name = 4; - - /** - * User's description. - */ - string description = 5; - - /** - * User's email up to 200 symbols. - * Can be null if there is no access. - */ - optional string email = 6; -} - -message Users { - repeated User users = 1; -} \ No newline at end of file diff --git a/rsocket-engine/build.gradle.kts b/rsocket-engine/build.gradle.kts index 1421908..51945db 100644 --- a/rsocket-engine/build.gradle.kts +++ b/rsocket-engine/build.gradle.kts @@ -17,4 +17,22 @@ dependencies { commonMainImplementation(libs.kotlinx.serialization) commonMainImplementation(libs.kotlinx.datetime) commonMainImplementation(libs.rsocket.client) +} + +deployLibrary { + ssh(tag = "rsocket-engine to maven.timemates.io") { + host = System.getenv("TIMEMATES_SSH_HOST") + user = System.getenv("TIMEMATES_SSH_USER") + password = System.getenv("TIMEMATES_SSH_PASSWORD") + deployPath = System.getenv("TIMEMATES_SSH_DEPLOY_PATH") + + group = "io.timemates" + componentName = "kotlin" + artifactId = "rsocket-engine" + name = "rsocket-engine" + + description = "TimeMates rsocket adapter for SDK" + + version = System.getenv("TIMEMATES_SDK_VERSION") + } } \ No newline at end of file diff --git a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/handler/SafeExceptionResult.kt b/sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/handler/SafeExceptionResult.kt deleted file mode 100644 index 416c51c..0000000 --- a/sdk/src/commonMain/kotlin/io/timemates/sdk/common/exceptions/handler/SafeExceptionResult.kt +++ /dev/null @@ -1,225 +0,0 @@ -@file:OptIn(InternalApi::class, ExperimentalTimeMatesApi::class) - -package io.timemates.sdk.common.exceptions.handler - -import io.timemates.sdk.common.annotations.ApiStatus -import io.timemates.sdk.common.annotations.ExperimentalTimeMatesApi -import io.timemates.sdk.common.annotations.InternalApi -import io.timemates.sdk.common.exceptions.NotFoundException -import io.timemates.sdk.common.exceptions.TimeMatesException -import io.timemates.sdk.common.exceptions.TooManyRequestsException -import io.timemates.sdk.common.exceptions.UnauthorizedException -import io.timemates.sdk.common.exceptions.UnavailableException -import io.timemates.sdk.common.types.TimeMatesEntity - -/** - * Represents a type-safe wrapper class for handling exceptions in the context of an operation's result. - * - * The [SafeExceptionResult] class provides a convenient way to handle exceptions and control the flow of execution based on the encountered exception types. - * It is designed to ensure type safety by using the generic type parameters [T] for the result value and [E] for the exception type. - * - * @param T The type of the result value. - * @param E The type of the exception. - * @property result The original result of the operation. - */ -@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) -@JvmInline -public value class SafeExceptionResult @InternalApi constructor( - @property:InternalApi public val result: Result -) - -/** - * Converts a [Result] into a [SafeExceptionResult] for safe exception handling. - * - * The [safeResult] function is used to wrap the original [Result] in a [SafeExceptionResult], - * which allows for more controlled handling of exceptions within the operation's result. - * - * @receiver The original result of the operation. - * @return The [SafeExceptionResult] containing the original result. - */ -@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) -public fun Result.safeResult(): SafeExceptionResult { - return SafeExceptionResult(this) -} - -/** - * Executes a specified block if the encountered exception is of type [UnauthorizedException]. - * - * The [whenUnauthorized] function enables controlled handling of the [UnauthorizedException] by executing the provided block - * if the encountered exception matches the type [UnauthorizedException]. - * - * @param block The block of code to be executed if the encountered exception is [UnauthorizedException]. - * @return The [SafeExceptionResult] after executing the block. - */ -public inline fun SafeExceptionResult.whenUnauthorized( - block: (UnauthorizedException) -> Unit -): SafeExceptionResult { - val exception = result.exceptionOrNull() - if (exception is UnauthorizedException) - block(exception) - - return SafeExceptionResult(result) -} - -/** - * Executes a specified block if the encountered exception is of type [UnavailableException]. - * - * The [whenUnavailable] function allows for controlled handling of the [UnavailableException] by executing the provided block - * if the encountered exception matches the type [UnavailableException]. - * - * @param block The block of code to be executed if the encountered exception is [UnavailableException]. - * @return The [SafeExceptionResult] after executing the block. - */ -public inline fun SafeExceptionResult.whenUnavailable( - block: (UnavailableException) -> Unit -): SafeExceptionResult { - val exception = result.exceptionOrNull() - if (exception is UnavailableException) - block(exception) - - return SafeExceptionResult(result) -} - -/** - * Executes a specified block if the encountered exception is of type [TooManyRequestsException]. - * - * The [whenTooManyRequests] function allows for controlled handling of the [TooManyRequestsException] by executing the provided block - * if the encountered exception matches the type [TooManyRequestsException]. - * - * @param block The block of code to be executed if the encountered exception is [TooManyRequestsException]. - * @return The [SafeExceptionResult] after executing the block. - */ -public inline fun SafeExceptionResult.whenTooManyRequests( - block: (TooManyRequestsException) -> Unit -): SafeExceptionResult { - val exception = result.exceptionOrNull() - if (exception is TooManyRequestsException) - block(exception) - - return SafeExceptionResult(result) -} - -/** - * Executes a specified block if the encountered exception is of type [NotFoundException]. - * - * The [whenNotFound] function allows for controlled handling of the [NotFoundException] by executing the provided block - * if the encountered exception matches the type [NotFoundException]. - * - * @param block The block of code to be executed if the encountered exception is [NotFoundException]. - * @return The [SafeExceptionResult] after executing the block. - */ -public inline fun SafeExceptionResult.whenNotFound( - block: (NotFoundException) -> Unit -): SafeExceptionResult { - val exception = result.exceptionOrNull() - if (exception is NotFoundException) - block(exception) - - return SafeExceptionResult(result) -} - -/** - * Ignores the [NotFoundException] exception and continues execution. - * - * The [ignoreNotFound] function allows for ignoring the [NotFoundException] exception - * and continuing the flow of execution without interruption. - * - * @receiver The [SafeExceptionResult]. - * @return The [SafeExceptionResult] after ignoring the [NotFoundException]. - */ -public fun SafeExceptionResult.ignoreNotFound(): SafeExceptionResult { - return SafeExceptionResult(result) -} - -/** - * Executes a specified block if any exception is encountered. - * - * **Any inheritor of [TimeMatesException] are ignored here.** - * - * The [whenOtherError] function allows for handling any encountered exception by executing the provided block. - * It is useful for executing common error-handling code regardless of the specific exception type. - * - * @param block The block of code to be executed if any exception is encountered. - * @return The [SafeExceptionResult] after executing the block. - */ -@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) -public inline fun SafeExceptionResult.whenOtherError( - block: (E) -> Unit -): SafeExceptionResult { - result.exceptionOrNull()?.takeIf { it !is TimeMatesException }?.let { - @Suppress("UNCHECKED_CAST") - block(it as E) - } - - return SafeExceptionResult(result) -} - -/** - * Handles **ANY** throwable, even inheritors of [TimeMatesException]. You should use it if - * you want to handle some failure logic more than one time or when you want to ignore type-safe - * way of handling failures with [whenUnauthorized], [whenUnavailable], etc. - * - * But, if it's possible, it's better to use just [Result] API instead of [SafeExceptionResult]. - */ -@ExperimentalTimeMatesApi(status = ApiStatus.NEEDS_REVISION) -public inline fun SafeExceptionResult.whenAnyError( - block: (Throwable) -> Unit -): SafeExceptionResult { - result.exceptionOrNull()?.let(block) - - return SafeExceptionResult(result) -} - -/** - * Executes a specified block if the operation is successful. - * - * The [whenSuccess] function allows for executing a block of code if the operation is successful, - * providing access to the result value for further processing. - * - * @param block The block of code to be executed if the operation is successful. - */ -public inline fun SafeExceptionResult.whenSuccess( - block: (T) -> Unit -) { - if(result.isSuccess) - block(result.getOrThrow()) -} - -/** - * Ignores the [UnauthorizedException] exception and continues execution. - * - * The [ignoreUnauthorized] function allows for ignoring the [UnauthorizedException] exception - * and continuing the flow of execution without interruption. - * - * @receiver The [SafeExceptionResult]. - * @return The [SafeExceptionResult] after ignoring the [UnauthorizedException]. - */ -public fun SafeExceptionResult.ignoreUnauthorized(): SafeExceptionResult { - return SafeExceptionResult(result) -} - -/** - * Ignores the [TooManyRequestsException] exception and continues execution. - * - * The [ignoreTooManyRequests] function allows for ignoring the [TooManyRequestsException] exception - * and continuing the flow of execution without interruption. - * - * @receiver The [SafeExceptionResult]. - * @return The [SafeExceptionResult] after ignoring the [TooManyRequestsException]. - */ -public fun SafeExceptionResult.ignoreTooManyRequests(): SafeExceptionResult { - return SafeExceptionResult(result) -} - -/** - * Ignores the [UnavailableException] exception and continues execution. - * - * The [ignoreUnavailable] function allows for ignoring the [UnavailableException] exception - * and continuing the flow of execution without interruption. - * - * @receiver The [SafeExceptionResult]. - * @return The [SafeExceptionResult] after ignoring the [UnavailableException]. - */ -public fun SafeExceptionResult.ignoreUnavailable(): SafeExceptionResult { - return SafeExceptionResult(result) -} diff --git a/settings.gradle.kts b/settings.gradle.kts index 52e3530..6c84a0e 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -23,6 +23,4 @@ rootProject.name = "timemates-sdk" includeBuild("build-logic/publish-library-plugin") include(":sdk") -include(":grpc-engine") include(":rsocket-engine") -include(":grpc-engine:android")