Skip to content

Commit

Permalink
Add uuid v7 lib
Browse files Browse the repository at this point in the history
  • Loading branch information
mani1232 committed Jul 2, 2024
1 parent 7a0ebe3 commit 41d531f
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 20 deletions.
2 changes: 2 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ cache = "2.1.1-SNAPSHOT"
dokka = "1.9.20"
datetime = "0.6.0"
logging = "7.0.0"
uuid = "0.0.26"

[libraries]

other-cache = { module = "com.mayakapps.kache:kache", version.ref = "cache" }
kotlinx-coroutines = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "coroutines" }
kotlinx-datetime = { module = "org.jetbrains.kotlinx:kotlinx-datetime", version.ref = "datetime" }
kotlinx-uuid = { module = "app.softwork:kotlinx-uuid-core", version.ref = "uuid" }
kotlinx-serialization-json = { module = "org.jetbrains.kotlinx:kotlinx-serialization-json-io", version.ref = "serializationJson" }

kotlin-reflect = { module = "org.jetbrains.kotlin:kotlin-reflect", version.ref = "kotlin" }
Expand Down
2 changes: 1 addition & 1 deletion kpaypal-api/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ kotlin {
api(libs.kotlinx.datetime)
api(libs.kotlinx.serialization.json)
api(libs.kotlin.reflect)
api(libs.kotlinx.uuid)
implementation(libs.kotlin.logging)

api(libs.ktor.serialization.json)
Expand All @@ -41,7 +42,6 @@ kotlin {
jsMain {
dependencies {
api(libs.ktor.client.js)
api(npm("uuid", ">= 10.0.0"))
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions kpaypal-api/src/commonMain/kotlin/cc/worldmandia/Utils.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
package cc.worldmandia

expect fun encodeToBase64(input: String): String

expect fun generateUUID(): String
expect fun encodeToBase64(input: String): String
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package cc.worldmandia.paypalApi.orderApi.builders

import cc.worldmandia.OrderDsl
import cc.worldmandia.generateUUID
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import kotlinx.uuid.UUIDExperimentalAPI
import kotlinx.uuid.UUIDv7

@Serializable
data class PurchaseUnit(
Expand All @@ -20,7 +21,8 @@ data class PurchaseUnit(
private lateinit var amount: Amount
var description: String? = null
var customId: String? = null
var referenceId: String = generateUUID()
@OptIn(UUIDExperimentalAPI::class)
var referenceId: String = UUIDv7(42).toString(false)
var softDescriptor: String? = null
var items: List<Item>? = null
var invoiceId: String? = null
Expand Down
10 changes: 1 addition & 9 deletions kpaypal-api/src/jsMain/kotlin/cc/worldmandia/Utils.js.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,4 @@ package cc.worldmandia

actual fun encodeToBase64(input: String): String {
return js("btoa(input)") as String
}

actual fun generateUUID(): String {
return v4()
}

@JsModule("uuid")
@JsNonModule
external fun v4(): String
}
5 changes: 0 additions & 5 deletions kpaypal-api/src/jvmMain/kotlin/cc/worldmandia/Utils.jvm.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package cc.worldmandia

import java.util.*
import java.util.Base64.getEncoder

actual fun encodeToBase64(input: String): String {
return getEncoder().encodeToString(input.toByteArray())
}

actual fun generateUUID(): String {
return UUID.randomUUID().toString()
}

0 comments on commit 41d531f

Please sign in to comment.