@doorstepai/dropoff-sdk 2.2.0 → 2.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/README.md +267 -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 +10066 -6190
  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 +3833 -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 +10066 -6190
  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 +10066 -6190
  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 +3833 -3248
  27. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/DoorstepDropoffSDK.yml +3802 -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
@@ -9,24 +9,41 @@ import {
9
9
  import { useEffect } from 'react';
10
10
 
11
11
  import { DoorstepAI } from './DoorstepAI';
12
+ import type { DoorstepPermissionInput } from './DoorstepAI';
12
13
 
13
14
  const DoorstepAIView = requireNativeComponent('RootDoorstepAIView');
14
15
 
16
+ /**
17
+ * Drop-in bootstrap: mount it once, near the root, and it runs the SDK's
18
+ * `init` + `setApiKey` and the permission sequence for you. Everything it does is
19
+ * available a la carte on {@link DoorstepAI} — this component exists so a host
20
+ * that just wants the default flow does not have to write it.
21
+ */
15
22
  export function RootDoorstepAI(props: {
16
23
  apiKey: string;
17
24
  notificationTitle?: string;
18
25
  notificationText?: string;
19
26
  /**
20
- * Whether to include Bluetooth in the permission request: Android's "Nearby
21
- * devices" grant, iOS's Bluetooth prompt. Defaults to ON, as both natives do.
22
- * Set `false` to narrow the request to the base set (location + motion) — the
23
- * only narrowing `requestPermissions` can honour.
27
+ * The whitelist handed to `requestPermissions`: **exactly these buckets are
28
+ * requested and nothing else.** Omit it to request every bucket the platform
29
+ * has, which is the SDK's own default.
30
+ */
31
+ permissions?: DoorstepPermissionInput[];
32
+ /**
33
+ * @deprecated Pass a {@link permissions} whitelist instead — it can narrow any
34
+ * bucket, not just this one. Kept because it was the published prop: `false`
35
+ * drops the platform's Bluetooth bucket from the default whitelist. Ignored when
36
+ * `permissions` is given.
24
37
  */
25
38
  requestBluetooth?: boolean;
26
39
  /**
27
- * Run the second-phase `ACCESS_BACKGROUND_LOCATION` request on Android
28
- * (default: on). Turn it off only if your app asks for background location from
29
- * its own onboarding UI — without the grant the SDK cannot start a session while
40
+ * Run the second-phase background-location request (`locationAlways`) once
41
+ * foreground location has been granted. Default on.
42
+ *
43
+ * It has to be a second phase because Android forbids bundling background
44
+ * location with the foreground ask — a bundled request is auto-denied from
45
+ * Android 11 on. Turn it off if your app asks for "Allow all the time" from its
46
+ * own onboarding UI; without the grant the SDK cannot collect while
30
47
  * backgrounded and route geofences fire foreground-only.
31
48
  */
32
49
  requestBackgroundLocation?: boolean;
@@ -35,6 +52,7 @@ export function RootDoorstepAI(props: {
35
52
  apiKey,
36
53
  notificationTitle,
37
54
  notificationText,
55
+ permissions,
38
56
  requestBluetooth,
39
57
  requestBackgroundLocation,
40
58
  } = props;
@@ -43,32 +61,53 @@ export function RootDoorstepAI(props: {
43
61
  let cancelled = false;
44
62
  let backgroundPhaseSettled = false;
45
63
 
46
- // Android requires ACCESS_BACKGROUND_LOCATION to be requested SEPARATELY, and
47
- // only once foreground location is granted — asking earlier burns the request
48
- // on an automatic denial. The foreground grant result is delivered to the
49
- // Activity rather than to JS, so re-run this against native's own predicates
50
- // whenever the host returns to the foreground instead of guessing at the
51
- // dialog outcome.
64
+ // The effective whitelist. `permissions` wins; `requestBluetooth: false` is
65
+ // expressed as "every bucket except this platform's BLE one", which is what
66
+ // the old two-boolean requester meant by it.
67
+ const whitelist: DoorstepPermissionInput[] | undefined =
68
+ permissions ??
69
+ (requestBluetooth === false
70
+ ? DoorstepAI.allPermissionBuckets().filter(
71
+ (bucket) => bucket !== 'bluetooth' && bucket !== 'bluetoothScan'
72
+ )
73
+ : undefined);
74
+
75
+ // Whether background location is ours to ask for at all: the host can turn the
76
+ // phase off, and a whitelist that does not name the bucket must not have it
77
+ // added back behind the host's back.
78
+ const backgroundInScope =
79
+ requestBackgroundLocation !== false &&
80
+ (whitelist == null ||
81
+ whitelist.some((p) => p === 'locationAlways' || p === 'location'));
82
+
83
+ /**
84
+ * Phase 2. `locationAlways` is only ever asked ALONE and only after foreground
85
+ * location is granted — the SDK enforces both rules and reports a refusal to
86
+ * ask rather than asking anyway, so this can be called optimistically. It is
87
+ * re-run on each foreground because on Android the foreground grant result is
88
+ * delivered to the Activity, not to JS.
89
+ */
52
90
  const runBackgroundLocationPhase = async () => {
53
- if (
54
- cancelled ||
55
- backgroundPhaseSettled ||
56
- Platform.OS !== 'android' ||
57
- requestBackgroundLocation === false
58
- ) {
59
- return;
60
- }
91
+ if (cancelled || backgroundPhaseSettled || !backgroundInScope) return;
61
92
  try {
62
- if (await DoorstepAI.hasBackgroundLocationPermission()) {
93
+ const { statuses } = await DoorstepAI.checkPermissions([
94
+ 'locationWhenInUse',
95
+ 'locationAlways',
96
+ ]);
97
+ const always = statuses.locationAlways?.state;
98
+ if (always === 'granted') {
63
99
  backgroundPhaseSettled = true;
64
100
  return;
65
101
  }
66
- // Gate on native's own predicate. It is stricter than "location granted"
67
- // (it also covers POST_NOTIFICATIONS), which is the safe direction: a
68
- // premature request is spent, a deferred one can still be made later.
69
- if (!(await DoorstepAI.hasRequiredPermissions())) return;
102
+ // Foreground first: asking earlier spends the request on an automatic
103
+ // denial (Android) or shows the wrong prompt (iOS).
104
+ if (statuses.locationWhenInUse?.state !== 'granted') return;
105
+ // On iOS `whenInUseOnly` is a deliberate user choice and the SDK declines
106
+ // to re-prompt for it; the call is still made because native is the right
107
+ // place for that decision, and it comes back `deferred` rather than
108
+ // prompting.
70
109
  backgroundPhaseSettled = true;
71
- await DoorstepAI.requestBackgroundLocationPermission();
110
+ await DoorstepAI.requestPermissions(['locationAlways']);
72
111
  } catch (err) {
73
112
  console.warn('DOORSTEPAI - background location request failed:', err);
74
113
  }
@@ -91,25 +130,15 @@ export function RootDoorstepAI(props: {
91
130
  if (cancelled) return;
92
131
 
93
132
  try {
94
- // One requester for both platforms; it dispatches natively. Safe at launch
95
- // on iOS only because native defaults `onlyIfNotDetermined` to true: the
96
- // location prompt is skipped unless authorization is .notDetermined, so
97
- // this cannot re-escalate a user's "While Using the App" choice on every
98
- // launch.
99
- //
100
- // `permissions` can only narrow Bluetooth (see `requestPermissions`), so
101
- // `requestBluetooth === false` is expressed by omitting 'bluetooth' from
102
- // the array; location and motion ride the base set either way.
103
- const status = await DoorstepAI.requestPermissions(
104
- requestBluetooth === false
105
- ? { permissions: ['location', 'motion'] }
106
- : undefined
107
- );
133
+ // One requester for both platforms; native dispatches. Safe at launch on
134
+ // iOS only because native defaults `onlyIfNotDetermined` to true: an
135
+ // already-answered permission is left alone, so this cannot re-escalate a
136
+ // user's "While Using the App" choice on every launch.
137
+ const { statuses } = await DoorstepAI.requestPermissions(whitelist);
108
138
  if (cancelled) return;
109
- // This resolves only once the user has ANSWERED, so the state is final and
110
- // the second-phase background prompt can be issued straight away instead of
111
- // waiting for the next foreground. On iOS the phase is a no-op.
112
- if (status.permissions.location === 'granted') {
139
+ // Resolves only once the user has ANSWERED, so this state is final and
140
+ // phase 2 can run straight away instead of waiting for the next foreground.
141
+ if (statuses.locationWhenInUse?.state === 'granted') {
113
142
  await runBackgroundLocationPhase();
114
143
  }
115
144
  } catch (err) {
@@ -127,6 +156,7 @@ export function RootDoorstepAI(props: {
127
156
  apiKey,
128
157
  notificationTitle,
129
158
  notificationText,
159
+ permissions,
130
160
  requestBluetooth,
131
161
  requestBackgroundLocation,
132
162
  ]);
package/src/index.tsx CHANGED
@@ -4,10 +4,16 @@ export type {
4
4
  AddressType,
5
5
  LatLngObject,
6
6
  StartDeliveryOptions,
7
+ DoorstepPermission,
8
+ DoorstepPermissionAlias,
9
+ DoorstepPermissionInput,
10
+ DoorstepPermissionState,
11
+ DoorstepPermissionStatus,
7
12
  PermissionState,
8
13
  DoorstepPermissionType,
9
14
  PermissionStatus,
10
15
  PermissionRequestOptions,
16
+ PermissionRequestResult,
11
17
  SDKLogLevel,
12
18
  DeliveryStop,
13
19
  RouteGeofenceOptions,