@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.
- package/README.md +265 -112
- package/android/build.gradle +5 -1
- package/android/src/main/java/com/doorstepai/dropoffsdk/DoorstepAIModule.kt +368 -136
- package/ios/DoorstepAI.mm +8 -1
- package/ios/DoorstepAI.swift +120 -139
- package/ios/DoorstepDropoffSDK.xcframework/Info.plist +5 -5
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/DoorstepDropoffSDK +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.abi.json +10176 -6209
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +82 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.swiftinterface +82 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +10 -10
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/DWARF/DoorstepDropoffSDK +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/DoorstepDropoffSDK.yml +3867 -3248
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/DoorstepDropoffSDK +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +10176 -6209
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +82 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +82 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +10176 -6209
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +82 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +82 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +20 -20
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/DWARF/DoorstepDropoffSDK +0 -0
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/DoorstepDropoffSDK.yml +3868 -3248
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/DoorstepDropoffSDK.yml +3836 -3233
- package/lib/module/DoorstepAI.js +306 -71
- package/lib/module/DoorstepAI.js.map +1 -1
- package/lib/module/RootDoorstepAI.js +50 -32
- package/lib/module/RootDoorstepAI.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/DoorstepAI.d.ts +271 -73
- package/lib/typescript/src/DoorstepAI.d.ts.map +1 -1
- package/lib/typescript/src/RootDoorstepAI.d.ts +24 -7
- package/lib/typescript/src/RootDoorstepAI.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +1 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/DoorstepAI.tsx +425 -91
- package/src/RootDoorstepAI.tsx +75 -45
- package/src/index.tsx +6 -0
package/src/DoorstepAI.tsx
CHANGED
|
@@ -103,62 +103,280 @@ type StartDeliveryOptions = {
|
|
|
103
103
|
};
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
|
-
*
|
|
107
|
-
* spelled
|
|
106
|
+
* A runtime-permission **bucket** — one bucket is one user-visible OS decision,
|
|
107
|
+
* spelled exactly as the native SDK spells it.
|
|
108
|
+
*
|
|
109
|
+
* The buckets are deliberately OS-specific, because the platforms are: iOS has a
|
|
110
|
+
* single Motion & Fitness authorization and no WiFi-scan permission at all,
|
|
111
|
+
* Android splits BLE scanning, nearby-WiFi and notifications into their own
|
|
112
|
+
* dialogs. Only the two location buckets exist on both.
|
|
113
|
+
*
|
|
114
|
+
* | bucket | iOS | Android |
|
|
115
|
+
* |---|---|---|
|
|
116
|
+
* | `locationWhenInUse` | `requestWhenInUseAuthorization` | `ACCESS_FINE_LOCATION` + `ACCESS_COARSE_LOCATION` |
|
|
117
|
+
* | `locationAlways` | `requestAlwaysAuthorization` | `ACCESS_BACKGROUND_LOCATION` |
|
|
118
|
+
* | `motionFitness` | Motion & Fitness | — (use `activityRecognition`) |
|
|
119
|
+
* | `activityRecognition` | — (use `motionFitness`) | `ACTIVITY_RECOGNITION` |
|
|
120
|
+
* | `bluetooth` | `CBCentralManager` | — (use `bluetoothScan`) |
|
|
121
|
+
* | `bluetoothScan` | — (use `bluetooth`) | `BLUETOOTH_SCAN` (API 31+) |
|
|
122
|
+
* | `nearbyWifiDevices` | — | `NEARBY_WIFI_DEVICES` (API 33+) |
|
|
123
|
+
* | `notifications` | — | `POST_NOTIFICATIONS` (API 33+) |
|
|
124
|
+
*
|
|
125
|
+
* You may pass **either platform's** name on either platform: the wrapper
|
|
126
|
+
* translates the counterpart bucket (`motionFitness` ⇄ `activityRecognition`,
|
|
127
|
+
* `bluetooth` ⇄ `bluetoothScan`) so one whitelist works on both without a
|
|
128
|
+
* `Platform.OS` branch. A bucket with no counterpart at all (`nearbyWifiDevices`
|
|
129
|
+
* / `notifications` on iOS) is reported back in `unsupported` rather than
|
|
130
|
+
* silently dropped.
|
|
108
131
|
*/
|
|
109
|
-
type
|
|
132
|
+
type DoorstepPermission =
|
|
133
|
+
| 'locationWhenInUse'
|
|
134
|
+
| 'locationAlways'
|
|
135
|
+
| 'motionFitness'
|
|
136
|
+
| 'bluetooth'
|
|
137
|
+
| 'activityRecognition'
|
|
138
|
+
| 'bluetoothScan'
|
|
139
|
+
| 'nearbyWifiDevices'
|
|
140
|
+
| 'notifications';
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* Coarse aliases accepted anywhere a {@link DoorstepPermission} is, kept because
|
|
144
|
+
* they are what the published 2.x wrapper API took. Each expands to this
|
|
145
|
+
* platform's buckets: `location` → both location buckets, `motion` / `activity`
|
|
146
|
+
* → the platform's motion bucket, `bluetooth` → the platform's BLE bucket
|
|
147
|
+
* (`bluetooth` is also a real iOS bucket name, so it is both).
|
|
148
|
+
*/
|
|
149
|
+
type DoorstepPermissionAlias = 'location' | 'motion' | 'activity';
|
|
150
|
+
|
|
151
|
+
/** Anything the whitelist accepts. */
|
|
152
|
+
type DoorstepPermissionInput = DoorstepPermission | DoorstepPermissionAlias;
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* The state of one bucket. Eight states, **identical names on both platforms**,
|
|
156
|
+
* so host code branches once.
|
|
157
|
+
*
|
|
158
|
+
* - `granted` — held right now.
|
|
159
|
+
* - `notDetermined` — never asked; a request will show a dialog.
|
|
160
|
+
* - `whenInUseOnly` — **load-bearing.** Foreground location held, background not
|
|
161
|
+
* (iOS "While Using the App" / Android foreground-only). Only ever reported for
|
|
162
|
+
* `locationAlways`. Never treat it as `granted`: background collection and
|
|
163
|
+
* route geofencing do not work in it.
|
|
164
|
+
* - `denied` — refused, but another prompt is still possible. Android only; iOS
|
|
165
|
+
* refusals are always final.
|
|
166
|
+
* - `permanentlyDenied` — refused with no further prompt possible. Deep-link the
|
|
167
|
+
* user to Settings. Every iOS refusal lands here.
|
|
168
|
+
* - `restricted` — blocked by device policy / MDM / Screen Time.
|
|
169
|
+
* - `unavailable` — the OS version or the hardware does not have it. Not a
|
|
170
|
+
* failure, nothing to request.
|
|
171
|
+
* - `notDeclared` — **the HOST BUILD is missing the declaration**
|
|
172
|
+
* (`<uses-permission>` on Android, an `NS…UsageDescription` key on iOS), so the
|
|
173
|
+
* OS would never show a dialog. Fixable by you; it is NOT a user refusal.
|
|
174
|
+
*/
|
|
175
|
+
type DoorstepPermissionState =
|
|
176
|
+
| 'granted'
|
|
177
|
+
| 'notDetermined'
|
|
178
|
+
| 'whenInUseOnly'
|
|
179
|
+
| 'denied'
|
|
180
|
+
| 'permanentlyDenied'
|
|
181
|
+
| 'restricted'
|
|
182
|
+
| 'unavailable'
|
|
183
|
+
| 'notDeclared';
|
|
184
|
+
|
|
185
|
+
/** The evaluated state of one bucket. */
|
|
186
|
+
type DoorstepPermissionStatus = {
|
|
187
|
+
permission: DoorstepPermission;
|
|
188
|
+
state: DoorstepPermissionState;
|
|
189
|
+
/**
|
|
190
|
+
* Raw evidence in the OS's own vocabulary (`"authorizedWhenInUse"`,
|
|
191
|
+
* `"ACCESS_FINE_LOCATION=granted,ACCESS_COARSE_LOCATION=denied"`, …).
|
|
192
|
+
* Diagnostic only — never branch on it.
|
|
193
|
+
*/
|
|
194
|
+
osStatus: string;
|
|
195
|
+
/** True when `requestPermissions` would actually raise a dialog for it. */
|
|
196
|
+
canRequest: boolean;
|
|
197
|
+
};
|
|
110
198
|
|
|
111
199
|
/**
|
|
112
|
-
* The permission
|
|
200
|
+
* The grant state of one permission in the **legacy** three-value vocabulary the
|
|
201
|
+
* published 2.x wrapper API used. `'prompt'` means "not determined yet".
|
|
113
202
|
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
203
|
+
* @deprecated Read {@link PermissionStatus.statuses} instead — it distinguishes
|
|
204
|
+
* `whenInUseOnly`, `permanentlyDenied` and `notDeclared`, all of which collapse
|
|
205
|
+
* away here.
|
|
206
|
+
*/
|
|
207
|
+
type PermissionState = 'granted' | 'denied' | 'prompt';
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* The three coarse domains of the legacy view.
|
|
117
211
|
*
|
|
118
|
-
*
|
|
119
|
-
* is passed, as a **deprecated alias for `'motion'`** — it was the published name
|
|
120
|
-
* in `@doorstepai/dropoff-sdk-capacitor` 1.0.4 and dropping it would break hosts.
|
|
121
|
-
* It is normalised to `'motion'` before it reaches native, and it is never a key
|
|
122
|
-
* of {@link PermissionStatus}.
|
|
212
|
+
* @deprecated Use {@link DoorstepPermission}.
|
|
123
213
|
*/
|
|
124
214
|
type DoorstepPermissionType = 'location' | 'motion' | 'bluetooth';
|
|
125
215
|
|
|
126
|
-
/**
|
|
216
|
+
/** What {@link DoorstepAIModule.checkPermissions} answers. */
|
|
127
217
|
interface PermissionStatus {
|
|
218
|
+
/**
|
|
219
|
+
* One entry per whitelisted bucket, keyed by bucket name. This is the real
|
|
220
|
+
* answer; everything else on this object is a convenience over it.
|
|
221
|
+
*/
|
|
222
|
+
statuses: Partial<Record<DoorstepPermission, DoorstepPermissionStatus>>;
|
|
223
|
+
/**
|
|
224
|
+
* The legacy three-key view, kept so hosts written against the published 2.x
|
|
225
|
+
* API keep working. Collapsed from `statuses` as: `whenInUseOnly` and
|
|
226
|
+
* `unavailable` → `'granted'`, `notDetermined` → `'prompt'`, everything else
|
|
227
|
+
* (including `notDeclared`) → `'denied'`.
|
|
228
|
+
*
|
|
229
|
+
* `motion` is unconditionally `'granted'` on Android, as it has always been, and
|
|
230
|
+
* that is the honest answer to what the key asks: Android's IMU streams need no
|
|
231
|
+
* runtime grant, so motion collection is always possible. `activityRecognition`
|
|
232
|
+
* adds only the step-counter streams — read `statuses.activityRecognition` if you
|
|
233
|
+
* need its real state. On iOS `motion` does track Motion & Fitness, which really
|
|
234
|
+
* does gate capability there.
|
|
235
|
+
*
|
|
236
|
+
* @deprecated Read `statuses`.
|
|
237
|
+
*/
|
|
128
238
|
permissions: Record<DoorstepPermissionType, PermissionState>;
|
|
239
|
+
/**
|
|
240
|
+
* Whitelist entries this platform has no bucket for, echoed back rather than
|
|
241
|
+
* dropped in silence (e.g. `notifications` on iOS).
|
|
242
|
+
*/
|
|
243
|
+
unsupported: string[];
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** What {@link DoorstepAIModule.requestPermissions} answers. */
|
|
247
|
+
interface PermissionRequestResult extends PermissionStatus {
|
|
248
|
+
/** Buckets a dialog was actually raised for. */
|
|
249
|
+
requested: DoorstepPermission[];
|
|
250
|
+
/**
|
|
251
|
+
* Whitelisted buckets that were already answered, so the default policy left
|
|
252
|
+
* them alone.
|
|
253
|
+
*/
|
|
254
|
+
alreadyDetermined: DoorstepPermission[];
|
|
255
|
+
/**
|
|
256
|
+
* Whitelisted buckets that cannot be requested on this device or in this build
|
|
257
|
+
* (`unavailable` or `notDeclared`).
|
|
258
|
+
*/
|
|
259
|
+
unavailable: DoorstepPermission[];
|
|
260
|
+
/**
|
|
261
|
+
* Whitelisted buckets deliberately skipped, with the reason. The one to expect:
|
|
262
|
+
* `locationAlways` is only ever asked **alone and after foreground location is
|
|
263
|
+
* granted**, so a whitelist containing anything else askable defers it — call
|
|
264
|
+
* again once the first batch is answered.
|
|
265
|
+
*/
|
|
266
|
+
deferred: Partial<Record<DoorstepPermission, string>>;
|
|
267
|
+
/** True when at least one dialog was raised. */
|
|
268
|
+
didRequest: boolean;
|
|
269
|
+
/**
|
|
270
|
+
* Android only, diagnostic: the manifest permission strings actually passed to
|
|
271
|
+
* `ActivityCompat.requestPermissions`.
|
|
272
|
+
*/
|
|
273
|
+
androidPermissions?: string[];
|
|
129
274
|
}
|
|
130
275
|
|
|
131
276
|
/** Options for {@link DoorstepAIModule.requestPermissions}. */
|
|
132
277
|
interface PermissionRequestOptions {
|
|
133
278
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* **This array can only narrow Bluetooth.** Both natives request their whole
|
|
137
|
-
* required set behind a single `includeBluetooth` / `requestBluetooth` flag —
|
|
138
|
-
* neither exposes per-permission selection — so the array is read as
|
|
139
|
-
* `includeBluetooth = permissions.includes('bluetooth')` and `location` and
|
|
140
|
-
* `motion` always ride the base set. Passing `['bluetooth']` alone therefore
|
|
141
|
-
* still requests the base set as well. Documented rather than silently
|
|
142
|
-
* swallowed: an array the wrapper cannot honour would be a lie.
|
|
279
|
+
* The whitelist: **exactly these buckets are requested, and nothing else**.
|
|
280
|
+
* Omit it (or pass `undefined`) to request every bucket the platform has.
|
|
143
281
|
*
|
|
144
|
-
*
|
|
282
|
+
* An empty array requests nothing — it is not the same as omitting the field.
|
|
145
283
|
*/
|
|
146
|
-
permissions?:
|
|
284
|
+
permissions?: DoorstepPermissionInput[];
|
|
285
|
+
/**
|
|
286
|
+
* Skip buckets the user has already answered. Default `true`, which is what
|
|
287
|
+
* makes a launch-time call safe and what stops a deliberate "While Using the
|
|
288
|
+
* App" choice from being re-escalated. **iOS only** — on Android a first denial
|
|
289
|
+
* is re-askable by design, so the native planner always re-asks it.
|
|
290
|
+
*/
|
|
291
|
+
onlyIfNotDetermined?: boolean;
|
|
292
|
+
/**
|
|
293
|
+
* How long to wait for each answer before giving up and reporting the state as
|
|
294
|
+
* it stands (default 120 s). A prompt the user never answers is reported
|
|
295
|
+
* `notDetermined`, not guessed at.
|
|
296
|
+
*/
|
|
297
|
+
timeoutSeconds?: number;
|
|
147
298
|
}
|
|
148
299
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
300
|
+
// ---- Whitelist normalisation ----------------------------------------------
|
|
301
|
+
//
|
|
302
|
+
// A NAMING translation, not a permission list: it maps the names the two native
|
|
303
|
+
// SDKs use onto each other so one host whitelist compiles on both. It never adds
|
|
304
|
+
// or removes a bucket of its own accord, and it never decides what gets
|
|
305
|
+
// requested — the native planner owns that.
|
|
306
|
+
|
|
307
|
+
const IOS_ALIASES: Record<string, DoorstepPermission[]> = {
|
|
308
|
+
location: ['locationWhenInUse', 'locationAlways'],
|
|
309
|
+
locationwheninuse: ['locationWhenInUse'],
|
|
310
|
+
locationalways: ['locationAlways'],
|
|
311
|
+
motion: ['motionFitness'],
|
|
312
|
+
activity: ['motionFitness'],
|
|
313
|
+
motionfitness: ['motionFitness'],
|
|
314
|
+
activityrecognition: ['motionFitness'],
|
|
315
|
+
bluetooth: ['bluetooth'],
|
|
316
|
+
bluetoothscan: ['bluetooth'],
|
|
317
|
+
nearbywifidevices: [],
|
|
318
|
+
notifications: [],
|
|
319
|
+
};
|
|
320
|
+
|
|
321
|
+
const ANDROID_ALIASES: Record<string, DoorstepPermission[]> = {
|
|
322
|
+
location: ['locationWhenInUse', 'locationAlways'],
|
|
323
|
+
locationwheninuse: ['locationWhenInUse'],
|
|
324
|
+
locationalways: ['locationAlways'],
|
|
325
|
+
motion: ['activityRecognition'],
|
|
326
|
+
activity: ['activityRecognition'],
|
|
327
|
+
motionfitness: ['activityRecognition'],
|
|
328
|
+
activityrecognition: ['activityRecognition'],
|
|
329
|
+
bluetooth: ['bluetoothScan'],
|
|
330
|
+
bluetoothscan: ['bluetoothScan'],
|
|
331
|
+
nearbywifidevices: ['nearbyWifiDevices'],
|
|
332
|
+
notifications: ['notifications'],
|
|
333
|
+
};
|
|
334
|
+
|
|
335
|
+
/** Every bucket this platform has, derived from the one alias table above. */
|
|
336
|
+
function platformBuckets(): DoorstepPermission[] {
|
|
337
|
+
const table = Platform.OS === 'ios' ? IOS_ALIASES : ANDROID_ALIASES;
|
|
338
|
+
const out: DoorstepPermission[] = [];
|
|
339
|
+
for (const mapped of Object.values(table)) {
|
|
340
|
+
for (const bucket of mapped) if (!out.includes(bucket)) out.push(bucket);
|
|
341
|
+
}
|
|
342
|
+
return out;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
type NormalizedWhitelist = {
|
|
346
|
+
/** `undefined` = no whitelist = every bucket. Never `[]` for that case. */
|
|
347
|
+
buckets: DoorstepPermission[] | undefined;
|
|
348
|
+
unsupported: string[];
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
function normalizeWhitelist(
|
|
352
|
+
permissions: DoorstepPermissionInput[] | undefined
|
|
353
|
+
): NormalizedWhitelist {
|
|
354
|
+
if (permissions == null) return { buckets: undefined, unsupported: [] };
|
|
355
|
+
const table = Platform.OS === 'ios' ? IOS_ALIASES : ANDROID_ALIASES;
|
|
356
|
+
const buckets: DoorstepPermission[] = [];
|
|
357
|
+
const unsupported: string[] = [];
|
|
358
|
+
for (const raw of permissions) {
|
|
359
|
+
const mapped = table[String(raw).trim().toLowerCase()];
|
|
360
|
+
if (mapped == null || mapped.length === 0) {
|
|
361
|
+
unsupported.push(String(raw));
|
|
362
|
+
continue;
|
|
363
|
+
}
|
|
364
|
+
for (const bucket of mapped) {
|
|
365
|
+
if (!buckets.includes(bucket)) buckets.push(bucket);
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return { buckets, unsupported };
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
/** Merges the wrapper-side `unsupported` list into whatever native answered. */
|
|
372
|
+
function withUnsupported<T extends { unsupported?: string[] }>(
|
|
373
|
+
payload: T,
|
|
374
|
+
unsupported: string[]
|
|
375
|
+
): T & { unsupported: string[] } {
|
|
376
|
+
return {
|
|
377
|
+
...payload,
|
|
378
|
+
unsupported: [...(payload.unsupported ?? []), ...unsupported],
|
|
379
|
+
};
|
|
162
380
|
}
|
|
163
381
|
|
|
164
382
|
/**
|
|
@@ -217,6 +435,40 @@ class DoorstepAIModule {
|
|
|
217
435
|
DoorstepAI.setApiKey(apiKey);
|
|
218
436
|
}
|
|
219
437
|
|
|
438
|
+
/**
|
|
439
|
+
* Sets the API key for the Doorstep Go service, which is a separate credential
|
|
440
|
+
* from {@link setApiKey}. Present on both native SDKs; a no-op if you do not use
|
|
441
|
+
* Doorstep Go.
|
|
442
|
+
*/
|
|
443
|
+
static setDoorstepGoApiKey(apiKey: string) {
|
|
444
|
+
DoorstepAI.setDoorstepGoApiKey(apiKey);
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
/**
|
|
448
|
+
* The native SDK's internal-state dump as compact JSON, for bug reports and
|
|
449
|
+
* support logs. Free-form and unstable — never branch on it. **iOS only**
|
|
450
|
+
* (`DoorstepAI.debugStateJson()`); the Android SDK has no counterpart, so it
|
|
451
|
+
* rejects there.
|
|
452
|
+
*/
|
|
453
|
+
static debugStateJson(): Promise<string> {
|
|
454
|
+
if (Platform.OS !== 'ios') {
|
|
455
|
+
return unsupportedOnThisPlatform('debugStateJson', 'iOS');
|
|
456
|
+
}
|
|
457
|
+
return DoorstepAI.debugStateJson();
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Re-registers the raw-GNSS callbacks after the OS has dropped them (some
|
|
462
|
+
* devices stop delivering measurements without reporting an error). **Android
|
|
463
|
+
* only** — iOS has no raw-GNSS access at all, so it rejects there.
|
|
464
|
+
*/
|
|
465
|
+
static retryGnssCallbacks(): Promise<boolean> {
|
|
466
|
+
if (Platform.OS !== 'android') {
|
|
467
|
+
return unsupportedOnThisPlatform('retryGnssCallbacks', 'Android');
|
|
468
|
+
}
|
|
469
|
+
return DoorstepAI.retryGnssCallbacks();
|
|
470
|
+
}
|
|
471
|
+
|
|
220
472
|
// ---- Runtime permissions -------------------------------------------------
|
|
221
473
|
// Every method below is a pass-through to the native SDK's own permission API.
|
|
222
474
|
// The SDK owns the permission list and the prompt ordering; this wrapper used to
|
|
@@ -278,68 +530,143 @@ class DoorstepAIModule {
|
|
|
278
530
|
}
|
|
279
531
|
|
|
280
532
|
/**
|
|
281
|
-
* The current
|
|
282
|
-
*
|
|
283
|
-
*
|
|
284
|
-
* authorizationStatus()` / `CBManager.authorization` on iOS,
|
|
285
|
-
* `ContextCompat.checkSelfPermission` on Android) and shows no dialog.
|
|
533
|
+
* The current state of the whitelisted permission buckets, on both platforms.
|
|
534
|
+
* **Pure observation — never prompts**, so it is safe at launch, on every
|
|
535
|
+
* screen, as often as you like.
|
|
286
536
|
*
|
|
287
|
-
*
|
|
288
|
-
* (`DoorstepAI.getRequiredPermissions()` on Android); the wrapper keeps no
|
|
289
|
-
* permission list of its own, it only reports the state of what native names.
|
|
537
|
+
* @param permissions whitelist; omit for every bucket this platform has.
|
|
290
538
|
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
*
|
|
539
|
+
* ```ts
|
|
540
|
+
* const { statuses } = await DoorstepAI.checkPermissions();
|
|
541
|
+
* if (statuses.locationAlways?.state === 'whenInUseOnly') {
|
|
542
|
+
* // foreground location only: background collection and route geofencing
|
|
543
|
+
* // will NOT work. Never read this as 'granted'.
|
|
544
|
+
* }
|
|
545
|
+
* ```
|
|
546
|
+
*
|
|
547
|
+
* The buckets and their states come straight from the native SDKs
|
|
548
|
+
* (`DoorstepAI.checkPermissions(...)` on both platforms) — the wrapper keeps no
|
|
549
|
+
* permission list and no state machine of its own.
|
|
294
550
|
*/
|
|
295
|
-
static checkPermissions(
|
|
296
|
-
|
|
551
|
+
static async checkPermissions(
|
|
552
|
+
permissions?: DoorstepPermissionInput[]
|
|
553
|
+
): Promise<PermissionStatus> {
|
|
554
|
+
const { buckets, unsupported } = normalizeWhitelist(permissions);
|
|
555
|
+
const payload = await DoorstepAI.checkPermissions(buckets ?? null);
|
|
556
|
+
return withUnsupported(payload as PermissionStatus, unsupported);
|
|
297
557
|
}
|
|
298
558
|
|
|
299
559
|
/**
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
* permissions (`DoorstepAI.requestPermissions(activity, requestCode,
|
|
303
|
-
* includeBluetooth)`, only the not-yet-granted ones) and iOS's Location +
|
|
304
|
-
* Motion/Fitness + Bluetooth prompts
|
|
305
|
-
* (`DoorstepAI.requestAllPermissions(requestAlwaysLocation:requestBluetooth:onlyIfNotDetermined:)`).
|
|
560
|
+
* Every permission bucket this platform has — the whitelist
|
|
561
|
+
* {@link requestPermissions} uses when you pass none.
|
|
306
562
|
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
563
|
+
* Useful for building a permission screen that lists what the SDK can ask for
|
|
564
|
+
* without hardcoding a per-platform list. Synchronous: it is the wrapper's name
|
|
565
|
+
* table, not a device read. Use {@link checkPermissions} for state.
|
|
566
|
+
*/
|
|
567
|
+
static allPermissionBuckets(): DoorstepPermission[] {
|
|
568
|
+
return platformBuckets();
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
/**
|
|
572
|
+
* {@link checkPermissions} rendered as the native SDK's own compact JSON — for
|
|
573
|
+
* bug reports, support logs and scripted on-device assertions.
|
|
309
574
|
*
|
|
310
|
-
*
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
575
|
+
* Shape: `{"<bucket>":{"state":"…","canRequest":true|false,"os":"…"}}`.
|
|
576
|
+
*/
|
|
577
|
+
static checkPermissionsJson(
|
|
578
|
+
permissions?: DoorstepPermissionInput[]
|
|
579
|
+
): Promise<string> {
|
|
580
|
+
const { buckets } = normalizeWhitelist(permissions);
|
|
581
|
+
return DoorstepAI.checkPermissionsJson(buckets ?? null);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
/**
|
|
585
|
+
* The one permission requester, and the only one hosts should need.
|
|
316
586
|
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
*
|
|
320
|
-
* `
|
|
321
|
-
*
|
|
322
|
-
*
|
|
587
|
+
* **No argument requests every bucket the platform has. An argument is a
|
|
588
|
+
* whitelist: exactly those buckets are requested and nothing else.** That is
|
|
589
|
+
* the native contract on both platforms
|
|
590
|
+
* (`DoorstepAI.requestPermissions(_ permissions:…)` on iOS,
|
|
591
|
+
* `DoorstepAI.requestPermissions(activity, permissions)` on Android) and this
|
|
592
|
+
* method is a pass-through to it — the wrapper does not decide what gets asked.
|
|
323
593
|
*
|
|
324
|
-
*
|
|
594
|
+
* ```ts
|
|
595
|
+
* await DoorstepAI.requestPermissions(); // everything
|
|
596
|
+
* await DoorstepAI.requestPermissions(['locationWhenInUse']); // just that
|
|
597
|
+
* await DoorstepAI.requestPermissions({ permissions: ['location', 'motion'] });
|
|
598
|
+
* ```
|
|
325
599
|
*
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
*
|
|
600
|
+
* Accepts the array directly or the legacy `{ permissions: [...] }` object; the
|
|
601
|
+
* object form additionally carries `onlyIfNotDetermined` (iOS) and
|
|
602
|
+
* `timeoutSeconds`.
|
|
329
603
|
*
|
|
330
|
-
*
|
|
331
|
-
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
604
|
+
* **Resolves only AFTER the user has answered**, with the settled state — a
|
|
605
|
+
* status read while a dialog is still up would be a lie. Anything the native
|
|
606
|
+
* planner declines to ask comes back explained rather than silent:
|
|
607
|
+
* `alreadyDetermined`, `unavailable`, `deferred`.
|
|
608
|
+
*
|
|
609
|
+
* The deferral to expect: **`locationAlways` is only ever requested alone, and
|
|
610
|
+
* only once foreground location is granted** (Android auto-denies a bundled
|
|
611
|
+
* background ask; iOS shows the When-In-Use prompt first and offers the Always
|
|
612
|
+
* upgrade later on its own schedule). So a full-whitelist call typically returns
|
|
613
|
+
* `locationAlways` in `deferred` — call again, with just that bucket, after the
|
|
614
|
+
* first batch is answered.
|
|
615
|
+
*
|
|
616
|
+
* A second call made while one is still in flight does not interleave prompt
|
|
617
|
+
* sequences: iOS reports every bucket as `deferred`, Android rejects with
|
|
618
|
+
* `E_PERMISSION_REQUEST_IN_FLIGHT`.
|
|
619
|
+
*
|
|
620
|
+
* iOS guidance from the SDK: call this **once, from a user-initiated flow**, not
|
|
621
|
+
* from app launch.
|
|
622
|
+
*/
|
|
623
|
+
static async requestPermissions(
|
|
624
|
+
options?: DoorstepPermissionInput[] | PermissionRequestOptions
|
|
625
|
+
): Promise<PermissionRequestResult> {
|
|
626
|
+
const opts: PermissionRequestOptions = Array.isArray(options)
|
|
627
|
+
? { permissions: options }
|
|
628
|
+
: (options ?? {});
|
|
629
|
+
const { buckets, unsupported } = normalizeWhitelist(opts.permissions);
|
|
630
|
+
const payload = await DoorstepAI.requestPermissions({
|
|
631
|
+
permissions: buckets ?? null,
|
|
632
|
+
onlyIfNotDetermined: opts.onlyIfNotDetermined ?? null,
|
|
633
|
+
timeoutSeconds: opts.timeoutSeconds ?? null,
|
|
634
|
+
});
|
|
635
|
+
return withUnsupported(payload as PermissionRequestResult, unsupported);
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
/**
|
|
639
|
+
* Forward your Activity's `onRequestPermissionsResult` to the SDK. **Android
|
|
640
|
+
* only; a no-op elsewhere.**
|
|
641
|
+
*
|
|
642
|
+
* Optional but worth wiring: it is the only way the SDK can tell a refusal it
|
|
643
|
+
* may re-ask (`denied`) from one only Settings can fix (`permanentlyDenied`).
|
|
644
|
+
* Android reports the same signals for "permanently denied" and "never asked",
|
|
645
|
+
* and a *cancelled* dialog leaves the same trace as a denial — so the SDK
|
|
646
|
+
* refuses to guess and reports the re-askable `denied` until a real,
|
|
647
|
+
* host-forwarded answer says otherwise.
|
|
648
|
+
*
|
|
649
|
+
* It also settles a `requestPermissions` promise the moment the real answer
|
|
650
|
+
* arrives, instead of waiting on the activity-lifecycle backstop.
|
|
651
|
+
*
|
|
652
|
+
* ```kotlin
|
|
653
|
+
* // MainActivity.kt
|
|
654
|
+
* override fun onRequestPermissionsResult(
|
|
655
|
+
* requestCode: Int, permissions: Array<out String>, grantResults: IntArray
|
|
656
|
+
* ) {
|
|
657
|
+
* super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
|
658
|
+
* DoorstepAI.notePermissionRequestResult(this, permissions, grantResults)
|
|
659
|
+
* }
|
|
660
|
+
* ```
|
|
661
|
+
*
|
|
662
|
+
* If you would rather not touch Kotlin, call this from JS with the same values.
|
|
663
|
+
*/
|
|
664
|
+
static async notePermissionRequestResult(
|
|
665
|
+
permissions: string[],
|
|
666
|
+
grantResults: number[]
|
|
667
|
+
): Promise<void> {
|
|
668
|
+
if (Platform.OS !== 'android') return;
|
|
669
|
+
await DoorstepAI.notePermissionRequestResult(permissions, grantResults);
|
|
343
670
|
}
|
|
344
671
|
|
|
345
672
|
/**
|
|
@@ -355,10 +682,11 @@ class DoorstepAIModule {
|
|
|
355
682
|
* the two calls for you — deciding when the user has been told why the app wants
|
|
356
683
|
* "Allow all the time" is the host's, not the wrapper's.
|
|
357
684
|
*
|
|
358
|
-
* On iOS the same intent is
|
|
359
|
-
* `
|
|
360
|
-
*
|
|
361
|
-
*
|
|
685
|
+
* On iOS the same intent is the `locationAlways` bucket of
|
|
686
|
+
* `requestPermissions`; there is no iOS counterpart to this method, so it
|
|
687
|
+
* rejects there rather than resolving a made-up answer. On Android you can also
|
|
688
|
+
* express it as `requestPermissions(['locationAlways'])` — same prompt, and it
|
|
689
|
+
* reports back why if the OS would have refused to show it.
|
|
362
690
|
*
|
|
363
691
|
* Resolves `true` when a request was actually issued (false below API 29 or when
|
|
364
692
|
* already granted).
|
|
@@ -802,10 +1130,16 @@ export type {
|
|
|
802
1130
|
AddressType,
|
|
803
1131
|
LatLngObject,
|
|
804
1132
|
StartDeliveryOptions,
|
|
1133
|
+
DoorstepPermission,
|
|
1134
|
+
DoorstepPermissionAlias,
|
|
1135
|
+
DoorstepPermissionInput,
|
|
1136
|
+
DoorstepPermissionState,
|
|
1137
|
+
DoorstepPermissionStatus,
|
|
805
1138
|
PermissionState,
|
|
806
1139
|
DoorstepPermissionType,
|
|
807
1140
|
PermissionStatus,
|
|
808
1141
|
PermissionRequestOptions,
|
|
1142
|
+
PermissionRequestResult,
|
|
809
1143
|
SDKLogLevel,
|
|
810
1144
|
DeliveryStop,
|
|
811
1145
|
RouteGeofenceOptions,
|