expo-iap 3.0.8 → 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +2 -2
- package/CONTRIBUTING.md +19 -0
- package/README.md +18 -6
- package/android/build.gradle +24 -1
- package/android/src/main/java/expo/modules/iap/ExpoIapLog.kt +69 -0
- package/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +190 -59
- package/build/index.d.ts +20 -47
- package/build/index.d.ts.map +1 -1
- package/build/index.js +94 -137
- package/build/index.js.map +1 -1
- package/build/modules/android.d.ts.map +1 -1
- package/build/modules/android.js +2 -1
- package/build/modules/android.js.map +1 -1
- package/build/modules/ios.d.ts +16 -1
- package/build/modules/ios.d.ts.map +1 -1
- package/build/modules/ios.js +29 -16
- package/build/modules/ios.js.map +1 -1
- package/build/types.d.ts +8 -6
- package/build/types.d.ts.map +1 -1
- package/build/types.js.map +1 -1
- package/build/useIAP.d.ts +1 -1
- package/build/useIAP.d.ts.map +1 -1
- package/build/useIAP.js +12 -15
- package/build/useIAP.js.map +1 -1
- package/build/utils/errorMapping.d.ts +32 -23
- package/build/utils/errorMapping.d.ts.map +1 -1
- package/build/utils/errorMapping.js +117 -22
- package/build/utils/errorMapping.js.map +1 -1
- package/ios/ExpoIap.podspec +3 -2
- package/ios/ExpoIapHelper.swift +96 -0
- package/ios/ExpoIapLog.swift +127 -0
- package/ios/ExpoIapModule.swift +218 -340
- package/openiap-versions.json +5 -0
- package/package.json +2 -2
- package/plugin/build/withIAP.js +6 -4
- package/plugin/src/withIAP.ts +14 -4
- package/scripts/update-types.mjs +20 -1
- package/src/index.ts +122 -165
- package/src/modules/android.ts +2 -1
- package/src/modules/ios.ts +31 -19
- package/src/types.ts +8 -6
- package/src/useIAP.ts +17 -25
- package/src/utils/errorMapping.ts +203 -23
- package/build/purchase-error.d.ts +0 -67
- package/build/purchase-error.d.ts.map +0 -1
- package/build/purchase-error.js +0 -166
- package/build/purchase-error.js.map +0 -1
- package/build/utils/purchase.d.ts +0 -9
- package/build/utils/purchase.d.ts.map +0 -1
- package/build/utils/purchase.js +0 -34
- package/build/utils/purchase.js.map +0 -1
- package/src/purchase-error.ts +0 -265
- package/src/utils/purchase.ts +0 -52
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import Foundation
|
|
2
|
+
#if canImport(os)
|
|
3
|
+
import os
|
|
4
|
+
#endif
|
|
5
|
+
|
|
6
|
+
enum ExpoIapLog {
|
|
7
|
+
enum Level: String {
|
|
8
|
+
case debug
|
|
9
|
+
case info
|
|
10
|
+
case warn
|
|
11
|
+
case error
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
private static var isEnabled: Bool = {
|
|
15
|
+
#if DEBUG
|
|
16
|
+
true
|
|
17
|
+
#else
|
|
18
|
+
false
|
|
19
|
+
#endif
|
|
20
|
+
}()
|
|
21
|
+
|
|
22
|
+
private static var customHandler: ((Level, String) -> Void)?
|
|
23
|
+
|
|
24
|
+
static func setEnabled(_ enabled: Bool) {
|
|
25
|
+
isEnabled = enabled
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
static func setHandler(_ handler: ((Level, String) -> Void)?) {
|
|
29
|
+
customHandler = handler
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
static func debug(_ message: String) { log(.debug, message) }
|
|
33
|
+
static func info(_ message: String) { log(.info, message) }
|
|
34
|
+
static func warn(_ message: String) { log(.warn, message) }
|
|
35
|
+
static func error(_ message: String) { log(.error, message) }
|
|
36
|
+
|
|
37
|
+
static func payload(_ name: String, payload: Any?) {
|
|
38
|
+
debug("\(name) payload: \(stringify(payload))")
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
static func result(_ name: String, value: Any?) {
|
|
42
|
+
debug("\(name) result: \(stringify(value))")
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
static func failure(_ name: String, error: Error) {
|
|
46
|
+
ExpoIapLog.error("\(name) failed: \(error.localizedDescription)")
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
private static func log(_ level: Level, _ message: String) {
|
|
50
|
+
guard isEnabled else { return }
|
|
51
|
+
|
|
52
|
+
if let handler = customHandler {
|
|
53
|
+
handler(level, message)
|
|
54
|
+
return
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#if canImport(os)
|
|
58
|
+
let logger = Logger(subsystem: "dev.hyo.expo-iap", category: "ExpoIap")
|
|
59
|
+
let formatted = "[ExpoIap] \(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)")
|
|
69
|
+
}
|
|
70
|
+
#else
|
|
71
|
+
NSLog("[ExpoIap][%@] %@", level.rawValue.uppercased(), message)
|
|
72
|
+
#endif
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
private static func stringify(_ value: Any?) -> String {
|
|
76
|
+
guard let sanitized = sanitize(value) else {
|
|
77
|
+
return "null"
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if JSONSerialization.isValidJSONObject(sanitized),
|
|
81
|
+
let data = try? JSONSerialization.data(withJSONObject: sanitized, options: []) {
|
|
82
|
+
return String(data: data, encoding: .utf8) ?? String(describing: sanitized)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return String(describing: sanitized)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
private static func sanitize(_ value: Any?) -> Any? {
|
|
89
|
+
guard let value else { return nil }
|
|
90
|
+
|
|
91
|
+
if let dictionary = value as? [String: Any] {
|
|
92
|
+
return sanitizeDictionary(dictionary)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if let optionalDictionary = value as? [String: Any?] {
|
|
96
|
+
var compact: [String: Any] = [:]
|
|
97
|
+
for (key, optionalValue) in optionalDictionary {
|
|
98
|
+
if let optionalValue {
|
|
99
|
+
compact[key] = optionalValue
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return sanitizeDictionary(compact)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if let array = value as? [Any] {
|
|
106
|
+
return array.compactMap { sanitize($0) }
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if let optionalArray = value as? [Any?] {
|
|
110
|
+
return optionalArray.compactMap { sanitize($0) }
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return value
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
private static func sanitizeDictionary(_ dictionary: [String: Any]) -> [String: Any] {
|
|
117
|
+
var sanitized: [String: Any] = [:]
|
|
118
|
+
for (key, value) in dictionary {
|
|
119
|
+
if key.lowercased().contains("token") {
|
|
120
|
+
sanitized[key] = "hidden"
|
|
121
|
+
} else if let sanitizedValue = sanitize(value) {
|
|
122
|
+
sanitized[key] = sanitizedValue
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return sanitized
|
|
126
|
+
}
|
|
127
|
+
}
|