@doorstepai/dropoff-sdk 2.1.2 → 2.2.0

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/CHANGELOG.md +66 -0
  2. package/README.md +115 -3
  3. package/android/build.gradle +1 -1
  4. package/android/src/main/java/com/doorstepai/dropoffsdk/DoorstepAIModule.kt +332 -0
  5. package/ios/DoorstepAI.mm +5 -2
  6. package/ios/DoorstepAI.swift +170 -2
  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 +1374 -413
  9. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +13 -4
  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 +13 -4
  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 +3248 -2687
  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 +1374 -413
  17. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +13 -4
  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 +13 -4
  20. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +1374 -413
  21. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +13 -4
  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 +13 -4
  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 +3248 -2687
  27. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/DoorstepDropoffSDK.yml +3233 -2674
  28. package/lib/module/DoorstepAI.js +190 -12
  29. package/lib/module/DoorstepAI.js.map +1 -1
  30. package/lib/module/RootDoorstepAI.js +70 -26
  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 +151 -7
  34. package/lib/typescript/src/DoorstepAI.d.ts.map +1 -1
  35. package/lib/typescript/src/RootDoorstepAI.d.ts +14 -3
  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 +2 -1
  40. package/src/DoorstepAI.tsx +241 -23
  41. package/src/RootDoorstepAI.tsx +98 -45
  42. package/src/index.tsx +4 -0
@@ -3,7 +3,7 @@ import {
3
3
  View,
4
4
  Platform,
5
5
  StyleSheet,
6
- PermissionsAndroid,
6
+ AppState,
7
7
  } from 'react-native';
8
8
 
9
9
  import { useEffect } from 'react';
@@ -16,66 +16,119 @@ export function RootDoorstepAI(props: {
16
16
  apiKey: string;
17
17
  notificationTitle?: string;
18
18
  notificationText?: string;
19
- /** Opt-in: also request Bluetooth (BLE) permission. Off by default — only
20
- * needed if the `ble` config section is enabled for your fleet. */
19
+ /**
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.
24
+ */
21
25
  requestBluetooth?: boolean;
26
+ /**
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
30
+ * backgrounded and route geofences fire foreground-only.
31
+ */
32
+ requestBackgroundLocation?: boolean;
22
33
  }) {
34
+ const {
35
+ apiKey,
36
+ notificationTitle,
37
+ notificationText,
38
+ requestBluetooth,
39
+ requestBackgroundLocation,
40
+ } = props;
41
+
23
42
  useEffect(() => {
24
- const initializeAndRequestPermissions = async () => {
25
- if (Platform.OS === 'android') {
26
- await DoorstepAI.init(
27
- props.notificationTitle || '',
28
- props.notificationText || ''
29
- );
43
+ let cancelled = false;
44
+ let backgroundPhaseSettled = false;
45
+
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.
52
+ const runBackgroundLocationPhase = async () => {
53
+ if (
54
+ cancelled ||
55
+ backgroundPhaseSettled ||
56
+ Platform.OS !== 'android' ||
57
+ requestBackgroundLocation === false
58
+ ) {
59
+ return;
60
+ }
61
+ try {
62
+ if (await DoorstepAI.hasBackgroundLocationPermission()) {
63
+ backgroundPhaseSettled = true;
64
+ return;
65
+ }
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;
70
+ backgroundPhaseSettled = true;
71
+ await DoorstepAI.requestBackgroundLocationPermission();
72
+ } catch (err) {
73
+ console.warn('DOORSTEPAI - background location request failed:', err);
30
74
  }
75
+ };
31
76
 
32
- DoorstepAI.setApiKey(props.apiKey);
77
+ // Registered synchronously so the effect cleanup always has it to remove.
78
+ const appStateSubscription = AppState.addEventListener(
79
+ 'change',
80
+ (state) => {
81
+ if (state === 'active') runBackgroundLocationPhase();
82
+ }
83
+ );
33
84
 
85
+ const initializeAndRequestPermissions = async () => {
34
86
  if (Platform.OS === 'android') {
35
- try {
36
- const permissionsToRequest = [
37
- PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
38
- PermissionsAndroid.PERMISSIONS.ACTIVITY_RECOGNITION,
39
- ];
40
- // Opt-in Bluetooth (BLE) — Android 12+ "Nearby devices" (BLUETOOTH_SCAN).
41
- if (props.requestBluetooth && PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN) {
42
- permissionsToRequest.push(PermissionsAndroid.PERMISSIONS.BLUETOOTH_SCAN);
43
- }
87
+ await DoorstepAI.init(notificationTitle || '', notificationText || '');
88
+ }
44
89
 
45
- const granted =
46
- await PermissionsAndroid.requestMultiple(permissionsToRequest);
90
+ DoorstepAI.setApiKey(apiKey);
91
+ if (cancelled) return;
47
92
 
48
- if (
49
- granted[PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION] ===
50
- PermissionsAndroid.RESULTS.GRANTED &&
51
- granted[PermissionsAndroid.PERMISSIONS.ACTIVITY_RECOGNITION] ===
52
- PermissionsAndroid.RESULTS.GRANTED
53
- ) {
54
- console.log('Required Android permissions granted');
55
- } else {
56
- console.warn('One or more required Android permissions denied');
57
- }
58
- } catch (err) {
59
- console.warn('Error requesting Android permissions:', err);
60
- }
61
- } else if (Platform.OS === 'ios') {
62
- console.log(
63
- 'iOS: Ensure location and motion usage descriptions are in Info.plist'
93
+ 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
64
107
  );
65
- // Opt-in Bluetooth: triggers the iOS BT prompt (needs
66
- // NSBluetoothAlwaysUsageDescription in the host Info.plist).
67
- if (props.requestBluetooth) {
68
- DoorstepAI.requestAllPermissions(true, true);
108
+ 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') {
113
+ await runBackgroundLocationPhase();
69
114
  }
115
+ } catch (err) {
116
+ console.warn('DOORSTEPAI - permission request failed:', err);
70
117
  }
71
118
  };
72
119
 
73
120
  initializeAndRequestPermissions();
121
+
122
+ return () => {
123
+ cancelled = true;
124
+ appStateSubscription.remove();
125
+ };
74
126
  }, [
75
- props.apiKey,
76
- props.notificationTitle,
77
- props.notificationText,
78
- props.requestBluetooth,
127
+ apiKey,
128
+ notificationTitle,
129
+ notificationText,
130
+ requestBluetooth,
131
+ requestBackgroundLocation,
79
132
  ]);
80
133
 
81
134
  // On iOS, the native view might handle triggering permission prompts if needed.
package/src/index.tsx CHANGED
@@ -4,6 +4,10 @@ export type {
4
4
  AddressType,
5
5
  LatLngObject,
6
6
  StartDeliveryOptions,
7
+ PermissionState,
8
+ DoorstepPermissionType,
9
+ PermissionStatus,
10
+ PermissionRequestOptions,
7
11
  SDKLogLevel,
8
12
  DeliveryStop,
9
13
  RouteGeofenceOptions,