react-native-spike-sdk 4.6.13 → 4.8.13-beta.1
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 +1 -1
- package/android/src/main/java/com/spikesdk/SpikeMappers.kt +0 -46
- package/android/src/main/java/com/spikesdk/SpikeSdkModule.kt +18 -476
- package/ios/SpikeExceptionMapper.swift +4 -12
- package/ios/SpikeSdk.m +5 -79
- package/ios/SpikeSdk.swift +28 -417
- package/lib/commonjs/Spike.js +35 -58
- package/lib/commonjs/Spike.js.map +1 -1
- package/lib/commonjs/SpikeException.js +15 -94
- package/lib/commonjs/SpikeException.js.map +1 -1
- package/lib/commonjs/index.js +1 -71
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/commonjs/version.js.map +1 -1
- package/lib/module/Spike.js +34 -56
- package/lib/module/Spike.js.map +1 -1
- package/lib/module/SpikeException.js +14 -83
- package/lib/module/SpikeException.js.map +1 -1
- package/lib/module/index.js +4 -8
- package/lib/module/index.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/module/version.js.map +1 -1
- package/lib/typescript/Spike.d.ts +22 -29
- package/lib/typescript/Spike.d.ts.map +1 -1
- package/lib/typescript/SpikeException.d.ts +5 -30
- package/lib/typescript/SpikeException.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +5 -24
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/lib/typescript/version.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/Spike.ts +45 -89
- package/src/SpikeException.ts +13 -96
- package/src/index.ts +2 -61
- package/src/version.ts +1 -1
- package/android/src/main/java/com/spikesdk/SpikeConnectionLogger.kt +0 -37
- package/ios/SpikeConnectionListener.swift +0 -17
- package/ios/SpikeConnectionLogger.swift +0 -43
- package/ios/SpikeDataTypeMapper.swift +0 -255
- package/lib/commonjs/DataModels/SpikeActivitiesStreamDataEntry.js +0 -2
- package/lib/commonjs/DataModels/SpikeActivitiesStreamDataEntry.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeActivitiesSummaryDataEntry.js +0 -2
- package/lib/commonjs/DataModels/SpikeActivitiesSummaryDataEntry.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeBodyDataEntry.js +0 -2
- package/lib/commonjs/DataModels/SpikeBodyDataEntry.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeBreathingDataEntry.js +0 -2
- package/lib/commonjs/DataModels/SpikeBreathingDataEntry.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeCaloriesDataEntry.js +0 -2
- package/lib/commonjs/DataModels/SpikeCaloriesDataEntry.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeData.js +0 -6
- package/lib/commonjs/DataModels/SpikeData.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeDataTypes.js +0 -23
- package/lib/commonjs/DataModels/SpikeDataTypes.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeDistanceDataEntry.js +0 -2
- package/lib/commonjs/DataModels/SpikeDistanceDataEntry.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeEcgDataEntry.js +0 -2
- package/lib/commonjs/DataModels/SpikeEcgDataEntry.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeGlucoseDataEntry.js +0 -2
- package/lib/commonjs/DataModels/SpikeGlucoseDataEntry.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeHeartDataEntry.js +0 -2
- package/lib/commonjs/DataModels/SpikeHeartDataEntry.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeOxygenSaturationDataEntry.js +0 -2
- package/lib/commonjs/DataModels/SpikeOxygenSaturationDataEntry.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeSleepDataEntry.js +0 -2
- package/lib/commonjs/DataModels/SpikeSleepDataEntry.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeStepsDataEntry.js +0 -2
- package/lib/commonjs/DataModels/SpikeStepsDataEntry.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeStepsIntradayDataEntry.js +0 -2
- package/lib/commonjs/DataModels/SpikeStepsIntradayDataEntry.js.map +0 -1
- package/lib/commonjs/DataModels/SpikeWebhookJob.js +0 -2
- package/lib/commonjs/DataModels/SpikeWebhookJob.js.map +0 -1
- package/lib/commonjs/DataTypes/SpikeDataType.js +0 -59
- package/lib/commonjs/DataTypes/SpikeDataType.js.map +0 -1
- package/lib/commonjs/SpikeBackgroundDeliveriesLogger.js +0 -2
- package/lib/commonjs/SpikeBackgroundDeliveriesLogger.js.map +0 -1
- package/lib/commonjs/SpikeConnection.js +0 -301
- package/lib/commonjs/SpikeConnection.js.map +0 -1
- package/lib/commonjs/SpikeConnectionTypes.js +0 -6
- package/lib/commonjs/SpikeConnectionTypes.js.map +0 -1
- package/lib/commonjs/SpikeLogger.js +0 -6
- package/lib/commonjs/SpikeLogger.js.map +0 -1
- package/lib/module/DataModels/SpikeActivitiesStreamDataEntry.js +0 -2
- package/lib/module/DataModels/SpikeActivitiesStreamDataEntry.js.map +0 -1
- package/lib/module/DataModels/SpikeActivitiesSummaryDataEntry.js +0 -2
- package/lib/module/DataModels/SpikeActivitiesSummaryDataEntry.js.map +0 -1
- package/lib/module/DataModels/SpikeBodyDataEntry.js +0 -2
- package/lib/module/DataModels/SpikeBodyDataEntry.js.map +0 -1
- package/lib/module/DataModels/SpikeBreathingDataEntry.js +0 -2
- package/lib/module/DataModels/SpikeBreathingDataEntry.js.map +0 -1
- package/lib/module/DataModels/SpikeCaloriesDataEntry.js +0 -2
- package/lib/module/DataModels/SpikeCaloriesDataEntry.js.map +0 -1
- package/lib/module/DataModels/SpikeData.js +0 -4
- package/lib/module/DataModels/SpikeData.js.map +0 -1
- package/lib/module/DataModels/SpikeDataTypes.js +0 -19
- package/lib/module/DataModels/SpikeDataTypes.js.map +0 -1
- package/lib/module/DataModels/SpikeDistanceDataEntry.js +0 -2
- package/lib/module/DataModels/SpikeDistanceDataEntry.js.map +0 -1
- package/lib/module/DataModels/SpikeEcgDataEntry.js +0 -2
- package/lib/module/DataModels/SpikeEcgDataEntry.js.map +0 -1
- package/lib/module/DataModels/SpikeGlucoseDataEntry.js +0 -2
- package/lib/module/DataModels/SpikeGlucoseDataEntry.js.map +0 -1
- package/lib/module/DataModels/SpikeHeartDataEntry.js +0 -2
- package/lib/module/DataModels/SpikeHeartDataEntry.js.map +0 -1
- package/lib/module/DataModels/SpikeOxygenSaturationDataEntry.js +0 -2
- package/lib/module/DataModels/SpikeOxygenSaturationDataEntry.js.map +0 -1
- package/lib/module/DataModels/SpikeSleepDataEntry.js +0 -2
- package/lib/module/DataModels/SpikeSleepDataEntry.js.map +0 -1
- package/lib/module/DataModels/SpikeStepsDataEntry.js +0 -2
- package/lib/module/DataModels/SpikeStepsDataEntry.js.map +0 -1
- package/lib/module/DataModels/SpikeStepsIntradayDataEntry.js +0 -2
- package/lib/module/DataModels/SpikeStepsIntradayDataEntry.js.map +0 -1
- package/lib/module/DataModels/SpikeWebhookJob.js +0 -2
- package/lib/module/DataModels/SpikeWebhookJob.js.map +0 -1
- package/lib/module/DataTypes/SpikeDataType.js +0 -42
- package/lib/module/DataTypes/SpikeDataType.js.map +0 -1
- package/lib/module/SpikeBackgroundDeliveriesLogger.js +0 -2
- package/lib/module/SpikeBackgroundDeliveriesLogger.js.map +0 -1
- package/lib/module/SpikeConnection.js +0 -296
- package/lib/module/SpikeConnection.js.map +0 -1
- package/lib/module/SpikeConnectionTypes.js +0 -4
- package/lib/module/SpikeConnectionTypes.js.map +0 -1
- package/lib/module/SpikeLogger.js +0 -4
- package/lib/module/SpikeLogger.js.map +0 -1
- package/lib/typescript/DataModels/SpikeActivitiesStreamDataEntry.d.ts +0 -66
- package/lib/typescript/DataModels/SpikeActivitiesStreamDataEntry.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeActivitiesSummaryDataEntry.d.ts +0 -29
- package/lib/typescript/DataModels/SpikeActivitiesSummaryDataEntry.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeBodyDataEntry.d.ts +0 -54
- package/lib/typescript/DataModels/SpikeBodyDataEntry.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeBreathingDataEntry.d.ts +0 -13
- package/lib/typescript/DataModels/SpikeBreathingDataEntry.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeCaloriesDataEntry.d.ts +0 -15
- package/lib/typescript/DataModels/SpikeCaloriesDataEntry.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeData.d.ts +0 -27
- package/lib/typescript/DataModels/SpikeData.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeDataTypes.d.ts +0 -17
- package/lib/typescript/DataModels/SpikeDataTypes.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeDistanceDataEntry.d.ts +0 -13
- package/lib/typescript/DataModels/SpikeDistanceDataEntry.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeEcgDataEntry.d.ts +0 -13
- package/lib/typescript/DataModels/SpikeEcgDataEntry.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeGlucoseDataEntry.d.ts +0 -21
- package/lib/typescript/DataModels/SpikeGlucoseDataEntry.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeHeartDataEntry.d.ts +0 -32
- package/lib/typescript/DataModels/SpikeHeartDataEntry.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeOxygenSaturationDataEntry.d.ts +0 -15
- package/lib/typescript/DataModels/SpikeOxygenSaturationDataEntry.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeSleepDataEntry.d.ts +0 -30
- package/lib/typescript/DataModels/SpikeSleepDataEntry.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeStepsDataEntry.d.ts +0 -13
- package/lib/typescript/DataModels/SpikeStepsDataEntry.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeStepsIntradayDataEntry.d.ts +0 -17
- package/lib/typescript/DataModels/SpikeStepsIntradayDataEntry.d.ts.map +0 -1
- package/lib/typescript/DataModels/SpikeWebhookJob.d.ts +0 -11
- package/lib/typescript/DataModels/SpikeWebhookJob.d.ts.map +0 -1
- package/lib/typescript/DataTypes/SpikeDataType.d.ts +0 -68
- package/lib/typescript/DataTypes/SpikeDataType.d.ts.map +0 -1
- package/lib/typescript/SpikeBackgroundDeliveriesLogger.d.ts +0 -4
- package/lib/typescript/SpikeBackgroundDeliveriesLogger.d.ts.map +0 -1
- package/lib/typescript/SpikeConnection.d.ts +0 -63
- package/lib/typescript/SpikeConnection.d.ts.map +0 -1
- package/lib/typescript/SpikeConnectionTypes.d.ts +0 -102
- package/lib/typescript/SpikeConnectionTypes.d.ts.map +0 -1
- package/lib/typescript/SpikeLogger.d.ts +0 -13
- package/lib/typescript/SpikeLogger.d.ts.map +0 -1
- package/src/DataModels/SpikeActivitiesStreamDataEntry.ts +0 -67
- package/src/DataModels/SpikeActivitiesSummaryDataEntry.ts +0 -28
- package/src/DataModels/SpikeBodyDataEntry.ts +0 -61
- package/src/DataModels/SpikeBreathingDataEntry.ts +0 -12
- package/src/DataModels/SpikeCaloriesDataEntry.ts +0 -13
- package/src/DataModels/SpikeData.ts +0 -38
- package/src/DataModels/SpikeDataTypes.ts +0 -31
- package/src/DataModels/SpikeDistanceDataEntry.ts +0 -12
- package/src/DataModels/SpikeEcgDataEntry.ts +0 -12
- package/src/DataModels/SpikeGlucoseDataEntry.ts +0 -20
- package/src/DataModels/SpikeHeartDataEntry.ts +0 -34
- package/src/DataModels/SpikeOxygenSaturationDataEntry.ts +0 -14
- package/src/DataModels/SpikeSleepDataEntry.ts +0 -29
- package/src/DataModels/SpikeStepsDataEntry.ts +0 -12
- package/src/DataModels/SpikeStepsIntradayDataEntry.ts +0 -16
- package/src/DataModels/SpikeWebhookJob.ts +0 -10
- package/src/DataTypes/SpikeDataType.ts +0 -93
- package/src/SpikeBackgroundDeliveriesLogger.ts +0 -3
- package/src/SpikeConnection.ts +0 -495
- package/src/SpikeConnectionTypes.ts +0 -124
- package/src/SpikeLogger.ts +0 -14
package/ios/SpikeSdk.m
CHANGED
|
@@ -5,86 +5,9 @@
|
|
|
5
5
|
|
|
6
6
|
// MARK: Spike SDK level
|
|
7
7
|
|
|
8
|
-
RCT_EXTERN_METHOD(createConnection: (NSString)uuid
|
|
9
|
-
withAppId: (NSString)appId
|
|
10
|
-
withAuthToken: (NSString)authToken
|
|
11
|
-
withCustomerEndUserId: (NSString)customerEndUserId
|
|
12
|
-
withCallbackUrl: (NSString)callbackUrl
|
|
13
|
-
withUseLogger: (BOOL)useLogger
|
|
14
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
15
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
16
|
-
|
|
17
|
-
RCT_EXTERN_METHOD(getBackgroundConnections: (RCTPromiseResolveBlock)resolve
|
|
18
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
19
|
-
|
|
20
|
-
RCT_EXTERN_METHOD(ensurePermissionsAreGranted: (NSArray<NSString>)permissions
|
|
21
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
22
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
23
|
-
|
|
24
8
|
RCT_EXTERN_METHOD(isHealthDataAvailable: (RCTPromiseResolveBlock)resolve
|
|
25
9
|
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
26
10
|
|
|
27
|
-
// MARK: SpikeConnection level
|
|
28
|
-
|
|
29
|
-
RCT_EXTERN_METHOD(getAppId: (NSString)connectionUUID
|
|
30
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
31
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
32
|
-
|
|
33
|
-
RCT_EXTERN_METHOD(getSpikeEndUserId: (NSString)connectionUUID
|
|
34
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
35
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
36
|
-
|
|
37
|
-
RCT_EXTERN_METHOD(getCustomerEndUserId: (NSString)connectionUUID
|
|
38
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
39
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
40
|
-
|
|
41
|
-
RCT_EXTERN_METHOD(close: (NSString)connectionUUID
|
|
42
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
43
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
44
|
-
|
|
45
|
-
RCT_EXTERN_METHOD(extractData: (NSString)connectionUUID
|
|
46
|
-
withDataType: (NSString)dataType
|
|
47
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
48
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
49
|
-
|
|
50
|
-
RCT_EXTERN_METHOD(extractDataInRange: (NSString)connectionUUID
|
|
51
|
-
withDataType: (NSString)dataType
|
|
52
|
-
withFromDateMillis: (double)fromDateMillis
|
|
53
|
-
withToDateMillis: (double)toDateMillis
|
|
54
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
55
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
56
|
-
|
|
57
|
-
// MARK: SpikeWebhookConnection level
|
|
58
|
-
|
|
59
|
-
RCT_EXTERN_METHOD(getCallbackUrl: (NSString)connectionUUID
|
|
60
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
61
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
62
|
-
|
|
63
|
-
RCT_EXTERN_METHOD(extractAndPostData: (NSString)connectionUUID
|
|
64
|
-
withDataType: (NSString)dataType
|
|
65
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
66
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
67
|
-
|
|
68
|
-
RCT_EXTERN_METHOD(extractAndPostDataInRange: (NSString)connectionUUID
|
|
69
|
-
withDataType: (NSString)dataType
|
|
70
|
-
withFromDateMillis: (double)fromDateMillis
|
|
71
|
-
withToDateMillis: (double)toDateMillis
|
|
72
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
73
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
74
|
-
|
|
75
|
-
RCT_EXTERN_METHOD(enableBackgroundDelivery: (NSString)connectionUUID
|
|
76
|
-
withDataTypes: (NSArray<NSString>)dataTypes
|
|
77
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
78
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
79
|
-
|
|
80
|
-
RCT_EXTERN_METHOD(getBackgroundDeliveryDataTypes: (NSString)connectionUUID
|
|
81
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
82
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
83
|
-
|
|
84
|
-
RCT_EXTERN_METHOD(setListener: (NSString)connectionUUID
|
|
85
|
-
withResolver: (RCTPromiseResolveBlock)resolve
|
|
86
|
-
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
87
|
-
|
|
88
11
|
// MARK: - New API - V3
|
|
89
12
|
|
|
90
13
|
// MARK: Spike SDK level
|
|
@@ -96,6 +19,11 @@ RCT_EXTERN_METHOD(createConnectionAPIv3: (NSString)uuid
|
|
|
96
19
|
withResolver: (RCTPromiseResolveBlock)resolve
|
|
97
20
|
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
98
21
|
|
|
22
|
+
RCT_EXTERN_METHOD(createConnectionAPIv3WithAuthToken: (NSString)uuid
|
|
23
|
+
withAuthToken: (NSString)authToken
|
|
24
|
+
withResolver: (RCTPromiseResolveBlock)resolve
|
|
25
|
+
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
26
|
+
|
|
99
27
|
RCT_EXTERN_METHOD(closeV3: (NSString)connectionUUID
|
|
100
28
|
withResolver: (RCTPromiseResolveBlock)resolve
|
|
101
29
|
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
@@ -186,8 +114,6 @@ RCT_EXTERN_METHOD(getSleep: (NSString)connectionUUID
|
|
|
186
114
|
withResolver: (RCTPromiseResolveBlock)resolve
|
|
187
115
|
withRejecter: (RCTPromiseRejectBlock)reject)
|
|
188
116
|
|
|
189
|
-
// V3 has to be added because "enableBackgroundDelivery"
|
|
190
|
-
// method from old sdk is still present
|
|
191
117
|
RCT_EXTERN_METHOD(enableBackgroundDeliveryV3: (NSString)connectionUUID
|
|
192
118
|
withStatistics: (NSArray<NSString>)statistics
|
|
193
119
|
metrics: (NSArray<NSString>)metrics
|
package/ios/SpikeSdk.swift
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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(
|
|
@@ -512,6 +102,27 @@ class SpikeSdk: RCTEventEmitter {
|
|
|
512
102
|
}
|
|
513
103
|
}
|
|
514
104
|
|
|
105
|
+
@objc(createConnectionAPIv3WithAuthToken:
|
|
106
|
+
withAuthToken:
|
|
107
|
+
withResolver:withRejecter:)
|
|
108
|
+
func createConnectionWithAuthToken(uuid: String,
|
|
109
|
+
authToken: String,
|
|
110
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
111
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
112
|
+
Task {
|
|
113
|
+
do {
|
|
114
|
+
let connection = try await Spike.createConnectionAPIv3(
|
|
115
|
+
authToken: authToken
|
|
116
|
+
)
|
|
117
|
+
addConnectionV3(connection, withUUID: uuid)
|
|
118
|
+
resolve(Void())
|
|
119
|
+
|
|
120
|
+
} catch let error {
|
|
121
|
+
spikeReject(with: error, reject: reject)
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
515
126
|
@objc(closeV3:
|
|
516
127
|
withResolver:
|
|
517
128
|
withRejecter:)
|