diff --git a/README.md b/README.md index 3d086dc..57ef626 100644 --- a/README.md +++ b/README.md @@ -1,30 +1,4 @@ - - -* [Current status](#current-status) -* [build/run java/js targets](#buildrun-javajs-targets) - * [run js](#run-js) - * [run jvm](#run-jvm) - * [native](#native) -* [positives](#positives) -* [negatives](#negatives) -* [debugging crashes](#debugging-crashes) - * [js stack trace](#js-stack-trace) - * [js debugger](#js-debugger) - * [java stack trace](#java-stack-trace) - * [java debugging](#java-debugging) - * [issues](#issues) - - - -## Current status - -jvm and js targets working with `getEligibility` request. -It creates jwt and gets auth token with it. Then it uses the token in getEligibility request. - -- jvm crypto - hmcrypto-java -- js crypto - jsrsasign - -Next request implementations are trivial because crypto and auth is the hardest part. +# HMKit Fleet Multiplatform ## build/run java/js targets @@ -48,93 +22,4 @@ in js folder: `yarn && tsx ./src/index.ts` ### native -currently not implemented - -## positives - -- Main purpose of sharing the http request logic with Coroutines can be exported to both JVM and JS. - -Coroutines work. Ktor http client works. - -- has code completions with Typescript .d.ts definitions - - can generate TS docs from this - -```typescript -// import { HMKitFleet, Environment } from "hmkit-fleet" // types working -import { HMKitFleet, Environment } from "hmkit-fleet/kotlin/hmkit-fleet-mp-hmkit-fleet.mjs" // build working -import fs from "fs" - -let privateKey = fs.readFileSync("private-key.json", "utf8") - -let env = Environment.SANDBOX - -let hmkit = new HMKitFleet(privateKey, env) - -hmkit.getEligibility("vin1", env).then((response) => { - console.log(response) -}) -``` - -![completions](./docs/completions.png) -check out generated types in [docs](./docs/hmkit-fleet-hmkit-fleet.d.ts) - -## negatives - -- if run into a problem, then it is probably a lot slower/impossible to resolve it. Jetbrains needs to update - their multiplatform. For instance their TypeScript support is experimental, but Typescript has been around for a long - time already. -- There is more overhead to manage 2 platforms -- need separate HMKitFleet classes for js and jvm. It's because Js has Promise return type and Java - has CompletableFuture. These return types cannot be mixed in Kotlin - -### JVM negatives - -adds new dependencies: -- ktor. With native jvm, only OkHttp was used. - -## debugging crashes - -### js stack trace - -``` -➜ node index.js - throw SerializationException_init_$Create$(notRegisteredMessage(_this__u8e3s4) + 'To get enum serializer on Kotlin/JS, it should be annotated with @Serializable annotation.'); - ^ -SerializationException: Serializer for class 'Brand' is not found. -Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied. -To get enum serializer on Kotlin/JS, it should be annotated with @Serializable annotation. - at platformSpecificSerializerNotRegistered (/opt/buildAgent/work/b2fef8360e1bcf3d/core/jsMain/src/kotlinx/serialization/internal/Platform.kt:45:11) - at serializer (/opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/Serializers.kt:134:10) - at requestBody (/opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/internal/Platform.common.kt:80:1) - at $getEligibilityCOROUTINE$0.protoOf.hh (/Users/tonis/workspace/src/commonMain/kotlin/network/UtilityRequests.kt:49:20) -``` - -It shows the Kotlin line where the exception was thrown(`UtilityRequests.kt:49:20`). Not problematic to debug. - -### js debugger - -node js: they recommend normal node -debugging: https://nodejs.org/en/docs/guides/debugging-getting-started#jetbrains-webstorm-2017-1-and-other-jetbrains-ides - -The mjs source code for this is not clean, but it is kind of readable -![img](docs/js-debugging.png) - -### java stack trace - -The java compiled version looks exactly like the current one. I think there won't be any difference for the clients. - -- verified -- package is correct (for spring targets that require a package) - -### java debugging - -With implementation project(""), the debugging works normally - -I tested it with releasing to sonatype and debugging in a sample app - -### issues - -Currently, cannot get both building and types working in js. I don't know how to map .mjs with types in vscode. - -I think Js target can be set to experimental, and can be used by customers to quickly verify their use case. If it -works, then they can use the js target. +currently not implemented \ No newline at end of file diff --git a/docs/multiplatform-overview.md b/docs/multiplatform-overview.md new file mode 100644 index 0000000..ddeb7c3 --- /dev/null +++ b/docs/multiplatform-overview.md @@ -0,0 +1,139 @@ + + * [Current status](#current-status) + * [build/run java/js targets](#buildrun-javajs-targets) + * [run js](#run-js) + * [run jvm](#run-jvm) + * [native](#native) + * [positives](#positives) + * [negatives](#negatives) + * [JVM negatives](#jvm-negatives) + * [debugging crashes](#debugging-crashes) + * [js stack trace](#js-stack-trace) + * [js debugger](#js-debugger) + * [java stack trace](#java-stack-trace) + * [java debugging](#java-debugging) + * [issues](#issues) + + +## Current status + +jvm and js targets working with `getEligibility` request. +It creates jwt and gets auth token with it. Then it uses the token in getEligibility request. + +- jvm crypto - hmcrypto-java +- js crypto - jsrsasign + +Next request implementations are trivial because crypto and auth is the hardest part. + +## build/run java/js targets + +### run js + +build and run js: + +`./gradlew assemble && cd hmkit-fleet-consumer-js && yarn && tsx ./src/index.ts && cd -` + +continuous building - don't have to manually build on every change + +`./gradle assemble --continuous` +in js folder: `yarn && tsx ./src/index.ts` + +- js will be located in `build/dist/js/productionLibrary/` +- java will be located in `build/libs/` + +### run jvm + +`./gradlew :consumer-jvm:run ` + +### native + +currently not implemented + +## positives + +- Main purpose of sharing the http request logic with Coroutines can be exported to both JVM and JS. + +Coroutines work. Ktor http client works. + +- has code completions with Typescript .d.ts definitions + - can generate TS docs from this + +```typescript +// import { HMKitFleet, Environment } from "hmkit-fleet" // types working +import { HMKitFleet, Environment } from "hmkit-fleet/kotlin/hmkit-fleet-mp-hmkit-fleet.mjs" // build working +import fs from "fs" + +let privateKey = fs.readFileSync("private-key.json", "utf8") + +let env = Environment.SANDBOX + +let hmkit = new HMKitFleet(privateKey, env) + +hmkit.getEligibility("vin1", env).then((response) => { + console.log(response) +}) +``` + +![completions](./docs/completions.png) +check out generated types in [docs](./docs/hmkit-fleet-hmkit-fleet.d.ts) + +## negatives + +- if run into a problem, then it is probably a lot slower/impossible to resolve it. Jetbrains needs to update + their multiplatform. For instance their TypeScript support is experimental, but Typescript has been around for a long + time already. +- There is more overhead to manage 2 platforms +- need separate HMKitFleet classes for js and jvm. It's because Js has Promise return type and Java + has CompletableFuture. These return types cannot be mixed in Kotlin + +### JVM negatives + +adds new dependencies: +- ktor. With native jvm, only OkHttp was used. + +## debugging crashes + +### js stack trace + +``` +➜ node index.js + throw SerializationException_init_$Create$(notRegisteredMessage(_this__u8e3s4) + 'To get enum serializer on Kotlin/JS, it should be annotated with @Serializable annotation.'); + ^ +SerializationException: Serializer for class 'Brand' is not found. +Please ensure that class is marked as '@Serializable' and that the serialization compiler plugin is applied. +To get enum serializer on Kotlin/JS, it should be annotated with @Serializable annotation. + at platformSpecificSerializerNotRegistered (/opt/buildAgent/work/b2fef8360e1bcf3d/core/jsMain/src/kotlinx/serialization/internal/Platform.kt:45:11) + at serializer (/opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/Serializers.kt:134:10) + at requestBody (/opt/buildAgent/work/b2fef8360e1bcf3d/core/commonMain/src/kotlinx/serialization/internal/Platform.common.kt:80:1) + at $getEligibilityCOROUTINE$0.protoOf.hh (/Users/tonis/workspace/src/commonMain/kotlin/network/UtilityRequests.kt:49:20) +``` + +It shows the Kotlin line where the exception was thrown(`UtilityRequests.kt:49:20`). Not problematic to debug. + +### js debugger + +node js: they recommend normal node +debugging: https://nodejs.org/en/docs/guides/debugging-getting-started#jetbrains-webstorm-2017-1-and-other-jetbrains-ides + +The mjs source code for this is not clean, but it is kind of readable +![img](docs/js-debugging.png) + +### java stack trace + +The java compiled version looks exactly like the current one. I think there won't be any difference for the clients. + +- verified +- package is correct (for spring targets that require a package) + +### java debugging + +With implementation project(""), the debugging works normally + +I tested it with releasing to sonatype and debugging in a sample app + +### issues + +Currently, cannot get both building and types working in js. I don't know how to map .mjs with types in vscode. + +I think Js target can be set to experimental, and can be used by customers to quickly verify their use case. If it +works, then they can use the js target. diff --git a/hmkit-fleet/src/jsMain/kotlin/HMKitFleet.kt b/hmkit-fleet/src/jsMain/kotlin/HMKitFleet.kt index 053e05d..3139e37 100644 --- a/hmkit-fleet/src/jsMain/kotlin/HMKitFleet.kt +++ b/hmkit-fleet/src/jsMain/kotlin/HMKitFleet.kt @@ -11,14 +11,8 @@ import com.highmobility.hmkitfleet.model.RequestClearanceResponse import com.highmobility.hmkitfleet.network.Response import com.highmobility.hmkitfleet.network.UtilityRequests import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.async -import kotlinx.coroutines.delay -import kotlinx.coroutines.launch import kotlinx.coroutines.promise -import kotlinx.serialization.json.Json.Default.configuration -import platform.Crypto import kotlin.js.Promise -import kotlin.jvm.JvmOverloads /** * HMKitFleet is the access point for the Fleet SDK functionality. It is accessed by