react-native-spike-sdk 4.5.23 → 4.7.13

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 (193) hide show
  1. package/android/build.gradle +1 -1
  2. package/android/src/main/java/com/spikesdk/SpikeMappers.kt +0 -46
  3. package/android/src/main/java/com/spikesdk/SpikeSdkModule.kt +50 -483
  4. package/ios/SpikeExceptionMapper.swift +4 -12
  5. package/ios/SpikeSdk.m +8 -79
  6. package/ios/SpikeSdk.swift +62 -419
  7. package/lib/commonjs/Spike.js +1 -57
  8. package/lib/commonjs/Spike.js.map +1 -1
  9. package/lib/commonjs/SpikeException.js +15 -94
  10. package/lib/commonjs/SpikeException.js.map +1 -1
  11. package/lib/commonjs/index.js +0 -71
  12. package/lib/commonjs/index.js.map +1 -1
  13. package/lib/commonjs/v3/SpikeRNConnectionAPIv3.js +40 -17
  14. package/lib/commonjs/v3/SpikeRNConnectionAPIv3.js.map +1 -1
  15. package/lib/commonjs/version.js +1 -1
  16. package/lib/module/Spike.js +1 -55
  17. package/lib/module/Spike.js.map +1 -1
  18. package/lib/module/SpikeException.js +14 -83
  19. package/lib/module/SpikeException.js.map +1 -1
  20. package/lib/module/index.js +3 -8
  21. package/lib/module/index.js.map +1 -1
  22. package/lib/module/v3/SpikeRNConnectionAPIv3.js +40 -17
  23. package/lib/module/v3/SpikeRNConnectionAPIv3.js.map +1 -1
  24. package/lib/module/version.js +1 -1
  25. package/lib/typescript/Spike.d.ts +2 -29
  26. package/lib/typescript/Spike.d.ts.map +1 -1
  27. package/lib/typescript/SpikeException.d.ts +5 -30
  28. package/lib/typescript/SpikeException.d.ts.map +1 -1
  29. package/lib/typescript/index.d.ts +6 -25
  30. package/lib/typescript/index.d.ts.map +1 -1
  31. package/lib/typescript/v3/DataModels/BackgroundDeliveryConfig.d.ts +2 -0
  32. package/lib/typescript/v3/DataModels/BackgroundDeliveryConfig.d.ts.map +1 -1
  33. package/lib/typescript/v3/SpikeRNConnectionAPIv3.d.ts +34 -9
  34. package/lib/typescript/v3/SpikeRNConnectionAPIv3.d.ts.map +1 -1
  35. package/lib/typescript/version.d.ts +1 -1
  36. package/package.json +2 -2
  37. package/src/Spike.ts +4 -89
  38. package/src/SpikeException.ts +13 -96
  39. package/src/index.ts +2 -61
  40. package/src/v3/DataModels/BackgroundDeliveryConfig.ts +2 -0
  41. package/src/v3/SpikeRNConnectionAPIv3.ts +82 -19
  42. package/src/version.ts +1 -1
  43. package/android/src/main/java/com/spikesdk/SpikeConnectionLogger.kt +0 -37
  44. package/ios/SpikeConnectionListener.swift +0 -17
  45. package/ios/SpikeConnectionLogger.swift +0 -43
  46. package/ios/SpikeDataTypeMapper.swift +0 -255
  47. package/lib/commonjs/DataModels/SpikeActivitiesStreamDataEntry.js +0 -2
  48. package/lib/commonjs/DataModels/SpikeActivitiesStreamDataEntry.js.map +0 -1
  49. package/lib/commonjs/DataModels/SpikeActivitiesSummaryDataEntry.js +0 -2
  50. package/lib/commonjs/DataModels/SpikeActivitiesSummaryDataEntry.js.map +0 -1
  51. package/lib/commonjs/DataModels/SpikeBodyDataEntry.js +0 -2
  52. package/lib/commonjs/DataModels/SpikeBodyDataEntry.js.map +0 -1
  53. package/lib/commonjs/DataModels/SpikeBreathingDataEntry.js +0 -2
  54. package/lib/commonjs/DataModels/SpikeBreathingDataEntry.js.map +0 -1
  55. package/lib/commonjs/DataModels/SpikeCaloriesDataEntry.js +0 -2
  56. package/lib/commonjs/DataModels/SpikeCaloriesDataEntry.js.map +0 -1
  57. package/lib/commonjs/DataModels/SpikeData.js +0 -6
  58. package/lib/commonjs/DataModels/SpikeData.js.map +0 -1
  59. package/lib/commonjs/DataModels/SpikeDataTypes.js +0 -23
  60. package/lib/commonjs/DataModels/SpikeDataTypes.js.map +0 -1
  61. package/lib/commonjs/DataModels/SpikeDistanceDataEntry.js +0 -2
  62. package/lib/commonjs/DataModels/SpikeDistanceDataEntry.js.map +0 -1
  63. package/lib/commonjs/DataModels/SpikeEcgDataEntry.js +0 -2
  64. package/lib/commonjs/DataModels/SpikeEcgDataEntry.js.map +0 -1
  65. package/lib/commonjs/DataModels/SpikeGlucoseDataEntry.js +0 -2
  66. package/lib/commonjs/DataModels/SpikeGlucoseDataEntry.js.map +0 -1
  67. package/lib/commonjs/DataModels/SpikeHeartDataEntry.js +0 -2
  68. package/lib/commonjs/DataModels/SpikeHeartDataEntry.js.map +0 -1
  69. package/lib/commonjs/DataModels/SpikeOxygenSaturationDataEntry.js +0 -2
  70. package/lib/commonjs/DataModels/SpikeOxygenSaturationDataEntry.js.map +0 -1
  71. package/lib/commonjs/DataModels/SpikeSleepDataEntry.js +0 -2
  72. package/lib/commonjs/DataModels/SpikeSleepDataEntry.js.map +0 -1
  73. package/lib/commonjs/DataModels/SpikeStepsDataEntry.js +0 -2
  74. package/lib/commonjs/DataModels/SpikeStepsDataEntry.js.map +0 -1
  75. package/lib/commonjs/DataModels/SpikeStepsIntradayDataEntry.js +0 -2
  76. package/lib/commonjs/DataModels/SpikeStepsIntradayDataEntry.js.map +0 -1
  77. package/lib/commonjs/DataModels/SpikeWebhookJob.js +0 -2
  78. package/lib/commonjs/DataModels/SpikeWebhookJob.js.map +0 -1
  79. package/lib/commonjs/DataTypes/SpikeDataType.js +0 -59
  80. package/lib/commonjs/DataTypes/SpikeDataType.js.map +0 -1
  81. package/lib/commonjs/SpikeBackgroundDeliveriesLogger.js +0 -2
  82. package/lib/commonjs/SpikeBackgroundDeliveriesLogger.js.map +0 -1
  83. package/lib/commonjs/SpikeConnection.js +0 -301
  84. package/lib/commonjs/SpikeConnection.js.map +0 -1
  85. package/lib/commonjs/SpikeConnectionTypes.js +0 -6
  86. package/lib/commonjs/SpikeConnectionTypes.js.map +0 -1
  87. package/lib/commonjs/SpikeLogger.js +0 -6
  88. package/lib/commonjs/SpikeLogger.js.map +0 -1
  89. package/lib/module/DataModels/SpikeActivitiesStreamDataEntry.js +0 -2
  90. package/lib/module/DataModels/SpikeActivitiesStreamDataEntry.js.map +0 -1
  91. package/lib/module/DataModels/SpikeActivitiesSummaryDataEntry.js +0 -2
  92. package/lib/module/DataModels/SpikeActivitiesSummaryDataEntry.js.map +0 -1
  93. package/lib/module/DataModels/SpikeBodyDataEntry.js +0 -2
  94. package/lib/module/DataModels/SpikeBodyDataEntry.js.map +0 -1
  95. package/lib/module/DataModels/SpikeBreathingDataEntry.js +0 -2
  96. package/lib/module/DataModels/SpikeBreathingDataEntry.js.map +0 -1
  97. package/lib/module/DataModels/SpikeCaloriesDataEntry.js +0 -2
  98. package/lib/module/DataModels/SpikeCaloriesDataEntry.js.map +0 -1
  99. package/lib/module/DataModels/SpikeData.js +0 -4
  100. package/lib/module/DataModels/SpikeData.js.map +0 -1
  101. package/lib/module/DataModels/SpikeDataTypes.js +0 -19
  102. package/lib/module/DataModels/SpikeDataTypes.js.map +0 -1
  103. package/lib/module/DataModels/SpikeDistanceDataEntry.js +0 -2
  104. package/lib/module/DataModels/SpikeDistanceDataEntry.js.map +0 -1
  105. package/lib/module/DataModels/SpikeEcgDataEntry.js +0 -2
  106. package/lib/module/DataModels/SpikeEcgDataEntry.js.map +0 -1
  107. package/lib/module/DataModels/SpikeGlucoseDataEntry.js +0 -2
  108. package/lib/module/DataModels/SpikeGlucoseDataEntry.js.map +0 -1
  109. package/lib/module/DataModels/SpikeHeartDataEntry.js +0 -2
  110. package/lib/module/DataModels/SpikeHeartDataEntry.js.map +0 -1
  111. package/lib/module/DataModels/SpikeOxygenSaturationDataEntry.js +0 -2
  112. package/lib/module/DataModels/SpikeOxygenSaturationDataEntry.js.map +0 -1
  113. package/lib/module/DataModels/SpikeSleepDataEntry.js +0 -2
  114. package/lib/module/DataModels/SpikeSleepDataEntry.js.map +0 -1
  115. package/lib/module/DataModels/SpikeStepsDataEntry.js +0 -2
  116. package/lib/module/DataModels/SpikeStepsDataEntry.js.map +0 -1
  117. package/lib/module/DataModels/SpikeStepsIntradayDataEntry.js +0 -2
  118. package/lib/module/DataModels/SpikeStepsIntradayDataEntry.js.map +0 -1
  119. package/lib/module/DataModels/SpikeWebhookJob.js +0 -2
  120. package/lib/module/DataModels/SpikeWebhookJob.js.map +0 -1
  121. package/lib/module/DataTypes/SpikeDataType.js +0 -42
  122. package/lib/module/DataTypes/SpikeDataType.js.map +0 -1
  123. package/lib/module/SpikeBackgroundDeliveriesLogger.js +0 -2
  124. package/lib/module/SpikeBackgroundDeliveriesLogger.js.map +0 -1
  125. package/lib/module/SpikeConnection.js +0 -296
  126. package/lib/module/SpikeConnection.js.map +0 -1
  127. package/lib/module/SpikeConnectionTypes.js +0 -4
  128. package/lib/module/SpikeConnectionTypes.js.map +0 -1
  129. package/lib/module/SpikeLogger.js +0 -4
  130. package/lib/module/SpikeLogger.js.map +0 -1
  131. package/lib/typescript/DataModels/SpikeActivitiesStreamDataEntry.d.ts +0 -66
  132. package/lib/typescript/DataModels/SpikeActivitiesStreamDataEntry.d.ts.map +0 -1
  133. package/lib/typescript/DataModels/SpikeActivitiesSummaryDataEntry.d.ts +0 -29
  134. package/lib/typescript/DataModels/SpikeActivitiesSummaryDataEntry.d.ts.map +0 -1
  135. package/lib/typescript/DataModels/SpikeBodyDataEntry.d.ts +0 -54
  136. package/lib/typescript/DataModels/SpikeBodyDataEntry.d.ts.map +0 -1
  137. package/lib/typescript/DataModels/SpikeBreathingDataEntry.d.ts +0 -13
  138. package/lib/typescript/DataModels/SpikeBreathingDataEntry.d.ts.map +0 -1
  139. package/lib/typescript/DataModels/SpikeCaloriesDataEntry.d.ts +0 -15
  140. package/lib/typescript/DataModels/SpikeCaloriesDataEntry.d.ts.map +0 -1
  141. package/lib/typescript/DataModels/SpikeData.d.ts +0 -27
  142. package/lib/typescript/DataModels/SpikeData.d.ts.map +0 -1
  143. package/lib/typescript/DataModels/SpikeDataTypes.d.ts +0 -17
  144. package/lib/typescript/DataModels/SpikeDataTypes.d.ts.map +0 -1
  145. package/lib/typescript/DataModels/SpikeDistanceDataEntry.d.ts +0 -13
  146. package/lib/typescript/DataModels/SpikeDistanceDataEntry.d.ts.map +0 -1
  147. package/lib/typescript/DataModels/SpikeEcgDataEntry.d.ts +0 -13
  148. package/lib/typescript/DataModels/SpikeEcgDataEntry.d.ts.map +0 -1
  149. package/lib/typescript/DataModels/SpikeGlucoseDataEntry.d.ts +0 -21
  150. package/lib/typescript/DataModels/SpikeGlucoseDataEntry.d.ts.map +0 -1
  151. package/lib/typescript/DataModels/SpikeHeartDataEntry.d.ts +0 -32
  152. package/lib/typescript/DataModels/SpikeHeartDataEntry.d.ts.map +0 -1
  153. package/lib/typescript/DataModels/SpikeOxygenSaturationDataEntry.d.ts +0 -15
  154. package/lib/typescript/DataModels/SpikeOxygenSaturationDataEntry.d.ts.map +0 -1
  155. package/lib/typescript/DataModels/SpikeSleepDataEntry.d.ts +0 -30
  156. package/lib/typescript/DataModels/SpikeSleepDataEntry.d.ts.map +0 -1
  157. package/lib/typescript/DataModels/SpikeStepsDataEntry.d.ts +0 -13
  158. package/lib/typescript/DataModels/SpikeStepsDataEntry.d.ts.map +0 -1
  159. package/lib/typescript/DataModels/SpikeStepsIntradayDataEntry.d.ts +0 -17
  160. package/lib/typescript/DataModels/SpikeStepsIntradayDataEntry.d.ts.map +0 -1
  161. package/lib/typescript/DataModels/SpikeWebhookJob.d.ts +0 -11
  162. package/lib/typescript/DataModels/SpikeWebhookJob.d.ts.map +0 -1
  163. package/lib/typescript/DataTypes/SpikeDataType.d.ts +0 -68
  164. package/lib/typescript/DataTypes/SpikeDataType.d.ts.map +0 -1
  165. package/lib/typescript/SpikeBackgroundDeliveriesLogger.d.ts +0 -4
  166. package/lib/typescript/SpikeBackgroundDeliveriesLogger.d.ts.map +0 -1
  167. package/lib/typescript/SpikeConnection.d.ts +0 -63
  168. package/lib/typescript/SpikeConnection.d.ts.map +0 -1
  169. package/lib/typescript/SpikeConnectionTypes.d.ts +0 -102
  170. package/lib/typescript/SpikeConnectionTypes.d.ts.map +0 -1
  171. package/lib/typescript/SpikeLogger.d.ts +0 -13
  172. package/lib/typescript/SpikeLogger.d.ts.map +0 -1
  173. package/src/DataModels/SpikeActivitiesStreamDataEntry.ts +0 -67
  174. package/src/DataModels/SpikeActivitiesSummaryDataEntry.ts +0 -28
  175. package/src/DataModels/SpikeBodyDataEntry.ts +0 -61
  176. package/src/DataModels/SpikeBreathingDataEntry.ts +0 -12
  177. package/src/DataModels/SpikeCaloriesDataEntry.ts +0 -13
  178. package/src/DataModels/SpikeData.ts +0 -38
  179. package/src/DataModels/SpikeDataTypes.ts +0 -31
  180. package/src/DataModels/SpikeDistanceDataEntry.ts +0 -12
  181. package/src/DataModels/SpikeEcgDataEntry.ts +0 -12
  182. package/src/DataModels/SpikeGlucoseDataEntry.ts +0 -20
  183. package/src/DataModels/SpikeHeartDataEntry.ts +0 -34
  184. package/src/DataModels/SpikeOxygenSaturationDataEntry.ts +0 -14
  185. package/src/DataModels/SpikeSleepDataEntry.ts +0 -29
  186. package/src/DataModels/SpikeStepsDataEntry.ts +0 -12
  187. package/src/DataModels/SpikeStepsIntradayDataEntry.ts +0 -16
  188. package/src/DataModels/SpikeWebhookJob.ts +0 -10
  189. package/src/DataTypes/SpikeDataType.ts +0 -93
  190. package/src/SpikeBackgroundDeliveriesLogger.ts +0 -3
  191. package/src/SpikeConnection.ts +0 -495
  192. package/src/SpikeConnectionTypes.ts +0 -124
  193. package/src/SpikeLogger.ts +0 -14
@@ -1,5 +1,7 @@
1
1
  import Foundation
2
+ import BackgroundTasks
2
3
  import SpikeSDK
4
+ import SwiftUI
3
5
  import React
4
6
 
5
7
  @objc(SpikeSdk)
@@ -13,79 +15,9 @@ class SpikeSdk: RCTEventEmitter {
13
15
  super.init()
14
16
  }
15
17
 
16
- // MARK: - Connections dictionary
17
-
18
- /// Do not use this directly, use `addConnection` and `getConnection` instead
19
- private var _connections: [String: SpikeConnection] = [:]
20
- private let queue = DispatchQueue(label: "com.spike.rn.SpikeSdk.connections")
21
-
22
- /// Add new connection to the dictionary in a thread-safe manner
23
- private func addConnection(_ connection: SpikeConnection, withUUID uuid: String) {
24
- queue.sync {
25
- _connections[uuid] = connection
26
- }
27
- }
28
-
29
- /// Synchronised read for safe multithreaded usage
30
- private func getConnection(withUUID uuid: String) -> SpikeConnection? {
31
- queue.sync {
32
- _connections[uuid]
33
- }
34
- }
35
-
36
18
  // MARK: - Spike SDK level
37
-
38
- @objc(createConnection:
39
- withAppId:
40
- withAuthToken:
41
- withCustomerEndUserId:
42
- withCallbackUrl:
43
- withUseLogger:
44
- withResolver:withRejecter:)
45
- func createConnection(uuid: String,
46
- appId: String,
47
- authToken: String,
48
- customerEndUserId: String,
49
- callbackUrl: String?,
50
- useLogger: Bool,
51
- resolve: @escaping RCTPromiseResolveBlock,
52
- reject: @escaping RCTPromiseRejectBlock) {
53
- Task {
54
- do {
55
- let logger = useLogger ? self.createLogger(connectionUUID: uuid) : nil
56
- let spikeConnection = try await Spike.createConnection(
57
- appId: appId,
58
- authToken: authToken,
59
- customerEndUserId: customerEndUserId,
60
- callbackUrl: callbackUrl != nil ? URL(string: callbackUrl!) : nil,
61
- logger: logger)
62
- addConnection(spikeConnection, withUUID: uuid)
63
- resolve(Void())
64
- } catch let error {
65
- spikeReject(with: error, reject: reject)
66
- }
67
- }
68
- }
69
-
70
- @objc(getBackgroundConnections:
71
- withRejecter:)
72
- func getBackgroundConnections(resolve: @escaping RCTPromiseResolveBlock,
73
- reject: @escaping RCTPromiseRejectBlock) {
74
- Task {
75
- do {
76
- let spikeConnections = try await Spike.getBackgroundConnections()
77
- var connectionsUUIDs: [String] = []
78
- for connection in spikeConnections {
79
- let uuid = UUID().uuidString
80
- addConnection(connection, withUUID: uuid)
81
- connectionsUUIDs.append(uuid)
82
- }
83
- resolve(connectionsUUIDs)
84
- } catch let error {
85
- spikeReject(with: error, reject: reject)
86
- }
87
- }
88
- }
19
+
20
+ private let queue = DispatchQueue(label: "com.spike.rn.SpikeSdk.connections")
89
21
 
90
22
  @objc(isHealthDataAvailable:
91
23
  withRejecter:)
@@ -96,359 +28,17 @@ class SpikeSdk: RCTEventEmitter {
96
28
  resolve(isAvailable)
97
29
  }
98
30
  }
99
-
100
- @objc(ensurePermissionsAreGranted:
101
- withResolver:
102
- withRejecter:)
103
- func ensurePermissionsAreGranted(permissions: [String],
104
- resolve: @escaping RCTPromiseResolveBlock,
105
- reject: @escaping RCTPromiseRejectBlock) {
106
- Task {
107
- do {
108
- let dataTypes = permissions.map { SpikeDataTypeMapper.mapDataType($0) }
109
- try await Spike.ensurePermissionsAreGranted(permissions: dataTypes)
110
- resolve(Void())
111
- } catch let error {
112
- spikeReject(with: error, reject: reject)
113
- }
114
- }
115
- }
116
-
117
- // MARK: SpikeConnection level
118
-
119
- @objc(getAppId:
120
- withResolver:
121
- withRejecter:)
122
- func getAppId(connectionUUID: String,
123
- resolve: @escaping RCTPromiseResolveBlock,
124
- reject: @escaping RCTPromiseRejectBlock) {
125
- guard let connection = getConnection(withUUID: connectionUUID) else {
126
- spikeReject(with: SpikeConnectionNotFoundException(), reject: reject)
127
- return
128
- }
129
-
130
- do {
131
- let value = try connection.getAppId()
132
- resolve(value)
133
- } catch let error {
134
- spikeReject(with: error, reject: reject)
135
- }
136
- }
137
-
138
- @objc(getSpikeEndUserId:
139
- withResolver:
140
- withRejecter:)
141
- func getSpikeEndUserId(connectionUUID: String,
142
- resolve: @escaping RCTPromiseResolveBlock,
143
- reject: @escaping RCTPromiseRejectBlock) {
144
- guard let connection = getConnection(withUUID: connectionUUID) else {
145
- spikeReject(with: SpikeConnectionNotFoundException(), reject: reject)
146
- return
147
- }
148
-
149
- do {
150
- let value = try connection.getSpikeEndUserId()
151
- resolve(value)
152
- } catch let error {
153
- spikeReject(with: error, reject: reject)
154
- }
155
- }
156
-
157
- @objc(getCustomerEndUserId:
158
- withResolver:
159
- withRejecter:)
160
- func getCustomerEndUserId(connectionUUID: String,
161
- resolve: @escaping RCTPromiseResolveBlock,
162
- reject: @escaping RCTPromiseRejectBlock) {
163
- guard let connection = getConnection(withUUID: connectionUUID) else {
164
- spikeReject(with: SpikeConnectionNotFoundException(), reject: reject)
165
- return
166
- }
167
-
168
- do {
169
- let value = try connection.getCustomerEndUserId()
170
- resolve(value)
171
- } catch let error {
172
- spikeReject(with: error, reject: reject)
173
- }
174
- }
175
-
176
- @objc(close:
177
- withResolver:
178
- withRejecter:)
179
- func close(connectionUUID: String,
180
- resolve: @escaping RCTPromiseResolveBlock,
181
- reject: @escaping RCTPromiseRejectBlock) {
182
- guard let connection = getConnection(withUUID: connectionUUID) else {
183
- spikeReject(with: SpikeConnectionNotFoundException(), reject: reject)
184
- return
185
- }
186
-
187
- do {
188
- try connection.close()
189
- resolve(Void())
190
- } catch let error {
191
- spikeReject(with: error, reject: reject)
192
- }
193
- }
194
-
195
- @objc(extractData:
196
- withDataType:
197
- withResolver:
198
- withRejecter:)
199
- func extractData(connectionUUID: String,
200
- dataType: String,
201
- resolve: @escaping RCTPromiseResolveBlock,
202
- reject: @escaping RCTPromiseRejectBlock) {
203
- guard let connection = getConnection(withUUID: connectionUUID) else {
204
- spikeReject(with: SpikeConnectionNotFoundException(), reject: reject)
205
- return
206
- }
207
-
208
- Task {
209
- do {
210
- let result = try await SpikeDataTypeMapper.extractData(dataType,
211
- connection: connection)
212
- if let dataString = result {
213
- resolve(dataString)
214
- } else {
215
- spikeReject(with: SpikeDataExtractionException(), reject: reject)
216
- }
217
- } catch let error {
218
- spikeReject(with: error, reject: reject)
219
- }
220
- }
221
- }
222
-
223
- @objc(extractDataInRange:
224
- withDataType:
225
- withFromDateMillis:
226
- withToDateMillis:
227
- withResolver:
228
- withRejecter:)
229
- func extractDataInRange(connectionUUID: String,
230
- dataType: String,
231
- fromDateMillis: Double,
232
- toDateMillis: Double,
233
- resolve: @escaping RCTPromiseResolveBlock,
234
- reject: @escaping RCTPromiseRejectBlock) {
235
- guard let connection = getConnection(withUUID: connectionUUID) else {
236
- spikeReject(with: SpikeConnectionNotFoundException(), reject: reject)
237
- return
238
- }
239
-
240
- Task {
241
- do {
242
- let fromDate = Date(timeIntervalSince1970: fromDateMillis/1000)
243
- let toDate = Date(timeIntervalSince1970: toDateMillis/1000)
244
- let result = try await SpikeDataTypeMapper.extractDataInRange(dataType,
245
- connection: connection,
246
- from: fromDate,
247
- to: toDate)
248
- if let dataString = result {
249
- resolve(dataString)
250
- } else {
251
- spikeReject(with: SpikeDataExtractionException(), reject: reject)
252
- }
253
- } catch let error {
254
- spikeReject(with: error, reject: reject)
255
- }
256
- }
257
- }
258
-
259
- // MARK: SpikeWebhookConnection level
260
-
261
- @objc(getCallbackUrl:
262
- withResolver:
263
- withRejecter:)
264
- func getCallbackUrl(connectionUUID: String,
265
- resolve: @escaping RCTPromiseResolveBlock,
266
- reject: @escaping RCTPromiseRejectBlock) {
267
- guard let connection = getConnection(withUUID: connectionUUID) else {
268
- spikeReject(with: SpikeConnectionNotFoundException(), reject: reject)
269
- return
270
- }
271
-
272
- do {
273
- let value = try connection.getCallbackUrl()
274
- resolve(value.absoluteString)
275
- } catch let error {
276
- spikeReject(with: error, reject: reject)
277
- }
278
- }
279
-
280
- @objc(extractAndPostData:
281
- withDataType:
282
- withResolver:
283
- withRejecter:)
284
- func extractAndPostData(connectionUUID: String,
285
- dataType: String,
286
- resolve: @escaping RCTPromiseResolveBlock,
287
- reject: @escaping RCTPromiseRejectBlock) {
288
- guard let connection = getConnection(withUUID: connectionUUID) else {
289
- spikeReject(with: SpikeConnectionNotFoundException(), reject: reject)
290
- return
291
- }
292
-
293
- Task {
294
- do {
295
- let result = try await SpikeDataTypeMapper.extractAndPostData(dataType,
296
- connection: connection)
297
- if let dataString = result {
298
- resolve(dataString)
299
- } else {
300
- spikeReject(with: SpikeDataExtractionException(), reject: reject)
301
- }
302
- } catch let error {
303
- spikeReject(with: error, reject: reject)
304
- }
305
- }
306
- }
307
-
308
- @objc(extractAndPostDataInRange:
309
- withDataType:
310
- withFromDateMillis:
311
- withToDateMillis:
312
- withResolver:
313
- withRejecter:)
314
- func extractAndPostDataInRange(connectionUUID: String,
315
- dataType: String,
316
- fromDateMillis: Double,
317
- toDateMillis: Double,
318
- resolve: @escaping RCTPromiseResolveBlock,
319
- reject: @escaping RCTPromiseRejectBlock) {
320
- guard let connection = getConnection(withUUID: connectionUUID) else {
321
- spikeReject(with: SpikeConnectionNotFoundException(), reject: reject)
322
- return
323
- }
324
-
325
- Task {
326
- do {
327
- let fromDate = Date(timeIntervalSince1970: fromDateMillis/1000)
328
- let toDate = Date(timeIntervalSince1970: toDateMillis/1000)
329
- let result = try await SpikeDataTypeMapper.extractAndPostDataInRange(dataType,
330
- connection: connection,
331
- from: fromDate,
332
- to: toDate)
333
- if let dataString = result {
334
- resolve(dataString)
335
- } else {
336
- spikeReject(with: SpikeDataExtractionException(), reject: reject)
337
- }
338
- } catch let error {
339
- spikeReject(with: error, reject: reject)
340
- }
341
- }
342
- }
343
-
344
- @objc(enableBackgroundDelivery:
345
- withDataTypes:
346
- withResolver:
347
- withRejecter:)
348
- func enableBackgroundDelivery(connectionUUID: String,
349
- dataTypes: [String],
350
- resolve: @escaping RCTPromiseResolveBlock,
351
- reject: @escaping RCTPromiseRejectBlock) {
352
- guard let connection = getConnection(withUUID: connectionUUID) else {
353
- spikeReject(with: SpikeConnectionNotFoundException(), reject: reject)
354
- return
355
- }
356
-
357
- Task {
358
- do {
359
- let types = dataTypes.map { SpikeDataTypeMapper.mapDataType($0) }
360
- try await connection.enableBackgroundDelivery(dataTypes: types)
361
- resolve(Void())
362
- } catch let error {
363
- spikeReject(with: error, reject: reject)
364
- }
365
- }
366
- }
367
-
368
- @objc(getBackgroundDeliveryDataTypes:
369
- withResolver:
370
- withRejecter:)
371
- func getBackgroundDeliveryDataTypes(connectionUUID: String,
372
- resolve: @escaping RCTPromiseResolveBlock,
373
- reject: @escaping RCTPromiseRejectBlock) {
374
- guard let connection = getConnection(withUUID: connectionUUID) else {
375
- spikeReject(with: SpikeConnectionNotFoundException(), reject: reject)
376
- return
377
- }
378
-
379
- Task {
380
- do {
381
- let dataTypes = try await connection.getBackgroundDeliveryDataTypes()
382
- let dataTypesString = dataTypes.map { SpikeDataTypeMapper.mapDataTypeToString($0) }
383
- resolve(dataTypesString)
384
- } catch let error {
385
- spikeReject(with: error, reject: reject)
386
- }
387
- }
388
- }
389
-
390
- @objc(setListener:
391
- withResolver:
392
- withRejecter:)
393
- func setListener(connectionUUID: String,
394
- resolve: @escaping RCTPromiseResolveBlock,
395
- reject: @escaping RCTPromiseRejectBlock) {
396
- guard let connection = getConnection(withUUID: connectionUUID) else {
397
- spikeReject(with: SpikeConnectionNotFoundException(), reject: reject)
398
- return
399
- }
400
-
401
- do {
402
- let listener = createListener(connectionUUID: connectionUUID)
403
- try connection.setListener(listener: listener)
404
- resolve(Void())
405
- } catch let error {
406
- spikeReject(with: error, reject: reject)
407
- }
408
- }
409
-
31
+
410
32
  // MARK: Supported events
411
-
33
+
412
34
  override func supportedEvents() -> [String]! {
413
35
  return [
414
- "onDebug",
415
- "onInfo",
416
- "onError",
417
- "onBackgroundLog",
418
36
  "onSdkLog",
419
37
  ]
420
38
  }
421
-
422
- // MARK: Private methods
423
-
424
- private func createLogger(connectionUUID: String) -> SpikeLogger {
425
- return SpikeConnectionLogger(connectionUUID: connectionUUID) { [weak self] connectionUUID, level, message in
426
- let body = [
427
- "connectionUUID": connectionUUID,
428
- "message": message
429
- ]
430
- switch level {
431
- case .debug:
432
- self?.sendEvent(withName: "onDebug", body: body)
433
- case .info:
434
- self?.sendEvent(withName: "onInfo", body: body)
435
- case .error:
436
- self?.sendEvent(withName: "onError", body: body)
437
- }
438
- }
439
- }
440
39
 
441
- private func createListener(connectionUUID: String) -> SpikeBackgroundDeliveriesLogger {
442
- return SpikeConnectionListener(connectionUUID: connectionUUID) { [weak self] connectionUUID, log in
443
- let body = [
444
- "connectionUUID": connectionUUID,
445
- "log": log
446
- ]
447
- self?.sendEvent(withName: "onBackgroundLog", body: body)
448
- }
449
- }
40
+ // MARK: Private methods
450
41
 
451
-
452
42
  private func spikeReject(with error: Error, reject: RCTPromiseRejectBlock) {
453
43
  let message = (error as? SpikeException)?.description
454
44
  reject(
@@ -476,6 +66,12 @@ class SpikeSdk: RCTEventEmitter {
476
66
  _connectionsV3[uuid]
477
67
  }
478
68
  }
69
+
70
+ private func removeConnectionV3(withUUID uuid: String) {
71
+ queue.sync {
72
+ _connectionsV3.removeValue(forKey: uuid)
73
+ }
74
+ }
479
75
 
480
76
  // SpikeSDK level
481
77
 
@@ -505,6 +101,29 @@ class SpikeSdk: RCTEventEmitter {
505
101
  }
506
102
  }
507
103
  }
104
+
105
+ @objc(closeV3:
106
+ withResolver:
107
+ withRejecter:)
108
+ func closeV3(
109
+ connectionUUID: String,
110
+ resolve: @escaping RCTPromiseResolveBlock,
111
+ reject: @escaping RCTPromiseRejectBlock
112
+ ) {
113
+ Task {
114
+ do {
115
+ guard let connection = getConnectionV3(withUUID: connectionUUID) else {
116
+ spikeReject(with: SpikeConnectionNotFoundException(), reject: reject)
117
+ return
118
+ }
119
+ try await connection.close()
120
+ removeConnectionV3(withUUID: connectionUUID)
121
+ resolve(Void())
122
+ } catch let error {
123
+ spikeReject(with: error, reject: reject)
124
+ }
125
+ }
126
+ }
508
127
 
509
128
  @objc(createConnectionAPIv3Legacy:
510
129
  withAppId:
@@ -567,6 +186,7 @@ class SpikeSdk: RCTEventEmitter {
567
186
  metrics:
568
187
  activityConfigs:
569
188
  sleepConfigs:
189
+ nutritionalFields:
570
190
  withResolver:
571
191
  withRejecter:)
572
192
  func requestPermissionsFromHealthKit(
@@ -575,6 +195,7 @@ class SpikeSdk: RCTEventEmitter {
575
195
  forMetrics metrics: [String],
576
196
  forActivityConfigs activityConfigs: [String],
577
197
  forSleepConfigs sleepConfigs: [String],
198
+ nutritionalFields: [String],
578
199
  resolve: @escaping RCTPromiseResolveBlock,
579
200
  reject: @escaping RCTPromiseRejectBlock
580
201
  ) {
@@ -596,12 +217,16 @@ class SpikeSdk: RCTEventEmitter {
596
217
  let sleepConfigsObjects = sleepConfigs.compactMap {
597
218
  try? makeSleepConfig(fromString: $0)
598
219
  }
220
+ let nutritionFieldsObjects = nutritionalFields.compactMap {
221
+ NutritionalField(rawValue: $0)
222
+ }
599
223
 
600
224
  try await connection.requestPermissionsFromHealthKit(
601
225
  forStatistics: stats,
602
226
  forMetrics: metricsObjects,
603
227
  forActivities: activityConfigsObjects,
604
- forSleep: sleepConfigsObjects
228
+ forSleep: sleepConfigsObjects,
229
+ forNutrition: nutritionFieldsObjects
605
230
  )
606
231
 
607
232
  resolve(Void())
@@ -616,6 +241,7 @@ class SpikeSdk: RCTEventEmitter {
616
241
  metrics:
617
242
  activityConfigs:
618
243
  sleepConfigs:
244
+ nutritionalFields:
619
245
  days:
620
246
  withResolver:
621
247
  withRejecter:)
@@ -625,6 +251,7 @@ class SpikeSdk: RCTEventEmitter {
625
251
  metrics: [String],
626
252
  activityConfigs: [String],
627
253
  sleepConfigs: [String],
254
+ nutritionalFields: [String],
628
255
  days: String?,
629
256
  resolve: @escaping RCTPromiseResolveBlock,
630
257
  reject: @escaping RCTPromiseRejectBlock
@@ -647,6 +274,9 @@ class SpikeSdk: RCTEventEmitter {
647
274
  let sleepConfigsObjects = sleepConfigs.compactMap {
648
275
  try? makeSleepConfig(fromString: $0)
649
276
  }
277
+ let nutritionFieldsObjects = nutritionalFields.compactMap {
278
+ NutritionalField(rawValue: $0)
279
+ }
650
280
 
651
281
  let daysValue: Int? = days != nil ? Int(days!) : nil
652
282
  try await connection.requestPermissionsFromHealthKitAndBackfill(
@@ -654,6 +284,7 @@ class SpikeSdk: RCTEventEmitter {
654
284
  forMetrics: metricsObjects,
655
285
  forActivities: activityConfigsObjects,
656
286
  forSleep: sleepConfigsObjects,
287
+ forNutrition: nutritionFieldsObjects,
657
288
  backfillDays: daysValue
658
289
  )
659
290
 
@@ -916,6 +547,7 @@ class SpikeSdk: RCTEventEmitter {
916
547
  metrics:
917
548
  activityConfigs:
918
549
  sleepConfigs:
550
+ nutritionalFields:
919
551
  withResolver:
920
552
  withRejecter:)
921
553
  func enableBackgroundDeliveryV3(
@@ -924,6 +556,7 @@ class SpikeSdk: RCTEventEmitter {
924
556
  metrics: [String],
925
557
  activityConfigs: [String],
926
558
  sleepConfigs: [String],
559
+ nutritionalFields: [String],
927
560
  resolve: @escaping RCTPromiseResolveBlock,
928
561
  reject: @escaping RCTPromiseRejectBlock
929
562
  ) {
@@ -946,12 +579,16 @@ class SpikeSdk: RCTEventEmitter {
946
579
  let sleepConfigsObjects = sleepConfigs.compactMap {
947
580
  try? makeSleepConfig(fromString: $0)
948
581
  }
582
+ let nutritionFieldsObjects = nutritionalFields.compactMap {
583
+ NutritionalField(rawValue: $0)
584
+ }
949
585
 
950
586
  try await connection.enableBackgroundDelivery(
951
587
  forStatistics: stats,
952
588
  forMetrics: metricsObjects,
953
589
  forActivities: activityConfigsObjects,
954
- forSleep: sleepConfigsObjects
590
+ forSleep: sleepConfigsObjects,
591
+ forNutrition: nutritionFieldsObjects
955
592
  )
956
593
 
957
594
  resolve(true)
@@ -966,6 +603,7 @@ class SpikeSdk: RCTEventEmitter {
966
603
  metrics:
967
604
  activityConfigs:
968
605
  sleepConfigs:
606
+ nutritionalFields:
969
607
  days:
970
608
  withResolver:
971
609
  withRejecter:)
@@ -975,6 +613,7 @@ class SpikeSdk: RCTEventEmitter {
975
613
  metrics: [String],
976
614
  activityConfigs: [String],
977
615
  sleepConfigs: [String],
616
+ nutritionalFields: [String],
978
617
  days: String?,
979
618
  resolve: @escaping RCTPromiseResolveBlock,
980
619
  reject: @escaping RCTPromiseRejectBlock
@@ -997,6 +636,9 @@ class SpikeSdk: RCTEventEmitter {
997
636
  let sleepConfigsObjects = sleepConfigs.compactMap {
998
637
  try? makeSleepConfig(fromString: $0)
999
638
  }
639
+ let nutritionFieldsObjects = nutritionalFields.compactMap {
640
+ NutritionalField(rawValue: $0)
641
+ }
1000
642
 
1001
643
  let daysValue: Int? = days != nil ? Int(days!) : nil
1002
644
  try await connection.backfill(
@@ -1004,6 +646,7 @@ class SpikeSdk: RCTEventEmitter {
1004
646
  forMetrics: metricsObjects,
1005
647
  forActivities: activityConfigsObjects,
1006
648
  forSleep: sleepConfigsObjects,
649
+ forNutrition: nutritionFieldsObjects,
1007
650
  days: daysValue
1008
651
  )
1009
652
 
@@ -3,9 +3,8 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.setLogCallback = exports.isPackageInstalled = exports.isHealthDataAvailable = exports.getBackgroundConnections = exports.ensurePermissionsAreGranted = exports.createConnectionAPIv3Legacy = exports.createConnectionAPIv3 = exports.createConnection = void 0;
6
+ exports.setLogCallback = exports.isPackageInstalled = exports.isHealthDataAvailable = exports.createConnectionAPIv3Legacy = exports.createConnectionAPIv3 = void 0;
7
7
  var _reactNative = require("react-native");
8
- var _SpikeConnection = require("./SpikeConnection");
9
8
  var _SpikeException = require("./SpikeException");
10
9
  var _SpikeSdk = require("./SpikeSdk");
11
10
  var _SpikeRNConnectionAPIv = require("./v3/SpikeRNConnectionAPIv3");
@@ -13,58 +12,6 @@ var _version = require("./version");
13
12
  /**
14
13
  * @ignore
15
14
  */
16
-
17
- /**
18
- * @deprecated Use createConnectionAPIv3 instead. See https://docs.spikeapi.com/sdk-docs/react-native/usage-guide
19
- * @ignore
20
- */
21
- const createConnection = async (config, logger) => {
22
- if (!_SpikeSdk.SpikeSdk) throw new _SpikeException.SpikeException();
23
- try {
24
- const connectionUUID = generateUUID();
25
- const spikeConnection = new _SpikeConnection.SpikeConnection(connectionUUID, logger);
26
- await _SpikeSdk.SpikeSdk.createConnection(connectionUUID, config.appId, config.authToken, config.customerEndUserId, config.callbackUrl ?? null, !!logger);
27
- return spikeConnection;
28
- } catch (error) {
29
- throw (0, _SpikeException.unwrapSpikeException)(error);
30
- }
31
- };
32
-
33
- /**
34
- * @deprecated Deprecated
35
- * @ignore
36
- */
37
- exports.createConnection = createConnection;
38
- const getBackgroundConnections = async () => {
39
- if (!_SpikeSdk.SpikeSdk) throw new _SpikeException.SpikeException();
40
- try {
41
- const connectionUUIDs = await _SpikeSdk.SpikeSdk.getBackgroundConnections();
42
- const connections = connectionUUIDs.map(uuid => new _SpikeConnection.SpikeConnection(uuid));
43
- return connections;
44
- } catch (error) {
45
- throw (0, _SpikeException.unwrapSpikeException)(error);
46
- }
47
- };
48
-
49
- /**
50
- * @deprecated Deprecated
51
- * @ignore
52
- */
53
- exports.getBackgroundConnections = getBackgroundConnections;
54
- const ensurePermissionsAreGranted = async permissions => {
55
- if (_reactNative.Platform.OS !== 'ios') return;
56
- if (!_SpikeSdk.SpikeSdk) throw new _SpikeException.SpikeException();
57
- try {
58
- await _SpikeSdk.SpikeSdk.ensurePermissionsAreGranted(permissions.map(permissionType => permissionType.rawValue));
59
- } catch (error) {
60
- throw (0, _SpikeException.unwrapSpikeException)(error);
61
- }
62
- };
63
-
64
- /**
65
- * @ignore
66
- */
67
- exports.ensurePermissionsAreGranted = ensurePermissionsAreGranted;
68
15
  const isPackageInstalled = async () => {
69
16
  if (_reactNative.Platform.OS !== 'android') return true;
70
17
  if (!_SpikeSdk.SpikeSdk) throw new _SpikeException.SpikeException();
@@ -196,13 +143,10 @@ exports.createConnectionAPIv3Legacy = createConnectionAPIv3Legacy;
196
143
  const setLogCallback = async callback => {
197
144
  if (!_SpikeSdk.SpikeSdk) throw new _SpikeException.SpikeException("No SpikeSDK found");
198
145
  try {
199
- // Set up event listener for both iOS and Android
200
146
  const eventEmitter = new _reactNative.NativeEventEmitter(_SpikeSdk.SpikeSdk);
201
147
  const subscription = eventEmitter.addListener('onSdkLog', event => {
202
148
  callback(event.level, event.message);
203
149
  });
204
-
205
- // Store subscription for potential cleanup
206
150
  _SpikeSdk.SpikeSdk._logSubscription = subscription;
207
151
  await _SpikeSdk.SpikeSdk.setLogCallback(callback);
208
152
  } catch (error) {