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.
Files changed (53) hide show
  1. package/CLAUDE.md +2 -2
  2. package/CONTRIBUTING.md +19 -0
  3. package/README.md +18 -6
  4. package/android/build.gradle +24 -1
  5. package/android/src/main/java/expo/modules/iap/ExpoIapLog.kt +69 -0
  6. package/android/src/main/java/expo/modules/iap/ExpoIapModule.kt +190 -59
  7. package/build/index.d.ts +20 -47
  8. package/build/index.d.ts.map +1 -1
  9. package/build/index.js +94 -137
  10. package/build/index.js.map +1 -1
  11. package/build/modules/android.d.ts.map +1 -1
  12. package/build/modules/android.js +2 -1
  13. package/build/modules/android.js.map +1 -1
  14. package/build/modules/ios.d.ts +16 -1
  15. package/build/modules/ios.d.ts.map +1 -1
  16. package/build/modules/ios.js +29 -16
  17. package/build/modules/ios.js.map +1 -1
  18. package/build/types.d.ts +8 -6
  19. package/build/types.d.ts.map +1 -1
  20. package/build/types.js.map +1 -1
  21. package/build/useIAP.d.ts +1 -1
  22. package/build/useIAP.d.ts.map +1 -1
  23. package/build/useIAP.js +12 -15
  24. package/build/useIAP.js.map +1 -1
  25. package/build/utils/errorMapping.d.ts +32 -23
  26. package/build/utils/errorMapping.d.ts.map +1 -1
  27. package/build/utils/errorMapping.js +117 -22
  28. package/build/utils/errorMapping.js.map +1 -1
  29. package/ios/ExpoIap.podspec +3 -2
  30. package/ios/ExpoIapHelper.swift +96 -0
  31. package/ios/ExpoIapLog.swift +127 -0
  32. package/ios/ExpoIapModule.swift +218 -340
  33. package/openiap-versions.json +5 -0
  34. package/package.json +2 -2
  35. package/plugin/build/withIAP.js +6 -4
  36. package/plugin/src/withIAP.ts +14 -4
  37. package/scripts/update-types.mjs +20 -1
  38. package/src/index.ts +122 -165
  39. package/src/modules/android.ts +2 -1
  40. package/src/modules/ios.ts +31 -19
  41. package/src/types.ts +8 -6
  42. package/src/useIAP.ts +17 -25
  43. package/src/utils/errorMapping.ts +203 -23
  44. package/build/purchase-error.d.ts +0 -67
  45. package/build/purchase-error.d.ts.map +0 -1
  46. package/build/purchase-error.js +0 -166
  47. package/build/purchase-error.js.map +0 -1
  48. package/build/utils/purchase.d.ts +0 -9
  49. package/build/utils/purchase.d.ts.map +0 -1
  50. package/build/utils/purchase.js +0 -34
  51. package/build/utils/purchase.js.map +0 -1
  52. package/src/purchase-error.ts +0 -265
  53. 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
+ }