Skip to content
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

DIA-2621 add usnat to /meta-data #508

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ConsentViewController/Classes/Consents/SPCCPAConsent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ protocol CampaignConsent {

override open var description: String {
"""
UserConsent(
SPCCPAConsent(
- uuid: \(uuid ?? "")
- status: \(status.rawValue)
- rejectedVendors: \(rejectedVendors)
Expand Down
61 changes: 61 additions & 0 deletions ConsentViewController/Classes/Consents/SPUSNatConsent.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//
// SPUSNatConsent.swift
// Pods
//
// Created by Andre Herculano on 02.11.23.
//

import Foundation

@objcMembers public class SPUSNatConsent: NSObject, Codable, CampaignConsent, NSCopying {
var uuid: String?

var applies: Bool

var dateCreated: SPDate

/// Used by the rendering app
var webConsentPayload: SPWebConsentPayload?

override open var description: String {
"""
SPUSNatConsent(
- uuid: \(uuid ?? "")
- applies: \(applies)
- dateCreated: \(dateCreated)
)
"""
}

init(
uuid: String? = nil,
applies: Bool,
dateCreated: SPDate,
webConsentPayload: SPWebConsentPayload? = nil
) {
self.uuid = uuid
self.applies = applies
self.dateCreated = dateCreated
}

public static func empty() -> SPUSNatConsent { SPUSNatConsent(
applies: false,
dateCreated: .now()
)}

override public func isEqual(_ object: Any?) -> Bool {
if let other = object as? SPUSNatConsent {
return other.uuid == uuid &&
other.applies == applies
} else {
return false
}
}

public func copy(with zone: NSZone? = nil) -> Any { SPUSNatConsent(
uuid: uuid,
applies: applies,
dateCreated: dateCreated,
webConsentPayload: webConsentPayload
)}
}
45 changes: 34 additions & 11 deletions ConsentViewController/Classes/Consents/SPUserData.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ public struct SPWebConsents: Codable, Equatable {
}
}

let gdpr: SPWebConsent?
let ccpa: SPWebConsent?
let gdpr, ccpa, usnat: SPWebConsent?

public init(gdpr: SPWebConsent? = nil, ccpa: SPWebConsent? = nil) {
public init(gdpr: SPWebConsent? = nil, ccpa: SPWebConsent? = nil, usnat: SPWebConsent? = nil) {
self.gdpr = gdpr
self.ccpa = ccpa
self.usnat = usnat
}
}

public class SPConsent<ConsentType: Codable & Equatable & NSCopying>: NSObject, Codable, NSCopying {
/// The consents data. See: `SPGDPRConsent`, `SPCCPAConsent`
/// The consents data. See: `SPGDPRConsent`, `SPCCPAConsent`, `SPUSNatConsent`
public let consents: ConsentType?

// swiftlint:disable:next todo
Expand Down Expand Up @@ -66,27 +66,35 @@ public class SPConsent<ConsentType: Codable & Equatable & NSCopying>: NSObject,
/// - SeeAlso: `SPCCPAConsent`
public let ccpa: SPConsent<SPCCPAConsent>?

/// Consent data for USNat. This attribute will be nil if your setup doesn't include a CCPA campaign
/// - SeeAlso: `SPUSNatConsent`
public let usnat: SPConsent<SPUSNatConsent>?

var webConsents: SPWebConsents { SPWebConsents(
gdpr: .init(uuid: gdpr?.consents?.uuid, webConsentPayload: gdpr?.consents?.webConsentPayload),
ccpa: .init(uuid: ccpa?.consents?.uuid, webConsentPayload: ccpa?.consents?.webConsentPayload)
ccpa: .init(uuid: ccpa?.consents?.uuid, webConsentPayload: ccpa?.consents?.webConsentPayload),
usnat: .init(uuid: usnat?.consents?.uuid, webConsentPayload: usnat?.consents?.webConsentPayload)
)}

override public var description: String {
"gdpr: \(String(describing: gdpr)), ccpa: \(String(describing: ccpa))"
"gdpr: \(String(describing: gdpr)), ccpa: \(String(describing: ccpa)), usnat: \(String(describing: usnat))"
}

public init(
gdpr: SPConsent<SPGDPRConsent>? = nil,
ccpa: SPConsent<SPCCPAConsent>? = nil
ccpa: SPConsent<SPCCPAConsent>? = nil,
usnat: SPConsent<SPUSNatConsent>? = nil
) {
self.gdpr = gdpr
self.ccpa = ccpa
self.usnat = usnat
}

public func copy(with zone: NSZone? = nil) -> Any {
SPUserData(
gdpr: gdpr?.copy() as? SPConsent<SPGDPRConsent>,
ccpa: ccpa?.copy() as? SPConsent<SPCCPAConsent>
ccpa: ccpa?.copy() as? SPConsent<SPCCPAConsent>,
usnat: usnat?.copy() as? SPConsent<SPUSNatConsent>
)
}

Expand All @@ -95,7 +103,9 @@ public class SPConsent<ConsentType: Codable & Equatable & NSCopying>: NSObject,
return gdpr?.applies == object.gdpr?.applies &&
gdpr?.consents == object.gdpr?.consents &&
ccpa?.applies == object.ccpa?.applies &&
ccpa?.consents == object.ccpa?.consents
ccpa?.consents == object.ccpa?.consents &&
usnat?.applies == object.usnat?.applies &&
usnat?.consents == object.usnat?.consents
} else {
return false
}
Expand All @@ -107,6 +117,8 @@ public protocol SPObjcUserData {
func objcGDPRApplies() -> Bool
func objcCCPAConsents() -> SPCCPAConsent?
func objcCCPAApplies() -> Bool
func objcUSNatConsents() -> SPUSNatConsent?
func objcUSNatApplies() -> Bool
}

@objc extension SPUserData: SPObjcUserData {
Expand All @@ -121,14 +133,25 @@ public protocol SPObjcUserData {
gdpr?.applies ?? false
}

/// Returns GDPR consent data if any available.
/// Returns CCPA consent data if any available.
/// - SeeAlso: `SPCCPAConsent`
public func objcCCPAConsents() -> SPCCPAConsent? {
ccpa?.consents
}

/// Indicates whether GDPR applies based on the VendorList configuration.
/// Indicates whether CCPA applies based on the VendorList configuration.
public func objcCCPAApplies() -> Bool {
ccpa?.applies ?? false
}

/// Returns USNat consent data if any available.
/// - SeeAlso: `SPUSNatConsent`
public func objcUSNatConsents() -> SPUSNatConsent? {
usnat?.consents
}

/// Indicates whether USNat applies based on the VendorList configuration.
public func objcUSNatApplies() -> Bool {
usnat?.applies ?? false
}
}
6 changes: 4 additions & 2 deletions ConsentViewController/Classes/SPCampaigns.swift
Original file line number Diff line number Diff line change
Expand Up @@ -99,18 +99,18 @@ public typealias SPTargetingParams = [String: String]
}
}

/// Set `gdpr` and/or `ccpa` if you wish to cover any of those legislations.
/// It's important to notice the campaign you passed as parameter needs to have
/// a active vendor list of that legislation.
@objcMembers public class SPCampaigns: NSObject {
public let environment: SPCampaignEnv
public let gdpr, ccpa, ios14: SPCampaign?
public let gdpr, ccpa, usnat, ios14: SPCampaign?

override public var description: String {
"""
SPCampaigns
- gdpr: \(gdpr as Any)
- cppa: \(ccpa as Any)
- usnat: \(usnat as Any)
- ios14: \(ios14 as Any)
- environment: \(environment)
"""
Expand All @@ -119,11 +119,13 @@ public typealias SPTargetingParams = [String: String]
public init(
gdpr: SPCampaign? = nil,
ccpa: SPCampaign? = nil,
usnat: SPCampaign? = nil,
ios14: SPCampaign? = nil,
environment: SPCampaignEnv = .Public
) {
self.gdpr = gdpr
self.ccpa = ccpa
self.usnat = usnat
self.ios14 = ios14
self.environment = environment
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,27 @@ struct MetaDataResponse: Decodable, Equatable {
struct GDPR: Decodable, Equatable {
let additionsChangeDate: SPDate
let legalBasisChangeDate: SPDate
let version: Int
let _id: String
let childPmId: String?
let applies: Bool
let sampleRate: Float
}
struct USNat: Decodable, Equatable {
let _id: String
let additionsChangeDate: SPDate
let applies: Bool
let sampleRate: Float
}

let ccpa: CCPA?
let gdpr: GDPR?
let usnat: USNat?
}

struct MetaDataQueryParam: QueryParamEncodable {
struct Campaign: Encodable {
let groupPmId: String?
}

let gdpr, ccpa: Campaign?
let gdpr, ccpa, usnat: Campaign?
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,25 @@ class SourcepointClientCoordinator: SPClientCoordinator {
var wasSampledAt: Float?
}

struct UsNatMetaData: Codable, SPSampleable, Equatable {
var additionsChangeDate = SPDate.now()
var sampleRate = Float(1)
var wasSampled: Bool?
var wasSampledAt: Float?
}

struct AttCampaign: Codable {
var lastMessage: LastMessageData?
var status: SPIDFAStatus { SPIDFAStatus.current() }
}

var gdpr: SPGDPRConsent?
var ccpa: SPCCPAConsent?
var usnat: SPUSNatConsent?
var ios14: AttCampaign?
var gdprMetaData: GDPRMetaData?
var ccpaMetaData: CCPAMetaData?
var usNatMetaData: UsNatMetaData?
var localState: SPJson?
var nonKeyedLocalState: SPJson?
var storedAuthId: String?
Expand Down Expand Up @@ -185,14 +194,19 @@ class SourcepointClientCoordinator: SPClientCoordinator {
var metaDataParamsFromState: MetaDataQueryParam {
.init(
gdpr: campaigns.gdpr != nil ?
.init(
groupPmId: campaigns.gdpr?.groupPmId
) :
nil,
.init(
groupPmId: campaigns.gdpr?.groupPmId
) :
nil,
ccpa: campaigns.ccpa != nil ?
.init(
groupPmId: campaigns.ccpa?.groupPmId
) :
nil,
usnat: campaigns.usnat != nil ?
.init(
groupPmId: campaigns.usnat?.groupPmId
) :
nil
)
}
Expand Down Expand Up @@ -240,6 +254,9 @@ class SourcepointClientCoordinator: SPClientCoordinator {
nil,
ccpa: campaigns.ccpa != nil ?
.init(consents: state.ccpa, applies: state.ccpa?.applies ?? false) :
nil,
usnat: campaigns.usnat != nil ?
.init(consents: state.usnat, applies: state.usnat?.applies ?? false) :
nil
)
}
Expand Down Expand Up @@ -285,6 +302,11 @@ class SourcepointClientCoordinator: SPClientCoordinator {
localState.ccpa?.applies = localStorage.userData.ccpa?.applies ?? false
localState.ccpaMetaData = .init()
}
if localCampaigns.usnat != nil, localState.usnat == nil {
localState.usnat = localStorage.userData.usnat?.consents ?? .empty()
localState.usnat?.applies = localStorage.userData.usnat?.applies ?? false
localState.usNatMetaData = .init()
}
if localCampaigns.ios14 != nil, localState.ios14 == nil {
localState.ios14 = .init()
}
Expand Down Expand Up @@ -393,6 +415,10 @@ class SourcepointClientCoordinator: SPClientCoordinator {
state.ccpa?.applies = ccpaMetaData.applies
state.ccpaMetaData?.updateSampleFields(ccpaMetaData.sampleRate)
}
if let usnatMetaData = response.usnat {
state.usnat?.applies = usnatMetaData.applies
state.usNatMetaData?.updateSampleFields(usnatMetaData.sampleRate)
}
storage.spState = state
}

Expand Down
4 changes: 4 additions & 0 deletions Example/ConsentViewController.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,7 @@
82EA4E362491328A00DC01C9 /* InMemoryStorageMock.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82EA4E352491328A00DC01C9 /* InMemoryStorageMock.swift */; };
82EA4FA42488EB7300BA48BF /* SPUserDefaultsSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82ACF6AB2487E73C006E207A /* SPUserDefaultsSpec.swift */; };
82EA4FA62489171200BA48BF /* UserDefaultsExtensionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82EA4FA52489171200BA48BF /* UserDefaultsExtensionSpec.swift */; };
82F136452AF3E78A0047A6F8 /* SPUSNatConsentSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82F136442AF3E78A0047A6F8 /* SPUSNatConsentSpec.swift */; };
82F9411824A10379007D30B1 /* CustomMatchers.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82F9411724A10379007D30B1 /* CustomMatchers.swift */; };
82F9411A24A10416007D30B1 /* ExampleApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82F9411924A10416007D30B1 /* ExampleApp.swift */; };
82FA47732A3C90DC0065BF6D /* SPPublisherDataSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 82FA47722A3C90DC0065BF6D /* SPPublisherDataSpec.swift */; };
Expand Down Expand Up @@ -741,6 +742,7 @@
82EA4E332491324400DC01C9 /* LocalStorageMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = LocalStorageMock.swift; path = Helpers/LocalStorageMock.swift; sourceTree = "<group>"; };
82EA4E352491328A00DC01C9 /* InMemoryStorageMock.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = InMemoryStorageMock.swift; path = Helpers/InMemoryStorageMock.swift; sourceTree = "<group>"; };
82EA4FA52489171200BA48BF /* UserDefaultsExtensionSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UserDefaultsExtensionSpec.swift; sourceTree = "<group>"; };
82F136442AF3E78A0047A6F8 /* SPUSNatConsentSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPUSNatConsentSpec.swift; sourceTree = "<group>"; };
82F9411724A10379007D30B1 /* CustomMatchers.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomMatchers.swift; sourceTree = "<group>"; };
82F9411924A10416007D30B1 /* ExampleApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ExampleApp.swift; sourceTree = "<group>"; };
82FA47722A3C90DC0065BF6D /* SPPublisherDataSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SPPublisherDataSpec.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1929,6 +1931,7 @@
AAA25A682A28ABFE005FE84A /* SPConsentManagerSpec.swift */,
822E88F52A7BC5AF00843B2B /* IncludeDataSpec.swift */,
822E88F72A7BC8CB00843B2B /* SPGPPConfigSpec.swift */,
82F136442AF3E78A0047A6F8 /* SPUSNatConsentSpec.swift */,
);
path = ConsentViewController_ExampleTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -3561,6 +3564,7 @@
82BB0E6A28BF3433006FBB60 /* SPDateCreatedSpec.swift in Sources */,
822E88F82A7BC8CB00843B2B /* SPGPPConfigSpec.swift in Sources */,
6D687AD724A8F1C1001DFB11 /* MessageMock.swift in Sources */,
82F136452AF3E78A0047A6F8 /* SPUSNatConsentSpec.swift in Sources */,
82665C312444ECF600CCE738 /* SPJsonSpec.swift in Sources */,
82EA4E32249101EC00DC01C9 /* SourcePointClientMock.swift in Sources */,
826D31B1249A46C40026A6B9 /* GDPRUIiDelegateMock.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ class SourcePointClientMock: SourcePointProtocol {
if let error = error {
handler(.failure(error))
} else {
handler(.success(.init(ccpa: nil, gdpr: nil)))
handler(.success(.init(ccpa: nil, gdpr: nil, usnat: nil)))
}
}

Expand Down
Loading