@doorstepai/dropoff-sdk 2.1.2 → 2.2.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 (42) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +115 -3
  3. package/android/build.gradle +1 -1
  4. package/android/src/main/java/com/doorstepai/dropoffsdk/DoorstepAIModule.kt +332 -0
  5. package/ios/DoorstepAI.mm +5 -2
  6. package/ios/DoorstepAI.swift +170 -2
  7. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/DoorstepDropoffSDK +0 -0
  8. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.abi.json +1374 -413
  9. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +13 -4
  10. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  11. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.swiftinterface +13 -4
  12. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +10 -10
  13. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/DWARF/DoorstepDropoffSDK +0 -0
  14. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/DoorstepDropoffSDK.yml +3248 -2687
  15. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/DoorstepDropoffSDK +0 -0
  16. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +1374 -413
  17. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +13 -4
  18. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  19. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +13 -4
  20. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +1374 -413
  21. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +13 -4
  22. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  23. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +13 -4
  24. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +20 -20
  25. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/DWARF/DoorstepDropoffSDK +0 -0
  26. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/DoorstepDropoffSDK.yml +3248 -2687
  27. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/DoorstepDropoffSDK.yml +3233 -2674
  28. package/lib/module/DoorstepAI.js +190 -12
  29. package/lib/module/DoorstepAI.js.map +1 -1
  30. package/lib/module/RootDoorstepAI.js +70 -26
  31. package/lib/module/RootDoorstepAI.js.map +1 -1
  32. package/lib/module/index.js.map +1 -1
  33. package/lib/typescript/src/DoorstepAI.d.ts +151 -7
  34. package/lib/typescript/src/DoorstepAI.d.ts.map +1 -1
  35. package/lib/typescript/src/RootDoorstepAI.d.ts +14 -3
  36. package/lib/typescript/src/RootDoorstepAI.d.ts.map +1 -1
  37. package/lib/typescript/src/index.d.ts +1 -1
  38. package/lib/typescript/src/index.d.ts.map +1 -1
  39. package/package.json +2 -1
  40. package/src/DoorstepAI.tsx +241 -23
  41. package/src/RootDoorstepAI.tsx +98 -45
  42. package/src/index.tsx +4 -0
@@ -1,5 +1,8 @@
1
1
  import Foundation
2
2
  import React
3
+ import CoreBluetooth
4
+ import CoreLocation
5
+ import CoreMotion
3
6
  import DoorstepDropoffSDK
4
7
 
5
8
  @objc(DoorstepAI)
@@ -60,9 +63,174 @@ class DoorstepAIBridge: RCTEventEmitter {
60
63
  DoorstepAI.setApiKey(key: apiKey)
61
64
  }
62
65
 
66
+ // MARK: - Permissions
67
+ //
68
+ // Reading a permission's state and OWNING permission policy are two different
69
+ // things, and only the first belongs in a wrapper. Everything below reads the
70
+ // platform's own status APIs — all three are non-prompting — and dispatches the
71
+ // actual request to the native SDK, which keeps the permission list, the flags
72
+ // and the ordering. In particular this file must never instantiate a
73
+ // `CBCentralManager`: doing so PROMPTS, and it hard-crashes a host that has no
74
+ // `NSBluetoothAlwaysUsageDescription`. That is exactly why a wrapper-owned
75
+ // central manager was deleted, and why the SDK's own `MetadataCollector` reads
76
+ // the static `CBManager.authorization` instead.
77
+
78
+ /// How long `requestPermissions` waits for the user to answer before giving up
79
+ /// and resolving with the state as it stands.
80
+ private static let permissionAnswerTimeout: TimeInterval = 120
81
+ private static let permissionPollInterval: TimeInterval = 0.25
82
+
83
+ /// Main-thread confined. Guards against a second `requestPermissions` racing a
84
+ /// prompt sequence that is still on screen.
85
+ private static var permissionRequestInFlight = false
86
+
87
+ /// The instance `authorizationStatus` (FP2 6b — the deprecated class method is a
88
+ /// different, process-cached value from the one the SDK's own location code
89
+ /// trusts). Instantiating a `CLLocationManager` never prompts; only
90
+ /// `request*Authorization` does. The probe is local and unretained, so this file
91
+ /// owns no location manager.
92
+ private static func locationState() -> PermissionState {
93
+ let status: CLAuthorizationStatus
94
+ if #available(iOS 14.0, *) {
95
+ status = CLLocationManager().authorizationStatus
96
+ } else {
97
+ status = CLLocationManager.authorizationStatus()
98
+ }
99
+ switch status {
100
+ case .authorizedAlways, .authorizedWhenInUse: return .granted
101
+ case .denied, .restricted: return .denied
102
+ default: return .prompt
103
+ }
104
+ }
105
+
106
+ private static func motionState() -> PermissionState {
107
+ switch CMMotionActivityManager.authorizationStatus() {
108
+ case .authorized: return .granted
109
+ case .denied, .restricted: return .denied
110
+ default: return .prompt
111
+ }
112
+ }
113
+
114
+ /// Static `CBManager.authorization` (iOS 13.1+), never a `CBCentralManager`.
115
+ private static func bluetoothState() -> PermissionState {
116
+ if #available(iOS 13.1, *) {
117
+ switch CBManager.authorization {
118
+ case .allowedAlways: return .granted
119
+ case .denied, .restricted: return .denied
120
+ default: return .prompt
121
+ }
122
+ }
123
+ return .prompt
124
+ }
125
+
126
+ private enum PermissionState: String {
127
+ case granted, denied, prompt
128
+ }
129
+
130
+ private static func state(for permission: String) -> PermissionState {
131
+ switch permission {
132
+ case "location": return locationState()
133
+ case "motion": return motionState()
134
+ case "bluetooth": return bluetoothState()
135
+ default: return .prompt
136
+ }
137
+ }
138
+
139
+ /// `{ permissions: { location, motion, bluetooth } }` — the shape the published
140
+ /// wrapper API has always had.
141
+ private static func permissionStatusPayload() -> [String: Any] {
142
+ return [
143
+ "permissions": [
144
+ "location": locationState().rawValue,
145
+ "motion": motionState().rawValue,
146
+ "bluetooth": bluetoothState().rawValue,
147
+ ]
148
+ ]
149
+ }
150
+
63
151
  @objc
64
- func requestAllPermissions(_ requestAlwaysLocation: Bool, requestBluetooth: Bool) {
65
- DoorstepAI.requestAllPermissions(requestAlwaysLocation: requestAlwaysLocation, requestBluetooth: requestBluetooth)
152
+ func checkPermissions(_ resolve: @escaping RCTPromiseResolveBlock,
153
+ rejecter reject: @escaping RCTPromiseRejectBlock) {
154
+ // Main queue because `CLLocationManager` is main-thread affine.
155
+ DispatchQueue.main.async {
156
+ resolve(DoorstepAIBridge.permissionStatusPayload())
157
+ }
158
+ }
159
+
160
+ /// iOS half of the cross-platform requester.
161
+ ///
162
+ /// `options.permissions` can only narrow Bluetooth:
163
+ /// `requestAllPermissions` asks for its whole set behind one `requestBluetooth`
164
+ /// flag, so `requestBluetooth = permissions.contains("bluetooth")` (true when
165
+ /// `permissions` is absent) and location + motion always ride the base set.
166
+ /// `requestAlwaysLocation` and `onlyIfNotDetermined` are left at their NATIVE
167
+ /// defaults (both `true`) — `onlyIfNotDetermined` especially, because it is what
168
+ /// stops a launch-time call re-escalating a user's "While Using the App" choice.
169
+ ///
170
+ /// Resolves a `PermissionStatus` **after the user has answered**, never before:
171
+ /// `requestAllPermissions` returns `Void` and reports nothing, so the answer is
172
+ /// observed by re-reading the three non-prompting status APIs until every prompt
173
+ /// that will actually be raised has settled out of `.notDetermined`. The pending
174
+ /// set mirrors native's own gates (`onlyIfNotDetermined` for location,
175
+ /// `isActivityAvailable()` for motion, the `NSBluetoothAlwaysUsageDescription`
176
+ /// check for Bluetooth) so the wait cannot hang on a prompt native never shows.
177
+ @objc
178
+ func requestPermissions(_ options: NSDictionary?,
179
+ resolver resolve: @escaping RCTPromiseResolveBlock,
180
+ rejecter reject: @escaping RCTPromiseRejectBlock) {
181
+ let selected = (options?["permissions"] as? [String]).map { Set($0) }
182
+ DispatchQueue.main.async {
183
+ if DoorstepAIBridge.permissionRequestInFlight {
184
+ reject("E_PERMISSION_REQUEST_IN_FLIGHT",
185
+ "A permission request is already awaiting the user's answer.",
186
+ nil)
187
+ return
188
+ }
189
+ DoorstepAIBridge.permissionRequestInFlight = true
190
+
191
+ let requestBluetooth = selected?.contains("bluetooth") ?? true
192
+
193
+ var pending = Set<String>()
194
+ if DoorstepAIBridge.locationState() == .prompt {
195
+ pending.insert("location")
196
+ }
197
+ if DoorstepAIBridge.motionState() == .prompt,
198
+ CMMotionActivityManager.isActivityAvailable() {
199
+ pending.insert("motion")
200
+ }
201
+ if requestBluetooth,
202
+ DoorstepAIBridge.bluetoothState() == .prompt,
203
+ Bundle.main.object(forInfoDictionaryKey: "NSBluetoothAlwaysUsageDescription") != nil {
204
+ pending.insert("bluetooth")
205
+ }
206
+
207
+ DoorstepAI.requestAllPermissions(requestBluetooth: requestBluetooth)
208
+
209
+ DoorstepAIBridge.awaitPermissionAnswers(
210
+ pending: pending,
211
+ deadline: Date().addingTimeInterval(DoorstepAIBridge.permissionAnswerTimeout)
212
+ ) {
213
+ DoorstepAIBridge.permissionRequestInFlight = false
214
+ resolve(DoorstepAIBridge.permissionStatusPayload())
215
+ }
216
+ }
217
+ }
218
+
219
+ /// Polls the non-prompting status APIs on the main queue until nothing is left
220
+ /// `.notDetermined` or the deadline passes. Polling rather than a delegate is
221
+ /// deliberate: observing a `CLLocationManager` authorization change would mean
222
+ /// owning one, which is the wrapper-owned-manager pattern this surface removes.
223
+ private static func awaitPermissionAnswers(pending: Set<String>,
224
+ deadline: Date,
225
+ completion: @escaping () -> Void) {
226
+ let unanswered = pending.filter { state(for: $0) == .prompt }
227
+ if unanswered.isEmpty || Date() >= deadline {
228
+ completion()
229
+ return
230
+ }
231
+ DispatchQueue.main.asyncAfter(deadline: .now() + permissionPollInterval) {
232
+ awaitPermissionAnswers(pending: unanswered, deadline: deadline, completion: completion)
233
+ }
66
234
  }
67
235
 
68
236
  @objc