@doorstepai/dropoff-sdk-capacitor 1.0.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 (57) hide show
  1. package/DoorstepaiDropoffSdkCapacitor.podspec +22 -0
  2. package/LICENSE +20 -0
  3. package/README.md +401 -0
  4. package/android/build.gradle +48 -0
  5. package/android/src/main/AndroidManifest.xml +3 -0
  6. package/android/src/main/java/ai/doorstep/dropoffsdk/capacitor/DoorstepAIDropoffSDKPlugin.kt +291 -0
  7. package/dist/docs.json +705 -0
  8. package/dist/esm/definitions.d.ts +115 -0
  9. package/dist/esm/definitions.js +2 -0
  10. package/dist/esm/definitions.js.map +1 -0
  11. package/dist/esm/index.d.ts +4 -0
  12. package/dist/esm/index.js +27 -0
  13. package/dist/esm/index.js.map +1 -0
  14. package/dist/esm/web.d.ts +23 -0
  15. package/dist/esm/web.js +51 -0
  16. package/dist/esm/web.js.map +1 -0
  17. package/dist/plugin.cjs.js +87 -0
  18. package/dist/plugin.cjs.js.map +1 -0
  19. package/dist/plugin.js +90 -0
  20. package/dist/plugin.js.map +1 -0
  21. package/ios/DoorstepDropoffSDK.xcframework/Info.plist +48 -0
  22. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/DoorstepDropoffSDK +0 -0
  23. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Headers/DoorstepDropoffSDK.h +19 -0
  24. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Headers/RateReducer.h +117 -0
  25. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Info.plist +0 -0
  26. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.abi.json +5281 -0
  27. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.private.swiftinterface +117 -0
  28. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.swiftdoc +0 -0
  29. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios.swiftinterface +117 -0
  30. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/Modules/module.modulemap +6 -0
  31. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/PrivacyInfo.xcprivacy +39 -0
  32. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +201 -0
  33. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Info.plist +20 -0
  34. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/DWARF/DoorstepDropoffSDK +0 -0
  35. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/DoorstepDropoffSDK.yml +2108 -0
  36. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/DoorstepDropoffSDK +0 -0
  37. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Headers/DoorstepDropoffSDK.h +19 -0
  38. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Headers/RateReducer.h +117 -0
  39. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Info.plist +0 -0
  40. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.abi.json +5281 -0
  41. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.private.swiftinterface +117 -0
  42. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.swiftdoc +0 -0
  43. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/arm64-apple-ios-simulator.swiftinterface +117 -0
  44. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.abi.json +5281 -0
  45. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.private.swiftinterface +117 -0
  46. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.swiftdoc +0 -0
  47. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/DoorstepDropoffSDK.swiftmodule/x86_64-apple-ios-simulator.swiftinterface +117 -0
  48. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/Modules/module.modulemap +6 -0
  49. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/PrivacyInfo.xcprivacy +39 -0
  50. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/DoorstepDropoffSDK.framework/_CodeSignature/CodeResources +256 -0
  51. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Info.plist +20 -0
  52. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/DWARF/DoorstepDropoffSDK +0 -0
  53. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/aarch64/DoorstepDropoffSDK.yml +2108 -0
  54. package/ios/DoorstepDropoffSDK.xcframework/ios-arm64_x86_64-simulator/dSYMs/DoorstepDropoffSDK.framework.dSYM/Contents/Resources/Relocations/x86_64/DoorstepDropoffSDK.yml +2098 -0
  55. package/ios/Plugin/DoorstepAIDropoffSDKPlugin.m +22 -0
  56. package/ios/Plugin/DoorstepAIDropoffSDKPlugin.swift +313 -0
  57. package/package.json +78 -0
@@ -0,0 +1,291 @@
1
+ package ai.doorstep.dropoffsdk.capacitor
2
+
3
+ import android.Manifest
4
+ import android.util.Log
5
+ import com.getcapacitor.JSObject
6
+ import com.getcapacitor.Plugin
7
+ import com.getcapacitor.PluginCall
8
+ import com.getcapacitor.PluginMethod
9
+ import com.getcapacitor.annotation.CapacitorPlugin
10
+ import com.getcapacitor.annotation.Permission
11
+
12
+ import com.doorstepai.sdks.tracking.AddressType
13
+ import com.doorstepai.sdks.tracking.DoorstepAI
14
+ import com.doorstepai.sdks.tracking.DropoffType
15
+ import com.doorstepai.sdks.tracking.LatLngObject
16
+
17
+ import kotlinx.coroutines.CoroutineScope
18
+ import kotlinx.coroutines.Dispatchers
19
+ import kotlinx.coroutines.SupervisorJob
20
+ import kotlinx.coroutines.cancel
21
+ import kotlinx.coroutines.launch
22
+ import kotlinx.coroutines.withContext
23
+
24
+ @CapacitorPlugin(
25
+ name = "DoorstepAIDropoffSDK",
26
+ permissions = [
27
+ Permission(
28
+ alias = "location",
29
+ strings = [
30
+ Manifest.permission.ACCESS_FINE_LOCATION,
31
+ Manifest.permission.ACCESS_COARSE_LOCATION,
32
+ ],
33
+ ),
34
+ Permission(
35
+ alias = "activity",
36
+ strings = [Manifest.permission.ACTIVITY_RECOGNITION],
37
+ ),
38
+ ],
39
+ )
40
+ class DoorstepAIDropoffSDKPlugin : Plugin() {
41
+
42
+ private val scope = CoroutineScope(SupervisorJob() + Dispatchers.Main.immediate)
43
+
44
+ override fun load() {
45
+ super.load()
46
+ Log.d(TAG, "load(): plugin attached, ready for calls")
47
+ }
48
+
49
+ override fun handleOnDestroy() {
50
+ scope.cancel()
51
+ super.handleOnDestroy()
52
+ }
53
+
54
+ private fun ok(method: String, call: PluginCall) {
55
+ Log.d(TAG, "$method: resolved")
56
+ call.resolve()
57
+ }
58
+
59
+ private fun fail(method: String, call: PluginCall, code: String, message: String) {
60
+ Log.e(TAG, "$method: rejected code=$code message=$message")
61
+ call.reject(message, code)
62
+ }
63
+
64
+ companion object {
65
+ private const val TAG = "DoorstepAICapacitor"
66
+ }
67
+
68
+ @PluginMethod
69
+ fun init(call: PluginCall) {
70
+ val notificationTitle = call.getString("notificationTitle")
71
+ val notificationText = call.getString("notificationText")
72
+ Log.d(TAG, "init: title=$notificationTitle text=$notificationText")
73
+ val ctx = context
74
+ if (ctx == null) {
75
+ call.reject("context missing", "BAD_ARGS")
76
+ return
77
+ }
78
+ try {
79
+ DoorstepAI.init(ctx, notificationTitle, notificationText) { sdkResult ->
80
+ sdkResult.onSuccess {
81
+ call.resolve()
82
+ }.onFailure { error ->
83
+ call.reject(error.message ?: "Failed to initialize DoorstepAI", "INIT_ERROR")
84
+ }
85
+ }
86
+ } catch (e: Exception) {
87
+ call.reject(e.message ?: "Failed to initialize DoorstepAI", "INIT_ERROR")
88
+ }
89
+ }
90
+
91
+ @PluginMethod
92
+ fun setApiKey(call: PluginCall) {
93
+ val key = call.getString("key") ?: return call.reject("key missing", "BAD_ARGS")
94
+ Log.d(TAG, "setApiKey: key=${key.take(6)}…(${key.length} chars)")
95
+ try {
96
+ DoorstepAI.setAPIKey(key)
97
+ ok("setApiKey", call)
98
+ } catch (e: Exception) {
99
+ fail("setApiKey", call, "SDK_ERR", e.localizedMessage ?: "setApiKey failed")
100
+ }
101
+ }
102
+
103
+ @PluginMethod
104
+ fun startDeliveryByPlaceID(call: PluginCall) {
105
+ val placeID = call.getString("placeID")
106
+ val deliveryId = call.getString("deliveryId")
107
+ val timeoutSeconds = call.getDouble("timeoutSeconds")
108
+ Log.d(TAG, "startDeliveryByPlaceID: placeID=$placeID deliveryId=$deliveryId timeout=$timeoutSeconds")
109
+ if (placeID == null || deliveryId == null) {
110
+ return call.reject("placeID or deliveryId missing", "BAD_ARGS")
111
+ }
112
+ try {
113
+ DoorstepAI.startDeliveryByPlaceID(placeID, deliveryId, timeoutSeconds) { sdkResult ->
114
+ sdkResult.onSuccess { call.resolve() }
115
+ .onFailure { error ->
116
+ call.reject(error.message ?: "Failed to start delivery by Place ID", "DELIVERY_ERROR")
117
+ }
118
+ }
119
+ } catch (e: Exception) {
120
+ call.reject(e.message ?: "Failed to start delivery by Place ID", "DELIVERY_ERROR")
121
+ }
122
+ }
123
+
124
+ @PluginMethod
125
+ fun startDeliveryByPlusCode(call: PluginCall) {
126
+ val plusCode = call.getString("plusCode")
127
+ val deliveryId = call.getString("deliveryId")
128
+ val timeoutSeconds = call.getDouble("timeoutSeconds")
129
+ if (plusCode == null || deliveryId == null) {
130
+ return call.reject("plusCode or deliveryId missing", "BAD_ARGS")
131
+ }
132
+ try {
133
+ DoorstepAI.startDeliveryByPlusCode(plusCode, deliveryId, timeoutSeconds) { sdkResult ->
134
+ sdkResult.onSuccess { call.resolve() }
135
+ .onFailure { error ->
136
+ call.reject(error.message ?: "Failed to start delivery by Plus Code", "DELIVERY_ERROR")
137
+ }
138
+ }
139
+ } catch (e: Exception) {
140
+ call.reject(e.message ?: "Failed to start delivery by Plus Code", "DELIVERY_ERROR")
141
+ }
142
+ }
143
+
144
+ @PluginMethod
145
+ fun startDeliveryByAddress(call: PluginCall) = startDeliveryByAddressTypeImpl(call)
146
+
147
+ @PluginMethod
148
+ fun startDeliveryByAddressType(call: PluginCall) = startDeliveryByAddressTypeImpl(call)
149
+
150
+ private fun startDeliveryByAddressTypeImpl(call: PluginCall) {
151
+ val addrObj = call.getObject("address")
152
+ val deliveryId = call.getString("deliveryId")
153
+ val timeoutSeconds = call.getDouble("timeoutSeconds")
154
+ val coordinates = parseCoordinates(call.getObject("coordinates"))
155
+
156
+ if (addrObj == null
157
+ || deliveryId == null
158
+ || !addrObj.has("streetNumber")
159
+ || !addrObj.has("route")
160
+ || !addrObj.has("locality")
161
+ || !addrObj.has("administrativeAreaLevel1")
162
+ || !addrObj.has("postalCode")
163
+ ) {
164
+ return call.reject("address map missing fields or deliveryId missing", "BAD_ARGS")
165
+ }
166
+
167
+ try {
168
+ val addressType = AddressType(
169
+ streetNumber = addrObj.getString("streetNumber")!!,
170
+ route = addrObj.getString("route")!!,
171
+ subPremise = addrObj.optString("subPremise", ""),
172
+ locality = addrObj.getString("locality")!!,
173
+ administrativeAreaLevel1 = addrObj.getString("administrativeAreaLevel1")!!,
174
+ postalCode = addrObj.getString("postalCode")!!,
175
+ )
176
+ DoorstepAI.startDeliveryByAddressType(addressType, deliveryId, coordinates, timeoutSeconds) { sdkResult ->
177
+ sdkResult.onSuccess { call.resolve() }
178
+ .onFailure { error ->
179
+ call.reject(error.message ?: "Failed to start delivery by address", "DELIVERY_ERROR")
180
+ }
181
+ }
182
+ } catch (e: Exception) {
183
+ call.reject(e.message ?: "Failed to start delivery by address", "DELIVERY_ERROR")
184
+ }
185
+ }
186
+
187
+ @PluginMethod
188
+ fun startDeliveryByAddressString(call: PluginCall) {
189
+ val address = call.getString("address")
190
+ val deliveryId = call.getString("deliveryId")
191
+ val timeoutSeconds = call.getDouble("timeoutSeconds")
192
+ val coordinates = parseCoordinates(call.getObject("coordinates"))
193
+ if (address == null || deliveryId == null) {
194
+ return call.reject("address or deliveryId missing", "BAD_ARGS")
195
+ }
196
+ try {
197
+ DoorstepAI.startDeliveryByAddressString(address, deliveryId, coordinates, timeoutSeconds) { sdkResult ->
198
+ sdkResult.onSuccess { call.resolve() }
199
+ .onFailure { error ->
200
+ call.reject(error.message ?: "Failed to start delivery by address string", "DELIVERY_ERROR")
201
+ }
202
+ }
203
+ } catch (e: Exception) {
204
+ call.reject(e.message ?: "Failed to start delivery by address string", "DELIVERY_ERROR")
205
+ }
206
+ }
207
+
208
+ @PluginMethod
209
+ fun startDeliveryByLatLng(call: PluginCall) {
210
+ val latitude = call.getDouble("latitude")
211
+ val longitude = call.getDouble("longitude")
212
+ val subUnit = call.getString("subUnit") ?: ""
213
+ val deliveryId = call.getString("deliveryId")
214
+ val timeoutSeconds = call.getDouble("timeoutSeconds")
215
+ Log.d(TAG, "startDeliveryByLatLng: lat=$latitude lng=$longitude subUnit='$subUnit' deliveryId=$deliveryId timeout=$timeoutSeconds")
216
+ if (latitude == null || longitude == null || deliveryId == null) {
217
+ return call.reject("latitude, longitude or deliveryId missing", "BAD_ARGS")
218
+ }
219
+ try {
220
+ DoorstepAI.startDeliveryByLatLng(latitude, longitude, subUnit, deliveryId, timeoutSeconds) { sdkResult ->
221
+ sdkResult.onSuccess { call.resolve() }
222
+ .onFailure { error ->
223
+ call.reject(error.message ?: "Failed to start delivery by LatLng", "DELIVERY_ERROR")
224
+ }
225
+ }
226
+ } catch (e: Exception) {
227
+ call.reject(e.message ?: "Failed to start delivery by LatLng", "DELIVERY_ERROR")
228
+ }
229
+ }
230
+
231
+ @PluginMethod
232
+ fun markDropoff(call: PluginCall) {
233
+ val deliveryId = call.getString("deliveryId")
234
+ val dropoffTypeStr = call.getString("dropoffType")
235
+ Log.d(TAG, "markDropoff: deliveryId=$deliveryId type=$dropoffTypeStr")
236
+ if (deliveryId == null || dropoffTypeStr == null) {
237
+ return call.reject("deliveryId or dropoffType missing", "BAD_ARGS")
238
+ }
239
+ val dropoffType = when (dropoffTypeStr) {
240
+ "pod" -> DropoffType.POD
241
+ "non_pod" -> DropoffType.NON_POD
242
+ else -> return call.reject("dropoffType must be 'pod' or 'non_pod'", "BAD_ARGS")
243
+ }
244
+ scope.launch {
245
+ try {
246
+ withContext(Dispatchers.IO) {
247
+ DoorstepAI.markDropoff(deliveryId, dropoffType)
248
+ }
249
+ call.resolve()
250
+ } catch (e: Exception) {
251
+ call.reject(e.message ?: "Failed to mark dropoff", "SDK_ERR")
252
+ }
253
+ }
254
+ }
255
+
256
+ @PluginMethod
257
+ fun newEvent(call: PluginCall) {
258
+ val eventName = call.getString("eventName")
259
+ val deliveryId = call.getString("deliveryId")
260
+ Log.d(TAG, "newEvent: eventName=$eventName deliveryId=$deliveryId")
261
+ if (eventName == null || deliveryId == null) {
262
+ return call.reject("eventName or deliveryId missing", "BAD_ARGS")
263
+ }
264
+ try {
265
+ DoorstepAI.newEvent(eventName, deliveryId) { /* result swallowed in Flutter parity */ }
266
+ call.resolve()
267
+ } catch (e: Exception) {
268
+ call.reject(e.message ?: "Failed to save event", "EVENT_CREATION_ERROR")
269
+ }
270
+ }
271
+
272
+ @PluginMethod
273
+ fun stopDelivery(call: PluginCall) {
274
+ val deliveryId = call.getString("deliveryId") ?: return call.reject("deliveryId missing", "BAD_ARGS")
275
+ Log.d(TAG, "stopDelivery: deliveryId=$deliveryId")
276
+ try {
277
+ DoorstepAI.stopDelivery(deliveryId)
278
+ ok("stopDelivery", call)
279
+ } catch (e: Exception) {
280
+ fail("stopDelivery", call, "DELIVERY_STOP_ERROR", e.message ?: "Failed to stop delivery")
281
+ }
282
+ }
283
+
284
+ private fun parseCoordinates(obj: JSObject?): LatLngObject? {
285
+ if (obj == null) return null
286
+ val lat = obj.optDouble("lat", Double.NaN)
287
+ val lng = obj.optDouble("lng", Double.NaN)
288
+ if (lat.isNaN() || lng.isNaN()) return null
289
+ return LatLngObject(lat = lat, lng = lng)
290
+ }
291
+ }