@tryvital/vital-core-react-native 1.10.0 → 1.11.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/android/build.gradle
CHANGED
|
@@ -12,6 +12,8 @@ import com.squareup.moshi.adapter
|
|
|
12
12
|
import com.squareup.moshi.adapters.Rfc3339DateJsonAdapter
|
|
13
13
|
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
|
|
14
14
|
import io.tryvital.client.*
|
|
15
|
+
import io.tryvital.client.services.data.DataStage
|
|
16
|
+
import io.tryvital.client.services.data.IngestibleTimeseriesResource
|
|
15
17
|
import io.tryvital.client.services.data.ManualProviderSlug
|
|
16
18
|
import io.tryvital.client.services.data.ProviderSlug
|
|
17
19
|
import io.tryvital.client.services.data.Source
|
|
@@ -38,7 +40,7 @@ class VitalCoreReactNativeModule(reactContext: ReactApplicationContext) :
|
|
|
38
40
|
ReactContextBaseJavaModule(reactContext) {
|
|
39
41
|
|
|
40
42
|
private val mainScope = MainScope()
|
|
41
|
-
|
|
43
|
+
val client: VitalClient get() = VitalClient.getOrCreate(reactApplicationContext)
|
|
42
44
|
|
|
43
45
|
override fun getName(): String {
|
|
44
46
|
return NAME
|
|
@@ -46,7 +48,9 @@ class VitalCoreReactNativeModule(reactContext: ReactApplicationContext) :
|
|
|
46
48
|
|
|
47
49
|
@ReactMethod
|
|
48
50
|
fun setUserId(userId: String, promise: Promise) {
|
|
49
|
-
|
|
51
|
+
if (!client.isConfigured)
|
|
52
|
+
return promise.rejectCoreNotConfigured()
|
|
53
|
+
|
|
50
54
|
client.setUserId(userId)
|
|
51
55
|
promise.resolve(null)
|
|
52
56
|
}
|
|
@@ -56,9 +60,7 @@ class VitalCoreReactNativeModule(reactContext: ReactApplicationContext) :
|
|
|
56
60
|
try {
|
|
57
61
|
VitalLogger.getOrCreate().enabled = enableLogs
|
|
58
62
|
|
|
59
|
-
|
|
60
|
-
reactApplicationContext,
|
|
61
|
-
// TODO: Expose these as enum constants in the RN SDK
|
|
63
|
+
VitalClient.getOrCreate(reactApplicationContext).configure(
|
|
62
64
|
region = Region.valueOf(region.uppercase()),
|
|
63
65
|
environment = Environment.valueOf(environment.lowercase().replaceFirstChar { it.uppercase() }),
|
|
64
66
|
apiKey = apiKey
|
|
@@ -72,7 +74,8 @@ class VitalCoreReactNativeModule(reactContext: ReactApplicationContext) :
|
|
|
72
74
|
|
|
73
75
|
@ReactMethod
|
|
74
76
|
fun cleanUp(promise: Promise) {
|
|
75
|
-
|
|
77
|
+
if (!client.isConfigured)
|
|
78
|
+
return promise.rejectCoreNotConfigured()
|
|
76
79
|
|
|
77
80
|
mainScope.launch {
|
|
78
81
|
client.cleanUp()
|
|
@@ -82,7 +85,8 @@ class VitalCoreReactNativeModule(reactContext: ReactApplicationContext) :
|
|
|
82
85
|
|
|
83
86
|
@ReactMethod
|
|
84
87
|
fun hasUserConnectedTo(provider: String, promise: Promise) {
|
|
85
|
-
|
|
88
|
+
if (!client.isConfigured)
|
|
89
|
+
return promise.rejectCoreNotConfigured()
|
|
86
90
|
|
|
87
91
|
val slug = try { ProviderSlug.fromJsonName(provider) } catch (e: IllegalArgumentException) {
|
|
88
92
|
return promise.reject(VITAL_CORE_ERROR, "Unrecognized provider slug: $provider")
|
|
@@ -93,7 +97,9 @@ class VitalCoreReactNativeModule(reactContext: ReactApplicationContext) :
|
|
|
93
97
|
|
|
94
98
|
@ReactMethod
|
|
95
99
|
fun userConnectedSources(promise: Promise) {
|
|
96
|
-
|
|
100
|
+
if (!client.isConfigured)
|
|
101
|
+
return promise.rejectCoreNotConfigured()
|
|
102
|
+
|
|
97
103
|
val userId = client.currentUserId ?: return promise.rejectUserIDNotSet()
|
|
98
104
|
|
|
99
105
|
mainScope.launch {
|
|
@@ -120,7 +126,9 @@ class VitalCoreReactNativeModule(reactContext: ReactApplicationContext) :
|
|
|
120
126
|
|
|
121
127
|
@ReactMethod
|
|
122
128
|
fun deregisterProvider(provider: String, promise: Promise) {
|
|
123
|
-
|
|
129
|
+
if (!client.isConfigured)
|
|
130
|
+
return promise.rejectCoreNotConfigured()
|
|
131
|
+
|
|
124
132
|
val userId = client.currentUserId ?: return promise.rejectUserIDNotSet()
|
|
125
133
|
|
|
126
134
|
val slug = try { ProviderSlug.fromJsonName(provider) } catch (e: IllegalArgumentException) {
|
|
@@ -142,7 +150,9 @@ class VitalCoreReactNativeModule(reactContext: ReactApplicationContext) :
|
|
|
142
150
|
|
|
143
151
|
@ReactMethod
|
|
144
152
|
fun createConnectedSourceIfNotExist(provider: String, promise: Promise) {
|
|
145
|
-
|
|
153
|
+
if (!client.isConfigured)
|
|
154
|
+
return promise.rejectCoreNotConfigured()
|
|
155
|
+
|
|
146
156
|
val userId = client.currentUserId ?: return promise.rejectUserIDNotSet()
|
|
147
157
|
|
|
148
158
|
val slug = try { ManualProviderSlug.fromJsonName(provider) } catch (e: IllegalArgumentException) {
|
|
@@ -162,7 +172,9 @@ class VitalCoreReactNativeModule(reactContext: ReactApplicationContext) :
|
|
|
162
172
|
@ReactMethod
|
|
163
173
|
@OptIn(ExperimentalStdlibApi::class)
|
|
164
174
|
fun postTimeSeriesData(jsonString: String, provider: String, timeZoneString: String?, promise: Promise) {
|
|
165
|
-
|
|
175
|
+
if (!client.isConfigured)
|
|
176
|
+
return promise.rejectCoreNotConfigured()
|
|
177
|
+
|
|
166
178
|
val userId = client.currentUserId ?: return promise.rejectUserIDNotSet()
|
|
167
179
|
|
|
168
180
|
val slug = try { ManualProviderSlug.fromJsonName(provider) } catch (e: IllegalArgumentException) {
|
|
@@ -189,7 +201,7 @@ class VitalCoreReactNativeModule(reactContext: ReactApplicationContext) :
|
|
|
189
201
|
}
|
|
190
202
|
|
|
191
203
|
fun <T> makeTimeseriesPayload(data: T) = TimeseriesPayload(
|
|
192
|
-
stage =
|
|
204
|
+
stage = DataStage.Daily,
|
|
193
205
|
provider = slug,
|
|
194
206
|
startDate = null,
|
|
195
207
|
endDate = null,
|
|
@@ -201,9 +213,10 @@ class VitalCoreReactNativeModule(reactContext: ReactApplicationContext) :
|
|
|
201
213
|
try {
|
|
202
214
|
when (data) {
|
|
203
215
|
is ReactNativeTimeSeriesData.Glucose ->
|
|
204
|
-
client.vitalsService.
|
|
216
|
+
client.vitalsService.sendQuantitySamples(
|
|
205
217
|
userId = userId,
|
|
206
|
-
|
|
218
|
+
resource = IngestibleTimeseriesResource.BloodGlucose,
|
|
219
|
+
timeseriesPayload = makeTimeseriesPayload(
|
|
207
220
|
data.samples.map { it.payload }
|
|
208
221
|
)
|
|
209
222
|
)
|