Skip to content

Commit 4caee69

Browse files
committed
fix: apply code review
1 parent 34a40f1 commit 4caee69

File tree

4 files changed

+57
-28
lines changed

4 files changed

+57
-28
lines changed

.vscode/launch.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@
9292
"request": "launch",
9393
"program": "lib/main.dart",
9494
"cwd": "${workspaceFolder}/example",
95-
"deviceId": "00008101-0006455036D8001E",
9695
"args": []
9796
}
9897
],

example/lib/src/screens/subscription_flow_screen.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ Has token: ${purchase.purchaseToken != null && purchase.purchaseToken!.isNotEmpt
314314
_originalProducts[productKey] = product;
315315
}
316316

317-
_subscriptions = List<ProductCommon>.from(products, growable: false);
317+
_subscriptions = List.of(products, growable: false);
318318
_isLoadingProducts = false;
319319
});
320320
} catch (error) {

ios/Classes/FlutterIapHelper.swift

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,41 @@ import OpenIAP
44
enum FlutterIapHelper {
55
// MARK: - Sanitization
66

7+
private static let identifierKeys: Set<String> = [
8+
"id",
9+
"transactionId",
10+
"productId",
11+
"offerId",
12+
"originalTransactionIdentifierIOS",
13+
"subscriptionGroupIdIOS",
14+
"webOrderLineItemIdIOS",
15+
"orderIdAndroid",
16+
"obfuscatedAccountIdAndroid",
17+
"obfuscatedProfileIdAndroid"
18+
]
19+
20+
private static let sensitiveKeyFragments: [String] = [
21+
"token",
22+
"receipt",
23+
"jws",
24+
"signature"
25+
]
26+
727
static func sanitizeDictionary(_ dictionary: [String: Any?]) -> [String: Any] {
828
var result: [String: Any] = [:]
929
for (key, value) in dictionary {
10-
if let value {
11-
result[key] = value
30+
let lowerKey = key.lowercased()
31+
if sensitiveKeyFragments.contains(where: { lowerKey.contains($0) }) {
32+
result[key] = "hidden"
33+
continue
34+
}
35+
36+
guard let sanitizedValue = sanitizeValue(value) else { continue }
37+
38+
if let number = sanitizedValue as? NSNumber, identifierKeys.contains(key) {
39+
result[key] = number.stringValue
40+
} else {
41+
result[key] = sanitizedValue
1242
}
1343
}
1444
return result
@@ -21,27 +51,23 @@ enum FlutterIapHelper {
2151
static func sanitizeValue(_ value: Any?) -> Any? {
2252
guard let value else { return nil }
2353

24-
if let dictionary = value as? [String: Any] {
25-
return dictionary.reduce(into: [String: Any]()) { result, element in
26-
let (key, rawValue) = element
27-
if key.lowercased().contains("token") {
28-
result[key] = "hidden"
29-
} else if let sanitized = sanitizeValue(rawValue) {
30-
result[key] = sanitized
31-
}
32-
}
54+
if let dictionary = value as? [String: Any?] {
55+
return sanitizeDictionary(dictionary)
3356
}
3457

35-
if let optionalDictionary = value as? [String: Any?] {
58+
if let dictionary = value as? [String: Any] {
59+
let optionalDictionary = dictionary.reduce(into: [String: Any?]()) { result, element in
60+
result[element.key] = element.value
61+
}
3662
return sanitizeDictionary(optionalDictionary)
3763
}
3864

39-
if let array = value as? [Any] {
65+
if let array = value as? [Any?] {
4066
return array.compactMap { sanitizeValue($0) }
4167
}
4268

43-
if let optionalArray = value as? [Any?] {
44-
return optionalArray.compactMap { sanitizeValue($0) }
69+
if let array = value as? [Any] {
70+
return array.compactMap { sanitizeValue($0) }
4571
}
4672

4773
return value

ios/Classes/FlutterIapLog.swift

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,21 @@ enum FlutterIapLog {
5555
}
5656

5757
#if canImport(os)
58-
let logger = Logger(subsystem: "dev.hyo.flutter-inapp-purchase", category: "FlutterIap")
59-
let formatted = "[FlutterIap] \(message)"
60-
switch level {
61-
case .debug:
62-
logger.debug("\(formatted, privacy: .public)")
63-
case .info:
64-
logger.info("\(formatted, privacy: .public)")
65-
case .warn:
66-
logger.warning("\(formatted, privacy: .public)")
67-
case .error:
68-
logger.error("\(formatted, privacy: .public)")
58+
if #available(iOS 14.0, macOS 11.0, tvOS 14.0, watchOS 7.0, *) {
59+
let logger = Logger(subsystem: "dev.hyo.flutter-inapp-purchase", category: "FlutterIap")
60+
let formatted = "[FlutterIap] \(message)"
61+
switch level {
62+
case .debug:
63+
logger.debug("\(formatted, privacy: .public)")
64+
case .info:
65+
logger.info("\(formatted, privacy: .public)")
66+
case .warn:
67+
logger.warning("\(formatted, privacy: .public)")
68+
case .error:
69+
logger.error("\(formatted, privacy: .public)")
70+
}
71+
} else {
72+
NSLog("[FlutterIap][%@] %@", level.rawValue.uppercased(), message)
6973
}
7074
#else
7175
NSLog("[FlutterIap][%@] %@", level.rawValue.uppercased(), message)

0 commit comments

Comments
 (0)