@doorstepai/dropoff-sdk 2.2.7 → 2.2.9

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 (48) hide show
  1. package/README.md +78 -10
  2. package/android/build.gradle +1 -1
  3. package/android/src/main/java/com/doorstepai/dropoffsdk/DoorstepAIModule.kt +54 -6
  4. package/android/src/main/java/com/doorstepai/dropoffsdk/DoorstepEmbedViewManager.kt +63 -0
  5. package/android/src/main/java/com/doorstepai/dropoffsdk/HostForegroundServiceWaiter.kt +98 -0
  6. package/ios/DoorstepAI.mm +10 -0
  7. package/ios/DoorstepAI.swift +50 -6
  8. package/ios/DoorstepDropoffSDK.xcframework/Info.plist +5 -5
  9. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/DoorstepDropoffSDK +0 -0
  10. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.abi.json +12846 -6562
  11. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +142 -9
  12. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  13. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.swiftinterface +142 -9
  14. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +10 -10
  15. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/DWARF/DoorstepDropoffSDK +0 -0
  16. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/DoorstepDropoffSDK.yml +5069 -3867
  17. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/DoorstepDropoffSDK +0 -0
  18. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +12846 -6562
  19. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +142 -9
  20. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  21. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +142 -9
  22. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +12846 -6562
  23. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +142 -9
  24. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  25. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +142 -9
  26. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +20 -20
  27. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/DWARF/DoorstepDropoffSDK +0 -0
  28. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/DoorstepDropoffSDK.yml +5064 -3862
  29. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/DoorstepDropoffSDK.yml +5032 -3836
  30. package/ios/DoorstepEmbedViewManager.mm +9 -0
  31. package/ios/DoorstepEmbedViewManager.swift +46 -5
  32. package/lib/module/DoorstepAI.js +49 -2
  33. package/lib/module/DoorstepAI.js.map +1 -1
  34. package/lib/module/DoorstepEmbedView.js +23 -1
  35. package/lib/module/DoorstepEmbedView.js.map +1 -1
  36. package/lib/module/index.js.map +1 -1
  37. package/lib/typescript/embed-preload.example.d.ts +25 -0
  38. package/lib/typescript/embed-preload.example.d.ts.map +1 -0
  39. package/lib/typescript/src/DoorstepAI.d.ts +39 -8
  40. package/lib/typescript/src/DoorstepAI.d.ts.map +1 -1
  41. package/lib/typescript/src/DoorstepEmbedView.d.ts +34 -3
  42. package/lib/typescript/src/DoorstepEmbedView.d.ts.map +1 -1
  43. package/lib/typescript/src/index.d.ts +2 -2
  44. package/lib/typescript/src/index.d.ts.map +1 -1
  45. package/package.json +1 -1
  46. package/src/DoorstepAI.tsx +88 -7
  47. package/src/DoorstepEmbedView.tsx +64 -9
  48. package/src/index.tsx +3 -0
package/README.md CHANGED
@@ -142,7 +142,6 @@ DoorstepAI.setDoorstepGoApiKey('YOUR_DOORSTEP_GO_API_KEY');
142
142
  <DoorstepEmbedView
143
143
  address="1600 Pennsylvania Avenue NW, Washington, DC"
144
144
  deliveryID="delivery-123"
145
- mode="preview"
146
145
  inlineHeight={300}
147
146
  expandedHeight={600}
148
147
  linkAPI="https://api.core.doorstep.ai"
@@ -152,7 +151,9 @@ DoorstepAI.setDoorstepGoApiKey('YOUR_DOORSTEP_GO_API_KEY');
152
151
  polygonColor="#3291BC"
153
152
  parkingColor="#FF847B"
154
153
  onModeChanged={(mode) => console.log('embed mode', mode)}
155
- onError={(message) => console.warn('embed error', message)}
154
+ onLoad={() => console.log('embed navigation started')}
155
+ onSuccess={() => console.log('embed ready')}
156
+ onError={(message, error) => console.warn(error.code, error.stage, message)}
156
157
  />
157
158
  ```
158
159
 
@@ -163,6 +164,32 @@ prop. The component defaults its height to the active mode's `inlineHeight` or
163
164
  view mounted while it is visible, because detaching Android's WebGL-backed map
164
165
  destroys its graphics context.
165
166
 
167
+ For preloading and revealing the same mounted map only after `onSuccess`, see
168
+ [`embed-preload.example.tsx`](./embed-preload.example.tsx). It keeps the native
169
+ view attached at full size with opacity zero while loading, disables touch and
170
+ accessibility while hidden, and handles errors and a bounded preload timeout.
171
+ Use `show={false}` to preload for later, then set it to `true` to reveal once
172
+ ready. Keep its parent mounted and avoid navigation that detaches native screens.
173
+ This retains a live view in memory; it does not download a durable offline map.
174
+
175
+ `onLoad` fires when navigation starts after the signed link is created;
176
+ `onLoading` remains a compatibility alias. `onSuccess` fires when the page reports
177
+ map readiness, so use it to reveal a preloaded map. `onLoad` alone does not mean
178
+ the map is ready. These callbacks require the updated JavaScript package and a
179
+ rebuilt native app on both Android and iOS; an Expo OTA JavaScript update alone
180
+ cannot add missing native callbacks.
181
+
182
+ The optional `mapStyleToggle`, `gpsRecenterToggle`, `streetViewToggle`, and
183
+ `expandContractToggle` props default to `true` on both platforms. `endpoint={{lat, lng}}`
184
+ forwards destination coordinates, `fitGpsOnStart` defaults to `false`, and
185
+ `readyTimeoutSeconds` defaults to `15`. Native button analytics travel directly through
186
+ the native SDK's WebView bridge to Doorstep Go; React Native does not need to forward them.
187
+
188
+ `onError(message, error)` keeps the legacy message as its first argument and supplies a
189
+ `DoorstepEmbedError` as its second: `code`, `stage`, `message`, `isRetryable`, and optional
190
+ `httpStatusCode`/`requestId`. Both platforms use the same field names and enum values.
191
+ `onLoading` reports navigation starting; `onSuccess` reports page readiness.
192
+
166
193
  ### Deliveries
167
194
 
168
195
  All four starters take the same trailing `StartDeliveryOptions`:
@@ -210,10 +237,12 @@ signal, not a truthy return value. On iOS, listen for the SDK's
210
237
 
211
238
  ### Route geofencing
212
239
 
213
- The SDK fences each stop, auto-starts a session on geofence ENTER and stops it on
214
- EXIT (EXIT is gated on `markDropoff`; otherwise the per-session `timeoutSeconds`
215
- backstop cleans up). Needs location permission, and **background operation needs
216
- `locationAlways`**.
240
+ The SDK fences each stop and auto-starts a delivery on qualified ENTER. The server owns
241
+ radius and EXIT policy (`misc.geofence.waitForDropoff`): true/missing requires `markDropoff`
242
+ before EXIT stops the session; false permits unmarked EXIT and keeps the stop armed.
243
+ Whole-route telemetry is also server controlled. Background routes require location
244
+ authorization and the native SDK's supported foreground/background execution setup;
245
+ Always authorization provides the broadest recovery support.
217
246
 
218
247
  ```ts
219
248
  type DeliveryStop = {
@@ -221,18 +250,53 @@ type DeliveryStop = {
221
250
  address: string;
222
251
  latitude: number;
223
252
  longitude: number;
224
- radiusMeters?: number; // default: options.defaultRadiusMeters (250)
253
+ routeStopId?: string; // stable identity; defaults to deliveryId
254
+ radiusMeters?: number; // deprecated, ignored; radius is server controlled
225
255
  customerId?: string;
226
256
  driverId?: string;
227
257
  };
228
258
 
229
- type RouteGeofenceOptions = {
230
- defaultRadiusMeters?: number; // 250
259
+ type RouteOptions = {
260
+ defaultRadiusMeters?: number; // deprecated, ignored
231
261
  timeoutSeconds?: number; // per auto-started session
262
+ autoStopAfterDropoffSeconds?: number;
232
263
  manualForeground?: boolean; // Android only; ignored on iOS
264
+ maxAgeSeconds?: number; // Android only
265
+ clientRouteId?: string;
266
+ driverId?: string;
267
+ metadata?: Record<string, string>;
233
268
  };
269
+ // RouteGeofenceOptions remains a deprecated alias for source compatibility.
270
+ ```
271
+
272
+ For Android routes using a host-owned location foreground service, start that
273
+ service while the app is visible, then await readiness before starting the route:
274
+
275
+ ```ts
276
+ await Location.startLocationUpdatesAsync(LOCATION_TASK, locationOptions);
277
+ await DoorstepAI.waitForHostForegroundService({
278
+ timeoutMs: 10_000,
279
+ serviceClassName: 'expo.modules.location.services.LocationTaskService',
280
+ });
281
+ await DoorstepAI.startRouteGeofencing(stops, { manualForeground: true });
234
282
  ```
235
283
 
284
+ `waitForHostForegroundService(options?): Promise<void>` is Android-only and
285
+ rejects on iOS. It checks immediately, then every 100 ms using Android's own-app
286
+ running-service query. `timeoutMs` defaults to 10000 and accepts integer values
287
+ from 0 to 120000; zero performs one immediate check. Omit `serviceClassName` to
288
+ accept any foreground service in your app except Doorstep's tracking service.
289
+ For Expo, match its service class as above so unrelated services cannot satisfy
290
+ the wait. Rejections have native codes `HOST_FGS_TIMEOUT`,
291
+ `HOST_FGS_CHECK_FAILED`, or `HOST_FGS_CANCELLED` (module teardown).
292
+ The query is deprecated but still supports inspecting the caller's own services.
293
+
294
+ Success is a snapshot of foreground state, not proof of location-service type,
295
+ permissions, fresh fixes, or future uptime. Keep the host location service alive
296
+ for the entire route. This method does not start a service, initialize tracking,
297
+ or alter `manualForeground`. Updating JavaScript alone is insufficient: rebuild
298
+ the native Android app after updating the SDK.
299
+
236
300
  | method | notes |
237
301
  |---|---|
238
302
  | `startRouteGeofencing(stops, options?): Promise<void>` | Rejects if no stop has a `deliveryId` + coordinates. |
@@ -240,13 +304,17 @@ type RouteGeofenceOptions = {
240
304
  | `stopRouteGeofencing(): Promise<void>` | Teardown is handed to the tracking service / region manager, so `getMonitoredStops()` can still show the old list for a moment. |
241
305
  | `resumeRouteGeofencingIfNeeded(): Promise<void>` | **Call this on every launch.** A per-launch host obligation: without it Android silently loses route monitoring across a process kill. |
242
306
  | `getMonitoredStops(): Promise<DeliveryStop[]>` | The SDK's *intent* registry, not the OS's registered-region set. |
307
+ | `isRouteGeofencingActive(): Promise<boolean>` | Durable route intent, independent of an active delivery. |
308
+ | `getActiveRouteId(): Promise<string \| null>` | Canonical SDK route UUID on either platform. |
309
+ | `getActiveRouteRevision(): Promise<number \| null>` | Current manifest revision, or null without a route. |
310
+ | `addMetadata(deliveryId, metadata): Promise<void>` | Attach JSON metadata before or after a delivery session starts. |
243
311
  | `addGeofenceSessionListener(cb): EmitterSubscription \| undefined` | `{ deliveryId, type: 'STARTED' \| 'STOPPED', reason }`. Call `.remove()` to unsubscribe. |
244
312
 
245
313
  ```ts
246
314
  const sub = DoorstepAI.addGeofenceSessionListener(({ deliveryId, type, reason }) => {
247
315
  console.log(type, deliveryId, reason);
248
316
  });
249
- await DoorstepAI.startRouteGeofencing(stops, { defaultRadiusMeters: 250 });
317
+ await DoorstepAI.startRouteGeofencing(stops, { clientRouteId: 'route-123', driverId: 'driver-123' });
250
318
  // ...later
251
319
  sub?.remove();
252
320
  ```
@@ -90,7 +90,7 @@ dependencies {
90
90
  // `onRequestPermissionsResult` to `DoorstepAI.notePermissionRequestResult(...)`
91
91
  // (the only way the SDK can tell a re-askable denial from a permanent one), so
92
92
  // the SDK's types have to be on the host's compile classpath.
93
- api("ai.doorstep.com:doorstepai-dropoff-sdk:2.2.9")
93
+ api("ai.doorstep.com:doorstepai-dropoff-sdk:2.2.13")
94
94
  api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1"
95
95
  }
96
96
 
@@ -24,7 +24,7 @@ import com.facebook.react.bridge.Arguments
24
24
  import com.facebook.react.bridge.UiThreadUtil
25
25
  import com.facebook.react.modules.core.DeviceEventManagerModule
26
26
  import com.doorstepai.sdks.tracking.DeliveryStop
27
- import com.doorstepai.sdks.tracking.RouteGeofenceOptions
27
+ import com.doorstepai.sdks.tracking.RouteOptions
28
28
  import com.doorstepai.sdks.tracking.DoorstepPermission
29
29
  import com.doorstepai.sdks.tracking.DoorstepPermissionState
30
30
  import com.doorstepai.sdks.tracking.DoorstepPermissionStatus
@@ -796,6 +796,18 @@ class DoorstepAIModule(private val reactContext: ReactApplicationContext) :
796
796
 
797
797
  // ---- Route geofencing ----
798
798
 
799
+ private val hostForegroundServiceWaiter = HostForegroundServiceWaiter(reactContext)
800
+
801
+ @ReactMethod
802
+ fun waitForHostForegroundService(timeoutMs: Double, serviceClassName: String?, promise: Promise) {
803
+ if (!timeoutMs.isFinite() || timeoutMs < 0 || timeoutMs > 120_000 || timeoutMs % 1.0 != 0.0 ||
804
+ (serviceClassName != null && serviceClassName.isBlank())) {
805
+ promise.reject("INVALID_ARGUMENT", "timeoutMs must be an integer from 0 to 120000; serviceClassName must be nonempty")
806
+ return
807
+ }
808
+ hostForegroundServiceWaiter.waitFor(timeoutMs.toLong(), serviceClassName, promise)
809
+ }
810
+
799
811
  private val moduleScope = CoroutineScope(Dispatchers.Main + SupervisorJob())
800
812
  private var geofenceJob: Job? = null
801
813
 
@@ -884,6 +896,33 @@ class DoorstepAIModule(private val reactContext: ReactApplicationContext) :
884
896
  }
885
897
  }
886
898
 
899
+ @ReactMethod
900
+ fun isRouteGeofencingActive(promise: Promise) {
901
+ promise.resolve(DoorstepAI.isRouteGeofencingActive())
902
+ }
903
+
904
+ @ReactMethod
905
+ fun getActiveRouteId(promise: Promise) {
906
+ promise.resolve(DoorstepAI.activeRouteInstanceId)
907
+ }
908
+
909
+ @ReactMethod
910
+ fun getActiveRouteRevision(promise: Promise) {
911
+ promise.resolve(DoorstepAI.activeRouteRevision)
912
+ }
913
+
914
+ @ReactMethod
915
+ fun addMetadata(deliveryId: String, metadata: ReadableMap, promise: Promise) {
916
+ try {
917
+ DoorstepAI.addMetadata(deliveryId, metadata.toHashMap()) { result ->
918
+ result.onSuccess { promise.resolve(null) }
919
+ .onFailure { promise.reject("METADATA_ERROR", it.message ?: "Failed to add metadata") }
920
+ }
921
+ } catch (e: Exception) {
922
+ promise.reject("METADATA_ERROR", e.message ?: "Failed to add metadata")
923
+ }
924
+ }
925
+
887
926
  @ReactMethod
888
927
  fun removeListeners(count: Int) {
889
928
  // Required stub for NativeEventEmitter on Android. The single Flow collector
@@ -896,6 +935,7 @@ class DoorstepAIModule(private val reactContext: ReactApplicationContext) :
896
935
  }
897
936
 
898
937
  override fun invalidate() {
938
+ hostForegroundServiceWaiter.invalidate()
899
939
  if (activeInstance === this) activeInstance = null
900
940
  geofenceJob?.cancel()
901
941
  geofenceJob = null
@@ -920,20 +960,27 @@ class DoorstepAIModule(private val reactContext: ReactApplicationContext) :
920
960
  longitude = m.getDouble("longitude"),
921
961
  radiusMeters = if (m.hasKey("radiusMeters") && !m.isNull("radiusMeters")) m.getDouble("radiusMeters") else null,
922
962
  customerId = if (m.hasKey("customerId")) m.getString("customerId") else null,
923
- driverId = if (m.hasKey("driverId")) m.getString("driverId") else null
963
+ driverId = if (m.hasKey("driverId")) m.getString("driverId") else null,
964
+ routeStopId = if (m.hasKey("routeStopId")) m.getString("routeStopId") else null
924
965
  )
925
966
  )
926
967
  }
927
968
  return out
928
969
  }
929
970
 
930
- private fun parseRouteOptions(m: ReadableMap?): RouteGeofenceOptions {
931
- if (m == null) return RouteGeofenceOptions()
932
- return RouteGeofenceOptions(
971
+ private fun parseRouteOptions(m: ReadableMap?): RouteOptions {
972
+ if (m == null) return RouteOptions()
973
+ return RouteOptions(
933
974
  defaultRadiusMeters = if (m.hasKey("defaultRadiusMeters") && !m.isNull("defaultRadiusMeters")) m.getDouble("defaultRadiusMeters") else 250.0,
934
975
  timeoutSeconds = if (m.hasKey("timeoutSeconds") && !m.isNull("timeoutSeconds")) m.getDouble("timeoutSeconds") else null,
935
976
  autoStopAfterDropoffSeconds = if (m.hasKey("autoStopAfterDropoffSeconds") && !m.isNull("autoStopAfterDropoffSeconds")) m.getDouble("autoStopAfterDropoffSeconds") else null,
936
- manualForeground = if (m.hasKey("manualForeground") && !m.isNull("manualForeground")) m.getBoolean("manualForeground") else false
977
+ manualForeground = if (m.hasKey("manualForeground") && !m.isNull("manualForeground")) m.getBoolean("manualForeground") else false,
978
+ maxAgeSeconds = if (m.hasKey("maxAgeSeconds") && !m.isNull("maxAgeSeconds")) m.getDouble("maxAgeSeconds") else null,
979
+ clientRouteId = if (m.hasKey("clientRouteId")) m.getString("clientRouteId") else null,
980
+ driverId = if (m.hasKey("driverId")) m.getString("driverId") else null,
981
+ metadata = if (m.hasKey("metadata") && !m.isNull("metadata")) m.getMap("metadata")?.toHashMap()?.mapValues {
982
+ it.value as? String ?: throw IllegalArgumentException("Route metadata values must be strings")
983
+ }.orEmpty() else emptyMap()
937
984
  )
938
985
  }
939
986
 
@@ -946,6 +993,7 @@ class DoorstepAIModule(private val reactContext: ReactApplicationContext) :
946
993
  s.radiusMeters?.let { m.putDouble("radiusMeters", it) }
947
994
  s.customerId?.let { m.putString("customerId", it) }
948
995
  s.driverId?.let { m.putString("driverId", it) }
996
+ s.routeStopId?.let { m.putString("routeStopId", it) }
949
997
  return m
950
998
  }
951
999
 
@@ -2,6 +2,9 @@ package com.doorstepai.dropoffsdk
2
2
 
3
3
  import com.doorstepai.sdks.tracking.DoorstepEmbedView
4
4
  import com.doorstepai.sdks.tracking.EmbedMode
5
+ import com.doorstepai.sdks.tracking.LatLngObject
6
+ import com.doorstepai.sdks.tracking.DoorstepEmbedError
7
+ import com.facebook.react.bridge.ReadableMap
5
8
  import com.facebook.react.bridge.Arguments
6
9
  import com.facebook.react.bridge.ReactContext
7
10
  import com.facebook.react.common.MapBuilder
@@ -24,6 +27,11 @@ class DoorstepEmbedViewManager : SimpleViewManager<DoorstepEmbedView>() {
24
27
  var markerColor: String = "#027FB8",
25
28
  var polygonColor: String = "#3291BC",
26
29
  var parkingColor: String = "#FF847B",
30
+ var endpointLat: Double? = null,
31
+ var endpointLng: Double? = null,
32
+ var streetViewToggle: Boolean = true,
33
+ var fitGpsOnStart: Boolean = false,
34
+ var readyTimeoutSeconds: Double = 15.0,
27
35
  var loadedRequest: LoadRequest? = null,
28
36
  )
29
37
 
@@ -36,6 +44,11 @@ class DoorstepEmbedViewManager : SimpleViewManager<DoorstepEmbedView>() {
36
44
  val markerColor: String,
37
45
  val polygonColor: String,
38
46
  val parkingColor: String,
47
+ val endpointLat: Double?,
48
+ val endpointLng: Double?,
49
+ val streetViewToggle: Boolean,
50
+ val fitGpsOnStart: Boolean,
51
+ val readyTimeoutSeconds: Double,
39
52
  )
40
53
 
41
54
  private val propsByView = WeakHashMap<DoorstepEmbedView, Props>()
@@ -46,13 +59,26 @@ class DoorstepEmbedViewManager : SimpleViewManager<DoorstepEmbedView>() {
46
59
  val view = DoorstepEmbedView(reactContext)
47
60
  propsByView[view] = Props()
48
61
  view.onModeChanged = { mode ->
62
+ props(view).mode = mode
49
63
  emit(view, MODE_CHANGED_EVENT, Arguments.createMap().apply {
50
64
  putString("mode", mode.value)
51
65
  })
52
66
  }
67
+ view.onLoading = { emit(view, LOADING_EVENT, Arguments.createMap()) }
68
+ view.onSuccess = { emit(view, SUCCESS_EVENT, Arguments.createMap()) }
53
69
  view.onError = { error ->
54
70
  emit(view, ERROR_EVENT, Arguments.createMap().apply {
55
71
  putString("message", error.message)
72
+ putString("code", error.code.name)
73
+ putString("stage", when (error.stage) {
74
+ DoorstepEmbedError.Stage.LINK_GENERATION -> "linkGeneration"
75
+ DoorstepEmbedError.Stage.WEB_NAVIGATION -> "webNavigation"
76
+ DoorstepEmbedError.Stage.INITIALIZATION -> "initialization"
77
+ DoorstepEmbedError.Stage.RENDERING -> "rendering"
78
+ })
79
+ putBoolean("isRetryable", error.isRetryable)
80
+ error.httpStatusCode?.let { putInt("httpStatusCode", it) }
81
+ error.requestId?.let { putString("requestId", it) }
56
82
  })
57
83
  }
58
84
  return view
@@ -113,6 +139,30 @@ class DoorstepEmbedViewManager : SimpleViewManager<DoorstepEmbedView>() {
113
139
  props(view).parkingColor = value ?: "#FF847B"
114
140
  }
115
141
 
142
+ @ReactProp(name = "endpoint")
143
+ fun setEndpoint(view: DoorstepEmbedView, value: ReadableMap?) {
144
+ props(view).endpointLat = if (value != null && value.hasKey("lat") && !value.isNull("lat")) value.getDouble("lat") else null
145
+ props(view).endpointLng = if (value != null && value.hasKey("lng") && !value.isNull("lng")) value.getDouble("lng") else null
146
+ }
147
+
148
+ @ReactProp(name = "mapStyleToggle", defaultBoolean = true)
149
+ fun setMapStyleToggle(view: DoorstepEmbedView, value: Boolean) { view.mapStyleToggle = value }
150
+
151
+ @ReactProp(name = "gpsRecenterToggle", defaultBoolean = true)
152
+ fun setGpsRecenterToggle(view: DoorstepEmbedView, value: Boolean) { view.gpsRecenterToggle = value }
153
+
154
+ @ReactProp(name = "expandContractToggle", defaultBoolean = true)
155
+ fun setExpandContractToggle(view: DoorstepEmbedView, value: Boolean) { view.expandContractToggle = value }
156
+
157
+ @ReactProp(name = "streetViewToggle", defaultBoolean = true)
158
+ fun setStreetViewToggle(view: DoorstepEmbedView, value: Boolean) { props(view).streetViewToggle = value }
159
+
160
+ @ReactProp(name = "fitGpsOnStart", defaultBoolean = false)
161
+ fun setFitGpsOnStart(view: DoorstepEmbedView, value: Boolean) { props(view).fitGpsOnStart = value }
162
+
163
+ @ReactProp(name = "readyTimeoutSeconds", defaultDouble = 15.0)
164
+ fun setReadyTimeoutSeconds(view: DoorstepEmbedView, value: Double) { props(view).readyTimeoutSeconds = value }
165
+
116
166
  override fun onAfterUpdateTransaction(view: DoorstepEmbedView) {
117
167
  super.onAfterUpdateTransaction(view)
118
168
  val props = props(view)
@@ -130,6 +180,11 @@ class DoorstepEmbedViewManager : SimpleViewManager<DoorstepEmbedView>() {
130
180
  markerColor = props.markerColor,
131
181
  polygonColor = props.polygonColor,
132
182
  parkingColor = props.parkingColor,
183
+ endpointLat = props.endpointLat,
184
+ endpointLng = props.endpointLng,
185
+ streetViewToggle = props.streetViewToggle,
186
+ fitGpsOnStart = props.fitGpsOnStart,
187
+ readyTimeoutSeconds = props.readyTimeoutSeconds,
133
188
  )
134
189
  if (request == props.loadedRequest) return
135
190
  props.loadedRequest = request
@@ -142,6 +197,10 @@ class DoorstepEmbedViewManager : SimpleViewManager<DoorstepEmbedView>() {
142
197
  request.markerColor,
143
198
  request.polygonColor,
144
199
  request.parkingColor,
200
+ if (request.endpointLat != null && request.endpointLng != null) LatLngObject(request.endpointLat, request.endpointLng) else null,
201
+ request.streetViewToggle,
202
+ request.fitGpsOnStart,
203
+ request.readyTimeoutSeconds,
145
204
  )
146
205
  }
147
206
 
@@ -154,6 +213,8 @@ class DoorstepEmbedViewManager : SimpleViewManager<DoorstepEmbedView>() {
154
213
  override fun getExportedCustomDirectEventTypeConstants(): Map<String, Any> =
155
214
  MapBuilder.builder<String, Any>()
156
215
  .put(MODE_CHANGED_EVENT, MapBuilder.of("registrationName", "onModeChanged"))
216
+ .put(LOADING_EVENT, MapBuilder.of("registrationName", "onLoading"))
217
+ .put(SUCCESS_EVENT, MapBuilder.of("registrationName", "onSuccess"))
157
218
  .put(ERROR_EVENT, MapBuilder.of("registrationName", "onError"))
158
219
  .build()
159
220
 
@@ -171,6 +232,8 @@ class DoorstepEmbedViewManager : SimpleViewManager<DoorstepEmbedView>() {
171
232
  const val REACT_CLASS = "DoorstepEmbedView"
172
233
  const val MODE_CHANGED_EVENT = "topModeChanged"
173
234
  const val ERROR_EVENT = "topError"
235
+ const val LOADING_EVENT = "topLoading"
236
+ const val SUCCESS_EVENT = "topSuccess"
174
237
  const val DEFAULT_LINK_API = "https://api.core.doorstep.ai"
175
238
  const val DEFAULT_INLINE_HEIGHT = 300f
176
239
  const val DEFAULT_EXPANDED_HEIGHT = 600f
@@ -0,0 +1,98 @@
1
+ package com.doorstepai.dropoffsdk
2
+
3
+ import android.app.ActivityManager
4
+ import android.content.Context
5
+ import android.os.Handler
6
+ import android.os.Looper
7
+ import android.os.SystemClock
8
+ import com.facebook.react.bridge.Promise
9
+ import java.util.concurrent.atomic.AtomicBoolean
10
+
11
+ /** Queries only this application's services; never starts or promotes a service. */
12
+ internal class HostForegroundServiceWaiter(private val context: Context) {
13
+ private val handler = Handler(Looper.getMainLooper())
14
+ private val invalidated = AtomicBoolean(false)
15
+ // Accessed only on the main thread, including teardown.
16
+ private val pending = mutableSetOf<Wait>()
17
+
18
+ fun waitFor(timeoutMs: Long, serviceClassName: String?, promise: Promise) {
19
+ handler.post {
20
+ if (invalidated.get()) {
21
+ promise.reject("HOST_FGS_CANCELLED", "React Native module was destroyed")
22
+ } else {
23
+ val wait = Wait(SystemClock.elapsedRealtime() + timeoutMs, serviceClassName, promise)
24
+ pending.add(wait)
25
+ wait.run()
26
+ }
27
+ }
28
+ }
29
+
30
+ fun invalidate() {
31
+ invalidated.set(true)
32
+ handler.post {
33
+ pending.toList().forEach { it.cancel() }
34
+ }
35
+ }
36
+
37
+ private fun hostServiceIsForeground(serviceClassName: String?): Boolean {
38
+ val manager = context.getSystemService(Context.ACTIVITY_SERVICE) as? ActivityManager
39
+ ?: throw IllegalStateException("ActivityManager is unavailable")
40
+ @Suppress("DEPRECATION")
41
+ val services = manager.getRunningServices(Int.MAX_VALUE).orEmpty()
42
+ return services.any {
43
+ it.foreground && it.service.packageName == context.packageName &&
44
+ it.service.className != SDK_SERVICE_CLASS &&
45
+ (serviceClassName == null || it.service.className == serviceClassName)
46
+ }
47
+ }
48
+
49
+ private inner class Wait(
50
+ private val deadlineMs: Long,
51
+ private val serviceClassName: String?,
52
+ private val promise: Promise,
53
+ ) : Runnable {
54
+ private var settled = false
55
+
56
+ override fun run() {
57
+ if (settled) return
58
+ if (invalidated.get()) {
59
+ cancel()
60
+ return
61
+ }
62
+ try {
63
+ if (hostServiceIsForeground(serviceClassName)) {
64
+ finish()
65
+ promise.resolve(null)
66
+ return
67
+ }
68
+ val remainingMs = deadlineMs - SystemClock.elapsedRealtime()
69
+ if (remainingMs <= 0) {
70
+ finish()
71
+ promise.reject("HOST_FGS_TIMEOUT", "No matching host foreground service became ready before timeout")
72
+ return
73
+ }
74
+ handler.postDelayed(this, minOf(POLL_INTERVAL_MS, remainingMs))
75
+ } catch (error: Exception) {
76
+ finish()
77
+ promise.reject("HOST_FGS_CHECK_FAILED", "Unable to query host foreground services", error)
78
+ }
79
+ }
80
+
81
+ fun cancel() {
82
+ if (settled) return
83
+ finish()
84
+ promise.reject("HOST_FGS_CANCELLED", "React Native module was destroyed")
85
+ }
86
+
87
+ private fun finish() {
88
+ settled = true
89
+ handler.removeCallbacks(this)
90
+ pending.remove(this)
91
+ }
92
+ }
93
+
94
+ private companion object {
95
+ const val POLL_INTERVAL_MS = 100L
96
+ const val SDK_SERVICE_CLASS = "com.doorstepai.sdks.tracking.internal.TrackingService"
97
+ }
98
+ }
package/ios/DoorstepAI.mm CHANGED
@@ -95,5 +95,15 @@ RCT_EXTERN_METHOD(resumeRouteGeofencingIfNeeded:(RCTPromiseResolveBlock)resolve
95
95
  rejecter:(RCTPromiseRejectBlock)reject)
96
96
  RCT_EXTERN_METHOD(getMonitoredStops:(RCTPromiseResolveBlock)resolve
97
97
  rejecter:(RCTPromiseRejectBlock)reject)
98
+ RCT_EXTERN_METHOD(isRouteGeofencingActive:(RCTPromiseResolveBlock)resolve
99
+ rejecter:(RCTPromiseRejectBlock)reject)
100
+ RCT_EXTERN_METHOD(getActiveRouteId:(RCTPromiseResolveBlock)resolve
101
+ rejecter:(RCTPromiseRejectBlock)reject)
102
+ RCT_EXTERN_METHOD(getActiveRouteRevision:(RCTPromiseResolveBlock)resolve
103
+ rejecter:(RCTPromiseRejectBlock)reject)
104
+ RCT_EXTERN_METHOD(addMetadata:(nonnull NSString *)deliveryId
105
+ metadata:(nonnull NSDictionary *)metadata
106
+ resolver:(RCTPromiseResolveBlock)resolve
107
+ rejecter:(RCTPromiseRejectBlock)reject)
98
108
 
99
109
  @end
@@ -464,6 +464,10 @@ class DoorstepAIBridge: RCTEventEmitter {
464
464
  options: NSDictionary?,
465
465
  resolver resolve: @escaping RCTPromiseResolveBlock,
466
466
  rejecter reject: @escaping RCTPromiseRejectBlock) {
467
+ if let metadata = options?["metadata"], !(metadata is NSNull), !(metadata is [String: String]) {
468
+ reject("E_ROUTE_GEOFENCING", "Route metadata values must be strings", nil)
469
+ return
470
+ }
467
471
  let parsed: [DeliveryStop] = (stops as? [[String: Any]] ?? []).compactMap { parseDeliveryStop($0) }
468
472
  if parsed.isEmpty {
469
473
  reject("E_ROUTE_GEOFENCING", "startRouteGeofencing requires at least one valid stop (deliveryId + latitude + longitude)", nil)
@@ -513,6 +517,42 @@ class DoorstepAIBridge: RCTEventEmitter {
513
517
  }
514
518
  }
515
519
 
520
+ @objc
521
+ func isRouteGeofencingActive(_ resolve: @escaping RCTPromiseResolveBlock,
522
+ rejecter reject: @escaping RCTPromiseRejectBlock) {
523
+ DispatchQueue.main.async { resolve(DoorstepAI.isRouteGeofencingActive()) }
524
+ }
525
+
526
+ @objc
527
+ func getActiveRouteId(_ resolve: @escaping RCTPromiseResolveBlock,
528
+ rejecter reject: @escaping RCTPromiseRejectBlock) {
529
+ DispatchQueue.main.async { resolve(DoorstepAI.activeRouteId) }
530
+ }
531
+
532
+ @objc
533
+ func getActiveRouteRevision(_ resolve: @escaping RCTPromiseResolveBlock,
534
+ rejecter reject: @escaping RCTPromiseRejectBlock) {
535
+ DispatchQueue.main.async { resolve(DoorstepAI.activeRouteRevision) }
536
+ }
537
+
538
+ @objc
539
+ func addMetadata(_ deliveryId: String, metadata: NSDictionary,
540
+ resolver resolve: @escaping RCTPromiseResolveBlock,
541
+ rejecter reject: @escaping RCTPromiseRejectBlock) {
542
+ guard let values = metadata as? [String: Any] else {
543
+ reject("E_METADATA", "Metadata must be a JSON object", nil)
544
+ return
545
+ }
546
+ Task {
547
+ do {
548
+ try await DoorstepAI.addMetadata(deliveryId, values)
549
+ resolve(nil)
550
+ } catch {
551
+ reject("E_METADATA", error.localizedDescription, error)
552
+ }
553
+ }
554
+ }
555
+
516
556
  private func parseDeliveryStop(_ raw: [String: Any]) -> DeliveryStop? {
517
557
  guard let deliveryId = raw["deliveryId"] as? String,
518
558
  let latitude = (raw["latitude"] as? NSNumber)?.doubleValue,
@@ -520,6 +560,7 @@ class DoorstepAIBridge: RCTEventEmitter {
520
560
  return nil
521
561
  }
522
562
  return DeliveryStop(
563
+ routeStopId: raw["routeStopId"] as? String,
523
564
  deliveryId: deliveryId,
524
565
  address: (raw["address"] as? String) ?? "",
525
566
  latitude: latitude,
@@ -530,14 +571,16 @@ class DoorstepAIBridge: RCTEventEmitter {
530
571
  )
531
572
  }
532
573
 
533
- private func parseRouteOptions(_ raw: NSDictionary?) -> RouteGeofenceOptions {
534
- guard let o = raw as? [String: Any] else { return RouteGeofenceOptions() }
535
- // iOS RouteGeofenceOptions has no `manualForeground` (OS owns background region
536
- // monitoring); a JS-supplied manualForeground is intentionally ignored here.
537
- return RouteGeofenceOptions(
574
+ private func parseRouteOptions(_ raw: NSDictionary?) -> RouteOptions {
575
+ guard let o = raw as? [String: Any] else { return RouteOptions() }
576
+ // manualForeground and maxAgeSeconds are Android-only options.
577
+ return RouteOptions(
538
578
  defaultRadiusMeters: (o["defaultRadiusMeters"] as? NSNumber)?.doubleValue ?? 250,
539
579
  timeoutSeconds: (o["timeoutSeconds"] as? NSNumber)?.doubleValue,
540
- autoStopAfterDropoffSeconds: (o["autoStopAfterDropoffSeconds"] as? NSNumber)?.doubleValue
580
+ autoStopAfterDropoffSeconds: (o["autoStopAfterDropoffSeconds"] as? NSNumber)?.doubleValue,
581
+ clientRouteId: o["clientRouteId"] as? String,
582
+ driverId: o["driverId"] as? String,
583
+ metadata: o["metadata"] as? [String: String]
541
584
  )
542
585
  }
543
586
 
@@ -551,6 +594,7 @@ class DoorstepAIBridge: RCTEventEmitter {
551
594
  if let r = s.radiusMeters { m["radiusMeters"] = r }
552
595
  if let c = s.customerId { m["customerId"] = c }
553
596
  if let d = s.driverId { m["driverId"] = d }
597
+ if let id = s.routeStopId { m["routeStopId"] = id }
554
598
  return m
555
599
  }
556
600
 
@@ -10,15 +10,18 @@
10
10
  <key>DebugSymbolsPath</key>
11
11
  <string>dSYMs</string>
12
12
  <key>LibraryIdentifier</key>
13
- <string>ios-arm64</string>
13
+ <string>ios-arm64_x86_64-simulator</string>
14
14
  <key>LibraryPath</key>
15
15
  <string>DoorstepDropoffSDK.framework</string>
16
16
  <key>SupportedArchitectures</key>
17
17
  <array>
18
18
  <string>arm64</string>
19
+ <string>x86_64</string>
19
20
  </array>
20
21
  <key>SupportedPlatform</key>
21
22
  <string>ios</string>
23
+ <key>SupportedPlatformVariant</key>
24
+ <string>simulator</string>
22
25
  </dict>
23
26
  <dict>
24
27
  <key>BinaryPath</key>
@@ -26,18 +29,15 @@
26
29
  <key>DebugSymbolsPath</key>
27
30
  <string>dSYMs</string>
28
31
  <key>LibraryIdentifier</key>
29
- <string>ios-arm64_x86_64-simulator</string>
32
+ <string>ios-arm64</string>
30
33
  <key>LibraryPath</key>
31
34
  <string>DoorstepDropoffSDK.framework</string>
32
35
  <key>SupportedArchitectures</key>
33
36
  <array>
34
37
  <string>arm64</string>
35
- <string>x86_64</string>
36
38
  </array>
37
39
  <key>SupportedPlatform</key>
38
40
  <string>ios</string>
39
- <key>SupportedPlatformVariant</key>
40
- <string>simulator</string>
41
41
  </dict>
42
42
  </array>
43
43
  <key>CFBundlePackageType</key>