From 7298e7a9e7fa468fc4d396b9c77940257c46317d Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Tue, 23 Jul 2024 08:29:44 -0500 Subject: [PATCH 1/6] update graphQL mutation extraction --- Sources/BraintreeCore/BTHTTP.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Sources/BraintreeCore/BTHTTP.swift b/Sources/BraintreeCore/BTHTTP.swift index 7815e4e310..4cab3043c8 100644 --- a/Sources/BraintreeCore/BTHTTP.swift +++ b/Sources/BraintreeCore/BTHTTP.swift @@ -446,8 +446,14 @@ class BTHTTP: NSObject, URLSessionTaskDelegate { let json = try? JSONSerialization.jsonObject(with: data) let body = BTJSON(value: json) - guard let mutationName = body["operationName"].asString() else { return nil } - - return "mutation \(mutationName)" + if let mutationName = body["operationName"].asString() { + return "mutation \(mutationName)" + } else if let query = body["query"].asString() { + let queryDiscardHolder = query.replacingOccurrences(of: #"^[^\(]*"#, with: "", options: .regularExpression) + let finalQuery = query.replacingOccurrences(of: queryDiscardHolder, with: "") + return finalQuery + } + + return nil } } From 003133166c95d6c3b085cd217aa693346fee69ad Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Tue, 23 Jul 2024 08:56:21 -0500 Subject: [PATCH 2/6] update 3d secure path logic --- Sources/BraintreeCore/BTAPIClient.swift | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Sources/BraintreeCore/BTAPIClient.swift b/Sources/BraintreeCore/BTAPIClient.swift index cb646b2449..0969b3ddef 100644 --- a/Sources/BraintreeCore/BTAPIClient.swift +++ b/Sources/BraintreeCore/BTAPIClient.swift @@ -403,7 +403,21 @@ import Foundation func fetchAPITiming(path: String, connectionStartTime: Int?, requestStartTime: Int?, startTime: Int, endTime: Int) { let cleanedPath = path.replacingOccurrences(of: "/merchants/([A-Za-z0-9]+)/client_api", with: "", options: .regularExpression) - if cleanedPath != "/v1/tracking/batch/events" { + if cleanedPath.contains("three_d_secure") { + let threeDSecurePath = cleanedPath.replacingOccurrences( + of: "payment_methods/.*/three_d_secure", + with: "payment_methods/three_d_secure", + options: .regularExpression + ) + analyticsService?.sendAnalyticsEvent( + BTCoreAnalytics.apiRequestLatency, + connectionStartTime: connectionStartTime, + endpoint: threeDSecurePath, + endTime: endTime, + requestStartTime: requestStartTime, + startTime: startTime + ) + } else if cleanedPath != "/v1/tracking/batch/events" { analyticsService?.sendAnalyticsEvent( BTCoreAnalytics.apiRequestLatency, connectionStartTime: connectionStartTime, From 94339c207d213ffca17300b939a0f40e1df7739b Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Tue, 23 Jul 2024 10:39:16 -0500 Subject: [PATCH 3/6] cleanup --- Sources/BraintreeCore/BTHTTP.swift | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Sources/BraintreeCore/BTHTTP.swift b/Sources/BraintreeCore/BTHTTP.swift index 4cab3043c8..ef72f275e9 100644 --- a/Sources/BraintreeCore/BTHTTP.swift +++ b/Sources/BraintreeCore/BTHTTP.swift @@ -446,14 +446,12 @@ class BTHTTP: NSObject, URLSessionTaskDelegate { let json = try? JSONSerialization.jsonObject(with: data) let body = BTJSON(value: json) - if let mutationName = body["operationName"].asString() { - return "mutation \(mutationName)" - } else if let query = body["query"].asString() { - let queryDiscardHolder = query.replacingOccurrences(of: #"^[^\(]*"#, with: "", options: .regularExpression) - let finalQuery = query.replacingOccurrences(of: queryDiscardHolder, with: "") - return finalQuery + guard let query = body["query"].asString() else { + return nil } - return nil + let queryDiscardHolder = query.replacingOccurrences(of: #"^[^\(]*"#, with: "", options: .regularExpression) + let finalQuery = query.replacingOccurrences(of: queryDiscardHolder, with: "") + return finalQuery } } From d4c11300be728087d0df2faa85cea6b081bd23d8 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Tue, 23 Jul 2024 10:42:44 -0500 Subject: [PATCH 4/6] update test --- UnitTests/BraintreeCoreTests/BTHTTP_Tests.swift | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/UnitTests/BraintreeCoreTests/BTHTTP_Tests.swift b/UnitTests/BraintreeCoreTests/BTHTTP_Tests.swift index 4a63babe51..3da79f517b 100644 --- a/UnitTests/BraintreeCoreTests/BTHTTP_Tests.swift +++ b/UnitTests/BraintreeCoreTests/BTHTTP_Tests.swift @@ -757,7 +757,8 @@ final class BTHTTP_Tests: XCTestCase { var originalRequest = URLRequest(url: URL(string: "https://example.com/graphql")!) originalRequest.httpBody = """ { - "operationName": "TestMutation" + "operationName": "TestMutation", + "query": "mutation TestMutation()" } """.data(using: .utf8) let task = testURLSession.dataTask(with: originalRequest) From 3a9f507a22ac8b726544f8262421b5e15b3133a4 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Tue, 23 Jul 2024 11:07:15 -0500 Subject: [PATCH 5/6] add CHANGELOG entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1ce08a0564..5de4798c06 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ * BraintreeCore * Prevent duplicate outbound `v1/configuration` requests * Add network timeout of 30 seconds + * Update `endpoint` syntax sent to FPTI for 3D Secure and Venmo flows ## 6.23.0 (2024-07-15) * BraintreeShopperInsights (BETA) From 00fade197d79f4004aafd7f845a6a5c9bd2a3354 Mon Sep 17 00:00:00 2001 From: Jax DesMarais-Leder Date: Wed, 24 Jul 2024 14:46:28 -0500 Subject: [PATCH 6/6] PR feedback: consolidate logic for 3DS path --- Sources/BraintreeCore/BTAPIClient.swift | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/Sources/BraintreeCore/BTAPIClient.swift b/Sources/BraintreeCore/BTAPIClient.swift index 0969b3ddef..6c9da34960 100644 --- a/Sources/BraintreeCore/BTAPIClient.swift +++ b/Sources/BraintreeCore/BTAPIClient.swift @@ -401,23 +401,14 @@ import Foundation // MARK: BTAPITimingDelegate conformance func fetchAPITiming(path: String, connectionStartTime: Int?, requestStartTime: Int?, startTime: Int, endTime: Int) { - let cleanedPath = path.replacingOccurrences(of: "/merchants/([A-Za-z0-9]+)/client_api", with: "", options: .regularExpression) + var cleanedPath = path.replacingOccurrences(of: "/merchants/([A-Za-z0-9]+)/client_api", with: "", options: .regularExpression) + cleanedPath = cleanedPath.replacingOccurrences( + of: "payment_methods/.*/three_d_secure", + with: "payment_methods/three_d_secure", + options: .regularExpression + ) - if cleanedPath.contains("three_d_secure") { - let threeDSecurePath = cleanedPath.replacingOccurrences( - of: "payment_methods/.*/three_d_secure", - with: "payment_methods/three_d_secure", - options: .regularExpression - ) - analyticsService?.sendAnalyticsEvent( - BTCoreAnalytics.apiRequestLatency, - connectionStartTime: connectionStartTime, - endpoint: threeDSecurePath, - endTime: endTime, - requestStartTime: requestStartTime, - startTime: startTime - ) - } else if cleanedPath != "/v1/tracking/batch/events" { + if cleanedPath != "/v1/tracking/batch/events" { analyticsService?.sendAnalyticsEvent( BTCoreAnalytics.apiRequestLatency, connectionStartTime: connectionStartTime,