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

SP-8654 fix SPM build #360

Merged
merged 7 commits into from
Feb 1, 2022
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
15 changes: 14 additions & 1 deletion .github/workflows/swift.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Swift
name: Test
on:
workflow_dispatch:
push:
Expand All @@ -15,6 +15,19 @@ jobs:
- uses: actions/checkout@v2
- name: linting
run: swiftlint lint
BuildSwiftPackage:
runs-on: macos-11
steps:
- uses: actions/checkout@v2
- name: Select Xcode version 13.0
run: sudo xcode-select -s '/Applications/Xcode_13.0.app/Contents/Developer'
- name: Building Swift Package
run: xcodebuild clean build -scheme SPMBuild -workspace ConsentViewController.xcworkspace -destination 'platform=iOS Simulator,name=iPhone 13 Pro Max,OS=15.0' CODE_SIGN_IDENTITY="" CODE_SIGNING_REQUIRED=NO CODE_SIGN_ENTITLEMENTS="" CODE_SIGNING_ALLOWED="NO"
- uses: actions/upload-artifact@v2
if: failure()
name: Upload ObjCExampleApp tests results
with:
path: /Users/runner/Library/Developer/Xcode/DerivedData/**/*.xcresult
ObjC-ExampleApp-tests:
runs-on: macos-11
steps:
Expand Down
46 changes: 29 additions & 17 deletions ConsentViewController/Classes/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,37 @@
//

import Foundation
import UIKit

protocol SPUIValues {
static var defaultFallbackTextColorForDarkMode: UIColor { get }
}

let prod = (Bundle.framework.object(forInfoDictionaryKey: "SPEnv") as? String) != "staging"

struct Constants {
static let envParam = prod ? "prod" : "stage"
static let SP_ROOT = URL(string: prod ? "https://cdn.privacy-mgmt.com/" : "https://cdn.sp-stage.net/")!
static let WRAPPER_API = URL(string: "./wrapper/", relativeTo: SP_ROOT)!
static let GDPR_MESSAGE_URL = URL(string: "./v2/message/gdpr", relativeTo: WRAPPER_API)!
static let CCPA_MESSAGE_URL = URL(string: "./v2/message/ccpa", relativeTo: WRAPPER_API)!
static let ERROR_METRIS_URL = URL(string: "./metrics/v1/custom-metrics", relativeTo: WRAPPER_API)!
static let GET_MESSAGES_URL = URL(string: "./v2/get_messages/?env=\(envParam)", relativeTo: WRAPPER_API)!
static let GDPR_CONSENT_URL = URL(string: "./v2/messages/choice/gdpr/", relativeTo: WRAPPER_API)!
static let CCPA_CONSENT_URL = URL(string: "./v2/messages/choice/ccpa/", relativeTo: WRAPPER_API)!
static let IDFA_RERPORT_URL = URL(string: "./metrics/v1/apple-tracking?env=\(envParam)", relativeTo: WRAPPER_API)!
static let CUSTOM_CONSENT_URL = URL(string: "./tcfv2/v1/gdpr/custom-consent?env=\(envParam)&inApp=true", relativeTo: WRAPPER_API)!
static let MMS_MESSAGE_URL = URL(string: "./mms/v2/message", relativeTo: SP_ROOT)!
static let GDPR_PRIVACY_MANAGER_VIEW_URL = URL(string: "./consent/tcfv2/privacy-manager/privacy-manager-view", relativeTo: SP_ROOT)!
static let CCPA_PRIVACY_MANAGER_VIEW_URL = URL(string: "./ccpa/privacy-manager/privacy-manager-view", relativeTo: SP_ROOT)!
static let CCPA_PM_URL = URL(string: "./ccpa_pm/index.html", relativeTo: SP_ROOT)!
static let GDPR_PM_URL = URL(string: "./privacy-manager/index.html", relativeTo: SP_ROOT)!
static let defaultFallbackTextColorForDarkMode: UIColor = .black
struct Urls {
static let envParam = prod ? "prod" : "stage"
static let SP_ROOT = URL(string: prod ? "https://cdn.privacy-mgmt.com/" : "https://cdn.sp-stage.net/")!
static let WRAPPER_API = URL(string: "./wrapper/", relativeTo: SP_ROOT)!
static let GDPR_MESSAGE_URL = URL(string: "./v2/message/gdpr", relativeTo: WRAPPER_API)!
static let CCPA_MESSAGE_URL = URL(string: "./v2/message/ccpa", relativeTo: WRAPPER_API)!
static let ERROR_METRIS_URL = URL(string: "./metrics/v1/custom-metrics", relativeTo: WRAPPER_API)!
static let GET_MESSAGES_URL = URL(string: "./v2/get_messages/?env=\(envParam)", relativeTo: WRAPPER_API)!
static let GDPR_CONSENT_URL = URL(string: "./v2/messages/choice/gdpr/", relativeTo: WRAPPER_API)!
static let CCPA_CONSENT_URL = URL(string: "./v2/messages/choice/ccpa/", relativeTo: WRAPPER_API)!
static let IDFA_RERPORT_URL = URL(string: "./metrics/v1/apple-tracking?env=\(envParam)", relativeTo: WRAPPER_API)!
static let CUSTOM_CONSENT_URL = URL(string: "./tcfv2/v1/gdpr/custom-consent?env=\(envParam)&inApp=true", relativeTo: WRAPPER_API)!
static let MMS_MESSAGE_URL = URL(string: "./mms/v2/message", relativeTo: SP_ROOT)!
static let GDPR_PRIVACY_MANAGER_VIEW_URL = URL(string: "./consent/tcfv2/privacy-manager/privacy-manager-view", relativeTo: SP_ROOT)!
static let CCPA_PRIVACY_MANAGER_VIEW_URL = URL(string: "./ccpa/privacy-manager/privacy-manager-view", relativeTo: SP_ROOT)!
static let CCPA_PM_URL = URL(string: "./ccpa_pm/index.html", relativeTo: SP_ROOT)!
static let GDPR_PM_URL = URL(string: "./privacy-manager/index.html", relativeTo: SP_ROOT)!
}

struct UI {
struct DarkMode: SPUIValues {
static var defaultFallbackTextColorForDarkMode: UIColor { .black }
}
}
}
4 changes: 2 additions & 2 deletions ConsentViewController/Classes/SPConsentManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ import UIKit
public func loadGDPRPrivacyManager(withId id: String, tab: SPPrivacyManagerTab = .Default) {
messagesToShow += 1
#if os(iOS)
guard let pmUrl = Constants.GDPR_PM_URL.appendQueryItems([
guard let pmUrl = Constants.Urls.GDPR_PM_URL.appendQueryItems([
"message_id": id,
"pmTab": tab.rawValue,
"consentUUID": gdprUUID,
Expand Down Expand Up @@ -350,7 +350,7 @@ import UIKit
public func loadCCPAPrivacyManager(withId id: String, tab: SPPrivacyManagerTab = .Default) {
messagesToShow += 1
#if os(iOS)
guard let pmUrl = Constants.CCPA_PM_URL.appendQueryItems([
guard let pmUrl = Constants.Urls.CCPA_PM_URL.appendQueryItems([
"message_id": id,
"pmTab": tab.rawValue,
"ccpaUUID": ccpaUUID,
Expand Down
2 changes: 1 addition & 1 deletion ConsentViewController/Classes/SPNativeMessage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ import Foundation
try container.encode(choiceType, forKey: .choiceType)
}

enum CodingKeys: String, CodingKey { // swiftlint:disable:this nesting
enum CodingKeys: String, CodingKey {
case text, style, customFields, choiceType, url
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct GDPRVendor: Decodable {
let vendorType: VendorType
let consentCategories, legIntCategories: [Category]
let iabSpecialPurposes, iabFeatures, iabSpecialFeatures: [String]

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: Keys.self)
name = try container.decode(String.self, forKey: .name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
import Foundation
import UIKit

// swiftlint:disable nesting

@objcMembers class SPNativeFont: NSObject, Codable {
let fontSize: CGFloat
let fontWeight: String
Expand Down Expand Up @@ -164,7 +162,7 @@ class SPNativeButton: SPNativeUI {
class SPNativeImage: SPNativeUI {
class Settings: SPNativeUISettings {
let src: URL?

required init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: Keys.self)
src = try? container.decodeIfPresent(URL.self, forKey: .url) ?? (try? container.decodeIfPresent(URL.self, forKey: .src))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Foundation
let vendorId: String?
let policyUrl: URL?
let vendorType: GDPRVendor.VendorType?

init(from decoder: Decoder) throws {
let container = try decoder.container(keyedBy: Keys.self)
name = try container.decode(String.self, forKey: .name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ class SourcePointClient: SourcePointProtocol {
consentLanguage: consentLanguage,
campaigns: CampaignsRequest(from: campaigns)
)).map { body in
client.post(urlString: Constants.GET_MESSAGES_URL.absoluteString, body: body) { result in
client.post(urlString: Constants.Urls.GET_MESSAGES_URL.absoluteString, body: body) { result in
handler(Result {
try result.decoded() as MessagesResponse
}.mapError({
Expand All @@ -184,8 +184,8 @@ class SourcePointClient: SourcePointProtocol {
messageId: String,
handler: @escaping MessageHandler
) {
let url = Constants.GDPR_MESSAGE_URL.appendQueryItems([
"env": Constants.envParam,
let url = Constants.Urls.GDPR_MESSAGE_URL.appendQueryItems([
"env": Constants.Urls.envParam,
"consentLanguage": consentLanguage.rawValue,
"propertyId": propertyId,
"messageId": messageId,
Expand All @@ -206,8 +206,8 @@ class SourcePointClient: SourcePointProtocol {
messageId: String,
handler: @escaping MessageHandler
) {
let url = Constants.CCPA_MESSAGE_URL.appendQueryItems([
"env": Constants.envParam,
let url = Constants.Urls.CCPA_MESSAGE_URL.appendQueryItems([
"env": Constants.Urls.envParam,
"consentLanguage": consentLanguage.rawValue,
"propertyId": propertyId,
"messageId": messageId
Expand All @@ -222,7 +222,7 @@ class SourcePointClient: SourcePointProtocol {
}

func gdprPrivacyManagerView(propertyId: Int, consentLanguage: SPMessageLanguage, handler: @escaping GDPRPrivacyManagerViewHandler) {
let url = Constants.GDPR_PRIVACY_MANAGER_VIEW_URL.appendQueryItems([
let url = Constants.Urls.GDPR_PRIVACY_MANAGER_VIEW_URL.appendQueryItems([
"siteId": String(propertyId),
"consentLanguage": consentLanguage.rawValue
])!
Expand All @@ -236,7 +236,7 @@ class SourcePointClient: SourcePointProtocol {
}

func ccpaPrivacyManagerView(propertyId: Int, consentLanguage: SPMessageLanguage, handler: @escaping CCPAPrivacyManagerViewHandler) {
let url = Constants.CCPA_PRIVACY_MANAGER_VIEW_URL.appendQueryItems([
let url = Constants.Urls.CCPA_PRIVACY_MANAGER_VIEW_URL.appendQueryItems([
"siteId": String(propertyId),
"consentLanguage": consentLanguage.rawValue
])!
Expand All @@ -253,7 +253,7 @@ class SourcePointClient: SourcePointProtocol {
guard let actionUrl = URL(string: "\(actionType.rawValue)") else { return nil }

var components = URLComponents(url: actionUrl, resolvingAgainstBaseURL: true)
components?.queryItems = [URLQueryItem(name: "env", value: Constants.envParam)]
components?.queryItems = [URLQueryItem(name: "env", value: Constants.Urls.envParam)]
return components?.url(relativeTo: baseUrl)
}

Expand All @@ -265,7 +265,7 @@ class SourcePointClient: SourcePointProtocol {
pmSaveAndExitVariables: action.pmPayload,
requestUUID: requestUUID
)).map { body in
client.post(urlString: consentUrl(Constants.CCPA_CONSENT_URL, action.type)!.absoluteString, body: body) { result in
client.post(urlString: consentUrl(Constants.Urls.CCPA_CONSENT_URL, action.type)!.absoluteString, body: body) { result in
handler(Result {
let response = try result.decoded() as ConsentResponse
switch response.userConsent {
Expand All @@ -288,7 +288,7 @@ class SourcePointClient: SourcePointProtocol {
publisherData: action.publisherData,
requestUUID: requestUUID
)).map { body in
client.post(urlString: consentUrl(Constants.GDPR_CONSENT_URL, action.type)!.absoluteString, body: body) { result in
client.post(urlString: consentUrl(Constants.Urls.GDPR_CONSENT_URL, action.type)!.absoluteString, body: body) { result in
handler(Result {
let response = try result.decoded() as ConsentResponse
switch response.userConsent {
Expand All @@ -312,7 +312,7 @@ class SourcePointClient: SourcePointProtocol {
iosVersion: iosVersion,
appleTracking: AppleTrackingPayload(appleChoice: idfaStatus, appleMsgId: messageId, messagePartitionUUID: partitionUUID)
)).map {
client.post(urlString: Constants.IDFA_RERPORT_URL.absoluteString, body: $0) { _ in }
client.post(urlString: Constants.Urls.IDFA_RERPORT_URL.absoluteString, body: $0) { _ in }
}
}

Expand All @@ -330,7 +330,7 @@ class SourcePointClient: SourcePointProtocol {
categories: categories,
legIntCategories: legIntCategories
)).map { body in
client.post(urlString: Constants.CUSTOM_CONSENT_URL.absoluteString, body: body) { result in
client.post(urlString: Constants.Urls.CUSTOM_CONSENT_URL.absoluteString, body: body) { result in
handler(Result {
try result.decoded() as CustomConsentResponse
}.mapError {
Expand Down Expand Up @@ -359,7 +359,7 @@ class SourcePointClient: SourcePointProtocol {
propertyName: propertyName,
campaignType: campaignType
)).map {
client.post(urlString: Constants.ERROR_METRIS_URL.absoluteString, body: $0) { _ in }
client.post(urlString: Constants.Urls.ERROR_METRIS_URL.absoluteString, body: $0) { _ in }
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ extension UILabel {
func setDefaultTextColorForDarkMode() {
if #available(tvOS 13.0, *) {
if UITraitCollection.current.userInterfaceStyle == .dark {
self.textColor = Constants.defaultFallbackTextColorForDarkMode
self.textColor = Constants.UI.DarkMode.defaultFallbackTextColorForDarkMode
}
}
}
Expand Down
6 changes: 6 additions & 0 deletions Example/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,9 @@ identifier_name:
line_length:
warning: 180
error: 220
type_name:
min_length:
warning: 1
nesting:
type_level:
warning: 3
Loading