From a9c27e1108947ead65ac05464e2cca5d1324b1e5 Mon Sep 17 00:00:00 2001 From: Precious OSSAI Date: Tue, 23 Apr 2024 15:24:06 +0100 Subject: [PATCH 1/4] feat: improve frames mode logs --- Sources/Risk/Logging/LoggerService.swift | 19 +++++++++++-------- .../Risk/Models/RiskSDKInternalConfig.swift | 7 +++---- Sources/Risk/RiskSDKConfig.swift | 18 ++++++++++++++---- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/Sources/Risk/Logging/LoggerService.swift b/Sources/Risk/Logging/LoggerService.swift index 43742fd..550390d 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 @@ -140,6 +139,8 @@ struct LoggerService: LoggerServiceProtocol { 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,8 +156,8 @@ struct LoggerService: LoggerServiceProtocol { logger.enableRemoteProcessor( environment: logEnvironment, remoteProcessorMetadata: RemoteProcessorMetadata( - productIdentifier: Constants.productName, - productVersion: Constants.riskSdkVersion, + productIdentifier: productIdentifier, + productVersion: productVersion, environment: internalConfig.environment.rawValue, appPackageName: appPackageName, appPackageVersion: appPackageVersion, @@ -165,7 +166,9 @@ struct LoggerService: LoggerServiceProtocol { osVersion: osVersion ) ) - + + 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) { 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..e5f1d5b 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?) { 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 } } From f4e63e7720300d3f18442064fd6c42d912ce124d Mon Sep 17 00:00:00 2001 From: Precious OSSAI Date: Tue, 23 Apr 2024 15:26:35 +0100 Subject: [PATCH 2/4] feat: bump version --- Risk.podspec | 2 +- Sources/Risk/Logging/Constants.swift | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) 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" } From 80fabe8d21b7d163bdc971a1345a5fa2793105f9 Mon Sep 17 00:00:00 2001 From: Precious OSSAI Date: Tue, 23 Apr 2024 15:35:36 +0100 Subject: [PATCH 3/4] fix: add default value for frames options --- Sources/Risk/RiskSDKConfig.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Risk/RiskSDKConfig.swift b/Sources/Risk/RiskSDKConfig.swift index e5f1d5b..813a041 100644 --- a/Sources/Risk/RiskSDKConfig.swift +++ b/Sources/Risk/RiskSDKConfig.swift @@ -20,7 +20,7 @@ public struct RiskConfig { let environment: RiskEnvironment let framesOptions: FramesOptions? - public init(publicKey: String, environment: RiskEnvironment, framesOptions: FramesOptions?) { + public init(publicKey: String, environment: RiskEnvironment, framesOptions: FramesOptions? = nil) { self.publicKey = publicKey self.environment = environment self.framesOptions = framesOptions From 69124adb4c74627793fb85a3694b94fe8d134b53 Mon Sep 17 00:00:00 2001 From: Precious OSSAI Date: Thu, 25 Apr 2024 15:10:34 +0100 Subject: [PATCH 4/4] refactor: remove extra logger arguments --- Sources/Risk/Logging/LoggerService.swift | 31 +----------------------- 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/Sources/Risk/Logging/LoggerService.swift b/Sources/Risk/Logging/LoggerService.swift index 550390d..145e69d 100644 --- a/Sources/Risk/Logging/LoggerService.swift +++ b/Sources/Risk/Logging/LoggerService.swift @@ -130,14 +130,6 @@ 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 @@ -158,12 +150,7 @@ struct LoggerService: LoggerServiceProtocol { remoteProcessorMetadata: RemoteProcessorMetadata( productIdentifier: productIdentifier, productVersion: productVersion, - environment: internalConfig.environment.rawValue, - appPackageName: appPackageName, - appPackageVersion: appPackageVersion, - deviceName: deviceName, - platform: "iOS", - osVersion: osVersion + environment: internalConfig.environment.rawValue ) ) @@ -180,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))) - } - } }