From e2369d6c87d727e34ccb1ae2ef2bda7a11667299 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Kalici=C5=84ski?= Date: Wed, 23 Oct 2024 09:30:26 +0200 Subject: [PATCH] Minor changes required for JS Chat SDK --- .../gradle/PubNubKotlinMultiplatformPlugin.kt | 27 ++++++++++++------- .../kotlin/com/pubnub/api/PubNubImpl.kt | 11 ++++---- .../com/pubnub/api/enums/PNPushEnvironment.kt | 6 +++++ .../kotlin/com/pubnub/api/enums/PNPushType.kt | 6 +++++ .../pubnub/internal/v2/PNConfigurationImpl.kt | 4 +-- .../workers/SubscribeMessageProcessor.kt | 2 +- 6 files changed, 38 insertions(+), 18 deletions(-) diff --git a/build-logic/gradle-plugins/src/main/kotlin/com/pubnub/gradle/PubNubKotlinMultiplatformPlugin.kt b/build-logic/gradle-plugins/src/main/kotlin/com/pubnub/gradle/PubNubKotlinMultiplatformPlugin.kt index 12045aff7..fca12a342 100644 --- a/build-logic/gradle-plugins/src/main/kotlin/com/pubnub/gradle/PubNubKotlinMultiplatformPlugin.kt +++ b/build-logic/gradle-plugins/src/main/kotlin/com/pubnub/gradle/PubNubKotlinMultiplatformPlugin.kt @@ -64,21 +64,28 @@ class PubNubBaseKotlinMultiplatformPlugin : Plugin { if (enableJsTarget) { js { -> - useEsModules() - browser { + project.findProperty("JS_MODULE_NAME")?.toString()?.let { jsModuleName -> + moduleName = jsModuleName + } +// useEsModules() +// browser { +// testTask { +// it.useMocha { +// timeout = "10s" +// } +// } +// } +// binaries.executable() + binaries.library() + generateTypeScriptDefinitions() + + nodejs { testTask { it.useMocha { - timeout = "10s" + timeout = "5s" } } } -// nodejs { -// testTask { -// it.useMocha { -// timeout = "5s" -// } -// } -// } } } diff --git a/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/api/PubNubImpl.kt b/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/api/PubNubImpl.kt index 475fea430..95af93c05 100644 --- a/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/api/PubNubImpl.kt +++ b/pubnub-kotlin/pubnub-kotlin-api/src/jsMain/kotlin/com/pubnub/api/PubNubImpl.kt @@ -133,7 +133,7 @@ import com.pubnub.kmp.toJsMap import kotlin.js.json import PubNub as PubNubJs -class PubNubImpl(private val jsPubNub: PubNubJs) : PubNub { +class PubNubImpl(val jsPubNub: PubNubJs) : PubNub { constructor(configuration: PNConfiguration) : this(PubNubJs(configuration.toJs())) override val configuration: PNConfiguration @@ -560,7 +560,7 @@ class PubNubImpl(private val jsPubNub: PubNubJs) : PubNub { jsPubNub, createJsObject { this.channel = channel - this.data = ChannelMetadata( + this.data = createChannelMetadata( PatchValue.of(name), PatchValue.of(description), PatchValue.of(status), @@ -633,7 +633,7 @@ class PubNubImpl(private val jsPubNub: PubNubJs) : PubNub { return SetUUIDMetadataImpl( jsPubNub, createJsObject { - data = UUIDMetadata( + data = createUuidMetadata( PatchValue.of(name), PatchValue.of(externalId), PatchValue.of(profileUrl), @@ -676,6 +676,7 @@ class PubNubImpl(private val jsPubNub: PubNubJs) : PubNub { createJsObject { this.sort = sort.toJsMap() this.filter = filter + this.page = page.toMetadataPage() this.include = createJsObject { this.customFields = includeCustom this.totalCount = includeCount @@ -1117,7 +1118,7 @@ private fun Any.adjustCollectionTypes(): Any { } } -fun UUIDMetadata( +private fun createUuidMetadata( name: PatchValue, externalId: PatchValue, profileUrl: PatchValue, @@ -1137,7 +1138,7 @@ fun UUIDMetadata( return result } -fun ChannelMetadata( +private fun createChannelMetadata( name: PatchValue, description: PatchValue, status: PatchValue, diff --git a/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/enums/PNPushEnvironment.kt b/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/enums/PNPushEnvironment.kt index e145db68b..306241d0d 100644 --- a/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/enums/PNPushEnvironment.kt +++ b/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/enums/PNPushEnvironment.kt @@ -8,4 +8,10 @@ enum class PNPushEnvironment { fun toParamString(): String { return name.lowercase() } + + companion object { + fun fromParamString(paramString: String): PNPushEnvironment { + return entries.first { it.toParamString() == paramString } + } + } } diff --git a/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/enums/PNPushType.kt b/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/enums/PNPushType.kt index 644f5d214..8653ee33d 100644 --- a/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/enums/PNPushType.kt +++ b/pubnub-kotlin/pubnub-kotlin-core-api/src/commonMain/kotlin/com/pubnub/api/enums/PNPushType.kt @@ -12,6 +12,12 @@ enum class PNPushType(private val value: String) { return value.lowercase() } + companion object { + fun fromParamString(paramString: String): PNPushType { + return entries.first { it.toParamString() == paramString } + } + } + override fun toString(): String { return value } diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/v2/PNConfigurationImpl.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/v2/PNConfigurationImpl.kt index c7d4ed311..2620096e1 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/v2/PNConfigurationImpl.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/v2/PNConfigurationImpl.kt @@ -97,8 +97,8 @@ class PNConfigurationImpl( @Deprecated( message = "The authKey parameter is deprecated because it relates to deprecated Access Manager (PAM V2) and will be removed in the future." + - "Please, use createPNConfiguration without authKey instead and migrate to new Access Manager " + - "(PAM V3) https://www.pubnub.com/docs/general/resources/migration-guides/pam-v3-migration ", + "Please, use createPNConfiguration without authKey instead and migrate to new Access Manager " + + "(PAM V3) https://www.pubnub.com/docs/general/resources/migration-guides/pam-v3-migration ", level = DeprecationLevel.WARNING, replaceWith = ReplaceWith( "createPNConfiguration(userId, subscribeKey, publishKey, secretKey, logVerbosity)" diff --git a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/workers/SubscribeMessageProcessor.kt b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/workers/SubscribeMessageProcessor.kt index 18ded7546..b39d08fab 100644 --- a/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/workers/SubscribeMessageProcessor.kt +++ b/pubnub-kotlin/pubnub-kotlin-impl/src/main/kotlin/com/pubnub/internal/workers/SubscribeMessageProcessor.kt @@ -193,7 +193,7 @@ internal class SubscribeMessageProcessor( ) val queryParams = ArrayList() val authToken = - if (pubnub.tokenManager.getToken() != null){ + if (pubnub.tokenManager.getToken() != null) { pubnub.tokenManager.getToken() } else if (pubnub.configuration.authKey.isValid()) { pubnub.configuration.authKey