一键导入
cmp-app-integration
Rules and workflow for integrating Constellation Mobile SDK into a Compose Multiplatform application
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Rules and workflow for integrating Constellation Mobile SDK into a Compose Multiplatform application
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Rules and guidelines for overriding UI field components in the Compose Multiplatform SDK
Rules and guidelines for writing Android instrumented UI tests for the android-cmp-app sample
Rules and workflow for migrating Angular TypeScript components to plain ES module JavaScript for the scripts/ bridge layer
Rules and guidelines for creating components in the core Kotlin module
Rules and guidelines for writing unit tests for JavaScript components in the scripts/ bridge layer
Rules and guidelines for creating Compose Multiplatform UI components in the ui-components-cmp module
| name | cmp-app-integration |
| description | Rules and workflow for integrating Constellation Mobile SDK into a Compose Multiplatform application |
You are an interactive assistant. You have to ask all questions mentioned in the instruction. You cannot skip any of them. Ask a series of questions per each part of the instruction separately. Your job is to integrate the Constellation Mobile SDK library (com.pega.constellation.sdk.kmp) with a client Compose Multiplatform application. For SDK code, please browse https://github.com/pegasystems/constellation-mobile-sdk
To do that please follow below steps:
===== Instructions =====
Cloning and publishing library to Maven Local: In order to use this library user needs to have it published on Maven Local repository.
Setting up gradle in client application
Add following dependencies to app build.gradle.kts in commonMain dependencies
val sdkVersion = "<SDK_VERSION>" // use newest version found in local maven.
implementation("com.pega.constellation.sdk.kmp:ui-components-cmp:$sdkVersion") implementation("com.pega.constellation.sdk.kmp:ui-renderer-cmp:$sdkVersion") implementation("com.pega.constellation.sdk.kmp:core:$sdkVersion") implementation("com.pega.constellation.sdk.kmp:engine-webview:$sdkVersion")
Add the following dependency to androidMain dependencies:
val okHttpVersion = "<OK_HTTP_VERSION>" // use newest available version implementation("com.squareup.okhttp3:okhttp:$okHttpVersion")
Init AppContext:
Create SDK engine:
class AndroidWebViewEngine(
private val context: Context,
private val scope: CoroutineScope,
private val okHttpClient: OkHttpClient,
private val nonDxOkHttpClient: OkHttpClient = defaultHttpClient()
) : ConstellationSdkEngine
val httpClient = AndroidWebViewEngine.defaultHttpClient()
.newBuilder()
.addInterceptor(AuthInterceptor()) // add it only if client said so
.build()
example of AuthInterceptor:
class AuthInterceptor : Interceptor {
override fun intercept(chain: Interceptor.Chain): Response {
val token = "TOKEN_HERE" // e.g. "Bearer some_encoded_value"
val newRequest = chain.request().newBuilder()
.header("Authorization", token)
.build()
return chain.proceed(newRequest)
}
}
Leave "TOKEN_HERE" as dummy input. App developer will paste real token later.val engine = AndroidWebViewEngine(
context = this,
scope = this.lifecycleScope,
okHttpClient = httpClient
)
Implement ResourceProvider in iosMain sourceset - ResourceProviderImpl
interface ResourceProvider {
fun shouldHandle(request: NSURLRequest): Boolean
suspend fun performRequest(request: NSURLRequest): Pair<NSData, NSURLResponse>
}
You have to ask user where he wants the ResourceProviderImpl object be created. You can suggest him to choose main ViewController.
Create WKWebViewBasedEngine with ResourceProviderImpl object as "provider" argument in the same place as chosen in 2.
Create new file called SDKConfig.kt with object SDKConfig.
Add const val PEGA_URL string property to keep information about Pega URL
Ask user for Pega server url. It should end with "prweb"
Add const val PEGA_CASE_CLASS_NAME string property to keep information about caseClassName
Ask user for "caseClassName" of the case he wants the app to create. This step is required and if nothing is provided then ask user to contact Pega server admin and ask again for "caseClassName".
Add const val AUTH_TOKEN string property with dummy value "TOKEN_HERE" to keep information about authentication token.
Please change "TOKEN_HERE" added in Android AuthInterceptor and iOS ResourceProviderImpl to SDKConfig.AUTH_TOKEN.
Create ConstellationSdkConfig object with provided url and debuggable boolean: val config = ConstellationSdkConfig(pegaUrl = SDKConfig.PEGA_URL, debuggable=) (ConstellationSdkConfig should be imported from com.pega.constellation.sdk.kmp.core)
Create ConstellationSdk instance
Showing Pega form
Render form.
The SDK provides several states that can be observed for seamless UI integration. Listen for state changes to automatically update the user interface. ConstellationSdk.State definition: (in com.pega.constellation.sdk.kmp.core)
interface ConstellationSdk {
sealed class State {
data object Initial : State()
data object Loading : State()
data class Ready(val environmentInfo: EnvironmentInfo, val root: RootContainerComponent) : State()
data class Error(val error: EngineError) : State()
data class Finished(val successMessage: String?) : State()
data object Cancelled : State()
}
}
use fun C.Render() for Ready state rendering. (in com.pega.constellation.sdk.kmp.ui.renderer.cmp)
Example code:
@Composable
fun PegaForm(sdk: ConstellationSdk) {
val state by sdk.state.collectAsState()
when (val s = state) {
is ConstellationSdk.State.Initial -> {}
is ConstellationSdk.State.Loading -> SomeLoader()
is ConstellationSdk.State.Ready -> s.root.Render()
is ConstellationSdk.State.Error -> SomeErrorSnackBar()
is ConstellationSdk.State.Finished -> SomeSnackBar()
is ConstellationSdk.State.Cancelled -> SomeCancelSnackBar()
}
}
SomeLoader() is any loader in compose. SomeErrorSnackBar() is any snackbar with error message. SomeSnackBar() is any snackbar showing successMessage message. SomeCancelSnackBar is any snackbar saying case processing has been canceled.
Please add some padding around rendered root view - like 16 dp