@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.
- package/CHANGELOG.md +66 -0
- package/README.md +308 -41
- package/android/build.gradle +5 -1
- package/android/src/main/java/com/doorstepai/dropoffsdk/DoorstepAIModule.kt +566 -2
- package/ios/DoorstepAI.mm +12 -2
- package/ios/DoorstepAI.swift +151 -2
- 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 +10582 -5745
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +95 -4
- 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 +95 -4
- 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 +3833 -2687
- 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 +10582 -5745
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +95 -4
- 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 +95 -4
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +10582 -5745
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +95 -4
- 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 +95 -4
- 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 +3833 -2687
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/DoorstepDropoffSDK.yml +3802 -2674
- package/lib/module/DoorstepAI.js +425 -12
- package/lib/module/DoorstepAI.js.map +1 -1
- package/lib/module/RootDoorstepAI.js +88 -26
- package/lib/module/RootDoorstepAI.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/DoorstepAI.d.ts +349 -7
- package/lib/typescript/src/DoorstepAI.d.ts.map +1 -1
- package/lib/typescript/src/RootDoorstepAI.d.ts +31 -3
- 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 +2 -1
- package/src/DoorstepAI.tsx +575 -23
- package/src/RootDoorstepAI.tsx +130 -47
- package/src/index.tsx +10 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@doorstepai/dropoff-sdk",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.2",
|
|
4
4
|
"description": "doorstep.ai dropoff sdk for React Native",
|
|
5
5
|
"source": "./src/index.tsx",
|
|
6
6
|
"main": "./lib/module/index.js",
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
"./package.json": "./package.json"
|
|
13
13
|
},
|
|
14
14
|
"files": [
|
|
15
|
+
"CHANGELOG.md",
|
|
15
16
|
"src",
|
|
16
17
|
"lib",
|
|
17
18
|
"android",
|
package/src/DoorstepAI.tsx
CHANGED
|
@@ -69,8 +69,12 @@ type GeofenceSessionEvent = {
|
|
|
69
69
|
type StartDeliveryOptions = {
|
|
70
70
|
/**
|
|
71
71
|
* Hard upper bound on the delivery's tracking session in seconds. When the
|
|
72
|
-
* timer fires the SDK calls `stopDelivery` automatically.
|
|
73
|
-
*
|
|
72
|
+
* timer fires the SDK calls `stopDelivery` automatically.
|
|
73
|
+
*
|
|
74
|
+
* Omit it for NO backstop — that is the native behaviour on both platforms.
|
|
75
|
+
* This wrapper used to substitute 3600 s here, which silently force-stopped
|
|
76
|
+
* every delivery at one hour and re-created a bug the native SDK had already
|
|
77
|
+
* removed. It now passes your value through untouched.
|
|
74
78
|
*/
|
|
75
79
|
timeoutSeconds?: number;
|
|
76
80
|
/**
|
|
@@ -98,12 +102,305 @@ type StartDeliveryOptions = {
|
|
|
98
102
|
driverId?: string;
|
|
99
103
|
};
|
|
100
104
|
|
|
105
|
+
/**
|
|
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.
|
|
131
|
+
*/
|
|
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
|
+
};
|
|
198
|
+
|
|
199
|
+
/**
|
|
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".
|
|
202
|
+
*
|
|
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.
|
|
211
|
+
*
|
|
212
|
+
* @deprecated Use {@link DoorstepPermission}.
|
|
213
|
+
*/
|
|
214
|
+
type DoorstepPermissionType = 'location' | 'motion' | 'bluetooth';
|
|
215
|
+
|
|
216
|
+
/** What {@link DoorstepAIModule.checkPermissions} answers. */
|
|
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
|
+
*/
|
|
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[];
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
/** Options for {@link DoorstepAIModule.requestPermissions}. */
|
|
277
|
+
interface PermissionRequestOptions {
|
|
278
|
+
/**
|
|
279
|
+
* The whitelist: **exactly these buckets are requested, and nothing else**.
|
|
280
|
+
* Omit it (or pass `undefined`) to request every bucket the platform has.
|
|
281
|
+
*
|
|
282
|
+
* An empty array requests nothing — it is not the same as omitting the field.
|
|
283
|
+
*/
|
|
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;
|
|
298
|
+
}
|
|
299
|
+
|
|
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
|
+
};
|
|
380
|
+
}
|
|
381
|
+
|
|
101
382
|
/**
|
|
102
383
|
* Mirrors the iOS SDK's `SDKLogLevel` enum. Only used by
|
|
103
384
|
* `configureRemoteLogging` (iOS only).
|
|
104
385
|
*/
|
|
105
386
|
type SDKLogLevel = 'debug' | 'info' | 'warning' | 'error' | 'critical';
|
|
106
387
|
|
|
388
|
+
/**
|
|
389
|
+
* Rejects instead of resolving a fabricated value: the Android runtime-permission
|
|
390
|
+
* query helpers have no counterpart on iOS, and a helper that silently resolved
|
|
391
|
+
* `true`/`[]` would read as "granted" / "nothing needed" to a cross-platform host.
|
|
392
|
+
*/
|
|
393
|
+
function unsupportedOnThisPlatform(
|
|
394
|
+
method: string,
|
|
395
|
+
supportedOn: 'iOS' | 'Android'
|
|
396
|
+
): Promise<never> {
|
|
397
|
+
return Promise.reject(
|
|
398
|
+
new Error(
|
|
399
|
+
`DoorstepAI.${method} is ${supportedOn}-only; there is no native counterpart on ${Platform.OS}.`
|
|
400
|
+
)
|
|
401
|
+
);
|
|
402
|
+
}
|
|
403
|
+
|
|
107
404
|
const SDK_LOG_LEVEL_RAW: Record<SDKLogLevel, number> = {
|
|
108
405
|
debug: 0,
|
|
109
406
|
info: 1,
|
|
@@ -112,8 +409,6 @@ const SDK_LOG_LEVEL_RAW: Record<SDKLogLevel, number> = {
|
|
|
112
409
|
critical: 4,
|
|
113
410
|
};
|
|
114
411
|
|
|
115
|
-
const DEFAULT_TIMEOUT_SECONDS = 3600;
|
|
116
|
-
|
|
117
412
|
class DoorstepAIModule {
|
|
118
413
|
static isInitialized = false;
|
|
119
414
|
|
|
@@ -141,17 +436,269 @@ class DoorstepAIModule {
|
|
|
141
436
|
}
|
|
142
437
|
|
|
143
438
|
/**
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
*
|
|
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.
|
|
147
442
|
*/
|
|
148
|
-
static
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
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
|
+
|
|
472
|
+
// ---- Runtime permissions -------------------------------------------------
|
|
473
|
+
// Every method below is a pass-through to the native SDK's own permission API.
|
|
474
|
+
// The SDK owns the permission list and the prompt ordering; this wrapper used to
|
|
475
|
+
// keep a second implementation beside it and drifted — it requested
|
|
476
|
+
// ACCESS_FINE_LOCATION with no ACCESS_COARSE_LOCATION (Android 12+ ignores that
|
|
477
|
+
// request outright), never requested ACCESS_BACKGROUND_LOCATION or
|
|
478
|
+
// POST_NOTIFICATIONS at all, and requested ACTIVITY_RECOGNITION, which native
|
|
479
|
+
// deliberately does not require (`internal/SensorCollectionManager.kt:139`).
|
|
480
|
+
|
|
481
|
+
/**
|
|
482
|
+
* The dangerous runtime permissions the native SDK needs on THIS device,
|
|
483
|
+
* version-gated. **Android only.**
|
|
484
|
+
*
|
|
485
|
+
* Foreground set only — it deliberately excludes `ACCESS_BACKGROUND_LOCATION`,
|
|
486
|
+
* which Android 11+ requires be requested separately and only after foreground
|
|
487
|
+
* location is granted (see `requestBackgroundLocationPermission`).
|
|
488
|
+
*
|
|
489
|
+
* Feed it to your own permission UI (e.g. `PermissionsAndroid.requestMultiple`)
|
|
490
|
+
* when you want the grant results in JS — it is the same list `requestPermissions`
|
|
491
|
+
* asks for, so the two cannot diverge.
|
|
492
|
+
*
|
|
493
|
+
* @param includeBluetooth include `BLUETOOTH_SCAN` (Android 12+) and
|
|
494
|
+
* `NEARBY_WIFI_DEVICES` (Android 13+). Native default: `true`.
|
|
495
|
+
*/
|
|
496
|
+
static getRequiredPermissions(includeBluetooth?: boolean): Promise<string[]> {
|
|
497
|
+
if (Platform.OS !== 'android') {
|
|
498
|
+
return unsupportedOnThisPlatform('getRequiredPermissions', 'Android');
|
|
499
|
+
}
|
|
500
|
+
return DoorstepAI.getRequiredPermissions(includeBluetooth ?? null);
|
|
501
|
+
}
|
|
502
|
+
|
|
503
|
+
/**
|
|
504
|
+
* True when every foreground permission the SDK needs is currently granted.
|
|
505
|
+
* **Android only.**
|
|
506
|
+
*
|
|
507
|
+
* @param includeBluetooth native default here is `false`, unlike the request
|
|
508
|
+
* methods — Bluetooth is optional, so a denied "Nearby devices" grant must not
|
|
509
|
+
* make the SDK look unusable.
|
|
510
|
+
*/
|
|
511
|
+
static hasRequiredPermissions(includeBluetooth?: boolean): Promise<boolean> {
|
|
512
|
+
if (Platform.OS !== 'android') {
|
|
513
|
+
return unsupportedOnThisPlatform('hasRequiredPermissions', 'Android');
|
|
514
|
+
}
|
|
515
|
+
return DoorstepAI.hasRequiredPermissions(includeBluetooth ?? null);
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
/**
|
|
519
|
+
* True when `ACCESS_BACKGROUND_LOCATION` is granted (always true below API 29,
|
|
520
|
+
* where it is not a separate grant). **Android only.**
|
|
521
|
+
*/
|
|
522
|
+
static hasBackgroundLocationPermission(): Promise<boolean> {
|
|
523
|
+
if (Platform.OS !== 'android') {
|
|
524
|
+
return unsupportedOnThisPlatform(
|
|
525
|
+
'hasBackgroundLocationPermission',
|
|
526
|
+
'Android'
|
|
527
|
+
);
|
|
528
|
+
}
|
|
529
|
+
return DoorstepAI.hasBackgroundLocationPermission();
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
/**
|
|
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.
|
|
536
|
+
*
|
|
537
|
+
* @param permissions whitelist; omit for every bucket this platform has.
|
|
538
|
+
*
|
|
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.
|
|
550
|
+
*/
|
|
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);
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Every permission bucket this platform has — the whitelist
|
|
561
|
+
* {@link requestPermissions} uses when you pass none.
|
|
562
|
+
*
|
|
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.
|
|
574
|
+
*
|
|
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.
|
|
586
|
+
*
|
|
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.
|
|
593
|
+
*
|
|
594
|
+
* ```ts
|
|
595
|
+
* await DoorstepAI.requestPermissions(); // everything
|
|
596
|
+
* await DoorstepAI.requestPermissions(['locationWhenInUse']); // just that
|
|
597
|
+
* await DoorstepAI.requestPermissions({ permissions: ['location', 'motion'] });
|
|
598
|
+
* ```
|
|
599
|
+
*
|
|
600
|
+
* Accepts the array directly or the legacy `{ permissions: [...] }` object; the
|
|
601
|
+
* object form additionally carries `onlyIfNotDetermined` (iOS) and
|
|
602
|
+
* `timeoutSeconds`.
|
|
603
|
+
*
|
|
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);
|
|
670
|
+
}
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Requests `ACCESS_BACKGROUND_LOCATION` (Android 10+), required to keep
|
|
674
|
+
* collecting once the host app is backgrounded or the screen is off — without it
|
|
675
|
+
* the SDK refuses to start a session from the background and route geofences
|
|
676
|
+
* only fire in the foreground. **Android only.**
|
|
677
|
+
*
|
|
678
|
+
* This is a separate entry point because Android makes it one: from Android 11+
|
|
679
|
+
* the OS refuses to bundle background location into the foreground request, so it
|
|
680
|
+
* has to be a SECOND prompt issued after foreground location is granted, and
|
|
681
|
+
* asking earlier burns it on an automatic denial. The wrapper does not sequence
|
|
682
|
+
* the two calls for you — deciding when the user has been told why the app wants
|
|
683
|
+
* "Allow all the time" is the host's, not the wrapper's.
|
|
684
|
+
*
|
|
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.
|
|
690
|
+
*
|
|
691
|
+
* Resolves `true` when a request was actually issued (false below API 29 or when
|
|
692
|
+
* already granted).
|
|
693
|
+
*/
|
|
694
|
+
static requestBackgroundLocationPermission(): Promise<boolean> {
|
|
695
|
+
if (Platform.OS !== 'android') {
|
|
696
|
+
return unsupportedOnThisPlatform(
|
|
697
|
+
'requestBackgroundLocationPermission',
|
|
698
|
+
'Android'
|
|
699
|
+
);
|
|
154
700
|
}
|
|
701
|
+
return DoorstepAI.requestBackgroundLocationPermission();
|
|
155
702
|
}
|
|
156
703
|
|
|
157
704
|
/**
|
|
@@ -185,8 +732,7 @@ class DoorstepAIModule {
|
|
|
185
732
|
options?: StartDeliveryOptions
|
|
186
733
|
) {
|
|
187
734
|
try {
|
|
188
|
-
const timeout =
|
|
189
|
-
timeoutSeconds ?? options?.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS;
|
|
735
|
+
const timeout = timeoutSeconds ?? options?.timeoutSeconds;
|
|
190
736
|
const autoStop = options?.autoStopAfterDropoffSeconds ?? null;
|
|
191
737
|
const customerId = options?.customerId ?? null;
|
|
192
738
|
const driverId = options?.driverId ?? null;
|
|
@@ -232,8 +778,7 @@ class DoorstepAIModule {
|
|
|
232
778
|
options?: StartDeliveryOptions
|
|
233
779
|
) {
|
|
234
780
|
try {
|
|
235
|
-
const timeout =
|
|
236
|
-
timeoutSeconds ?? options?.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS;
|
|
781
|
+
const timeout = timeoutSeconds ?? options?.timeoutSeconds;
|
|
237
782
|
const customerId = options?.customerId ?? null;
|
|
238
783
|
const driverId = options?.driverId ?? null;
|
|
239
784
|
// Android's deprecated startDeliveryByPlusCode does not accept
|
|
@@ -279,8 +824,7 @@ class DoorstepAIModule {
|
|
|
279
824
|
options?: StartDeliveryOptions
|
|
280
825
|
) {
|
|
281
826
|
try {
|
|
282
|
-
const timeout =
|
|
283
|
-
timeoutSeconds ?? options?.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS;
|
|
827
|
+
const timeout = timeoutSeconds ?? options?.timeoutSeconds;
|
|
284
828
|
const autoStop = options?.autoStopAfterDropoffSeconds ?? null;
|
|
285
829
|
const customerId = options?.customerId ?? null;
|
|
286
830
|
const driverId = options?.driverId ?? null;
|
|
@@ -325,8 +869,7 @@ class DoorstepAIModule {
|
|
|
325
869
|
options?: StartDeliveryOptions
|
|
326
870
|
) {
|
|
327
871
|
try {
|
|
328
|
-
const timeout =
|
|
329
|
-
timeoutSeconds ?? options?.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS;
|
|
872
|
+
const timeout = timeoutSeconds ?? options?.timeoutSeconds;
|
|
330
873
|
const autoStop = options?.autoStopAfterDropoffSeconds ?? null;
|
|
331
874
|
const customerId = options?.customerId ?? null;
|
|
332
875
|
const driverId = options?.driverId ?? null;
|
|
@@ -376,8 +919,7 @@ class DoorstepAIModule {
|
|
|
376
919
|
options?: StartDeliveryOptions
|
|
377
920
|
) {
|
|
378
921
|
try {
|
|
379
|
-
const timeout =
|
|
380
|
-
timeoutSeconds ?? options?.timeoutSeconds ?? DEFAULT_TIMEOUT_SECONDS;
|
|
922
|
+
const timeout = timeoutSeconds ?? options?.timeoutSeconds;
|
|
381
923
|
const customerId = options?.customerId ?? null;
|
|
382
924
|
const driverId = options?.driverId ?? null;
|
|
383
925
|
// Android's deprecated startDeliveryByLatLng does not accept
|
|
@@ -588,6 +1130,16 @@ export type {
|
|
|
588
1130
|
AddressType,
|
|
589
1131
|
LatLngObject,
|
|
590
1132
|
StartDeliveryOptions,
|
|
1133
|
+
DoorstepPermission,
|
|
1134
|
+
DoorstepPermissionAlias,
|
|
1135
|
+
DoorstepPermissionInput,
|
|
1136
|
+
DoorstepPermissionState,
|
|
1137
|
+
DoorstepPermissionStatus,
|
|
1138
|
+
PermissionState,
|
|
1139
|
+
DoorstepPermissionType,
|
|
1140
|
+
PermissionStatus,
|
|
1141
|
+
PermissionRequestOptions,
|
|
1142
|
+
PermissionRequestResult,
|
|
591
1143
|
SDKLogLevel,
|
|
592
1144
|
DeliveryStop,
|
|
593
1145
|
RouteGeofenceOptions,
|