@doorstepai/dropoff-sdk 2.1.2 → 2.2.2

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 (43) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/README.md +308 -41
  3. package/android/build.gradle +5 -1
  4. package/android/src/main/java/com/doorstepai/dropoffsdk/DoorstepAIModule.kt +566 -2
  5. package/ios/DoorstepAI.mm +12 -2
  6. package/ios/DoorstepAI.swift +151 -2
  7. package/ios/DoorstepDropoffSDK.xcframework/Info.plist +5 -5
  8. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/DoorstepDropoffSDK +0 -0
  9. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.abi.json +10582 -5745
  10. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +95 -4
  11. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  12. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.swiftinterface +95 -4
  13. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +10 -10
  14. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/DWARF/DoorstepDropoffSDK +0 -0
  15. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/DoorstepDropoffSDK.yml +3833 -2687
  16. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/DoorstepDropoffSDK +0 -0
  17. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +10582 -5745
  18. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +95 -4
  19. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  20. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +95 -4
  21. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +10582 -5745
  22. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +95 -4
  23. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  24. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +95 -4
  25. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +20 -20
  26. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/DWARF/DoorstepDropoffSDK +0 -0
  27. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/DoorstepDropoffSDK.yml +3833 -2687
  28. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/DoorstepDropoffSDK.yml +3802 -2674
  29. package/lib/module/DoorstepAI.js +425 -12
  30. package/lib/module/DoorstepAI.js.map +1 -1
  31. package/lib/module/RootDoorstepAI.js +88 -26
  32. package/lib/module/RootDoorstepAI.js.map +1 -1
  33. package/lib/module/index.js.map +1 -1
  34. package/lib/typescript/src/DoorstepAI.d.ts +349 -7
  35. package/lib/typescript/src/DoorstepAI.d.ts.map +1 -1
  36. package/lib/typescript/src/RootDoorstepAI.d.ts +31 -3
  37. package/lib/typescript/src/RootDoorstepAI.d.ts.map +1 -1
  38. package/lib/typescript/src/index.d.ts +1 -1
  39. package/lib/typescript/src/index.d.ts.map +1 -1
  40. package/package.json +2 -1
  41. package/src/DoorstepAI.tsx +575 -23
  42. package/src/RootDoorstepAI.tsx +130 -47
  43. package/src/index.tsx +10 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,66 @@
1
+ # Changelog
2
+
3
+ ## Unreleased
4
+
5
+ ### `checkPermissions` + `requestPermissions` are the permission surface again
6
+
7
+ The pair that shipped in `@doorstepai/dropoff-sdk-capacitor` 1.0.4 is restored as
8
+ the public permission API, with the published names and shapes, and is now
9
+ **identical across the React Native, Capacitor and Flutter wrappers**. It is
10
+ implemented over the native SDK — the wrapper owns no permission list, no alias
11
+ table for OS permissions, no request sequencing, and no `CLLocationManager` /
12
+ `CBCentralManager` of its own.
13
+
14
+ ```ts
15
+ type PermissionState = 'granted' | 'denied' | 'prompt';
16
+ type DoorstepPermissionType = 'location' | 'motion' | 'bluetooth';
17
+ interface PermissionStatus { permissions: Record<DoorstepPermissionType, PermissionState> }
18
+ interface PermissionRequestOptions { permissions?: Array<DoorstepPermissionType | 'activity'> }
19
+
20
+ checkPermissions(): Promise<PermissionStatus>;
21
+ requestPermissions(options?: PermissionRequestOptions): Promise<PermissionStatus>;
22
+ ```
23
+
24
+ - **Added `checkPermissions()`**, both platforms. Reads the platform's own
25
+ non-prompting status APIs — `CLLocationManager.authorizationStatus` (the instance
26
+ property), `CMMotionActivityManager.authorizationStatus()` and the static
27
+ `CBManager.authorization` on iOS; `ContextCompat.checkSelfPermission` on Android —
28
+ over the names `DoorstepAI.getRequiredPermissions()` returns. It never
29
+ instantiates a `CBCentralManager`, which would prompt and would crash a host
30
+ without `NSBluetoothAlwaysUsageDescription`.
31
+ - **`requestPermissions` now resolves a `PermissionStatus`, after the user answers.**
32
+ Previously it resolved as soon as the prompt was *issued*
33
+ (`{ requestedPermissions }` on Android, `{}` on iOS), which said nothing about the
34
+ outcome. A concurrent second call now **rejects** with
35
+ `E_PERMISSION_REQUEST_IN_FLIGHT` instead of interleaving prompt sequences. An
36
+ unanswered prompt resolves with the current state after 120 s rather than hanging.
37
+ - **Removed `RequestPermissionsOptions` and `PermissionRequestResult`.** The options
38
+ object is `PermissionRequestOptions` (`{ permissions? }`) and the result is
39
+ `PermissionStatus`. The `includeBluetooth`, `requestAlwaysLocation`,
40
+ `onlyIfNotDetermined` and `requestCode` options are gone; `requestAlwaysLocation`
41
+ and `onlyIfNotDetermined` are left at their native defaults (both `true`), which
42
+ is what keeps a launch-time call from re-escalating a "While Using the App"
43
+ choice.
44
+ - **`permissions` can only narrow Bluetooth**, and this is documented rather than
45
+ silently swallowed: both natives request their whole required set behind a single
46
+ `includeBluetooth` / `requestBluetooth` flag, so the array is read as
47
+ `includeBluetooth = permissions.includes('bluetooth')` (true when omitted) and
48
+ `location` + `motion` always ride the base set. Passing `['bluetooth']` alone
49
+ still requests the base set.
50
+ - **`'activity'` is still accepted** wherever a `DoorstepPermissionType` is passed,
51
+ as a deprecated alias for `'motion'`, because it was the published 1.0.4 type. It
52
+ is normalised in the JS layer, so neither bridge ever sees it, and it is never a
53
+ key of `PermissionStatus`.
54
+ - `<RootDoorstepAI />` now gates its second-phase background-location prompt on
55
+ `status.permissions.location === 'granted'` from the request itself, which is only
56
+ meaningful now that the promise resolves post-answer.
57
+
58
+ ### Unchanged
59
+
60
+ - `requestBackgroundLocationPermission()` stays a separate Android-only entry
61
+ point, because Android 11+ requires background location as a second prompt after
62
+ the foreground grant and refuses to bundle it into one call. The wrapper does not
63
+ sequence the two for you. The iOS expression of the same intent is native's
64
+ `requestAlwaysLocation`, which `requestPermissions` leaves at its default (`true`).
65
+ - The query helpers `getRequiredPermissions` / `hasRequiredPermissions` /
66
+ `hasBackgroundLocationPermission` keep their shape and stay Android-only.
package/README.md CHANGED
@@ -41,9 +41,28 @@ const App = () => {
41
41
  }
42
42
  ```
43
43
 
44
- This sets the API key and initializes the SDK when the app launches.
44
+ This sets the API key, initializes the SDK, and runs the permission sequence when
45
+ the app launches. Every part of it is available a la carte on `DoorstepAI` — the
46
+ component exists so a host that just wants the default flow does not have to write
47
+ it.
45
48
 
46
- The notification title/text is meant to be passed into the Foreground Service for Android. This alows for greater customization over exact text.
49
+ The notification title/text is passed to Android's foreground service, so you get
50
+ full control over that text.
51
+
52
+ Optional props:
53
+
54
+ | prop | default | what it does |
55
+ |---|---|---|
56
+ | `permissions` | *(every bucket)* | The whitelist handed to `requestPermissions`: **exactly these buckets are requested and nothing else.** See [Permissions](#-permissions). |
57
+ | `requestBackgroundLocation` | `true` | Run the second-phase `locationAlways` request once foreground location is granted. It has to be a second phase because Android auto-denies a background ask bundled with the foreground one. Turn it off if your own onboarding asks for "Allow all the time". |
58
+ | `requestBluetooth` | `true` | **Deprecated** — use `permissions`, which can narrow any bucket rather than just this one. `false` drops the platform's Bluetooth bucket from the default whitelist. |
59
+
60
+ ```jsx
61
+ <RootDoorstepAI
62
+ apiKey="YOUR_API_KEY_HERE"
63
+ permissions={['location', 'motion']} // no Bluetooth, no notifications
64
+ />
65
+ ```
47
66
 
48
67
  ---
49
68
 
@@ -93,62 +112,118 @@ import { DoorstepAI } from "@doorstepai/dropoff-sdk"
93
112
 
94
113
  ## 🔧 SDK API
95
114
 
96
- ### `DoorstepAI.init(): Promise<void>`
115
+ Every method below is a thin pass-through to the native iOS/Android SDK. Where a
116
+ method exists on only one platform it says so, and it **rejects** on the other
117
+ rather than resolving a fabricated value — a helper that quietly resolved
118
+ `true`/`[]` would read as "granted" / "nothing needed" to a cross-platform host.
97
119
 
98
- Initializes the DoorstepAI module on Android. Automatically handled by `RootDoorstepAI` if used properly.
120
+ ### Setup
99
121
 
100
- NOTE: You should never need to call this method directly.
122
+ | method | notes |
123
+ |---|---|
124
+ | `init(notificationTitle?, notificationText?): Promise<void>` | Android only (no-op on iOS). Handled for you by `<RootDoorstepAI />`. The title/text go on the foreground-service notification. |
125
+ | `setApiKey(apiKey): void` | Collection API key. |
126
+ | `setDoorstepGoApiKey(apiKey): void` | Doorstep Go is a **separate credential and realm**; a no-op if you do not use it. |
127
+ | `configureRemoteLogging({ enabled, minLevel?, flushIntervalSeconds?, batchSize?, maxQueueSize? }): void` | iOS only (no-op on Android, which drives remote logging from remote config). |
128
+ | `debugStateJson(): Promise<string>` | iOS only. Free-form internal-state dump for bug reports — never branch on it. |
129
+ | `retryGnssCallbacks(): Promise<boolean>` | Android only. Re-registers raw-GNSS callbacks after the OS silently stops delivering them. |
130
+ | `enableDevMode(apiKey)` / `validateDevModeAccess()` / `disableDevMode()` | Dev tooling. The last two are Android-only and answer `false` on iOS. |
101
131
 
102
- ---
103
-
104
- ### `DoorstepAI.setApiKey(apiKey: string): void`
132
+ ### Deliveries
105
133
 
106
- Sets the API key to authenticate SDK usage.
107
-
108
- ---
109
-
110
- ### `DoorstepAI.startDeliveryByPlaceID(placeID: string, deliveryId: string): Promise<string>`
111
-
112
- Starts a delivery using a Google Place ID. Returns a session ID on success.
113
-
114
- ---
115
-
116
- ### `DoorstepAI.startDeliveryByPlusCode(plusCode: string, deliveryId: string): Promise<string>`
117
-
118
- Starts a delivery using a Google Plus Code. Returns a session ID on success.
119
-
120
- ---
134
+ All four starters take the same trailing `StartDeliveryOptions`:
121
135
 
122
- ### `DoorstepAI.startDeliveryByAddress(address: AddressType, deliveryId: string): Promise<string>`
136
+ ```ts
137
+ type StartDeliveryOptions = {
138
+ timeoutSeconds?: number; // hard session cap; OMIT for none
139
+ autoStopAfterDropoffSeconds?: number; // countdown once markDropoff is called
140
+ manualForeground?: boolean; // Android only: host owns the FGS
141
+ customerId?: string;
142
+ driverId?: string;
143
+ };
144
+ ```
123
145
 
124
- Starts a delivery using a structured address object. Returns a session ID on success.
146
+ | method | notes |
147
+ |---|---|
148
+ | `startDeliveryByAddressString(address, deliveryId, timeoutSeconds?, coordinates?, options?)` | Preferred. Pass `coordinates` when you have them. |
149
+ | `startDeliveryByAddress(address: AddressType, deliveryId, timeoutSeconds?, coordinates?, options?)` | Structured address. |
150
+ | `startDeliveryByPlaceID(placeID, deliveryId, timeoutSeconds?, options?)` | Google Place ID. |
151
+ | `startDeliveryByLatLng(lat, lng, subUnit, deliveryId, timeoutSeconds?, options?)` | **Deprecated** — use an address method with `coordinates`. |
152
+ | `startDeliveryByPlusCode(plusCode, deliveryId, timeoutSeconds?, options?)` | **Deprecated** — same. |
153
+ | `markDropoff(deliveryId, 'pod' \| 'non_pod'): Promise<void>` | Also arms `autoStopAfterDropoffSeconds` and gates the geofence-EXIT stop. |
154
+ | `stopDelivery(deliveryId): Promise<void>` | |
155
+ | `newEvent(eventName, deliveryId, timestamp?): Promise<...>` | `timestamp` is optional epoch **seconds**. |
125
156
 
126
157
  ```ts
127
158
  type AddressType = {
128
159
  streetNumber: string;
129
160
  route: string;
130
- subPremise: string; // Apartment, suite, unit, etc.
131
- locality: string; // City
132
- administrativeAreaLevel1: string; // State/Province
161
+ subPremise: string; // apartment, suite, unit
162
+ locality: string; // city
163
+ administrativeAreaLevel1: string; // state/province
133
164
  postalCode: string;
134
- }
165
+ };
135
166
  ```
136
167
 
137
- ---
168
+ **`timeoutSeconds` omitted means NO backstop**, which is the native behaviour on
169
+ both platforms. (An older version of this wrapper substituted 3600 s here and
170
+ force-stopped every delivery at one hour.)
138
171
 
139
- ### `DoorstepAI.stopDelivery(deliveryId: string): Promise<void>`
172
+ One cross-platform difference the wrapper does not paper over: **Android resolves
173
+ the server session id** (`{"id":"<uuid>"}`) from a starter and **iOS resolves
174
+ nothing** — native returns `Void` there. Treat a resolved promise as the success
175
+ signal, not a truthy return value. On iOS, listen for the SDK's
176
+ `sessionServerIdAssignedNotification` natively if you need the id.
140
177
 
141
- Stops the specified delivery.
178
+ ### Route geofencing
142
179
 
143
- ---
180
+ The SDK fences each stop, auto-starts a session on geofence ENTER and stops it on
181
+ EXIT (EXIT is gated on `markDropoff`; otherwise the per-session `timeoutSeconds`
182
+ backstop cleans up). Needs location permission, and **background operation needs
183
+ `locationAlways`**.
184
+
185
+ ```ts
186
+ type DeliveryStop = {
187
+ deliveryId: string;
188
+ address: string;
189
+ latitude: number;
190
+ longitude: number;
191
+ radiusMeters?: number; // default: options.defaultRadiusMeters (250)
192
+ customerId?: string;
193
+ driverId?: string;
194
+ };
195
+
196
+ type RouteGeofenceOptions = {
197
+ defaultRadiusMeters?: number; // 250
198
+ timeoutSeconds?: number; // per auto-started session
199
+ autoStopAfterDropoffSeconds?: number;
200
+ manualForeground?: boolean; // Android only; ignored on iOS
201
+ };
202
+ ```
144
203
 
145
- ### `DoorstepAI.newEvent(eventName: string, deliveryId: string): Promise<void>`
204
+ | method | notes |
205
+ |---|---|
206
+ | `startRouteGeofencing(stops, options?): Promise<void>` | Rejects if no stop has a `deliveryId` + coordinates. |
207
+ | `updateRouteStops(stops): Promise<void>` | Replaces the list in place. **Removing a stop that has an active session stops it immediately** (reason `removed_from_route`) — not EXIT-driven, not dropoff-gated. Does not extend the route lease. |
208
+ | `stopRouteGeofencing(): Promise<void>` | Teardown is handed to the tracking service / region manager, so `getMonitoredStops()` can still show the old list for a moment. |
209
+ | `resumeRouteGeofencingIfNeeded(): Promise<void>` | **Call this on every launch.** A per-launch host obligation: without it Android silently loses route monitoring across a process kill. |
210
+ | `getMonitoredStops(): Promise<DeliveryStop[]>` | The SDK's *intent* registry, not the OS's registered-region set. |
211
+ | `addGeofenceSessionListener(cb): EmitterSubscription \| undefined` | `{ deliveryId, type: 'STARTED' \| 'STOPPED', reason }`. Call `.remove()` to unsubscribe. |
146
212
 
147
- Sends a delivery-related event for the specified delivery. Supported events include:
148
- - `"taking_pod"`
149
- - `"pod_captured"`
213
+ ```ts
214
+ const sub = DoorstepAI.addGeofenceSessionListener(({ deliveryId, type, reason }) => {
215
+ console.log(type, deliveryId, reason);
216
+ });
217
+ await DoorstepAI.startRouteGeofencing(stops, { defaultRadiusMeters: 250 });
218
+ // ...later
219
+ sub?.remove();
220
+ ```
150
221
 
151
- More can be added per vender/customer relationship.
222
+ ### Permissions
223
+
224
+ `checkPermissions`, `checkPermissionsJson`, `requestPermissions`,
225
+ `allPermissionBuckets`, `notePermissionRequestResult`, and the Android-only query
226
+ helpers. See [Permissions](#-permissions) below — that section is the reference.
152
227
 
153
228
  ---
154
229
 
@@ -192,6 +267,11 @@ In your `Info.plist`, include the following usage descriptions:
192
267
  <key>NSMotionUsageDescription</key>
193
268
  <string>This app uses motion data to enhance delivery tracking accuracy.</string>
194
269
 
270
+ <!-- Required if you let Bluetooth default to on (see the permission API below).
271
+ Without this key the SDK skips the Bluetooth request with a warning. -->
272
+ <key>NSBluetoothAlwaysUsageDescription</key>
273
+ <string>This app uses Bluetooth to improve delivery location accuracy.</string>
274
+
195
275
  <!-- Background Location Mode -->
196
276
  <key>UIBackgroundModes</key>
197
277
  <array>
@@ -201,17 +281,21 @@ In your `Info.plist`, include the following usage descriptions:
201
281
 
202
282
  ### 🤖 Android
203
283
 
204
- In your `AndroidManifest.xml`, include the following permissions:
284
+ The SDK's own manifest already declares every permission it needs, so manifest
285
+ merging supplies them to your app. Declare these only if you want them visible in
286
+ your own `AndroidManifest.xml`:
205
287
 
206
288
  ```xml
207
289
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
208
290
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
209
291
  <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
210
292
  <uses-permission android:name="android.permission.HIGH_SAMPLING_RATE_SENSORS" />
211
- <uses-permission android:name="android.permission.ACTIVITY_RECOGNITION" />
212
293
  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
213
294
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
295
+ <uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
214
296
  <uses-permission android:name="android.permission.POST_NOTIFICATIONS" />
297
+ <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
298
+ <uses-permission android:name="android.permission.NEARBY_WIFI_DEVICES" />
215
299
  <uses-permission android:name="android.permission.WAKE_LOCK" />
216
300
 
217
301
  <uses-feature android:name="android.hardware.sensor.accelerometer" />
@@ -221,6 +305,189 @@ In your `AndroidManifest.xml`, include the following permissions:
221
305
  <uses-feature android:name="android.hardware.sensor.proximity" />
222
306
  ```
223
307
 
224
- These permissions enable accurate location and motion tracking during delivery sessions.
308
+ ### Requesting them at runtime
309
+
310
+ `<RootDoorstepAI />` does this for you. Use the API directly if you drive
311
+ permissions from your own onboarding flow — every method delegates to the native
312
+ SDK's own whitelist permission API, so the buckets, the states, the prompt order
313
+ and the "what will I decline to ask, and why" planning stay whatever the SDK says
314
+ they are.
315
+
316
+ **One requester, both platforms. No argument requests everything; an argument is a
317
+ whitelist and nothing outside it is ever asked for.** Do not branch on
318
+ `Platform.OS` to ask for permissions — the branch is inside the wrapper, on
319
+ `DoorstepAI.requestPermissions(_ permissions:…)` (iOS) and
320
+ `DoorstepAI.requestPermissions(activity, permissions)` (Android).
321
+
322
+ ```ts
323
+ await DoorstepAI.requestPermissions(); // every bucket
324
+ await DoorstepAI.requestPermissions(['locationWhenInUse']); // only this one
325
+ await DoorstepAI.requestPermissions({ // object form
326
+ permissions: ['location', 'motion'],
327
+ onlyIfNotDetermined: true, // iOS
328
+ timeoutSeconds: 60,
329
+ });
330
+ ```
331
+
332
+ #### Buckets
333
+
334
+ A **bucket** is one user-visible OS decision. They are deliberately OS-specific,
335
+ because the platforms are — only the two location buckets exist on both:
336
+
337
+ | bucket | iOS | Android |
338
+ |---|---|---|
339
+ | `locationWhenInUse` | `requestWhenInUseAuthorization` | `ACCESS_FINE_LOCATION` + `ACCESS_COARSE_LOCATION` |
340
+ | `locationAlways` | `requestAlwaysAuthorization` | `ACCESS_BACKGROUND_LOCATION` |
341
+ | `motionFitness` | Motion & Fitness | — |
342
+ | `activityRecognition` | — | `ACTIVITY_RECOGNITION` |
343
+ | `bluetooth` | `CBCentralManager` | — |
344
+ | `bluetoothScan` | — | `BLUETOOTH_SCAN` (API 31+) |
345
+ | `nearbyWifiDevices` | — | `NEARBY_WIFI_DEVICES` (API 33+) |
346
+ | `notifications` | — | `POST_NOTIFICATIONS` (API 33+) |
347
+
348
+ You can pass **either platform's** name on either platform: the wrapper translates
349
+ the counterpart (`motionFitness` ⇄ `activityRecognition`, `bluetooth` ⇄
350
+ `bluetoothScan`), so one whitelist works on both without a `Platform.OS` branch. A
351
+ name with no counterpart at all (`notifications` on iOS) comes back in
352
+ `unsupported` rather than being dropped in silence. The coarse aliases `'location'`
353
+ (→ both location buckets), `'motion'` / `'activity'` and `'bluetooth'` are still
354
+ accepted — they are what the published 2.x API took.
355
+
356
+ `DoorstepAI.allPermissionBuckets()` returns this platform's list if you want to
357
+ build a permission screen without hardcoding it.
358
+
359
+ #### States
360
+
361
+ Eight states, **the same names on both platforms**, so host code branches once:
362
+
363
+ | state | meaning |
364
+ |---|---|
365
+ | `granted` | held right now |
366
+ | `notDetermined` | never asked; a request will show a dialog |
367
+ | `whenInUseOnly` | **foreground location held, background not.** Only ever reported for `locationAlways` |
368
+ | `denied` | refused, another prompt is still possible (Android only) |
369
+ | `permanentlyDenied` | refused, no further prompt possible — deep-link to Settings. Every iOS refusal lands here |
370
+ | `restricted` | blocked by device policy / MDM / Screen Time |
371
+ | `unavailable` | the OS version or the hardware does not have it. Not a failure |
372
+ | `notDeclared` | **your build is missing the declaration** (`<uses-permission>` / `NS…UsageDescription`). Not a user refusal — fixable by you |
373
+
374
+ `whenInUseOnly` is the load-bearing one: **never treat it as `granted`.** Background
375
+ collection and route geofencing do not work in it.
376
+
377
+ ```ts
378
+ // Read the current state. Pure observation — never shows a dialog.
379
+ const { statuses } = await DoorstepAI.checkPermissions();
380
+ if (statuses.locationAlways?.state === 'whenInUseOnly') {
381
+ // foreground-only: no background collection, no route geofencing
382
+ }
383
+ if (statuses.locationWhenInUse?.state === 'permanentlyDenied') {
384
+ // a request would be answered instantly with no dialog — send them to Settings
385
+ }
386
+ ```
387
+
388
+ #### What a request answers with
389
+
390
+ `requestPermissions` **resolves only after the user has answered**, with the settled
391
+ state — a status read while a prompt is still up would be a lie. Everything native
392
+ declined to ask comes back explained rather than silently not happening:
393
+
394
+ ```ts
395
+ const result = await DoorstepAI.requestPermissions();
396
+ result.requested; // buckets a dialog was actually raised for
397
+ result.alreadyDetermined; // already answered, so left alone
398
+ result.unavailable; // absent on this device / missing from this build
399
+ result.deferred; // deliberately skipped, with the reason
400
+ result.statuses; // state of every whitelisted bucket, after settling
401
+ result.permissions; // legacy { location, motion, bluetooth } view
402
+ result.unsupported; // whitelist entries this platform has no bucket for
403
+ ```
404
+
405
+ **Expect `locationAlways` in `deferred` on a full-whitelist call.** It is only ever
406
+ asked *alone* and only *after* foreground location is granted — Android auto-denies
407
+ a bundled background ask, and iOS shows the When-In-Use prompt first and offers the
408
+ Always upgrade later on its own schedule. So the standard two-phase flow is:
409
+
410
+ ```ts
411
+ const first = await DoorstepAI.requestPermissions();
412
+ if (first.statuses.locationWhenInUse?.state === 'granted') {
413
+ await DoorstepAI.requestPermissions(['locationAlways']);
414
+ }
415
+ ```
416
+
417
+ Device-measured, Moto G stylus 5G / Android 14: a full-whitelist call raises the
418
+ five askable dialogs in one batch and returns
419
+ `deferred: { locationAlways: 'ACCESS_BACKGROUND_LOCATION cannot be requested before
420
+ foreground location is granted…' }`. iPhone 16 Pro / iOS 26.6: it raises
421
+ `locationAlways`, `motionFitness` and `bluetooth` one at a time and returns
422
+ `deferred: { locationWhenInUse: 'covered by the locationAlways prompt in this call…' }`.
423
+
424
+ A second call made while one is still in flight does not interleave prompt
425
+ sequences: iOS reports every bucket as `deferred`, Android rejects with
426
+ `E_PERMISSION_REQUEST_IN_FLIGHT`. If the user never answers, the wait gives up after
427
+ `timeoutSeconds` (default 120 s) and resolves with the state as it stands.
428
+
429
+ iOS guidance from the SDK: call it **once, from a user-initiated flow**, not from
430
+ app launch.
431
+
432
+ #### Android: forward your grant results (optional, worth doing)
433
+
434
+ Android reports *identical* signals for "permanently denied" and "never asked", and
435
+ a **cancelled** dialog leaves the same trace as a denial. The SDK refuses to guess,
436
+ so without a real answer a refusal reports as the re-askable `denied`. Forward the
437
+ result and you get `permanentlyDenied` — and the JS promise settles on the answer
438
+ itself instead of on a window-focus heuristic:
439
+
440
+ ```kotlin
441
+ // MainActivity.kt
442
+ import com.doorstepai.dropoffsdk.DoorstepAIModule
443
+
444
+ override fun onRequestPermissionsResult(
445
+ requestCode: Int, permissions: Array<out String>, grantResults: IntArray
446
+ ) {
447
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
448
+ DoorstepAIModule.notePermissionRequestResult(this, permissions, grantResults)
449
+ }
450
+ ```
451
+
452
+ There is a JS entry point too (`DoorstepAI.notePermissionRequestResult(permissions,
453
+ grantResults)`) if the values reach you there instead.
454
+
455
+ #### Legacy three-value view
456
+
457
+ `statuses` is the real answer, but every result also carries the
458
+ `{ location, motion, bluetooth }` × `granted | denied | prompt` map the published
459
+ 2.x API returned, so existing hosts keep working. It is collapsed from `statuses`:
460
+ `whenInUseOnly` and `unavailable` → `granted`, `notDetermined` → `prompt`,
461
+ everything else (including `notDeclared`) → `denied`.
462
+
463
+ Two things it cannot tell you, which is why it is deprecated: While-In-Use vs
464
+ Always, and a host-build mistake vs a user refusal.
465
+
466
+ `motion` stays unconditionally `granted` on Android, exactly as in 2.x. That is the
467
+ honest answer to what the key asks — Android's IMU streams (accel, gyro, mag,
468
+ rotation vectors, barometer) need **no** runtime grant, so motion collection is
469
+ always possible there. `activityRecognition` adds only the step-counter streams,
470
+ and the SDK never blocks a session on it; read `statuses.activityRecognition` for
471
+ its real state. On iOS `motion` does track Motion & Fitness, which genuinely gates
472
+ `CMMotionActivityManager`, `CMSensorRecorder` and absolute altitude.
473
+
474
+ #### Android-only query helpers
475
+
476
+ These reject on iOS rather than resolving `true`/`[]`, which a cross-platform host
477
+ would read as "granted" / "nothing needed".
478
+
479
+ ```ts
480
+ await DoorstepAI.hasRequiredPermissions(); // -> boolean
481
+ await DoorstepAI.hasBackgroundLocationPermission(); // -> boolean
482
+ await DoorstepAI.requestBackgroundLocationPermission();
483
+
484
+ // Want the grant results in JS? Request the SDK's own flat list with RN's API.
485
+ const required = await DoorstepAI.getRequiredPermissions();
486
+ await PermissionsAndroid.requestMultiple(required);
487
+ ```
488
+
489
+ `requestPermissions(['locationAlways'])` is the cross-platform way to express the
490
+ same intent as `requestBackgroundLocationPermission()`, and it reports back why if
491
+ the OS would have refused to show the prompt.
225
492
 
226
493
  ---
@@ -86,7 +86,11 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
86
86
  dependencies {
87
87
  implementation "com.facebook.react:react-android"
88
88
  implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
89
- implementation("ai.doorstep.com:doorstepai-dropoff-sdk:2.1.3")
89
+ // `api`, not `implementation`: the host Activity is expected to forward
90
+ // `onRequestPermissionsResult` to `DoorstepAI.notePermissionRequestResult(...)`
91
+ // (the only way the SDK can tell a re-askable denial from a permanent one), so
92
+ // the SDK's types have to be on the host's compile classpath.
93
+ api("ai.doorstep.com:doorstepai-dropoff-sdk:2.2.2")
90
94
  api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1"
91
95
  }
92
96