@doorstepai/dropoff-sdk 1.0.7 → 1.0.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.
- package/README.md +33 -19
- package/android/build.gradle +1 -1
- package/android/src/main/java/com/doorstepai/dropoffsdk/DoorstepAIModule.kt +42 -32
- package/ios/DoorstepAI.mm +8 -2
- package/ios/DoorstepAI.swift +27 -22
- 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 +215 -57
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +6 -5
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.swiftinterface +6 -5
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +8 -8
- 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 +735 -677
- 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 +215 -57
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +6 -5
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +6 -5
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +215 -57
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +6 -5
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +6 -5
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +16 -16
- 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 +759 -701
- package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/DoorstepDropoffSDK.yml +759 -700
- package/lib/module/DoorstepAI.js +56 -29
- package/lib/module/DoorstepAI.js.map +1 -1
- package/lib/module/RootDoorstepAI.js.map +1 -1
- package/lib/typescript/src/DoorstepAI.d.ts +6 -5
- package/lib/typescript/src/DoorstepAI.d.ts.map +1 -1
- package/lib/typescript/src/RootDoorstepAI.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/DoorstepAI.tsx +64 -42
- package/src/RootDoorstepAI.tsx +4 -7
package/README.md
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
|
|
2
1
|
# DoorstepAI Dropoff SDK for React Native
|
|
3
2
|
|
|
4
3
|
The `@doorstepai/dropoff-sdk` provides a set of tools to integrate delivery tracking into your React Native application. This SDK enables seamless coordination between your delivery interface and DoorstepAI's backend systems.
|
|
@@ -52,22 +51,35 @@ import { DoorstepAI } from "@doorstepai/dropoff-sdk"
|
|
|
52
51
|
|
|
53
52
|
// Start a delivery using a Google Place ID
|
|
54
53
|
<Button title="Start Delivery" onPress={() => {
|
|
55
|
-
DoorstepAI.startDeliveryByPlaceID(
|
|
54
|
+
DoorstepAI.startDeliveryByPlaceID('destination_place_id', 'delivery_id_1');
|
|
55
|
+
}} />
|
|
56
|
+
|
|
57
|
+
// Start a delivery using an address
|
|
58
|
+
<Button title="Start Delivery by Address" onPress={() => {
|
|
59
|
+
const address = {
|
|
60
|
+
streetNumber: '123',
|
|
61
|
+
route: 'Main St',
|
|
62
|
+
subPremise: 'Apt 4B',
|
|
63
|
+
locality: 'New York',
|
|
64
|
+
administrativeAreaLevel1: 'NY',
|
|
65
|
+
postalCode: '10001'
|
|
66
|
+
};
|
|
67
|
+
DoorstepAI.startDeliveryByAddress(address, 'delivery_id_1');
|
|
56
68
|
}} />
|
|
57
69
|
|
|
58
70
|
// Send "taking_pod" event
|
|
59
71
|
<Button title="Taking POD" onPress={() => {
|
|
60
|
-
DoorstepAI.newEvent(
|
|
72
|
+
DoorstepAI.newEvent('taking_pod', 'delivery_id_1');
|
|
61
73
|
}} />
|
|
62
74
|
|
|
63
75
|
// Send "pod_captured" event
|
|
64
76
|
<Button title="POD Captured" onPress={() => {
|
|
65
|
-
DoorstepAI.newEvent(
|
|
77
|
+
DoorstepAI.newEvent('pod_captured', 'delivery_id_1');
|
|
66
78
|
}} />
|
|
67
79
|
|
|
68
80
|
// End the delivery
|
|
69
81
|
<Button title="End Delivery" onPress={() => {
|
|
70
|
-
DoorstepAI.stopDelivery();
|
|
82
|
+
DoorstepAI.stopDelivery('delivery_id_1');
|
|
71
83
|
}} />
|
|
72
84
|
```
|
|
73
85
|
|
|
@@ -89,43 +101,44 @@ Sets the API key to authenticate SDK usage.
|
|
|
89
101
|
|
|
90
102
|
---
|
|
91
103
|
|
|
92
|
-
### `DoorstepAI.startDeliveryByPlaceID(placeID: string): Promise<
|
|
104
|
+
### `DoorstepAI.startDeliveryByPlaceID(placeID: string, deliveryId: string): Promise<string>`
|
|
93
105
|
|
|
94
|
-
Starts a delivery using a Google Place ID.
|
|
106
|
+
Starts a delivery using a Google Place ID. Returns a session ID on success.
|
|
95
107
|
|
|
96
108
|
---
|
|
97
109
|
|
|
98
|
-
### `DoorstepAI.startDeliveryByPlusCode(plusCode: string): Promise<
|
|
110
|
+
### `DoorstepAI.startDeliveryByPlusCode(plusCode: string, deliveryId: string): Promise<string>`
|
|
99
111
|
|
|
100
|
-
Starts a delivery using a Google Plus Code.
|
|
112
|
+
Starts a delivery using a Google Plus Code. Returns a session ID on success.
|
|
101
113
|
|
|
102
114
|
---
|
|
103
115
|
|
|
104
|
-
### `DoorstepAI.startDeliveryByAddress(address: AddressType): Promise<
|
|
116
|
+
### `DoorstepAI.startDeliveryByAddress(address: AddressType, deliveryId: string): Promise<string>`
|
|
105
117
|
|
|
106
|
-
Starts a delivery using a structured address object.
|
|
118
|
+
Starts a delivery using a structured address object. Returns a session ID on success.
|
|
107
119
|
|
|
108
120
|
```ts
|
|
109
121
|
type AddressType = {
|
|
110
122
|
streetNumber: string;
|
|
111
123
|
route: string;
|
|
112
|
-
|
|
113
|
-
|
|
124
|
+
subPremise: string; // Apartment, suite, unit, etc.
|
|
125
|
+
locality: string; // City
|
|
126
|
+
administrativeAreaLevel1: string; // State/Province
|
|
114
127
|
postalCode: string;
|
|
115
128
|
}
|
|
116
129
|
```
|
|
117
130
|
|
|
118
131
|
---
|
|
119
132
|
|
|
120
|
-
### `DoorstepAI.stopDelivery(): Promise<void>`
|
|
133
|
+
### `DoorstepAI.stopDelivery(deliveryId: string): Promise<void>`
|
|
121
134
|
|
|
122
|
-
Stops the
|
|
135
|
+
Stops the specified delivery.
|
|
123
136
|
|
|
124
137
|
---
|
|
125
138
|
|
|
126
|
-
### `DoorstepAI.newEvent(eventName: string): Promise<void>`
|
|
139
|
+
### `DoorstepAI.newEvent(eventName: string, deliveryId: string): Promise<void>`
|
|
127
140
|
|
|
128
|
-
Sends a delivery-related event. Supported events include:
|
|
141
|
+
Sends a delivery-related event for the specified delivery. Supported events include:
|
|
129
142
|
- `"taking_pod"`
|
|
130
143
|
- `"pod_captured"`
|
|
131
144
|
|
|
@@ -138,6 +151,8 @@ More can be added per vender/customer relationship.
|
|
|
138
151
|
- Always wrap `DoorstepAI` API calls in `try/catch` or use `.catch()` for better error handling when applicable.
|
|
139
152
|
- Use the `RootDoorstepAI` component only **once** at the **root** of your app.
|
|
140
153
|
- Ensure your API key is securely stored and never hardcoded in production.
|
|
154
|
+
- Always provide a unique `deliveryId` for each delivery session.
|
|
155
|
+
- Keep track of the `deliveryId` throughout the delivery lifecycle as it's required for all operations.
|
|
141
156
|
|
|
142
157
|
---
|
|
143
158
|
|
|
@@ -148,8 +163,7 @@ If something isn't working as expected:
|
|
|
148
163
|
- Check console logs for `DoorstepAI initialized` or error messages.
|
|
149
164
|
- Verify that the API key is valid and accepted by the SDK.
|
|
150
165
|
- Ensure your permissions (e.g., location) are correctly set up on the device.
|
|
151
|
-
|
|
152
|
-
---
|
|
166
|
+
- Verify that you're using the correct `deliveryId` for each operation.
|
|
153
167
|
|
|
154
168
|
---
|
|
155
169
|
|
package/android/build.gradle
CHANGED
|
@@ -86,7 +86,7 @@ def kotlin_version = getExtOrDefault("kotlinVersion")
|
|
|
86
86
|
dependencies {
|
|
87
87
|
implementation "com.facebook.react:react-android"
|
|
88
88
|
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
|
|
89
|
-
implementation("ai.doorstep.com:doorstepai-dropoff-sdk:1.0.
|
|
89
|
+
implementation("ai.doorstep.com:doorstepai-dropoff-sdk:1.0.1")
|
|
90
90
|
api "org.jetbrains.kotlinx:kotlinx-serialization-json:1.5.1"
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -8,6 +8,7 @@ import com.facebook.react.bridge.ReactMethod
|
|
|
8
8
|
import com.facebook.react.bridge.Promise
|
|
9
9
|
import com.doorstepai.sdks.tracking.DoorstepAI
|
|
10
10
|
import com.doorstepai.sdks.tracking.AddressType
|
|
11
|
+
import com.facebook.react.bridge.ReadableMap
|
|
11
12
|
|
|
12
13
|
class DoorstepAIModule(private val reactContext: ReactApplicationContext) :
|
|
13
14
|
ReactContextBaseJavaModule(reactContext) {
|
|
@@ -32,57 +33,61 @@ class DoorstepAIModule(private val reactContext: ReactApplicationContext) :
|
|
|
32
33
|
}
|
|
33
34
|
|
|
34
35
|
@ReactMethod
|
|
35
|
-
fun startDeliveryByPlaceID(placeID: String, promise: Promise) {
|
|
36
|
+
fun startDeliveryByPlaceID(placeID: String, deliveryId: String, promise: Promise) {
|
|
36
37
|
try {
|
|
37
|
-
DoorstepAI.startDeliveryByPlaceID(placeID) { result ->
|
|
38
|
-
result.onSuccess {
|
|
39
|
-
promise.resolve(
|
|
38
|
+
DoorstepAI.startDeliveryByPlaceID(placeID, deliveryId) { result ->
|
|
39
|
+
result.onSuccess { sessionId ->
|
|
40
|
+
promise.resolve(sessionId)
|
|
40
41
|
}.onFailure { error ->
|
|
41
|
-
promise.reject("DELIVERY_ERROR", error.message ?: "Promise Rejection: Failed to start delivery")
|
|
42
|
+
promise.reject("DELIVERY_ERROR", error.message ?: "Promise Rejection: Failed to start delivery by Place ID")
|
|
42
43
|
}
|
|
43
44
|
}
|
|
44
45
|
} catch (e: Exception) {
|
|
45
|
-
promise.reject("DELIVERY_ERROR", e.message ?: "Failed to start delivery")
|
|
46
|
+
promise.reject("DELIVERY_ERROR", e.message ?: "Failed to start delivery by Place ID")
|
|
46
47
|
}
|
|
47
48
|
}
|
|
48
49
|
|
|
49
50
|
@ReactMethod
|
|
50
|
-
fun startDeliveryByPlusCode(plusCode: String, promise: Promise) {
|
|
51
|
+
fun startDeliveryByPlusCode(plusCode: String, deliveryId: String, promise: Promise) {
|
|
51
52
|
try {
|
|
52
|
-
DoorstepAI.startDeliveryByPlusCode(plusCode) { result ->
|
|
53
|
-
result.onSuccess {
|
|
54
|
-
promise.resolve(
|
|
53
|
+
DoorstepAI.startDeliveryByPlusCode(plusCode, deliveryId) { result ->
|
|
54
|
+
result.onSuccess { sessionId ->
|
|
55
|
+
promise.resolve(sessionId)
|
|
55
56
|
}.onFailure { error ->
|
|
56
|
-
promise.reject("DELIVERY_ERROR", error.message ?: "Promise Rejection: Failed to start delivery")
|
|
57
|
+
promise.reject("DELIVERY_ERROR", error.message ?: "Promise Rejection: Failed to start delivery by Plus Code")
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
} catch (e: Exception) {
|
|
60
|
-
promise.reject("DELIVERY_ERROR", e.message ?: "Failed to start delivery")
|
|
61
|
+
promise.reject("DELIVERY_ERROR", e.message ?: "Failed to start delivery by Plus Code")
|
|
61
62
|
}
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
@ReactMethod
|
|
65
66
|
fun startDeliveryByAddress(
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
locality: String,
|
|
69
|
-
administrativeAreaLevel1: String,
|
|
70
|
-
postalCode: String,
|
|
71
|
-
subPremise: String,
|
|
67
|
+
addressMap: ReadableMap,
|
|
68
|
+
deliveryId: String,
|
|
72
69
|
promise: Promise
|
|
73
70
|
) {
|
|
74
71
|
try {
|
|
72
|
+
val streetNumber = addressMap.getString("streetNumber") ?: ""
|
|
73
|
+
val route = addressMap.getString("route") ?: ""
|
|
74
|
+
val subPremise = addressMap.getString("subPremise") ?: ""
|
|
75
|
+
val locality = addressMap.getString("locality") ?: ""
|
|
76
|
+
val administrativeAreaLevel1 = addressMap.getString("administrativeAreaLevel1") ?: ""
|
|
77
|
+
val postalCode = addressMap.getString("postalCode") ?: ""
|
|
78
|
+
|
|
75
79
|
val address = AddressType(
|
|
76
80
|
streetNumber = streetNumber,
|
|
77
81
|
route = route,
|
|
82
|
+
subPremise = subPremise,
|
|
78
83
|
locality = locality,
|
|
79
84
|
administrativeAreaLevel1 = administrativeAreaLevel1,
|
|
80
|
-
postalCode = postalCode
|
|
81
|
-
subPremise = subPremise
|
|
85
|
+
postalCode = postalCode
|
|
82
86
|
)
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
|
|
88
|
+
DoorstepAI.startDeliveryByAddressType(address, deliveryId) { result ->
|
|
89
|
+
result.onSuccess { sessionId ->
|
|
90
|
+
promise.resolve(sessionId)
|
|
86
91
|
}.onFailure { error ->
|
|
87
92
|
promise.reject("DELIVERY_ERROR", error.message ?: "Promise Rejection: Failed to start delivery by address")
|
|
88
93
|
}
|
|
@@ -93,27 +98,27 @@ class DoorstepAIModule(private val reactContext: ReactApplicationContext) :
|
|
|
93
98
|
}
|
|
94
99
|
|
|
95
100
|
@ReactMethod
|
|
96
|
-
fun newEvent(eventName: String, promise: Promise) {
|
|
101
|
+
fun newEvent(eventName: String, deliveryId: String, promise: Promise) {
|
|
97
102
|
try {
|
|
98
|
-
DoorstepAI.newEvent(eventName) { result ->
|
|
99
|
-
result.onSuccess {
|
|
100
|
-
promise.resolve(
|
|
103
|
+
DoorstepAI.newEvent(eventName, deliveryId) { result ->
|
|
104
|
+
result.onSuccess { eventResponse ->
|
|
105
|
+
promise.resolve(eventResponse)
|
|
101
106
|
}.onFailure { error ->
|
|
102
|
-
promise.reject("
|
|
107
|
+
promise.reject("EVENT_CREATION_ERROR", error.message ?: "Promise Rejection: Failed to save event")
|
|
103
108
|
}
|
|
104
109
|
}
|
|
105
110
|
} catch (e: Exception) {
|
|
106
|
-
promise.reject("
|
|
111
|
+
promise.reject("EVENT_CREATION_ERROR", e.message ?: "Failed to save event")
|
|
107
112
|
}
|
|
108
113
|
}
|
|
109
114
|
|
|
110
115
|
@ReactMethod
|
|
111
|
-
fun stopDelivery(promise: Promise) {
|
|
116
|
+
fun stopDelivery(deliveryId: String, promise: Promise) {
|
|
112
117
|
try {
|
|
113
|
-
DoorstepAI.stopDelivery()
|
|
118
|
+
DoorstepAI.stopDelivery(deliveryId)
|
|
114
119
|
promise.resolve(true)
|
|
115
120
|
} catch (e: Exception) {
|
|
116
|
-
promise.reject("
|
|
121
|
+
promise.reject("DELIVERY_STOP_ERROR", e.message ?: "Failed to stop delivery")
|
|
117
122
|
}
|
|
118
123
|
}
|
|
119
124
|
|
|
@@ -122,6 +127,11 @@ class DoorstepAIModule(private val reactContext: ReactApplicationContext) :
|
|
|
122
127
|
DoorstepAI.setAPIKey(key)
|
|
123
128
|
}
|
|
124
129
|
|
|
130
|
+
@ReactMethod
|
|
131
|
+
fun setDevMode(devModeEnabled: Boolean) {
|
|
132
|
+
DoorstepAI.devMode = devModeEnabled
|
|
133
|
+
}
|
|
134
|
+
|
|
125
135
|
companion object {
|
|
126
136
|
const val NAME = "DoorstepAI"
|
|
127
137
|
}
|
package/ios/DoorstepAI.mm
CHANGED
|
@@ -3,19 +3,25 @@
|
|
|
3
3
|
@interface RCT_EXTERN_MODULE(DoorstepAI, NSObject)
|
|
4
4
|
|
|
5
5
|
RCT_EXTERN_METHOD(setApiKey:(NSString *)apiKey)
|
|
6
|
+
RCT_EXTERN_METHOD(setDevMode:(BOOL)devModeEnabled)
|
|
6
7
|
RCT_EXTERN_METHOD(startDeliveryByPlaceID:(NSString *)placeID
|
|
8
|
+
deliveryId:(NSString *)deliveryId
|
|
7
9
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
8
10
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
9
11
|
RCT_EXTERN_METHOD(startDeliveryByPlusCode:(NSString *)plusCode
|
|
12
|
+
deliveryId:(NSString *)deliveryId
|
|
10
13
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
11
14
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
12
|
-
RCT_EXTERN_METHOD(startDeliveryByAddress:(
|
|
15
|
+
RCT_EXTERN_METHOD(startDeliveryByAddress:(NSDictionary *)address
|
|
16
|
+
deliveryId:(NSString *)deliveryId
|
|
13
17
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
14
18
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
15
19
|
RCT_EXTERN_METHOD(newEvent:(NSString *)eventName
|
|
20
|
+
deliveryId:(NSString *)deliveryId
|
|
16
21
|
resolver:(RCTPromiseResolveBlock)resolve
|
|
17
22
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
18
|
-
RCT_EXTERN_METHOD(stopDelivery:(
|
|
23
|
+
RCT_EXTERN_METHOD(stopDelivery:(NSString *)deliveryId
|
|
24
|
+
resolver:(RCTPromiseResolveBlock)resolve
|
|
19
25
|
rejecter:(RCTPromiseRejectBlock)reject)
|
|
20
26
|
|
|
21
27
|
@end
|
package/ios/DoorstepAI.swift
CHANGED
|
@@ -10,6 +10,11 @@ class DoorstepAIBridge: NSObject {
|
|
|
10
10
|
return true
|
|
11
11
|
}
|
|
12
12
|
|
|
13
|
+
@objc
|
|
14
|
+
func setDevMode(_ devModeEnabled: Bool) {
|
|
15
|
+
DoorstepAI.devMode = devModeEnabled
|
|
16
|
+
}
|
|
17
|
+
|
|
13
18
|
@objc
|
|
14
19
|
func setApiKey(_ apiKey: String) {
|
|
15
20
|
DoorstepAI.setApiKey(key: apiKey)
|
|
@@ -17,12 +22,13 @@ class DoorstepAIBridge: NSObject {
|
|
|
17
22
|
|
|
18
23
|
@objc
|
|
19
24
|
func startDeliveryByPlaceID(_ placeID: NSString,
|
|
25
|
+
deliveryId: NSString,
|
|
20
26
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
21
27
|
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
22
28
|
// Use Swift's concurrency support to call the async method.
|
|
23
29
|
Task {
|
|
24
30
|
do {
|
|
25
|
-
try await DoorstepAI.startDeliveryByPlaceID(placeID: placeID as String)
|
|
31
|
+
try await DoorstepAI.startDeliveryByPlaceID(placeID: placeID as String, deliveryId: deliveryId as String)
|
|
26
32
|
resolve(nil)
|
|
27
33
|
} catch {
|
|
28
34
|
reject("E_START_DELIVERY", "Failed to start delivery by Place ID: \(error.localizedDescription)", error)
|
|
@@ -32,11 +38,12 @@ class DoorstepAIBridge: NSObject {
|
|
|
32
38
|
|
|
33
39
|
@objc
|
|
34
40
|
func startDeliveryByPlusCode(_ plusCode: NSString,
|
|
41
|
+
deliveryId: NSString,
|
|
35
42
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
36
43
|
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
37
44
|
Task {
|
|
38
45
|
do {
|
|
39
|
-
try await DoorstepAI.startDeliveryByPlusCode(plusCode: plusCode as String)
|
|
46
|
+
try await DoorstepAI.startDeliveryByPlusCode(plusCode: plusCode as String, deliveryId: deliveryId as String)
|
|
40
47
|
resolve(nil)
|
|
41
48
|
} catch {
|
|
42
49
|
reject("E_START_DELIVERY", "Failed to start delivery by Plus Code: \(error.localizedDescription)", error)
|
|
@@ -45,51 +52,48 @@ class DoorstepAIBridge: NSObject {
|
|
|
45
52
|
}
|
|
46
53
|
|
|
47
54
|
@objc
|
|
48
|
-
func startDeliveryByAddress(_
|
|
55
|
+
func startDeliveryByAddress(_ address: [String: Any],
|
|
56
|
+
deliveryId: NSString,
|
|
49
57
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
50
58
|
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
51
|
-
guard let data = (addressJSON as String).data(using: .utf8) else {
|
|
52
|
-
reject("E_INVALID_ADDRESS", "Invalid JSON string format.", nil)
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
|
|
56
59
|
Task {
|
|
60
|
+
print("Starting delivery by address: \(address)")
|
|
57
61
|
do {
|
|
58
|
-
guard let
|
|
59
|
-
let
|
|
60
|
-
let
|
|
61
|
-
let
|
|
62
|
-
let
|
|
63
|
-
let
|
|
64
|
-
|
|
65
|
-
reject("E_INVALID_ADDRESS", "Missing or invalid fields in address JSON.", nil)
|
|
62
|
+
guard let streetNumber = address["streetNumber"] as? String,
|
|
63
|
+
let route = address["route"] as? String,
|
|
64
|
+
let subPremise = address["subPremise"] as? String,
|
|
65
|
+
let locality = address["locality"] as? String,
|
|
66
|
+
let administrativeAreaLevel1 = address["administrativeAreaLevel1"] as? String,
|
|
67
|
+
let postalCode = address["postalCode"] as? String else {
|
|
68
|
+
reject("E_INVALID_ADDRESS", "Missing or invalid fields in address dictionary.", nil)
|
|
66
69
|
return
|
|
67
70
|
}
|
|
68
71
|
|
|
69
|
-
let
|
|
72
|
+
let addressStruct = AddressType(streetNumber: streetNumber,
|
|
70
73
|
route: route,
|
|
71
74
|
subPremise: subPremise,
|
|
72
75
|
locality: locality,
|
|
73
76
|
administrativeAreaLevel1: administrativeAreaLevel1,
|
|
74
77
|
postalCode: postalCode)
|
|
75
78
|
|
|
76
|
-
try await DoorstepAI.startDeliveryByAddressType(address:
|
|
79
|
+
try await DoorstepAI.startDeliveryByAddressType(address: addressStruct, deliveryId: deliveryId as String)
|
|
77
80
|
resolve(nil)
|
|
78
81
|
} catch let error as DoorstepAIError {
|
|
79
82
|
reject("E_START_DELIVERY", "Failed to start delivery by address: \(error.localizedDescription)", error)
|
|
80
83
|
} catch {
|
|
81
|
-
reject("
|
|
84
|
+
reject("E_UNKNOWN", "An unexpected error occurred: \(error.localizedDescription)", error)
|
|
82
85
|
}
|
|
83
86
|
}
|
|
84
87
|
}
|
|
85
88
|
|
|
86
89
|
@objc
|
|
87
90
|
func newEvent(_ eventName: NSString,
|
|
91
|
+
deliveryId: NSString,
|
|
88
92
|
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
89
93
|
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
90
94
|
Task {
|
|
91
95
|
do {
|
|
92
|
-
try await DoorstepAI.newEvent(eventName: eventName as String)
|
|
96
|
+
try await DoorstepAI.newEvent(eventName: eventName as String, deliveryId: deliveryId as String)
|
|
93
97
|
resolve(nil)
|
|
94
98
|
} catch {
|
|
95
99
|
reject("E_NEW_EVENT", "Failed to send event: \(error.localizedDescription)", error)
|
|
@@ -98,11 +102,12 @@ class DoorstepAIBridge: NSObject {
|
|
|
98
102
|
}
|
|
99
103
|
|
|
100
104
|
@objc
|
|
101
|
-
func stopDelivery(_
|
|
105
|
+
func stopDelivery(_ deliveryId: NSString,
|
|
106
|
+
resolver resolve: @escaping RCTPromiseResolveBlock,
|
|
102
107
|
rejecter reject: @escaping RCTPromiseRejectBlock) {
|
|
103
108
|
Task {
|
|
104
109
|
// stopDelivery does not throw so we simply await its completion
|
|
105
|
-
await DoorstepAI.stopDelivery()
|
|
110
|
+
await DoorstepAI.stopDelivery(deliveryId: deliveryId as String)
|
|
106
111
|
resolve(nil)
|
|
107
112
|
}
|
|
108
113
|
}
|