Skip to content

Commit

Permalink
Created util-shared module + misc updates
Browse files Browse the repository at this point in the history
  • Loading branch information
chRyNaN committed Feb 25, 2025
1 parent 5e8710c commit a666c03
Show file tree
Hide file tree
Showing 168 changed files with 688 additions and 428 deletions.
1 change: 1 addition & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 36 additions & 11 deletions api-vpn/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,15 +1,44 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("com.android.library")
id("org.jetbrains.compose")
id("org.jetbrains.kotlin.plugin.compose")
id("org.jetbrains.dokka")
id("mooncloak.multiplatform")
}

kotlin {
applyDefaultHierarchyTemplate()

// TODO: Re-enable: linuxArm64()
// TODO: Re-enable: linuxX64()

// TODO: Re-enable: mingwX64()

// TODO: Re-enable: macosX64()
// TODO: Re-enable: macosArm64()

iosArm64()
iosX64()
iosSimulatorArm64()

// TODO: Re-enable: tvosArm64()
// TODO: Re-enable: tvosX64()
// TODO: Re-enable: tvosSimulatorArm64()

// TODO: Re-enable: watchosArm32()
// TODO: Re-enable: watchosArm64()
// TODO: Re-enable: watchosX64()
// TODO: Re-enable: watchosSimulatorArm64()

androidTarget {
publishAllLibraryVariants()
}

jvm()

sourceSets {
all {
// Disable warnings and errors related to these expected @OptIn annotations.
Expand All @@ -24,6 +53,7 @@ kotlin {

val commonMain by getting {
dependencies {
api(project(":util-shared"))
api(project(":data-shared"))

// Coroutines
Expand Down Expand Up @@ -73,6 +103,11 @@ kotlin {
implementation(RussHWolf.multiplatformSettings.coroutines)
implementation(RussHWolf.multiplatformSettings.serialization)
implementation(RussHWolf.multiplatformSettings.noArg)

// Rich Text Utils
// https://github.com/mooncloak/textx
// Apache 2.0: https://github.com/mooncloak/textx/blob/main/LICENSE
api("com.mooncloak.kodetools.textx:textx-core:_")
}
}

Expand All @@ -82,16 +117,6 @@ kotlin {
implementation(KotlinX.coroutines.test)
}
}

val jsMain by getting {
dependencies {
}
}

val wasmJsMain by getting {
dependencies {
}
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mooncloak.vpn.app.shared.api.network
package com.mooncloak.vpn.api.shared.network

import android.annotation.SuppressLint
import android.content.Context
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.mooncloak.vpn.app.shared.api.network
package com.mooncloak.vpn.api.shared.network

import android.content.Context
import android.net.ConnectivityManager
import android.net.InetAddresses
import android.net.NetworkCapabilities
import android.net.wifi.WifiManager
import androidx.core.content.getSystemService
import com.mooncloak.kodetools.konstruct.annotations.Inject
import com.mooncloak.vpn.app.shared.util.ApplicationContext
import java.net.InetAddress

public class AndroidLocalNetworkManager @Inject public constructor(
public operator fun LocalNetworkManager.Companion.invoke(context: Context): LocalNetworkManager =
AndroidLocalNetworkManager(context = context)

internal class AndroidLocalNetworkManager internal constructor(
private val context: ApplicationContext
) : LocalNetworkManager {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
package com.mooncloak.vpn.app.shared.api
package com.mooncloak.vpn.api.shared

import com.mooncloak.kodetools.apix.core.ApiException
import com.mooncloak.kodetools.apix.core.ExperimentalApixApi
import com.mooncloak.kodetools.apix.core.HttpResponseBody
import com.mooncloak.kodetools.apix.core.getOrThrow
import com.mooncloak.kodetools.konstruct.annotations.Inject
import com.mooncloak.kodetools.locale.Country
import com.mooncloak.kodetools.locale.CountryCode
import com.mooncloak.kodetools.pagex.Cursor
Expand All @@ -16,20 +15,20 @@ import com.mooncloak.kodetools.pagex.ResolvedPage
import com.mooncloak.kodetools.pagex.SortOptions
import com.mooncloak.vpn.api.shared.app.Contributor
import com.mooncloak.vpn.api.shared.app.CurrentContributors
import com.mooncloak.vpn.app.shared.api.billing.BitcoinPlanInvoice
import com.mooncloak.vpn.app.shared.api.billing.GetPaymentInvoiceRequestBody
import com.mooncloak.vpn.app.shared.api.billing.GetPaymentStatusRequestBody
import com.mooncloak.vpn.app.shared.api.billing.PlanPaymentStatus
import com.mooncloak.vpn.app.shared.api.billing.ProofOfPurchase
import com.mooncloak.vpn.app.shared.api.key.Base64Key
import com.mooncloak.vpn.api.shared.billing.BitcoinPlanInvoice
import com.mooncloak.vpn.api.shared.billing.GetPaymentInvoiceRequestBody
import com.mooncloak.vpn.api.shared.billing.GetPaymentStatusRequestBody
import com.mooncloak.vpn.api.shared.billing.PlanPaymentStatus
import com.mooncloak.vpn.api.shared.billing.ProofOfPurchase
import com.mooncloak.vpn.api.shared.key.Base64Key
import com.mooncloak.vpn.api.shared.location.CountryFilters
import com.mooncloak.vpn.app.shared.api.plan.AvailablePlans
import com.mooncloak.vpn.app.shared.api.plan.Plan
import com.mooncloak.vpn.api.shared.plan.AvailablePlans
import com.mooncloak.vpn.api.shared.plan.Plan
import com.mooncloak.vpn.api.shared.reflection.HttpReflection
import com.mooncloak.vpn.app.shared.api.server.ClientRegistrationRequestBody
import com.mooncloak.vpn.app.shared.api.server.RegisteredClient
import com.mooncloak.vpn.app.shared.api.server.Server
import com.mooncloak.vpn.app.shared.api.server.ServerFilters
import com.mooncloak.vpn.api.shared.server.ClientRegistrationRequestBody
import com.mooncloak.vpn.api.shared.server.RegisteredClient
import com.mooncloak.vpn.api.shared.server.Server
import com.mooncloak.vpn.api.shared.server.ServerFilters
import com.mooncloak.vpn.api.shared.service.ServiceSubscription
import com.mooncloak.vpn.api.shared.service.ServiceSubscriptionUsage
import com.mooncloak.vpn.api.shared.service.ServiceTokens
Expand All @@ -38,6 +37,7 @@ import com.mooncloak.vpn.api.shared.token.RevokedTokenResponseBody
import com.mooncloak.vpn.api.shared.token.Token
import com.mooncloak.vpn.api.shared.token.TokenTypeHint
import com.mooncloak.vpn.api.shared.token.TransactionToken
import com.mooncloak.vpn.util.shared.coroutine.PlatformIO
import io.ktor.client.HttpClient
import io.ktor.client.call.body
import io.ktor.client.request.accept
Expand All @@ -52,26 +52,26 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

@OptIn(ExperimentalApixApi::class)
public class MooncloakVpnServiceHttpApi @Inject public constructor(
public class MooncloakVpnServiceHttpApi public constructor(
private val httpClient: HttpClient
) {

@Throws(ApiException::class, CancellationException::class)
public suspend fun getReflection(): HttpReflection = withContext(Dispatchers.IO) {
public suspend fun getReflection(): HttpReflection = withContext(Dispatchers.PlatformIO) {
val response = httpClient.get("https://mooncloak.com/api/mirror")

return@withContext response.body<HttpResponseBody<HttpReflection>>().getOrThrow()
}

@Throws(ApiException::class, CancellationException::class)
public suspend fun getAvailablePlans(): AvailablePlans = withContext(Dispatchers.IO) {
public suspend fun getAvailablePlans(): AvailablePlans = withContext(Dispatchers.PlatformIO) {
val response = httpClient.get("https://mooncloak.com/api/billing/plans")

return@withContext response.body<HttpResponseBody<AvailablePlans>>().getOrThrow()
}

@Throws(ApiException::class, CancellationException::class)
public suspend fun getPlan(id: String): Plan = withContext(Dispatchers.IO) {
public suspend fun getPlan(id: String): Plan = withContext(Dispatchers.PlatformIO) {
val response = httpClient.get("https://mooncloak.com/api/billing/plan/$id")

return@withContext response.body<HttpResponseBody<Plan>>().getOrThrow()
Expand All @@ -82,7 +82,7 @@ public class MooncloakVpnServiceHttpApi @Inject public constructor(
planId: String,
secret: String? = null,
token: Token? = null
): BitcoinPlanInvoice = withContext(Dispatchers.IO) {
): BitcoinPlanInvoice = withContext(Dispatchers.PlatformIO) {
val response = httpClient.post("https://mooncloak.com/api/vpn/payment/invoice") {
token?.value?.let { bearerAuth(it) }

Expand All @@ -105,7 +105,7 @@ public class MooncloakVpnServiceHttpApi @Inject public constructor(
paymentId: String,
token: TransactionToken,
secret: String? = null
): PlanPaymentStatus = withContext(Dispatchers.IO) {
): PlanPaymentStatus = withContext(Dispatchers.PlatformIO) {
val response = httpClient.post("https://mooncloak.com/api/vpn/payment/status") {
bearerAuth(token.value)

Expand All @@ -132,7 +132,7 @@ public class MooncloakVpnServiceHttpApi @Inject public constructor(
@Throws(ApiException::class, CancellationException::class)
public suspend fun exchangeToken(
receipt: ProofOfPurchase
): ServiceTokens = withContext(Dispatchers.IO) {
): ServiceTokens = withContext(Dispatchers.PlatformIO) {
val response = httpClient.post("https://mooncloak.com/api/vpn/token/exchange") {
contentType(ContentType.Application.Json)
accept(ContentType.Application.Json)
Expand All @@ -146,7 +146,7 @@ public class MooncloakVpnServiceHttpApi @Inject public constructor(
@Throws(ApiException::class, CancellationException::class)
public suspend fun refreshToken(
refreshToken: Token
): ServiceTokens = withContext(Dispatchers.IO) {
): ServiceTokens = withContext(Dispatchers.PlatformIO) {
val response = httpClient.post("https://mooncloak.com/api/vpn/token/refresh") {
bearerAuth(refreshToken.value)
}
Expand All @@ -157,7 +157,7 @@ public class MooncloakVpnServiceHttpApi @Inject public constructor(
@Throws(ApiException::class, CancellationException::class)
public suspend fun revokeToken(
refreshToken: Token
): Boolean = withContext(Dispatchers.IO) {
): Boolean = withContext(Dispatchers.PlatformIO) {
val response = httpClient.post("https://mooncloak.com/api/vpn/token/revoke") {
bearerAuth(refreshToken.value)

Expand All @@ -178,7 +178,7 @@ public class MooncloakVpnServiceHttpApi @Inject public constructor(
@Throws(ApiException::class, CancellationException::class)
public suspend fun getCurrentSubscription(
token: Token
): ServiceSubscription = withContext(Dispatchers.IO) {
): ServiceSubscription = withContext(Dispatchers.PlatformIO) {
val response = httpClient.post("https://mooncloak.com/api/vpn/subscription") {
bearerAuth(token.value)
}
Expand All @@ -189,7 +189,7 @@ public class MooncloakVpnServiceHttpApi @Inject public constructor(
@Throws(ApiException::class, CancellationException::class)
public suspend fun getCurrentSubscriptionUsage(
token: Token
): ServiceSubscriptionUsage = withContext(Dispatchers.IO) {
): ServiceSubscriptionUsage = withContext(Dispatchers.PlatformIO) {
val response = httpClient.post("https://mooncloak.com/api/vpn/subscription/usage") {
bearerAuth(token.value)
}
Expand All @@ -200,7 +200,7 @@ public class MooncloakVpnServiceHttpApi @Inject public constructor(
@Throws(ApiException::class, CancellationException::class)
public suspend fun getCountry(
code: CountryCode
): Country = withContext(Dispatchers.IO) {
): Country = withContext(Dispatchers.PlatformIO) {
val response = httpClient.get("https://mooncloak.com/api/vpn/service/country/${code.value}")

return@withContext response.body<HttpResponseBody<Country>>().getOrThrow()
Expand All @@ -214,7 +214,7 @@ public class MooncloakVpnServiceHttpApi @Inject public constructor(
count: UInt = DEFAULT_COUNT,
sort: SortOptions? = null,
filters: CountryFilters? = null
): ResolvedPage<Country> = withContext(Dispatchers.IO) {
): ResolvedPage<Country> = withContext(Dispatchers.PlatformIO) {
val pageRequest = PageRequest<String, CountryFilters>(
data = null,
direction = direction,
Expand All @@ -238,7 +238,7 @@ public class MooncloakVpnServiceHttpApi @Inject public constructor(
serverId: String,
clientPublicKey: Base64Key,
token: Token?
): RegisteredClient = withContext(Dispatchers.IO) {
): RegisteredClient = withContext(Dispatchers.PlatformIO) {
val response = httpClient.post("https://mooncloak.com/api/vpn/service/client/register") {
token?.value?.let { bearerAuth(it) }

Expand All @@ -259,7 +259,7 @@ public class MooncloakVpnServiceHttpApi @Inject public constructor(
public suspend fun getServer(
id: String,
token: Token? = null
): Server = withContext(Dispatchers.IO) {
): Server = withContext(Dispatchers.PlatformIO) {
val response = httpClient.get("https://mooncloak.com/api/vpn/service/server/$id") {
token?.value?.let { bearerAuth(it) }
}
Expand All @@ -276,7 +276,7 @@ public class MooncloakVpnServiceHttpApi @Inject public constructor(
count: UInt = DEFAULT_COUNT,
sort: SortOptions? = null,
filters: ServerFilters? = null
): ResolvedPage<Server> = withContext(Dispatchers.IO) {
): ResolvedPage<Server> = withContext(Dispatchers.PlatformIO) {
val pageRequest = PageRequest<String, ServerFilters>(
data = null,
direction = direction,
Expand All @@ -299,14 +299,14 @@ public class MooncloakVpnServiceHttpApi @Inject public constructor(
}

@Throws(ApiException::class, CancellationException::class)
public suspend fun getContributors(): CurrentContributors = withContext(Dispatchers.IO) {
public suspend fun getContributors(): CurrentContributors = withContext(Dispatchers.PlatformIO) {
val response = httpClient.get("https://mooncloak.com/api/vpn/app/contributor")

return@withContext response.body<HttpResponseBody<CurrentContributors>>().getOrThrow()
}

@Throws(ApiException::class, CancellationException::class)
public suspend fun getContributor(id: String): Contributor = withContext(Dispatchers.IO) {
public suspend fun getContributor(id: String): Contributor = withContext(Dispatchers.PlatformIO) {
val response = httpClient.get("https://mooncloak.com/api/vpn/app/contributor/$id")

return@withContext response.body<HttpResponseBody<Contributor>>().getOrThrow()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mooncloak.vpn.app.shared.api.billing
package com.mooncloak.vpn.api.shared.billing

import com.mooncloak.vpn.app.shared.api.plan.Plan
import com.mooncloak.vpn.api.shared.plan.Plan

public interface BillingManager : AutoCloseable {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.mooncloak.vpn.app.shared.api.billing
package com.mooncloak.vpn.api.shared.billing

import com.mooncloak.vpn.app.shared.api.plan.Plan
import com.mooncloak.vpn.api.shared.plan.Plan
import kotlin.contracts.ExperimentalContracts
import kotlin.contracts.contract

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mooncloak.vpn.app.shared.api.billing
package com.mooncloak.vpn.api.shared.billing

import androidx.compose.runtime.Immutable
import kotlinx.serialization.SerialName
Expand All @@ -15,7 +15,7 @@ import kotlinx.serialization.Serializable
*/
@Immutable
@Serializable
internal data class GetPaymentInvoiceRequestBody internal constructor(
public data class GetPaymentInvoiceRequestBody public constructor(
@SerialName(value = "plan_id") val planId: String,
@SerialName(value = "secret") val secret: String? = null
)
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package com.mooncloak.vpn.app.shared.api.billing
package com.mooncloak.vpn.api.shared.billing

import androidx.compose.runtime.Immutable
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Immutable
@Serializable
internal data class GetPaymentStatusRequestBody internal constructor(
public data class GetPaymentStatusRequestBody public constructor(
@SerialName(value = "payment_id") val paymentId: String,
@SerialName(value = "secret") val secret: String? = null
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.mooncloak.vpn.app.shared.api.billing
package com.mooncloak.vpn.api.shared.billing

import androidx.compose.runtime.Immutable
import com.mooncloak.vpn.app.shared.api.plan.Price
import com.mooncloak.vpn.api.shared.plan.Price
import com.mooncloak.vpn.api.shared.token.TransactionToken
import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.mooncloak.vpn.app.shared.api.billing
package com.mooncloak.vpn.api.shared.billing

import androidx.compose.runtime.Immutable
import com.mooncloak.kodetools.apix.core.ExperimentalApixApi
Expand Down
Loading

0 comments on commit a666c03

Please sign in to comment.