react-native-spike-sdk 0.2.10 → 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.
- package/README.md +271 -146
- package/android/build.gradle +14 -1
- package/android/gradle.properties +2 -1
- package/android/src/main/java/com/spikesdk/SpikeConnectionLogger.kt +37 -0
- package/android/src/main/java/com/spikesdk/SpikeMappers.kt +61 -0
- package/android/src/main/java/com/spikesdk/SpikeSdkModule.kt +413 -8
- package/ios/SpikeConnectionListener.swift +17 -0
- package/ios/SpikeConnectionLogger.swift +43 -0
- package/ios/SpikeDataTypeMapper.swift +207 -0
- package/ios/SpikeExceptionMapper.swift +34 -0
- package/ios/SpikeSdk.m +84 -17
- package/ios/SpikeSdk.swift +460 -129
- package/lib/commonjs/DataModels/SpikeActivitiesStreamDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeActivitiesStreamDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeActivitiesSummaryDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeActivitiesSummaryDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeBreathingDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeBreathingDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeCaloriesDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeCaloriesDataEntry.js.map +1 -0
- package/lib/commonjs/{SpikeInterface.js → DataModels/SpikeData.js} +1 -1
- package/lib/commonjs/DataModels/SpikeData.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeDataTypes.js +22 -0
- package/lib/commonjs/DataModels/SpikeDataTypes.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeDistanceDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeDistanceDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeGlucoseDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeGlucoseDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeHeartDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeHeartDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeOxygenSaturationDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeOxygenSaturationDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeSleepDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeSleepDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeStepsDataEntry.js +2 -0
- package/lib/commonjs/DataModels/SpikeStepsDataEntry.js.map +1 -0
- package/lib/commonjs/DataModels/SpikeWebhookJob.js +2 -0
- package/lib/commonjs/DataModels/SpikeWebhookJob.js.map +1 -0
- package/lib/commonjs/DataTypes/SpikeDataType.js +53 -0
- package/lib/commonjs/DataTypes/SpikeDataType.js.map +1 -0
- package/lib/commonjs/Spike.js +61 -46
- package/lib/commonjs/Spike.js.map +1 -1
- package/lib/commonjs/SpikeConnection.js +104 -0
- package/lib/commonjs/SpikeConnection.js.map +1 -0
- package/lib/commonjs/SpikeException.js +27 -0
- package/lib/commonjs/SpikeException.js.map +1 -0
- package/lib/commonjs/SpikeLogger.js +6 -0
- package/lib/commonjs/{SpikeDataType.js.map → SpikeLogger.js.map} +1 -1
- package/lib/commonjs/SpikeSdk.js +1 -1
- package/lib/commonjs/SpikeSdk.js.map +1 -1
- package/lib/commonjs/SpikeWebhookConnection.js +119 -0
- package/lib/commonjs/SpikeWebhookConnection.js.map +1 -0
- package/lib/commonjs/SpikeWebhookConnectionListener.js +6 -0
- package/lib/commonjs/{SpikeResultData.js.map → SpikeWebhookConnectionListener.js.map} +1 -1
- package/lib/commonjs/index.js +26 -7
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/DataModels/SpikeActivitiesStreamDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeActivitiesStreamDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeActivitiesSummaryDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeActivitiesSummaryDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeBreathingDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeBreathingDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeCaloriesDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeCaloriesDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeData.js +2 -0
- package/lib/module/DataModels/SpikeData.js.map +1 -0
- package/lib/module/DataModels/SpikeDataTypes.js +15 -0
- package/lib/module/DataModels/SpikeDataTypes.js.map +1 -0
- package/lib/module/DataModels/SpikeDistanceDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeDistanceDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeGlucoseDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeGlucoseDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeHeartDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeHeartDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeOxygenSaturationDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeOxygenSaturationDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeSleepDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeSleepDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeStepsDataEntry.js +2 -0
- package/lib/module/DataModels/SpikeStepsDataEntry.js.map +1 -0
- package/lib/module/DataModels/SpikeWebhookJob.js +2 -0
- package/lib/module/DataModels/SpikeWebhookJob.js.map +1 -0
- package/lib/module/DataTypes/SpikeDataType.js +36 -0
- package/lib/module/DataTypes/SpikeDataType.js.map +1 -0
- package/lib/module/Spike.js +56 -45
- package/lib/module/Spike.js.map +1 -1
- package/lib/module/SpikeConnection.js +97 -0
- package/lib/module/SpikeConnection.js.map +1 -0
- package/lib/module/SpikeException.js +11 -0
- package/lib/module/SpikeException.js.map +1 -0
- package/lib/module/SpikeLogger.js +2 -0
- package/lib/module/{SpikeDataType.js.map → SpikeLogger.js.map} +1 -1
- package/lib/module/SpikeSdk.js +1 -2
- package/lib/module/SpikeSdk.js.map +1 -1
- package/lib/module/SpikeWebhookConnection.js +112 -0
- package/lib/module/SpikeWebhookConnection.js.map +1 -0
- package/lib/module/SpikeWebhookConnectionListener.js +2 -0
- package/lib/{commonjs/SpikeSleepAnalysisResultData.js.map → module/SpikeWebhookConnectionListener.js.map} +1 -1
- package/lib/module/index.js +13 -5
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/{SpikeWorkoutResultData.d.ts → DataModels/SpikeActivitiesStreamDataEntry.d.ts} +15 -14
- package/lib/typescript/DataModels/SpikeActivitiesStreamDataEntry.d.ts.map +1 -0
- package/lib/typescript/{SpikeResultData.d.ts → DataModels/SpikeActivitiesSummaryDataEntry.d.ts} +5 -8
- package/lib/typescript/DataModels/SpikeActivitiesSummaryDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeBreathingDataEntry.d.ts +13 -0
- package/lib/typescript/DataModels/SpikeBreathingDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeCaloriesDataEntry.d.ts +15 -0
- package/lib/typescript/DataModels/SpikeCaloriesDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeData.d.ts +25 -0
- package/lib/typescript/DataModels/SpikeData.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeDataTypes.d.ts +15 -0
- package/lib/typescript/DataModels/SpikeDataTypes.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeDistanceDataEntry.d.ts +13 -0
- package/lib/typescript/DataModels/SpikeDistanceDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeGlucoseDataEntry.d.ts +4 -0
- package/lib/typescript/DataModels/SpikeGlucoseDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeHeartDataEntry.d.ts +32 -0
- package/lib/typescript/DataModels/SpikeHeartDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeOxygenSaturationDataEntry.d.ts +15 -0
- package/lib/typescript/DataModels/SpikeOxygenSaturationDataEntry.d.ts.map +1 -0
- package/lib/typescript/{SpikeSleepAnalysisResultData.d.ts → DataModels/SpikeSleepDataEntry.d.ts} +10 -13
- package/lib/typescript/DataModels/SpikeSleepDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeStepsDataEntry.d.ts +13 -0
- package/lib/typescript/DataModels/SpikeStepsDataEntry.d.ts.map +1 -0
- package/lib/typescript/DataModels/SpikeWebhookJob.d.ts +11 -0
- package/lib/typescript/DataModels/SpikeWebhookJob.d.ts.map +1 -0
- package/lib/typescript/DataTypes/SpikeDataType.d.ts +50 -0
- package/lib/typescript/DataTypes/SpikeDataType.d.ts.map +1 -0
- package/lib/typescript/Spike.d.ts +12 -13
- package/lib/typescript/Spike.d.ts.map +1 -1
- package/lib/typescript/SpikeConnection.d.ts +23 -0
- package/lib/typescript/SpikeConnection.d.ts.map +1 -0
- package/lib/typescript/SpikeException.d.ts +21 -0
- package/lib/typescript/SpikeException.d.ts.map +1 -0
- package/lib/typescript/SpikeLogger.d.ts +10 -0
- package/lib/typescript/SpikeLogger.d.ts.map +1 -0
- package/lib/typescript/SpikeSdk.d.ts.map +1 -1
- package/lib/typescript/SpikeWebhookConnection.d.ts +21 -0
- package/lib/typescript/SpikeWebhookConnection.d.ts.map +1 -0
- package/lib/typescript/SpikeWebhookConnectionListener.d.ts +6 -0
- package/lib/typescript/SpikeWebhookConnectionListener.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +16 -7
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/react-native-spike-sdk.podspec +2 -2
- package/src/{SpikeWorkoutResultData.ts → DataModels/SpikeActivitiesStreamDataEntry.ts} +14 -12
- package/src/{SpikeResultData.ts → DataModels/SpikeActivitiesSummaryDataEntry.ts} +4 -4
- package/src/DataModels/SpikeBreathingDataEntry.ts +12 -0
- package/src/DataModels/SpikeCaloriesDataEntry.ts +13 -0
- package/src/DataModels/SpikeData.ts +35 -0
- package/src/DataModels/SpikeDataTypes.ts +27 -0
- package/src/DataModels/SpikeDistanceDataEntry.ts +12 -0
- package/src/DataModels/SpikeGlucoseDataEntry.ts +3 -0
- package/src/DataModels/SpikeHeartDataEntry.ts +34 -0
- package/src/DataModels/SpikeOxygenSaturationDataEntry.ts +14 -0
- package/src/{SpikeSleepAnalysisResultData.ts → DataModels/SpikeSleepDataEntry.ts} +9 -7
- package/src/DataModels/SpikeStepsDataEntry.ts +11 -0
- package/src/DataModels/SpikeWebhookJob.ts +10 -0
- package/src/DataTypes/SpikeDataType.ts +87 -0
- package/src/Spike.ts +132 -73
- package/src/SpikeConnection.ts +151 -0
- package/src/SpikeException.ts +11 -0
- package/src/SpikeLogger.ts +11 -0
- package/src/SpikeSdk.ts +1 -3
- package/src/SpikeWebhookConnection.ts +201 -0
- package/src/SpikeWebhookConnectionListener.ts +9 -0
- package/src/index.ts +32 -20
- package/lib/commonjs/SpikeDataType.js +0 -2
- package/lib/commonjs/SpikeInterface.js.map +0 -1
- package/lib/commonjs/SpikeResultData.js +0 -2
- package/lib/commonjs/SpikeSleepAnalysisResultData.js +0 -2
- package/lib/commonjs/SpikeWorkoutResultData.js +0 -2
- package/lib/commonjs/SpikeWorkoutResultData.js.map +0 -1
- package/lib/commonjs/useSpikeEvents.js +0 -69
- package/lib/commonjs/useSpikeEvents.js.map +0 -1
- package/lib/module/SpikeDataType.js +0 -2
- package/lib/module/SpikeInterface.js +0 -2
- package/lib/module/SpikeInterface.js.map +0 -1
- package/lib/module/SpikeResultData.js +0 -2
- package/lib/module/SpikeResultData.js.map +0 -1
- package/lib/module/SpikeSleepAnalysisResultData.js +0 -2
- package/lib/module/SpikeSleepAnalysisResultData.js.map +0 -1
- package/lib/module/SpikeWorkoutResultData.js +0 -2
- package/lib/module/SpikeWorkoutResultData.js.map +0 -1
- package/lib/module/useSpikeEvents.js +0 -62
- package/lib/module/useSpikeEvents.js.map +0 -1
- package/lib/typescript/SpikeDataType.d.ts +0 -2
- package/lib/typescript/SpikeDataType.d.ts.map +0 -1
- package/lib/typescript/SpikeInterface.d.ts +0 -13
- package/lib/typescript/SpikeInterface.d.ts.map +0 -1
- package/lib/typescript/SpikeResultData.d.ts.map +0 -1
- package/lib/typescript/SpikeSleepAnalysisResultData.d.ts.map +0 -1
- package/lib/typescript/SpikeWorkoutResultData.d.ts.map +0 -1
- package/lib/typescript/useSpikeEvents.d.ts +0 -17
- package/lib/typescript/useSpikeEvents.d.ts.map +0 -1
- package/src/SpikeDataType.ts +0 -12
- package/src/SpikeInterface.ts +0 -30
- package/src/useSpikeEvents.ts +0 -89
package/ios/SpikeSdk.swift
CHANGED
|
@@ -4,176 +4,507 @@ import React
|
|
|
4
4
|
|
|
5
5
|
@objc(SpikeSdk)
|
|
6
6
|
class SpikeSdk: RCTEventEmitter {
|
|
7
|
-
|
|
7
|
+
|
|
8
|
+
override static func requiresMainQueueSetup() -> Bool {
|
|
9
|
+
return true
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
private var connections: [String: SpikeConnection] = [:]
|
|
13
|
+
|
|
8
14
|
override init() {
|
|
9
15
|
super.init()
|
|
10
|
-
|
|
11
|
-
Spike.shared.delegate = self
|
|
12
16
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
+
|
|
18
|
+
// MARK: Spike SDK level
|
|
19
|
+
|
|
20
|
+
@objc(createConnection:
|
|
21
|
+
withAppId:
|
|
22
|
+
withAuthToken:
|
|
23
|
+
withCustomerEndUserId:
|
|
24
|
+
withUseLogger:
|
|
25
|
+
withResolver:withRejecter:)
|
|
26
|
+
func createConnection(uuid: String,
|
|
27
|
+
appId: String,
|
|
28
|
+
authToken: String,
|
|
29
|
+
customerEndUserId: String,
|
|
30
|
+
useLogger: Bool,
|
|
31
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
32
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
33
|
+
Task {
|
|
34
|
+
do {
|
|
35
|
+
let logger = useLogger ? createLogger(connectionUUID: uuid) : nil
|
|
36
|
+
let spikeConnection = try await Spike.createConnection(
|
|
37
|
+
appId: appId,
|
|
38
|
+
authToken: authToken,
|
|
39
|
+
customerEndUserId: customerEndUserId,
|
|
40
|
+
logger: logger)
|
|
41
|
+
connections[uuid] = spikeConnection
|
|
42
|
+
resolve(Void())
|
|
43
|
+
} catch let error {
|
|
44
|
+
spikeReject(with: error, reject: reject)
|
|
45
|
+
}
|
|
46
|
+
}
|
|
17
47
|
}
|
|
18
|
-
|
|
19
|
-
@objc(
|
|
20
|
-
|
|
21
|
-
|
|
48
|
+
|
|
49
|
+
@objc(createWebhookConnection:
|
|
50
|
+
withAppId:
|
|
51
|
+
withAuthToken:
|
|
52
|
+
withCustomerEndUserId:
|
|
53
|
+
withCallbackUrl:
|
|
54
|
+
withUseLogger:
|
|
55
|
+
withResolver:
|
|
56
|
+
withRejecter:)
|
|
57
|
+
func createWebhookConnection(uuid: String,
|
|
58
|
+
appId: String,
|
|
59
|
+
authToken: String,
|
|
60
|
+
customerEndUserId: String,
|
|
61
|
+
callbackUrl: String,
|
|
62
|
+
useLogger: Bool,
|
|
63
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
64
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
65
|
+
guard let url = URL(string: callbackUrl) else {
|
|
66
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
67
|
+
return
|
|
68
|
+
}
|
|
69
|
+
Task {
|
|
70
|
+
do {
|
|
71
|
+
let logger = useLogger ? createLogger(connectionUUID: uuid) : nil
|
|
72
|
+
let spikeConnection = try await Spike.createConnection(
|
|
73
|
+
appId: appId,
|
|
74
|
+
authToken: authToken,
|
|
75
|
+
customerEndUserId: customerEndUserId,
|
|
76
|
+
callbackUrl: url,
|
|
77
|
+
logger: logger)
|
|
78
|
+
connections[uuid] = spikeConnection
|
|
79
|
+
resolve(uuid)
|
|
80
|
+
} catch let error {
|
|
81
|
+
spikeReject(with: error, reject: reject)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
22
84
|
}
|
|
23
|
-
|
|
24
|
-
@objc(
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
85
|
+
|
|
86
|
+
@objc(unpackConnection:
|
|
87
|
+
withConnection:
|
|
88
|
+
withUseLogger:
|
|
89
|
+
withResolver:
|
|
90
|
+
withRejecter:)
|
|
91
|
+
func unpackConnection(uuid: String,
|
|
92
|
+
connection: String,
|
|
93
|
+
useLogger: Bool,
|
|
94
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
95
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
96
|
+
Task {
|
|
97
|
+
do {
|
|
98
|
+
let logger = useLogger ? createLogger(connectionUUID: uuid) : nil
|
|
99
|
+
let spikeConnection = try await Spike.unpackConnection(connection: connection,
|
|
100
|
+
logger: logger)
|
|
101
|
+
connections[uuid] = spikeConnection
|
|
102
|
+
resolve(uuid)
|
|
103
|
+
} catch let error {
|
|
104
|
+
spikeReject(with: error, reject: reject)
|
|
105
|
+
}
|
|
106
|
+
}
|
|
29
107
|
}
|
|
30
108
|
|
|
31
|
-
@objc(
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
109
|
+
@objc(getBackgroundConnections:
|
|
110
|
+
withRejecter:)
|
|
111
|
+
func getBackgroundConnections(resolve: @escaping RCTPromiseResolveBlock,
|
|
112
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
113
|
+
Task {
|
|
114
|
+
do {
|
|
115
|
+
let spikeConnections = try await Spike.getBackgroundConnections()
|
|
116
|
+
var connectionsUUIDs: [String] = []
|
|
117
|
+
for connection in spikeConnections {
|
|
118
|
+
let uuid = UUID().uuidString
|
|
119
|
+
connections[uuid] = connection
|
|
120
|
+
connectionsUUIDs.append(uuid)
|
|
121
|
+
}
|
|
122
|
+
resolve(connectionsUUIDs)
|
|
123
|
+
} catch let error {
|
|
124
|
+
spikeReject(with: error, reject: reject)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
37
127
|
}
|
|
38
|
-
|
|
39
|
-
@objc(
|
|
40
|
-
|
|
41
|
-
|
|
128
|
+
|
|
129
|
+
@objc(ensurePermissionsAreGranted:
|
|
130
|
+
withResolver:
|
|
131
|
+
withRejecter:)
|
|
132
|
+
func ensurePermissionsAreGranted(permissions: [String],
|
|
133
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
134
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
135
|
+
Task {
|
|
136
|
+
do {
|
|
137
|
+
let dataTypes = permissions.map { SpikeDataTypeMapper.mapDataType($0) }
|
|
138
|
+
try await Spike.ensurePermissionsAreGranted(permissions: dataTypes)
|
|
139
|
+
resolve(Void())
|
|
140
|
+
} catch let error {
|
|
141
|
+
spikeReject(with: error, reject: reject)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
42
144
|
}
|
|
43
145
|
|
|
44
|
-
@objc(
|
|
45
|
-
func
|
|
46
|
-
Spike.
|
|
146
|
+
@objc(initialize)
|
|
147
|
+
func initialize() {
|
|
148
|
+
// Spike.configure()
|
|
47
149
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
150
|
+
|
|
151
|
+
// MARK: SpikeConnection level
|
|
152
|
+
|
|
153
|
+
@objc(getAppId:
|
|
154
|
+
withResolver:
|
|
155
|
+
withRejecter:)
|
|
156
|
+
func getAppId(connectionUUID: String,
|
|
157
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
158
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
159
|
+
guard let connection = connections[connectionUUID] else {
|
|
160
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
161
|
+
return
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
do {
|
|
165
|
+
let value = try connection.getAppId()
|
|
166
|
+
resolve(value)
|
|
167
|
+
} catch let error {
|
|
168
|
+
spikeReject(with: error, reject: reject)
|
|
169
|
+
}
|
|
53
170
|
}
|
|
54
171
|
|
|
55
|
-
@objc(
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
172
|
+
@objc(getSpikeEndUserId:
|
|
173
|
+
withResolver:
|
|
174
|
+
withRejecter:)
|
|
175
|
+
func getSpikeEndUserId(connectionUUID: String,
|
|
176
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
177
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
178
|
+
guard let connection = connections[connectionUUID] else {
|
|
179
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
180
|
+
return
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
do {
|
|
184
|
+
let value = try connection.getSpikeEndUserId()
|
|
185
|
+
resolve(value)
|
|
186
|
+
} catch let error {
|
|
187
|
+
spikeReject(with: error, reject: reject)
|
|
188
|
+
}
|
|
61
189
|
}
|
|
62
190
|
|
|
63
|
-
@objc(
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
191
|
+
@objc(getCustomerEndUserId:
|
|
192
|
+
withResolver:
|
|
193
|
+
withRejecter:)
|
|
194
|
+
func getCustomerEndUserId(connectionUUID: String,
|
|
195
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
196
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
197
|
+
guard let connection = connections[connectionUUID] else {
|
|
198
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
199
|
+
return
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
do {
|
|
203
|
+
let value = try connection.getCustomerEndUserId()
|
|
204
|
+
resolve(value)
|
|
205
|
+
} catch let error {
|
|
206
|
+
spikeReject(with: error, reject: reject)
|
|
70
207
|
}
|
|
71
208
|
}
|
|
72
209
|
|
|
73
|
-
@objc(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
210
|
+
@objc(close:
|
|
211
|
+
withResolver:
|
|
212
|
+
withRejecter:)
|
|
213
|
+
func close(connectionUUID: String,
|
|
214
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
215
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
216
|
+
guard let connection = connections[connectionUUID] else {
|
|
217
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
218
|
+
return
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
do {
|
|
222
|
+
try connection.close()
|
|
223
|
+
resolve(Void())
|
|
224
|
+
} catch let error {
|
|
225
|
+
spikeReject(with: error, reject: reject)
|
|
77
226
|
}
|
|
78
227
|
}
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
228
|
+
|
|
229
|
+
@objc(pack:
|
|
230
|
+
withResolver:
|
|
231
|
+
withRejecter:)
|
|
232
|
+
func pack(connectionUUID: String,
|
|
233
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
234
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
235
|
+
guard let connection = connections[connectionUUID] else {
|
|
236
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
237
|
+
return
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
do {
|
|
241
|
+
let value = try connection.pack()
|
|
242
|
+
resolve(value)
|
|
243
|
+
} catch let error {
|
|
244
|
+
spikeReject(with: error, reject: reject)
|
|
245
|
+
}
|
|
92
246
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
247
|
+
|
|
248
|
+
@objc(extractData:
|
|
249
|
+
withDataType:
|
|
250
|
+
withResolver:
|
|
251
|
+
withRejecter:)
|
|
252
|
+
func extractData(connectionUUID: String,
|
|
253
|
+
dataType: String,
|
|
254
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
255
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
256
|
+
guard let connection = connections[connectionUUID] else {
|
|
257
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
258
|
+
return
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
Task {
|
|
262
|
+
do {
|
|
263
|
+
let result = try await SpikeDataTypeMapper.extractData(dataType,
|
|
264
|
+
connection: connection)
|
|
265
|
+
if let dataString = result {
|
|
266
|
+
resolve(dataString)
|
|
267
|
+
} else {
|
|
268
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
269
|
+
}
|
|
270
|
+
} catch let error {
|
|
271
|
+
spikeReject(with: error, reject: reject)
|
|
272
|
+
}
|
|
273
|
+
}
|
|
96
274
|
}
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
275
|
+
|
|
276
|
+
@objc(extractDataInRange:
|
|
277
|
+
withDataType:
|
|
278
|
+
withFromDateMillis:
|
|
279
|
+
withToDateMillis:
|
|
280
|
+
withResolver:
|
|
281
|
+
withRejecter:)
|
|
282
|
+
func extractDataInRange(connectionUUID: String,
|
|
283
|
+
dataType: String,
|
|
284
|
+
fromDateMillis: Double,
|
|
285
|
+
toDateMillis: Double,
|
|
286
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
287
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
288
|
+
guard let connection = connections[connectionUUID] else {
|
|
289
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
290
|
+
return
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
Task {
|
|
294
|
+
do {
|
|
295
|
+
let fromDate = Date(timeIntervalSince1970: fromDateMillis/1000)
|
|
296
|
+
let toDate = Date(timeIntervalSince1970: toDateMillis/1000)
|
|
297
|
+
let result = try await SpikeDataTypeMapper.extractDataInRange(dataType,
|
|
298
|
+
connection: connection,
|
|
299
|
+
from: fromDate,
|
|
300
|
+
to: toDate)
|
|
301
|
+
if let dataString = result {
|
|
302
|
+
resolve(dataString)
|
|
303
|
+
} else {
|
|
304
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
305
|
+
}
|
|
306
|
+
} catch let error {
|
|
307
|
+
spikeReject(with: error, reject: reject)
|
|
125
308
|
}
|
|
126
309
|
}
|
|
127
310
|
}
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
extension SpikeSdk: SpikeDelegate {
|
|
131
311
|
|
|
132
|
-
|
|
133
|
-
|
|
312
|
+
// MARK: SpikeWebhookConnection level
|
|
313
|
+
|
|
314
|
+
@objc(getCallbackUrl:
|
|
315
|
+
withResolver:
|
|
316
|
+
withRejecter:)
|
|
317
|
+
func getCallbackUrl(connectionUUID: String,
|
|
318
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
319
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
320
|
+
guard let connection = connections[connectionUUID] as? SpikeWebhookConnection else {
|
|
321
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
322
|
+
return
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
do {
|
|
326
|
+
let value = try connection.getCallbackUrl()
|
|
327
|
+
resolve(value.absoluteString)
|
|
328
|
+
} catch let error {
|
|
329
|
+
spikeReject(with: error, reject: reject)
|
|
330
|
+
}
|
|
134
331
|
}
|
|
135
332
|
|
|
136
|
-
|
|
137
|
-
|
|
333
|
+
@objc(extractAndPostData:
|
|
334
|
+
withDataType:
|
|
335
|
+
withResolver:
|
|
336
|
+
withRejecter:)
|
|
337
|
+
func extractAndPostData(connectionUUID: String,
|
|
338
|
+
dataType: String,
|
|
339
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
340
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
341
|
+
guard let connection = connections[connectionUUID] as? SpikeWebhookConnection else {
|
|
342
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
343
|
+
return
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
Task {
|
|
347
|
+
do {
|
|
348
|
+
let result = try await SpikeDataTypeMapper.extractAndPostData(dataType,
|
|
349
|
+
connection: connection)
|
|
350
|
+
if let dataString = result {
|
|
351
|
+
resolve(dataString)
|
|
352
|
+
} else {
|
|
353
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
354
|
+
}
|
|
355
|
+
} catch let error {
|
|
356
|
+
spikeReject(with: error, reject: reject)
|
|
357
|
+
}
|
|
358
|
+
}
|
|
138
359
|
}
|
|
139
360
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
361
|
+
@objc(extractAndPostDataInRange:
|
|
362
|
+
withDataType:
|
|
363
|
+
withFromDateMillis:
|
|
364
|
+
withToDateMillis:
|
|
365
|
+
withResolver:
|
|
366
|
+
withRejecter:)
|
|
367
|
+
func extractAndPostDataInRange(connectionUUID: String,
|
|
368
|
+
dataType: String,
|
|
369
|
+
fromDateMillis: Double,
|
|
370
|
+
toDateMillis: Double,
|
|
371
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
372
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
373
|
+
guard let connection = connections[connectionUUID] as? SpikeWebhookConnection else {
|
|
374
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
375
|
+
return
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
Task {
|
|
379
|
+
do {
|
|
380
|
+
let fromDate = Date(timeIntervalSince1970: fromDateMillis/1000)
|
|
381
|
+
let toDate = Date(timeIntervalSince1970: toDateMillis/1000)
|
|
382
|
+
let result = try await SpikeDataTypeMapper.extractAndPostDataInRange(dataType,
|
|
383
|
+
connection: connection,
|
|
384
|
+
from: fromDate,
|
|
385
|
+
to: toDate)
|
|
386
|
+
if let dataString = result {
|
|
387
|
+
resolve(dataString)
|
|
388
|
+
} else {
|
|
389
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
390
|
+
}
|
|
391
|
+
} catch let error {
|
|
392
|
+
spikeReject(with: error, reject: reject)
|
|
393
|
+
}
|
|
145
394
|
}
|
|
146
395
|
}
|
|
147
396
|
|
|
148
|
-
|
|
149
|
-
|
|
397
|
+
@objc(enableBackgroundDelivery:
|
|
398
|
+
withDataTypes:
|
|
399
|
+
withResolver:
|
|
400
|
+
withRejecter:)
|
|
401
|
+
func enableBackgroundDelivery(connectionUUID: String,
|
|
402
|
+
dataTypes: [String],
|
|
403
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
404
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
405
|
+
guard let connection = connections[connectionUUID] as? SpikeWebhookConnection else {
|
|
406
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
407
|
+
return
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
Task {
|
|
411
|
+
do {
|
|
412
|
+
let types = dataTypes.map { SpikeDataTypeMapper.mapDataType($0) }
|
|
413
|
+
try await connection.enableBackgroundDelivery(dataTypes: types)
|
|
414
|
+
resolve(Void())
|
|
415
|
+
} catch let error {
|
|
416
|
+
spikeReject(with: error, reject: reject)
|
|
417
|
+
}
|
|
418
|
+
}
|
|
150
419
|
}
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
420
|
+
|
|
421
|
+
@objc(getBackgroundDeliveryDataTypes:
|
|
422
|
+
withResolver:
|
|
423
|
+
withRejecter:)
|
|
424
|
+
func getBackgroundDeliveryDataTypes(connectionUUID: String,
|
|
425
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
426
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
427
|
+
guard let connection = connections[connectionUUID] as? SpikeWebhookConnection else {
|
|
428
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
429
|
+
return
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
Task {
|
|
433
|
+
do {
|
|
434
|
+
let dataTypes = try await connection.getBackgroundDeliveryDataTypes()
|
|
435
|
+
let dataTypesString = dataTypes.map { SpikeDataTypeMapper.mapDataTypeToString($0) }
|
|
436
|
+
resolve(dataTypesString)
|
|
437
|
+
} catch let error {
|
|
438
|
+
spikeReject(with: error, reject: reject)
|
|
439
|
+
}
|
|
157
440
|
}
|
|
158
441
|
}
|
|
159
442
|
|
|
160
|
-
|
|
161
|
-
|
|
443
|
+
@objc(setListener:
|
|
444
|
+
withResolver:
|
|
445
|
+
withRejecter:)
|
|
446
|
+
func setListener(connectionUUID: String,
|
|
447
|
+
resolve: @escaping RCTPromiseResolveBlock,
|
|
448
|
+
reject: @escaping RCTPromiseRejectBlock) {
|
|
449
|
+
guard let connection = connections[connectionUUID] as? SpikeWebhookConnection else {
|
|
450
|
+
spikeReject(with: SpikeWrapperException(), reject: reject)
|
|
451
|
+
return
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
do {
|
|
455
|
+
let listener = createListener(connectionUUID: connectionUUID)
|
|
456
|
+
try connection.setListener(listener: listener)
|
|
457
|
+
resolve(Void())
|
|
458
|
+
} catch let error {
|
|
459
|
+
spikeReject(with: error, reject: reject)
|
|
460
|
+
}
|
|
162
461
|
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
462
|
+
|
|
463
|
+
// MARK: Supported events
|
|
464
|
+
|
|
465
|
+
override func supportedEvents() -> [String]! {
|
|
466
|
+
return [
|
|
467
|
+
"onDebug",
|
|
468
|
+
"onInfo",
|
|
469
|
+
"onError",
|
|
470
|
+
"onSubmissionFailure",
|
|
471
|
+
]
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// MARK: Private methods
|
|
475
|
+
|
|
476
|
+
private func createLogger(connectionUUID: String) -> SpikeLogger {
|
|
477
|
+
return SpikeConnectionLogger(connectionUUID: connectionUUID) { [weak self] connectionUUID, level, message in
|
|
478
|
+
let body = [
|
|
479
|
+
"connectionUUID": connectionUUID,
|
|
480
|
+
"message": message
|
|
481
|
+
]
|
|
482
|
+
switch level {
|
|
483
|
+
case .debug:
|
|
484
|
+
self?.sendEvent(withName: "onDebug", body: body)
|
|
485
|
+
case .info:
|
|
486
|
+
self?.sendEvent(withName: "onInfo", body: body)
|
|
487
|
+
case .error:
|
|
488
|
+
self?.sendEvent(withName: "onError", body: body)
|
|
489
|
+
}
|
|
169
490
|
}
|
|
170
491
|
}
|
|
171
492
|
|
|
172
|
-
func
|
|
173
|
-
|
|
493
|
+
private func createListener(connectionUUID: String) -> SpikeWebhookConnectionListener {
|
|
494
|
+
return SpikeConnectionListener(connectionUUID: connectionUUID) { [weak self] connectionUUID, webhookJob, exception in
|
|
495
|
+
let jobString = try? String(data: JSONEncoder().encode(webhookJob), encoding: .utf8)
|
|
496
|
+
let body = [
|
|
497
|
+
"connectionUUID": connectionUUID,
|
|
498
|
+
"exception": SpikeExceptionMapper.handleSpikeError(exception),
|
|
499
|
+
"webhookJob": jobString ?? ""
|
|
500
|
+
]
|
|
501
|
+
self?.sendEvent(withName: "onSubmissionFailure", body: body)
|
|
502
|
+
}
|
|
174
503
|
}
|
|
175
|
-
|
|
176
|
-
func
|
|
177
|
-
|
|
504
|
+
|
|
505
|
+
private func spikeReject(with error: Error, reject: RCTPromiseRejectBlock) {
|
|
506
|
+
let errorString = SpikeExceptionMapper.handleSpikeError(error)
|
|
507
|
+
reject(errorString, errorString, error)
|
|
178
508
|
}
|
|
509
|
+
|
|
179
510
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["DataModels/SpikeActivitiesStreamDataEntry.ts"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["DataModels/SpikeActivitiesSummaryDataEntry.ts"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["DataModels/SpikeBreathingDataEntry.ts"],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":[],"sourceRoot":"../../../src","sources":["DataModels/SpikeCaloriesDataEntry.ts"],"mappings":""}
|