diff --git a/Risk.podspec b/Risk.podspec index 7267e91..1b4eba8 100644 --- a/Risk.podspec +++ b/Risk.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "Risk" - s.version = "2.0.3" + s.version = "3.0.0" s.summary = "Checkout Risk package in Swift" s.description = <<-DESC Checkout Risk package in Swift. diff --git a/Sources/Risk/Logging/Constants.swift b/Sources/Risk/Logging/Constants.swift index d0f6a7c..045ff5d 100644 --- a/Sources/Risk/Logging/Constants.swift +++ b/Sources/Risk/Logging/Constants.swift @@ -9,7 +9,7 @@ import Foundation enum Constants { static let productName = "risk-ios-sdk" - static let riskSdkVersion = "2.0.3" + static let riskSdkVersion = "3.0.0" static let userAgent = "checkout-sdk-risk-ios/\(riskSdkVersion)" static let loggerTypeIdentifier = "com.checkout.risk-mobile-sdk" } diff --git a/Sources/Risk/Logging/LoggerService.swift b/Sources/Risk/Logging/LoggerService.swift index 43742fd..145e69d 100644 --- a/Sources/Risk/Logging/LoggerService.swift +++ b/Sources/Risk/Logging/LoggerService.swift @@ -50,6 +50,7 @@ extension LoggerServiceProtocol { let maskedPublicKey = getMaskedPublicKey(publicKey: internalConfig.merchantPublicKey) let ddTags = getDDTags(environment: internalConfig.environment.rawValue) var monitoringLevel: MonitoringLevel + let framesMode = internalConfig.framesOptions != nil let properties: [String: AnyCodable] switch riskEvent { @@ -69,13 +70,12 @@ extension LoggerServiceProtocol { case .published, .collected: properties = [ "Block": AnyCodable(latencyMetric.block), - "CorrelationId": AnyCodable(internalConfig.correlationId), "DeviceDataPersist": AnyCodable(latencyMetric.deviceDataPersist), "FpLoad": AnyCodable(latencyMetric.fpload), "FpPublish": AnyCodable(latencyMetric.fppublish), "Total": AnyCodable(latencyMetric.total), "EventType": AnyCodable(riskEvent.rawValue), - "FramesMode": AnyCodable(internalConfig.framesMode), + "FramesMode": AnyCodable(framesMode), "MaskedPublicKey": AnyCodable(maskedPublicKey), "ddTags": AnyCodable(ddTags), "RiskSDKVersion": AnyCodable(Constants.riskSdkVersion), @@ -86,13 +86,12 @@ extension LoggerServiceProtocol { case .publishFailure, .loadFailure, .publishDisabled: properties = [ "Block": AnyCodable(latencyMetric.block), - "CorrelationId": AnyCodable(internalConfig.correlationId), "DeviceDataPersist": AnyCodable(latencyMetric.deviceDataPersist), "FpLoad": AnyCodable(latencyMetric.fpload), "FpPublish": AnyCodable(latencyMetric.fppublish), "Total": AnyCodable(latencyMetric.total), "EventType": AnyCodable(riskEvent.rawValue), - "FramesMode": AnyCodable(internalConfig.framesMode), + "FramesMode": AnyCodable(framesMode), "MaskedPublicKey": AnyCodable(maskedPublicKey), "ddTags": AnyCodable(ddTags), "RiskSDKVersion": AnyCodable(Constants.riskSdkVersion), @@ -104,7 +103,7 @@ extension LoggerServiceProtocol { } return Event( - typeIdentifier: Constants.loggerTypeIdentifier, + typeIdentifier: riskEvent.rawValue, time: Date(), monitoringLevel: monitoringLevel, properties: properties @@ -131,15 +130,9 @@ struct LoggerService: LoggerServiceProtocol { } private func setup() { - - let appBundle = Bundle.main - let appPackageName = appBundle.bundleIdentifier ?? "unavailableAppPackageName" - let appPackageVersion = appBundle - .infoDictionary?["CFBundleShortVersionString"] as? String ?? "unavailableAppPackageVersion" - - let deviceName = getDeviceModel() - let osVersion = UIDevice.current.systemVersion let logEnvironment: Environment + let productIdentifier = internalConfig.framesOptions?.productIdentifier ?? Constants.productName + let productVersion = internalConfig.framesOptions?.version ?? Constants.riskSdkVersion switch internalConfig.environment { case .qa, .sandbox: @@ -155,17 +148,14 @@ struct LoggerService: LoggerServiceProtocol { logger.enableRemoteProcessor( environment: logEnvironment, remoteProcessorMetadata: RemoteProcessorMetadata( - productIdentifier: Constants.productName, - productVersion: Constants.riskSdkVersion, - environment: internalConfig.environment.rawValue, - appPackageName: appPackageName, - appPackageVersion: appPackageVersion, - deviceName: deviceName, - platform: "iOS", - osVersion: osVersion + productIdentifier: productIdentifier, + productVersion: productVersion, + environment: internalConfig.environment.rawValue ) ) - + + guard let correlationID = internalConfig.framesOptions?.correlationId else { return } + logger.add(metadata: CheckoutEventLogger.MetadataKey.correlationID.rawValue, value: correlationID) } func log(riskEvent: RiskEvent, blockTime: Double? = nil, deviceDataPersistTime: Double? = nil, fpLoadTime: Double? = nil, fpPublishTime: Double? = nil, deviceSessionId: String? = nil, requestId: String? = nil, error: RiskLogError? = nil) { @@ -177,20 +167,4 @@ struct LoggerService: LoggerServiceProtocol { let event = formatEvent(internalConfig: internalConfig, riskEvent: riskEvent, deviceSessionId: deviceSessionId, requestId: requestId, error: error, latencyMetric: latencyMetric) logger.log(event: event) } - - private func getDeviceModel() -> String { - #if targetEnvironment(simulator) - if let identifier = ProcessInfo().environment["SIMULATOR_MODEL_IDENTIFIER"] { - return identifier - } - #endif - - var systemInfo = utsname() - uname(&systemInfo) - let machineMirror = Mirror(reflecting: systemInfo.machine) - return machineMirror.children.reduce("") { identifier, element in - guard let value = element.value as? Int8, value != 0 else { return identifier } - return identifier + String(UnicodeScalar(UInt8(value))) - } - } } diff --git a/Sources/Risk/Models/RiskSDKInternalConfig.swift b/Sources/Risk/Models/RiskSDKInternalConfig.swift index 7b2957b..953d3e5 100644 --- a/Sources/Risk/Models/RiskSDKInternalConfig.swift +++ b/Sources/Risk/Models/RiskSDKInternalConfig.swift @@ -13,15 +13,14 @@ struct RiskSDKInternalConfig { let fingerprintEndpoint: String let integrationType: RiskIntegrationType let sourceType: SourceType - let framesMode: Bool let environment: RiskEnvironment - let correlationId: String + let framesOptions: FramesOptions? init(config: RiskConfig) { + framesOptions = config.framesOptions + let framesMode = framesOptions != nil merchantPublicKey = config.publicKey environment = config.environment - framesMode = config.framesMode - correlationId = config.framesMode ? config.correlationId : "" integrationType = framesMode ? .inFrames : .standalone sourceType = framesMode ? .cardToken : .riskSDK diff --git a/Sources/Risk/RiskSDKConfig.swift b/Sources/Risk/RiskSDKConfig.swift index 3ad7fb4..813a041 100644 --- a/Sources/Risk/RiskSDKConfig.swift +++ b/Sources/Risk/RiskSDKConfig.swift @@ -18,13 +18,23 @@ public enum RiskEnvironment: String { public struct RiskConfig { let publicKey: String let environment: RiskEnvironment - let framesMode: Bool - let correlationId: String + let framesOptions: FramesOptions? - public init(publicKey: String, environment: RiskEnvironment, framesMode: Bool = false, correlationId: String = "") { + public init(publicKey: String, environment: RiskEnvironment, framesOptions: FramesOptions? = nil) { self.publicKey = publicKey self.environment = environment - self.framesMode = framesMode + self.framesOptions = framesOptions + } +} + +public struct FramesOptions { + let correlationId: String + let version: String + let productIdentifier: String + + public init(productIdentifier: String, version: String, correlationId: String) { + self.productIdentifier = productIdentifier + self.version = version self.correlationId = correlationId } }