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.
- 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 +50 -483
- package/ios/SpikeExceptionMapper.swift +4 -12
- package/ios/SpikeSdk.m +8 -79
- package/ios/SpikeSdk.swift +62 -419
- package/lib/commonjs/Spike.js +1 -57
- 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 +0 -71
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/v3/SpikeRNConnectionAPIv3.js +40 -17
- package/lib/commonjs/v3/SpikeRNConnectionAPIv3.js.map +1 -1
- package/lib/commonjs/version.js +1 -1
- package/lib/module/Spike.js +1 -55
- 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 +3 -8
- package/lib/module/index.js.map +1 -1
- package/lib/module/v3/SpikeRNConnectionAPIv3.js +40 -17
- package/lib/module/v3/SpikeRNConnectionAPIv3.js.map +1 -1
- package/lib/module/version.js +1 -1
- package/lib/typescript/Spike.d.ts +2 -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 +6 -25
- package/lib/typescript/index.d.ts.map +1 -1
- package/lib/typescript/v3/DataModels/BackgroundDeliveryConfig.d.ts +2 -0
- package/lib/typescript/v3/DataModels/BackgroundDeliveryConfig.d.ts.map +1 -1
- package/lib/typescript/v3/SpikeRNConnectionAPIv3.d.ts +34 -9
- package/lib/typescript/v3/SpikeRNConnectionAPIv3.d.ts.map +1 -1
- package/lib/typescript/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/Spike.ts +4 -89
- package/src/SpikeException.ts +13 -96
- package/src/index.ts +2 -61
- package/src/v3/DataModels/BackgroundDeliveryConfig.ts +2 -0
- package/src/v3/SpikeRNConnectionAPIv3.ts +82 -19
- 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.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(
|
|
@@ -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
|
|
package/lib/commonjs/Spike.js
CHANGED
|
@@ -3,9 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.setLogCallback = exports.isPackageInstalled = exports.isHealthDataAvailable = exports.
|
|
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) {
|