@doorstepai/dropoff-sdk 2.2.0 → 2.2.3

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/README.md +265 -112
  2. package/android/build.gradle +5 -1
  3. package/android/src/main/java/com/doorstepai/dropoffsdk/DoorstepAIModule.kt +368 -136
  4. package/ios/DoorstepAI.mm +8 -1
  5. package/ios/DoorstepAI.swift +120 -139
  6. package/ios/DoorstepDropoffSDK.xcframework/Info.plist +5 -5
  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 +10176 -6209
  9. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +82 -0
  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 +82 -0
  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 +3867 -3248
  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 +10176 -6209
  17. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +82 -0
  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 +82 -0
  20. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +10176 -6209
  21. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +82 -0
  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 +82 -0
  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 +3868 -3248
  27. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/DoorstepDropoffSDK.yml +3836 -3233
  28. package/lib/module/DoorstepAI.js +306 -71
  29. package/lib/module/DoorstepAI.js.map +1 -1
  30. package/lib/module/RootDoorstepAI.js +50 -32
  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 +271 -73
  34. package/lib/typescript/src/DoorstepAI.d.ts.map +1 -1
  35. package/lib/typescript/src/RootDoorstepAI.d.ts +24 -7
  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 +1 -1
  40. package/src/DoorstepAI.tsx +425 -91
  41. package/src/RootDoorstepAI.tsx +75 -45
  42. package/src/index.tsx +6 -0
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,116 @@ import { DoorstepAI } from "@doorstepai/dropoff-sdk"
93
112
 
94
113
  ## 🔧 SDK API
95
114
 
96
- ### `DoorstepAI.init(): Promise<void>`
97
-
98
- Initializes the DoorstepAI module on Android. Automatically handled by `RootDoorstepAI` if used properly.
99
-
100
- NOTE: You should never need to call this method directly.
101
-
102
- ---
103
-
104
- ### `DoorstepAI.setApiKey(apiKey: string): void`
105
-
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.
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.
113
119
 
114
- ---
120
+ ### Setup
115
121
 
116
- ### `DoorstepAI.startDeliveryByPlusCode(plusCode: string, deliveryId: string): Promise<string>`
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. |
117
131
 
118
- Starts a delivery using a Google Plus Code. Returns a session ID on success.
132
+ ### Deliveries
119
133
 
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
+ manualForeground?: boolean; // Android only: host owns the FGS
140
+ customerId?: string;
141
+ driverId?: string;
142
+ };
143
+ ```
123
144
 
124
- Starts a delivery using a structured address object. Returns a session ID on success.
145
+ | method | notes |
146
+ |---|---|
147
+ | `startDeliveryByAddressString(address, deliveryId, timeoutSeconds?, coordinates?, options?)` | Preferred. Pass `coordinates` when you have them. |
148
+ | `startDeliveryByAddress(address: AddressType, deliveryId, timeoutSeconds?, coordinates?, options?)` | Structured address. |
149
+ | `startDeliveryByPlaceID(placeID, deliveryId, timeoutSeconds?, options?)` | Google Place ID. |
150
+ | `startDeliveryByLatLng(lat, lng, subUnit, deliveryId, timeoutSeconds?, options?)` | **Deprecated** — use an address method with `coordinates`. |
151
+ | `startDeliveryByPlusCode(plusCode, deliveryId, timeoutSeconds?, options?)` | **Deprecated** — same. |
152
+ | `markDropoff(deliveryId, 'pod' \| 'non_pod'): Promise<void>` | Records completion and gates the route-geofence EXIT stop. |
153
+ | `stopDelivery(deliveryId): Promise<void>` | |
154
+ | `newEvent(eventName, deliveryId, timestamp?): Promise<...>` | `timestamp` is optional epoch **seconds**. |
125
155
 
126
156
  ```ts
127
157
  type AddressType = {
128
158
  streetNumber: string;
129
159
  route: string;
130
- subPremise: string; // Apartment, suite, unit, etc.
131
- locality: string; // City
132
- administrativeAreaLevel1: string; // State/Province
160
+ subPremise: string; // apartment, suite, unit
161
+ locality: string; // city
162
+ administrativeAreaLevel1: string; // state/province
133
163
  postalCode: string;
134
- }
164
+ };
135
165
  ```
136
166
 
137
- ---
167
+ **`timeoutSeconds` omitted means NO backstop**, which is the native behaviour on
168
+ both platforms. (An older version of this wrapper substituted 3600 s here and
169
+ force-stopped every delivery at one hour.)
138
170
 
139
- ### `DoorstepAI.stopDelivery(deliveryId: string): Promise<void>`
171
+ One cross-platform difference the wrapper does not paper over: **Android resolves
172
+ the server session id** (`{"id":"<uuid>"}`) from a starter and **iOS resolves
173
+ nothing** — native returns `Void` there. Treat a resolved promise as the success
174
+ signal, not a truthy return value. On iOS, listen for the SDK's
175
+ `sessionServerIdAssignedNotification` natively if you need the id.
140
176
 
141
- Stops the specified delivery.
177
+ ### Route geofencing
142
178
 
143
- ---
179
+ The SDK fences each stop, auto-starts a session on geofence ENTER and stops it on
180
+ EXIT (EXIT is gated on `markDropoff`; otherwise the per-session `timeoutSeconds`
181
+ backstop cleans up). Needs location permission, and **background operation needs
182
+ `locationAlways`**.
144
183
 
145
- ### `DoorstepAI.newEvent(eventName: string, deliveryId: string): Promise<void>`
184
+ ```ts
185
+ type DeliveryStop = {
186
+ deliveryId: string;
187
+ address: string;
188
+ latitude: number;
189
+ longitude: number;
190
+ radiusMeters?: number; // default: options.defaultRadiusMeters (250)
191
+ customerId?: string;
192
+ driverId?: string;
193
+ };
194
+
195
+ type RouteGeofenceOptions = {
196
+ defaultRadiusMeters?: number; // 250
197
+ timeoutSeconds?: number; // per auto-started session
198
+ manualForeground?: boolean; // Android only; ignored on iOS
199
+ };
200
+ ```
146
201
 
147
- Sends a delivery-related event for the specified delivery. Supported events include:
148
- - `"taking_pod"`
149
- - `"pod_captured"`
202
+ | method | notes |
203
+ |---|---|
204
+ | `startRouteGeofencing(stops, options?): Promise<void>` | Rejects if no stop has a `deliveryId` + coordinates. |
205
+ | `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. |
206
+ | `stopRouteGeofencing(): Promise<void>` | Teardown is handed to the tracking service / region manager, so `getMonitoredStops()` can still show the old list for a moment. |
207
+ | `resumeRouteGeofencingIfNeeded(): Promise<void>` | **Call this on every launch.** A per-launch host obligation: without it Android silently loses route monitoring across a process kill. |
208
+ | `getMonitoredStops(): Promise<DeliveryStop[]>` | The SDK's *intent* registry, not the OS's registered-region set. |
209
+ | `addGeofenceSessionListener(cb): EmitterSubscription \| undefined` | `{ deliveryId, type: 'STARTED' \| 'STOPPED', reason }`. Call `.remove()` to unsubscribe. |
150
210
 
151
- More can be added per vender/customer relationship.
211
+ ```ts
212
+ const sub = DoorstepAI.addGeofenceSessionListener(({ deliveryId, type, reason }) => {
213
+ console.log(type, deliveryId, reason);
214
+ });
215
+ await DoorstepAI.startRouteGeofencing(stops, { defaultRadiusMeters: 250 });
216
+ // ...later
217
+ sub?.remove();
218
+ ```
219
+
220
+ ### Permissions
221
+
222
+ `checkPermissions`, `checkPermissionsJson`, `requestPermissions`,
223
+ `allPermissionBuckets`, `notePermissionRequestResult`, and the Android-only query
224
+ helpers. See [Permissions](#-permissions) below — that section is the reference.
152
225
 
153
226
  ---
154
227
 
@@ -234,105 +307,185 @@ your own `AndroidManifest.xml`:
234
307
 
235
308
  `<RootDoorstepAI />` does this for you. Use the API directly if you drive
236
309
  permissions from your own onboarding flow — every method delegates to the native
237
- SDK, so the list and the ordering stay whatever the SDK says they are.
310
+ SDK's own whitelist permission API, so the buckets, the states, the prompt order
311
+ and the "what will I decline to ask, and why" planning stay whatever the SDK says
312
+ they are.
238
313
 
239
- `checkPermissions` and `requestPermissions` are the **permission surface, identical
240
- on both platforms and identical to the Capacitor and Flutter wrappers**. Do not
241
- branch on `Platform.OS` to ask for permissions: the branch is inside the wrapper,
242
- dispatching to `DoorstepAI.requestPermissions(activity, requestCode,
243
- includeBluetooth)` on Android and
244
- `DoorstepAI.requestAllPermissions(requestAlwaysLocation:requestBluetooth:onlyIfNotDetermined:)`
245
- on iOS.
314
+ **One requester, both platforms. No argument requests everything; an argument is a
315
+ whitelist and nothing outside it is ever asked for.** Do not branch on
316
+ `Platform.OS` to ask for permissions — the branch is inside the wrapper, on
317
+ `DoorstepAI.requestPermissions(_ permissions:…)` (iOS) and
318
+ `DoorstepAI.requestPermissions(activity, permissions)` (Android).
246
319
 
247
320
  ```ts
248
- type PermissionState = 'granted' | 'denied' | 'prompt';
249
- type DoorstepPermissionType = 'location' | 'motion' | 'bluetooth';
321
+ await DoorstepAI.requestPermissions(); // every bucket
322
+ await DoorstepAI.requestPermissions(['locationWhenInUse']); // only this one
323
+ await DoorstepAI.requestPermissions({ // object form
324
+ permissions: ['location', 'motion'],
325
+ onlyIfNotDetermined: true, // iOS
326
+ timeoutSeconds: 60,
327
+ });
328
+ ```
250
329
 
251
- interface PermissionStatus {
252
- permissions: Record<DoorstepPermissionType, PermissionState>;
253
- }
330
+ #### Buckets
331
+
332
+ A **bucket** is one user-visible OS decision. They are deliberately OS-specific,
333
+ because the platforms are — only the two location buckets exist on both:
334
+
335
+ | bucket | iOS | Android |
336
+ |---|---|---|
337
+ | `locationWhenInUse` | `requestWhenInUseAuthorization` | `ACCESS_FINE_LOCATION` + `ACCESS_COARSE_LOCATION` |
338
+ | `locationAlways` | `requestAlwaysAuthorization` | `ACCESS_BACKGROUND_LOCATION` |
339
+ | `motionFitness` | Motion & Fitness | — |
340
+ | `activityRecognition` | — | `ACTIVITY_RECOGNITION` |
341
+ | `bluetooth` | `CBCentralManager` | — |
342
+ | `bluetoothScan` | — | `BLUETOOTH_SCAN` (API 31+) |
343
+ | `nearbyWifiDevices` | — | `NEARBY_WIFI_DEVICES` (API 33+) |
344
+ | `notifications` | — | `POST_NOTIFICATIONS` (API 33+) |
345
+
346
+ You can pass **either platform's** name on either platform: the wrapper translates
347
+ the counterpart (`motionFitness` ⇄ `activityRecognition`, `bluetooth` ⇄
348
+ `bluetoothScan`), so one whitelist works on both without a `Platform.OS` branch. A
349
+ name with no counterpart at all (`notifications` on iOS) comes back in
350
+ `unsupported` rather than being dropped in silence. The coarse aliases `'location'`
351
+ (→ both location buckets), `'motion'` / `'activity'` and `'bluetooth'` are still
352
+ accepted — they are what the published 2.x API took.
353
+
354
+ `DoorstepAI.allPermissionBuckets()` returns this platform's list if you want to
355
+ build a permission screen without hardcoding it.
356
+
357
+ #### States
358
+
359
+ Eight states, **the same names on both platforms**, so host code branches once:
360
+
361
+ | state | meaning |
362
+ |---|---|
363
+ | `granted` | held right now |
364
+ | `notDetermined` | never asked; a request will show a dialog |
365
+ | `whenInUseOnly` | **foreground location held, background not.** Only ever reported for `locationAlways` |
366
+ | `denied` | refused, another prompt is still possible (Android only) |
367
+ | `permanentlyDenied` | refused, no further prompt possible — deep-link to Settings. Every iOS refusal lands here |
368
+ | `restricted` | blocked by device policy / MDM / Screen Time |
369
+ | `unavailable` | the OS version or the hardware does not have it. Not a failure |
370
+ | `notDeclared` | **your build is missing the declaration** (`<uses-permission>` / `NS…UsageDescription`). Not a user refusal — fixable by you |
371
+
372
+ `whenInUseOnly` is the load-bearing one: **never treat it as `granted`.** Background
373
+ collection and route geofencing do not work in it.
254
374
 
255
- interface PermissionRequestOptions {
256
- permissions?: Array<DoorstepPermissionType | 'activity'>;
375
+ ```ts
376
+ // Read the current state. Pure observation — never shows a dialog.
377
+ const { statuses } = await DoorstepAI.checkPermissions();
378
+ if (statuses.locationAlways?.state === 'whenInUseOnly') {
379
+ // foreground-only: no background collection, no route geofencing
380
+ }
381
+ if (statuses.locationWhenInUse?.state === 'permanentlyDenied') {
382
+ // a request would be answered instantly with no dialog — send them to Settings
257
383
  }
258
-
259
- checkPermissions(): Promise<PermissionStatus>;
260
- requestPermissions(options?: PermissionRequestOptions): Promise<PermissionStatus>;
261
384
  ```
262
385
 
263
- ```ts
264
- // Read the current state. Never shows a dialog.
265
- const { permissions } = await DoorstepAI.checkPermissions();
266
- // -> { location: 'prompt', motion: 'granted', bluetooth: 'denied' }
386
+ #### What a request answers with
387
+
388
+ `requestPermissions` **resolves only after the user has answered**, with the settled
389
+ state — a status read while a prompt is still up would be a lie. Everything native
390
+ declined to ask comes back explained rather than silently not happening:
267
391
 
268
- // Ask. Resolves AFTER the user answers, with the resulting state.
269
- const after = await DoorstepAI.requestPermissions();
270
- if (after.permissions.location !== 'granted') { /* explain, offer Settings */ }
392
+ ```ts
393
+ const result = await DoorstepAI.requestPermissions();
394
+ result.requested; // buckets a dialog was actually raised for
395
+ result.alreadyDetermined; // already answered, so left alone
396
+ result.unavailable; // absent on this device / missing from this build
397
+ result.deferred; // deliberately skipped, with the reason
398
+ result.statuses; // state of every whitelisted bucket, after settling
399
+ result.permissions; // legacy { location, motion, bluetooth } view
400
+ result.unsupported; // whitelist entries this platform has no bucket for
271
401
  ```
272
402
 
273
- `checkPermissions` is pure observation: it reads `CLLocationManager.authorizationStatus`,
274
- `CMMotionActivityManager.authorizationStatus()` and `CBManager.authorization` on
275
- iOS, and `ContextCompat.checkSelfPermission` on Android, against the permission
276
- names the **native SDK** returns from `getRequiredPermissions()`. The wrapper keeps
277
- no permission list of its own. A bucket the native SDK needs no runtime grant for
278
- on this OS version reports `granted` — `motion` on Android (sensor collection needs
279
- none) and `bluetooth` below Android 12.
403
+ **Expect `locationAlways` in `deferred` on a full-whitelist call.** It is only ever
404
+ asked *alone* and only *after* foreground location is granted — Android auto-denies
405
+ a bundled background ask, and iOS shows the When-In-Use prompt first and offers the
406
+ Always upgrade later on its own schedule. So the standard two-phase flow is:
280
407
 
281
- `requestPermissions` **resolves only after the dialog has been answered**, because
282
- it returns a `PermissionStatus` and a status captured while the prompt is still up
283
- would be stale. A second call issued while one is still awaiting an answer
284
- **rejects** (`E_PERMISSION_REQUEST_IN_FLIGHT`) rather than interleaving two prompt
285
- sequences. If the user never answers, the wait gives up after 120 s and resolves
286
- with the state as it stands — still `prompt` for anything unanswered.
408
+ ```ts
409
+ const first = await DoorstepAI.requestPermissions();
410
+ if (first.statuses.locationWhenInUse?.state === 'granted') {
411
+ await DoorstepAI.requestPermissions(['locationAlways']);
412
+ }
413
+ ```
287
414
 
288
- #### `permissions` can only narrow Bluetooth
415
+ Device-measured, Moto G stylus 5G / Android 14: a full-whitelist call raises the
416
+ five askable dialogs in one batch and returns
417
+ `deferred: { locationAlways: 'ACCESS_BACKGROUND_LOCATION cannot be requested before
418
+ foreground location is granted…' }`. iPhone 16 Pro / iOS 26.6: it raises
419
+ `locationAlways`, `motionFitness` and `bluetooth` one at a time and returns
420
+ `deferred: { locationWhenInUse: 'covered by the locationAlways prompt in this call…' }`.
421
+
422
+ A second call made while one is still in flight does not interleave prompt
423
+ sequences: iOS reports every bucket as `deferred`, Android rejects with
424
+ `E_PERMISSION_REQUEST_IN_FLIGHT`. If the user never answers, the wait gives up after
425
+ `timeoutSeconds` (default 120 s) and resolves with the state as it stands.
426
+
427
+ iOS guidance from the SDK: call it **once, from a user-initiated flow**, not from
428
+ app launch.
429
+
430
+ #### Android: forward your grant results (optional, worth doing)
431
+
432
+ Android reports *identical* signals for "permanently denied" and "never asked", and
433
+ a **cancelled** dialog leaves the same trace as a denial. The SDK refuses to guess,
434
+ so without a real answer a refusal reports as the re-askable `denied`. Forward the
435
+ result and you get `permanentlyDenied` — and the JS promise settles on the answer
436
+ itself instead of on a window-focus heuristic:
437
+
438
+ ```kotlin
439
+ // MainActivity.kt
440
+ import com.doorstepai.dropoffsdk.DoorstepAIModule
441
+
442
+ override fun onRequestPermissionsResult(
443
+ requestCode: Int, permissions: Array<out String>, grantResults: IntArray
444
+ ) {
445
+ super.onRequestPermissionsResult(requestCode, permissions, grantResults)
446
+ DoorstepAIModule.notePermissionRequestResult(this, permissions, grantResults)
447
+ }
448
+ ```
289
449
 
290
- Neither native offers per-permission selection: each requests its **whole required
291
- set** behind one `includeBluetooth` / `requestBluetooth` flag. So the array is read
292
- as:
450
+ There is a JS entry point too (`DoorstepAI.notePermissionRequestResult(permissions,
451
+ grantResults)`) if the values reach you there instead.
293
452
 
294
- ```
295
- includeBluetooth = permissions === undefined || permissions.includes('bluetooth')
296
- ```
453
+ #### Legacy three-value view
297
454
 
298
- and **`location` and `motion` always ride the base set**. Passing `['bluetooth']`
299
- alone still requests the base set as well; passing `['location']` still shows the
300
- Motion & Fitness prompt on iOS. This is documented rather than silently swallowed —
301
- an array the wrapper cannot honour would be a lie.
455
+ `statuses` is the real answer, but every result also carries the
456
+ `{ location, motion, bluetooth }` × `granted | denied | prompt` map the published
457
+ 2.x API returned, so existing hosts keep working. It is collapsed from `statuses`:
458
+ `whenInUseOnly` and `unavailable` → `granted`, `notDetermined` → `prompt`,
459
+ everything else (including `notDeclared`) → `denied`.
302
460
 
303
- `'activity'` is still accepted in the array as a **deprecated alias for `'motion'`**
304
- (it was the published type in `@doorstepai/dropoff-sdk-capacitor` 1.0.4). It is
305
- normalised to `'motion'` before it reaches native and is never a key of
306
- `PermissionStatus`.
461
+ Two things it cannot tell you, which is why it is deprecated: While-In-Use vs
462
+ Always, and a host-build mistake vs a user refusal.
307
463
 
308
- **Background location is a second call on Android.** Android 11+ refuses to bundle
309
- `ACCESS_BACKGROUND_LOCATION` into the foreground request; it must be prompted
310
- separately, *after* foreground location is granted, or the OS spends it on an
311
- automatic denial. The wrapper does not sequence this for you.
464
+ `motion` stays unconditionally `granted` on Android, exactly as in 2.x. That is the
465
+ honest answer to what the key asks — Android's IMU streams (accel, gyro, mag,
466
+ rotation vectors, barometer) need **no** runtime grant, so motion collection is
467
+ always possible there. `activityRecognition` adds only the step-counter streams,
468
+ and the SDK never blocks a session on it; read `statuses.activityRecognition` for
469
+ its real state. On iOS `motion` does track Motion & Fitness, which genuinely gates
470
+ `CMMotionActivityManager`, `CMSensorRecorder` and absolute altitude.
312
471
 
313
- ```ts
314
- // Android only. On iOS the same intent is native's requestAlwaysLocation, which
315
- // requestPermissions leaves at its default (true) — this method has no iOS
316
- // counterpart and rejects there rather than inventing an answer.
317
- if (Platform.OS === 'android') {
318
- const { permissions } = await DoorstepAI.requestPermissions();
319
- if (permissions.location === 'granted') {
320
- if (!(await DoorstepAI.hasBackgroundLocationPermission())) {
321
- await DoorstepAI.requestBackgroundLocationPermission();
322
- }
323
- }
324
- }
325
- ```
472
+ #### Android-only query helpers
326
473
 
327
- The query helpers below are Android-only and reject on iOS rather than resolving
328
- `true`/`[]`, which a cross-platform host would read as "granted" / "nothing needed".
474
+ These reject on iOS rather than resolving `true`/`[]`, which a cross-platform host
475
+ would read as "granted" / "nothing needed".
329
476
 
330
477
  ```ts
331
- await DoorstepAI.hasRequiredPermissions(); // -> boolean
478
+ await DoorstepAI.hasRequiredPermissions(); // -> boolean
479
+ await DoorstepAI.hasBackgroundLocationPermission(); // -> boolean
480
+ await DoorstepAI.requestBackgroundLocationPermission();
332
481
 
333
- // Want the grant results in JS? Request the SDK's own list with RN's API.
482
+ // Want the grant results in JS? Request the SDK's own flat list with RN's API.
334
483
  const required = await DoorstepAI.getRequiredPermissions();
335
484
  await PermissionsAndroid.requestMultiple(required);
336
485
  ```
337
486
 
487
+ `requestPermissions(['locationAlways'])` is the cross-platform way to express the
488
+ same intent as `requestBackgroundLocationPermission()`, and it reports back why if
489
+ the OS would have refused to show the prompt.
490
+
338
491
  ---
@@ -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.2.0")
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.3")
90
94
  api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1"
91
95
  }
92
96