-
Notifications
You must be signed in to change notification settings - Fork 14
feat(MSDK-3261): add storage info and sdks field to ConsentDisclosure… #182
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -88,7 +88,8 @@ internal object GetCMPDataMock { | |
| domain = "domain", | ||
| description = "description", | ||
| ) | ||
| ) | ||
| ), | ||
| sdks = listOf() | ||
| ), | ||
| isHidden = false, | ||
| ) | ||
|
|
@@ -628,17 +629,20 @@ internal object GetCMPDataMock { | |
| "isDeactivated" to false, | ||
| "disableLegalBasis" to false, | ||
| "technologyUsed" to listOf("Cookies", "Pixel Tags"), | ||
| "deviceStorage" to listOf( | ||
| mapOf( | ||
| "identifier" to "identifier", | ||
| "type" to 2, | ||
| "name" to "name", | ||
| "maxAgeSeconds" to 123123L, | ||
| "cookieRefresh" to true, | ||
| "purposes" to listOf(1, 2, 3), | ||
| "domain" to "domain", | ||
| "description" to "description", | ||
| ) | ||
| "deviceStorage" to mapOf( | ||
| "disclosures" to listOf( | ||
| mapOf( | ||
| "identifier" to "identifier", | ||
| "type" to 2, | ||
| "name" to "name", | ||
| "maxAgeSeconds" to 123123L, | ||
| "cookieRefresh" to true, | ||
| "purposes" to listOf(1, 2, 3), | ||
| "domain" to "domain", | ||
| "description" to "description", | ||
| ) | ||
| ), | ||
| "sdks" to emptyList<Map<String, Any>>() | ||
| ), | ||
|
Comment on lines
+632
to
646
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [REFACTORING] In the expected map you changed "deviceStorage" from a list of maps to a single map with keys "disclosures" and "sdks". Confirm the code that consumes this expected map (test verification code) is updated accordingly. If many tests expect the old list shape, consider adding a small migration helper in tests to transform the new object into the older shape for backward-compatible assertions while the rest of the codebase is updated. |
||
| "isHidden" to false, | ||
| ) | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,12 +2,23 @@ package com.usercentrics.reactnative.extensions | |
|
|
||
| import com.usercentrics.sdk.v2.settings.data.ConsentDisclosure | ||
| import com.usercentrics.sdk.v2.settings.data.ConsentDisclosureObject | ||
| import com.usercentrics.sdk.v2.settings.data.ConsentDisclosureSDK | ||
|
|
||
| internal fun ConsentDisclosureObject?.serialize(): Any? { | ||
| if (this == null) { | ||
| return null | ||
| } | ||
| return disclosures.map { it.serialize() } | ||
| return mapOf( | ||
| "disclosures" to disclosures.map { it.serialize() }, | ||
| "sdks" to sdks.map { it.serialize() } | ||
| ) | ||
| } | ||
|
|
||
| private fun ConsentDisclosureSDK.serialize(): Map<String, Any> { | ||
| return mapOf( | ||
| "name" to name, | ||
| "use" to use | ||
| ) | ||
|
Comment on lines
+11
to
+21
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [VALIDATION] serialize() now serializes sdks unguarded: sdks.map { it.serialize() }. If ConsentDisclosureObject.sdks can be null, this will throw an NPE. Make this null-safe and preserve an empty list if absent: "sdks" to (sdks?.map { it.serialize() } ?: emptyList()). Also consider whether the nested structures need conversion to WritableMap at this level or are handled by the caller. import com.usercentrics.sdk.v2.settings.data.ConsentDisclosure
import com.usercentrics.sdk.v2.settings.data.ConsentDisclosureObject
import com.usercentrics.sdk.v2.settings.data.ConsentDisclosureSDK
internal fun ConsentDisclosureObject?.serialize(): Any? {
if (this == null) return null
return mapOf(
"disclosures" to disclosures.map { it.serialize() },
"sdks" to (sdks?.map { it.serialize() } ?: emptyList())
)
}
private fun ConsentDisclosureSDK.serialize(): Map<String, Any> {
return mapOf(
"name" to name,
"use" to use
)
} |
||
| } | ||
|
|
||
| internal fun ConsentDisclosure.serialize(): Any { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -364,7 +364,10 @@ extension UsercentricsService { | |
|
|
||
| extension ConsentDisclosureObject { | ||
| func toDictionary() -> Any { | ||
| return self.disclosures.map { $0.toDictionary() } | ||
| return [ | ||
| "disclosures": self.disclosures.map { $0.toDictionary() }, | ||
| "sdks": self.sdks.map { ["name": $0.name, "use": $0.use] } | ||
| ] | ||
|
Comment on lines
+367
to
+370
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [CRITICAL_BUG] You changed ConsentDisclosureObject.toDictionary() from returning an array of disclosures to returning a Dictionary with keys "disclosures" and "sdks". This is a breaking shape change for any consumers that previously expected an array. Either: 1) Ensure all call sites / JS/native bridge logic were updated to expect an object with keys {disclosures, sdks}; or 2) keep backward compatible shape (e.g. return the array for old callers and add a separate field or version). Additionally guard sdks for nil to avoid crashes: "sdks": self.sdks?.map { ["name": $0.name, "use": $0.use] } ?? [] extension ConsentDisclosureObject {
func toDictionary() -> Any {
return [
"disclosures": self.disclosures.map { $0.toDictionary() },
"sdks": (self.sdks ?? []).map { [
"name": $0.name as Any,
"use": $0.use as Any
]]
]
}
} |
||
| } | ||
| } | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -268,7 +268,8 @@ const disclosure: ConsentDisclosure = { | |
| } | ||
|
|
||
| const consentDisclosureObject: ConsentDisclosureObject = { | ||
| disclosures: [disclosure] | ||
| disclosures: [disclosure], | ||
| sdks: [], | ||
| } | ||
|
Comment on lines
+271
to
273
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [REFACTORING] You added sdks: [] to the test ConsentDisclosureObject fixture. After fixing the model types (see src/models/ConsentDisclosureObject.tsx), update this fixture's typing (if typings are enforced) to match ConsentDisclosureSDK[] and, if useful, add a minimal SDK entry to exercise serialization paths in tests (e.g. { name: 'sdkName', use: 'purpose' }). const consentDisclosureObject: ConsentDisclosureObject = {
disclosures: [disclosure],
sdks: [
{
name: "sdkName",
use: "purpose",
},
],
} |
||
|
|
||
| const ucService: UsercentricsService = { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,21 @@ | ||
| export class ConsentDisclosureSDK { | ||
| name: string | ||
| use: string | ||
|
|
||
| constructor(name: string, use: string) { | ||
| this.name = name | ||
| this.use = use | ||
| } | ||
| } | ||
|
|
||
| export class ConsentDisclosureObject { | ||
|
|
||
| disclosures: [ConsentDisclosure] | ||
| sdks: ConsentDisclosureSDK[] | ||
|
|
||
| constructor(disclosures: [ConsentDisclosure]) { | ||
| constructor(disclosures: [ConsentDisclosure], sdks?: ConsentDisclosureSDK[]) { | ||
| this.disclosures = disclosures | ||
| this.sdks = sdks ?? [] | ||
| } | ||
|
Comment on lines
11
to
19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 1. Ts sdks typed as tuple ConsentDisclosureObject.sdks is typed as a 1-element tuple ([ConsentDisclosureSDK]) even though the native payload is a variable-length list (including empty). This makes the published TypeScript API incorrect and can break consumers that have 0 or multiple SDK entries. Agent Prompt
|
||
| } | ||
|
|
||
|
|
||
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.
[VALIDATION] Mocks were updated to add sdks = listOf() inside ConsentDisclosureObject and the expected map for "deviceStorage" changed from a list to a map with keys disclosures/sdks. Ensure all test assertions and any other mock consumers are updated to the new structure. Also verify the real SDK's ConsentDisclosureObject constructor supports the new sdks parameter; otherwise tests will not compile.