@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.
- package/CHANGELOG.md +66 -0
- package/README.md +115 -3
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/doorstepai/dropoffsdk/DoorstepAIModule.kt +332 -0
- package/ios/DoorstepAI.mm +5 -2
- package/ios/DoorstepAI.swift +170 -2
- 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 +1374 -413
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +13 -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 +13 -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 +3248 -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 +1374 -413
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +13 -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 +13 -4
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +1374 -413
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +13 -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 +13 -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 +3248 -2687
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/DoorstepDropoffSDK.yml +3233 -2674
- package/lib/module/DoorstepAI.js +190 -12
- package/lib/module/DoorstepAI.js.map +1 -1
- package/lib/module/RootDoorstepAI.js +70 -26
- package/lib/module/RootDoorstepAI.js.map +1 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/DoorstepAI.d.ts +151 -7
- package/lib/typescript/src/DoorstepAI.d.ts.map +1 -1
- package/lib/typescript/src/RootDoorstepAI.d.ts +14 -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 +241 -23
- package/src/RootDoorstepAI.tsx +98 -45
- package/src/index.tsx +4 -0
package/src/RootDoorstepAI.tsx
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
View,
|
|
4
4
|
Platform,
|
|
5
5
|
StyleSheet,
|
|
6
|
-
|
|
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
|
-
/**
|
|
20
|
-
*
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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
|
-
|
|
46
|
-
|
|
90
|
+
DoorstepAI.setApiKey(apiKey);
|
|
91
|
+
if (cancelled) return;
|
|
47
92
|
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
-
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
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.
|