-
Notifications
You must be signed in to change notification settings - Fork 107
feat(paywalls): add web_view component schema (PWENG-98) #3650
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
alexrepty
wants to merge
1
commit into
main
Choose a base branch
from
alexrepty/paywalls-web-view-schema
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
purchases/src/main/kotlin/com/revenuecat/purchases/paywalls/components/WebViewComponent.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package com.revenuecat.purchases.paywalls.components | ||
|
|
||
| import androidx.compose.runtime.Immutable | ||
| import com.revenuecat.purchases.InternalRevenueCatAPI | ||
| import com.revenuecat.purchases.paywalls.components.properties.Size | ||
| import com.revenuecat.purchases.paywalls.components.properties.SizeConstraint | ||
| import com.revenuecat.purchases.paywalls.components.properties.SizeConstraint.Fill | ||
| import dev.drewhamilton.poko.Poko | ||
| import kotlinx.serialization.SerialName | ||
| import kotlinx.serialization.Serializable | ||
|
|
||
| /** | ||
| * A Paywalls V2 component that renders generic hosted web content (a web bundle entrypoint) inside a | ||
| * web view. | ||
| * | ||
| * Only [protocolVersion] `1` is currently supported. When [protocolVersion] is present the SDK | ||
| * isolates the web content from external sources (see the content blocking applied in the UI module): | ||
| * the bundle must be fully self-contained. | ||
| */ | ||
| @InternalRevenueCatAPI | ||
| @Poko | ||
| @Serializable | ||
| @SerialName("web_view") | ||
| @Immutable | ||
| public class WebViewComponent( | ||
| @get:JvmSynthetic | ||
| public val url: String, | ||
| @get:JvmSynthetic | ||
| public val id: String? = null, | ||
| @get:JvmSynthetic | ||
| public val name: String? = null, | ||
| @get:JvmSynthetic | ||
| public val visible: Boolean? = null, | ||
| @SerialName("protocol_version") | ||
| @get:JvmSynthetic | ||
| public val protocolVersion: Int? = null, | ||
| @get:JvmSynthetic | ||
| public val size: Size = Size(width = Fill, height = SizeConstraint.Fit), | ||
| ) : PaywallComponent |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
...hases/src/test/java/com/revenuecat/purchases/paywalls/components/WebViewComponentTests.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,127 @@ | ||
| package com.revenuecat.purchases.paywalls.components | ||
|
|
||
| import com.revenuecat.purchases.JsonTools | ||
| import com.revenuecat.purchases.paywalls.components.properties.Size | ||
| import com.revenuecat.purchases.paywalls.components.properties.SizeConstraint | ||
| import com.revenuecat.purchases.utils.filter | ||
| import org.assertj.core.api.Assertions.assertThat | ||
| import org.intellij.lang.annotations.Language | ||
| import org.junit.Test | ||
| import kotlin.test.assertEquals | ||
|
|
||
| class WebViewComponentTests { | ||
|
|
||
| @Language("json") | ||
| private val fullJson = """ | ||
| { | ||
| "id": "promo_web_view", | ||
| "type": "web_view", | ||
| "protocol_version": 1, | ||
| "url": "https://assets.pawwalls.com/web_bundles/123/index.html", | ||
| "size": { | ||
| "width": { "type": "fill" }, | ||
| "height": { "type": "fit" } | ||
| }, | ||
| "visible": true, | ||
| "name": "Promo web component" | ||
| } | ||
| """ | ||
|
|
||
| @Test | ||
| fun `deserializes full Khepri schema`() { | ||
| val actual = JsonTools.json.decodeFromString<PaywallComponent>(fullJson) | ||
|
|
||
| assertThat(actual).isInstanceOf(WebViewComponent::class.java) | ||
| val webView = actual as WebViewComponent | ||
|
|
||
| assertThat(webView.id).isEqualTo("promo_web_view") | ||
| assertThat(webView.name).isEqualTo("Promo web component") | ||
| assertThat(webView.visible).isTrue() | ||
| assertThat(webView.protocolVersion).isEqualTo(1) | ||
| assertThat(webView.url).isEqualTo("https://assets.pawwalls.com/web_bundles/123/index.html") | ||
| assertThat(webView.size).isEqualTo(Size(width = SizeConstraint.Fill, height = SizeConstraint.Fit)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `ignores capabilities declared by the schema`() { | ||
| // v1 isolates entirely from external sources via a fixed CSP, so any schema-declared | ||
| // capabilities are decoded-and-ignored rather than failing to parse. | ||
| @Language("json") | ||
| val json = """ | ||
| { | ||
| "type": "web_view", | ||
| "url": "https://paywalls.revenuecat.com/index.html", | ||
| "capabilities": { | ||
| "network_access": { "allowed_domains": ["api.segment.io"] }, | ||
| "camera": true, | ||
| "microphone": true, | ||
| "clipboard_write": true, | ||
| "clipboard_read": true, | ||
| "geolocation": true | ||
| } | ||
| } | ||
| """ | ||
|
|
||
| val actual = JsonTools.json.decodeFromString<PaywallComponent>(json) | ||
|
|
||
| assertEquals( | ||
| WebViewComponent(url = "https://paywalls.revenuecat.com/index.html"), | ||
| actual, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `deserializes template url correctly`() { | ||
| @Language("json") | ||
| val templateJson = """ | ||
| { | ||
| "type": "web_view", | ||
| "protocol_version": 1, | ||
| "url": "https://paywalls.revenuecat.com/{{ custom.animal }}.html" | ||
| } | ||
| """ | ||
|
|
||
| val actual = JsonTools.json.decodeFromString<PaywallComponent>(templateJson) | ||
|
|
||
| assertEquals( | ||
| WebViewComponent( | ||
| url = "https://paywalls.revenuecat.com/{{ custom.animal }}.html", | ||
| protocolVersion = 1, | ||
| ), | ||
| actual, | ||
| ) | ||
| } | ||
|
|
||
| @Test | ||
| fun `deserializes minimal shape with defaults for missing optional fields`() { | ||
| // Older/partial configs may omit protocol_version and size. These should still | ||
| // decode without crashing, using defaults. | ||
| @Language("json") | ||
| val minimalJson = """ | ||
| { | ||
| "type": "web_view", | ||
| "url": "https://paywalls.revenuecat.com/index.html" | ||
| } | ||
| """ | ||
|
|
||
| val actual = JsonTools.json.decodeFromString<PaywallComponent>(minimalJson) | ||
|
|
||
| assertEquals( | ||
| WebViewComponent(url = "https://paywalls.revenuecat.com/index.html"), | ||
| actual, | ||
| ) | ||
| val webView = actual as WebViewComponent | ||
| assertThat(webView.protocolVersion).isNull() | ||
| assertThat(webView.size).isEqualTo(Size(width = SizeConstraint.Fill, height = SizeConstraint.Fit)) | ||
| } | ||
|
|
||
| @Test | ||
| fun `filter treats web_view as a leaf component`() { | ||
| // web_view has no child components, so filtering a tree should return only the component itself. | ||
| val webView = WebViewComponent(url = "https://paywalls.revenuecat.com/index.html") | ||
|
|
||
| val matches = webView.filter { it is WebViewComponent } | ||
|
|
||
| assertThat(matches).containsExactly(webView) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule paywall-preview-resources
updated
from f7be24 to 382820
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are v2 capabilities which we deliberately omitted from the initial release.