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.
Files changed (198) hide show
  1. package/README.md +271 -146
  2. package/android/build.gradle +14 -1
  3. package/android/gradle.properties +2 -1
  4. package/android/src/main/java/com/spikesdk/SpikeConnectionLogger.kt +37 -0
  5. package/android/src/main/java/com/spikesdk/SpikeMappers.kt +61 -0
  6. package/android/src/main/java/com/spikesdk/SpikeSdkModule.kt +413 -8
  7. package/ios/SpikeConnectionListener.swift +17 -0
  8. package/ios/SpikeConnectionLogger.swift +43 -0
  9. package/ios/SpikeDataTypeMapper.swift +207 -0
  10. package/ios/SpikeExceptionMapper.swift +34 -0
  11. package/ios/SpikeSdk.m +84 -17
  12. package/ios/SpikeSdk.swift +460 -129
  13. package/lib/commonjs/DataModels/SpikeActivitiesStreamDataEntry.js +2 -0
  14. package/lib/commonjs/DataModels/SpikeActivitiesStreamDataEntry.js.map +1 -0
  15. package/lib/commonjs/DataModels/SpikeActivitiesSummaryDataEntry.js +2 -0
  16. package/lib/commonjs/DataModels/SpikeActivitiesSummaryDataEntry.js.map +1 -0
  17. package/lib/commonjs/DataModels/SpikeBreathingDataEntry.js +2 -0
  18. package/lib/commonjs/DataModels/SpikeBreathingDataEntry.js.map +1 -0
  19. package/lib/commonjs/DataModels/SpikeCaloriesDataEntry.js +2 -0
  20. package/lib/commonjs/DataModels/SpikeCaloriesDataEntry.js.map +1 -0
  21. package/lib/commonjs/{SpikeInterface.js → DataModels/SpikeData.js} +1 -1
  22. package/lib/commonjs/DataModels/SpikeData.js.map +1 -0
  23. package/lib/commonjs/DataModels/SpikeDataTypes.js +22 -0
  24. package/lib/commonjs/DataModels/SpikeDataTypes.js.map +1 -0
  25. package/lib/commonjs/DataModels/SpikeDistanceDataEntry.js +2 -0
  26. package/lib/commonjs/DataModels/SpikeDistanceDataEntry.js.map +1 -0
  27. package/lib/commonjs/DataModels/SpikeGlucoseDataEntry.js +2 -0
  28. package/lib/commonjs/DataModels/SpikeGlucoseDataEntry.js.map +1 -0
  29. package/lib/commonjs/DataModels/SpikeHeartDataEntry.js +2 -0
  30. package/lib/commonjs/DataModels/SpikeHeartDataEntry.js.map +1 -0
  31. package/lib/commonjs/DataModels/SpikeOxygenSaturationDataEntry.js +2 -0
  32. package/lib/commonjs/DataModels/SpikeOxygenSaturationDataEntry.js.map +1 -0
  33. package/lib/commonjs/DataModels/SpikeSleepDataEntry.js +2 -0
  34. package/lib/commonjs/DataModels/SpikeSleepDataEntry.js.map +1 -0
  35. package/lib/commonjs/DataModels/SpikeStepsDataEntry.js +2 -0
  36. package/lib/commonjs/DataModels/SpikeStepsDataEntry.js.map +1 -0
  37. package/lib/commonjs/DataModels/SpikeWebhookJob.js +2 -0
  38. package/lib/commonjs/DataModels/SpikeWebhookJob.js.map +1 -0
  39. package/lib/commonjs/DataTypes/SpikeDataType.js +53 -0
  40. package/lib/commonjs/DataTypes/SpikeDataType.js.map +1 -0
  41. package/lib/commonjs/Spike.js +61 -46
  42. package/lib/commonjs/Spike.js.map +1 -1
  43. package/lib/commonjs/SpikeConnection.js +104 -0
  44. package/lib/commonjs/SpikeConnection.js.map +1 -0
  45. package/lib/commonjs/SpikeException.js +27 -0
  46. package/lib/commonjs/SpikeException.js.map +1 -0
  47. package/lib/commonjs/SpikeLogger.js +6 -0
  48. package/lib/commonjs/{SpikeDataType.js.map → SpikeLogger.js.map} +1 -1
  49. package/lib/commonjs/SpikeSdk.js +1 -1
  50. package/lib/commonjs/SpikeSdk.js.map +1 -1
  51. package/lib/commonjs/SpikeWebhookConnection.js +119 -0
  52. package/lib/commonjs/SpikeWebhookConnection.js.map +1 -0
  53. package/lib/commonjs/SpikeWebhookConnectionListener.js +6 -0
  54. package/lib/commonjs/{SpikeResultData.js.map → SpikeWebhookConnectionListener.js.map} +1 -1
  55. package/lib/commonjs/index.js +26 -7
  56. package/lib/commonjs/index.js.map +1 -1
  57. package/lib/module/DataModels/SpikeActivitiesStreamDataEntry.js +2 -0
  58. package/lib/module/DataModels/SpikeActivitiesStreamDataEntry.js.map +1 -0
  59. package/lib/module/DataModels/SpikeActivitiesSummaryDataEntry.js +2 -0
  60. package/lib/module/DataModels/SpikeActivitiesSummaryDataEntry.js.map +1 -0
  61. package/lib/module/DataModels/SpikeBreathingDataEntry.js +2 -0
  62. package/lib/module/DataModels/SpikeBreathingDataEntry.js.map +1 -0
  63. package/lib/module/DataModels/SpikeCaloriesDataEntry.js +2 -0
  64. package/lib/module/DataModels/SpikeCaloriesDataEntry.js.map +1 -0
  65. package/lib/module/DataModels/SpikeData.js +2 -0
  66. package/lib/module/DataModels/SpikeData.js.map +1 -0
  67. package/lib/module/DataModels/SpikeDataTypes.js +15 -0
  68. package/lib/module/DataModels/SpikeDataTypes.js.map +1 -0
  69. package/lib/module/DataModels/SpikeDistanceDataEntry.js +2 -0
  70. package/lib/module/DataModels/SpikeDistanceDataEntry.js.map +1 -0
  71. package/lib/module/DataModels/SpikeGlucoseDataEntry.js +2 -0
  72. package/lib/module/DataModels/SpikeGlucoseDataEntry.js.map +1 -0
  73. package/lib/module/DataModels/SpikeHeartDataEntry.js +2 -0
  74. package/lib/module/DataModels/SpikeHeartDataEntry.js.map +1 -0
  75. package/lib/module/DataModels/SpikeOxygenSaturationDataEntry.js +2 -0
  76. package/lib/module/DataModels/SpikeOxygenSaturationDataEntry.js.map +1 -0
  77. package/lib/module/DataModels/SpikeSleepDataEntry.js +2 -0
  78. package/lib/module/DataModels/SpikeSleepDataEntry.js.map +1 -0
  79. package/lib/module/DataModels/SpikeStepsDataEntry.js +2 -0
  80. package/lib/module/DataModels/SpikeStepsDataEntry.js.map +1 -0
  81. package/lib/module/DataModels/SpikeWebhookJob.js +2 -0
  82. package/lib/module/DataModels/SpikeWebhookJob.js.map +1 -0
  83. package/lib/module/DataTypes/SpikeDataType.js +36 -0
  84. package/lib/module/DataTypes/SpikeDataType.js.map +1 -0
  85. package/lib/module/Spike.js +56 -45
  86. package/lib/module/Spike.js.map +1 -1
  87. package/lib/module/SpikeConnection.js +97 -0
  88. package/lib/module/SpikeConnection.js.map +1 -0
  89. package/lib/module/SpikeException.js +11 -0
  90. package/lib/module/SpikeException.js.map +1 -0
  91. package/lib/module/SpikeLogger.js +2 -0
  92. package/lib/module/{SpikeDataType.js.map → SpikeLogger.js.map} +1 -1
  93. package/lib/module/SpikeSdk.js +1 -2
  94. package/lib/module/SpikeSdk.js.map +1 -1
  95. package/lib/module/SpikeWebhookConnection.js +112 -0
  96. package/lib/module/SpikeWebhookConnection.js.map +1 -0
  97. package/lib/module/SpikeWebhookConnectionListener.js +2 -0
  98. package/lib/{commonjs/SpikeSleepAnalysisResultData.js.map → module/SpikeWebhookConnectionListener.js.map} +1 -1
  99. package/lib/module/index.js +13 -5
  100. package/lib/module/index.js.map +1 -1
  101. package/lib/typescript/{SpikeWorkoutResultData.d.ts → DataModels/SpikeActivitiesStreamDataEntry.d.ts} +15 -14
  102. package/lib/typescript/DataModels/SpikeActivitiesStreamDataEntry.d.ts.map +1 -0
  103. package/lib/typescript/{SpikeResultData.d.ts → DataModels/SpikeActivitiesSummaryDataEntry.d.ts} +5 -8
  104. package/lib/typescript/DataModels/SpikeActivitiesSummaryDataEntry.d.ts.map +1 -0
  105. package/lib/typescript/DataModels/SpikeBreathingDataEntry.d.ts +13 -0
  106. package/lib/typescript/DataModels/SpikeBreathingDataEntry.d.ts.map +1 -0
  107. package/lib/typescript/DataModels/SpikeCaloriesDataEntry.d.ts +15 -0
  108. package/lib/typescript/DataModels/SpikeCaloriesDataEntry.d.ts.map +1 -0
  109. package/lib/typescript/DataModels/SpikeData.d.ts +25 -0
  110. package/lib/typescript/DataModels/SpikeData.d.ts.map +1 -0
  111. package/lib/typescript/DataModels/SpikeDataTypes.d.ts +15 -0
  112. package/lib/typescript/DataModels/SpikeDataTypes.d.ts.map +1 -0
  113. package/lib/typescript/DataModels/SpikeDistanceDataEntry.d.ts +13 -0
  114. package/lib/typescript/DataModels/SpikeDistanceDataEntry.d.ts.map +1 -0
  115. package/lib/typescript/DataModels/SpikeGlucoseDataEntry.d.ts +4 -0
  116. package/lib/typescript/DataModels/SpikeGlucoseDataEntry.d.ts.map +1 -0
  117. package/lib/typescript/DataModels/SpikeHeartDataEntry.d.ts +32 -0
  118. package/lib/typescript/DataModels/SpikeHeartDataEntry.d.ts.map +1 -0
  119. package/lib/typescript/DataModels/SpikeOxygenSaturationDataEntry.d.ts +15 -0
  120. package/lib/typescript/DataModels/SpikeOxygenSaturationDataEntry.d.ts.map +1 -0
  121. package/lib/typescript/{SpikeSleepAnalysisResultData.d.ts → DataModels/SpikeSleepDataEntry.d.ts} +10 -13
  122. package/lib/typescript/DataModels/SpikeSleepDataEntry.d.ts.map +1 -0
  123. package/lib/typescript/DataModels/SpikeStepsDataEntry.d.ts +13 -0
  124. package/lib/typescript/DataModels/SpikeStepsDataEntry.d.ts.map +1 -0
  125. package/lib/typescript/DataModels/SpikeWebhookJob.d.ts +11 -0
  126. package/lib/typescript/DataModels/SpikeWebhookJob.d.ts.map +1 -0
  127. package/lib/typescript/DataTypes/SpikeDataType.d.ts +50 -0
  128. package/lib/typescript/DataTypes/SpikeDataType.d.ts.map +1 -0
  129. package/lib/typescript/Spike.d.ts +12 -13
  130. package/lib/typescript/Spike.d.ts.map +1 -1
  131. package/lib/typescript/SpikeConnection.d.ts +23 -0
  132. package/lib/typescript/SpikeConnection.d.ts.map +1 -0
  133. package/lib/typescript/SpikeException.d.ts +21 -0
  134. package/lib/typescript/SpikeException.d.ts.map +1 -0
  135. package/lib/typescript/SpikeLogger.d.ts +10 -0
  136. package/lib/typescript/SpikeLogger.d.ts.map +1 -0
  137. package/lib/typescript/SpikeSdk.d.ts.map +1 -1
  138. package/lib/typescript/SpikeWebhookConnection.d.ts +21 -0
  139. package/lib/typescript/SpikeWebhookConnection.d.ts.map +1 -0
  140. package/lib/typescript/SpikeWebhookConnectionListener.d.ts +6 -0
  141. package/lib/typescript/SpikeWebhookConnectionListener.d.ts.map +1 -0
  142. package/lib/typescript/index.d.ts +16 -7
  143. package/lib/typescript/index.d.ts.map +1 -1
  144. package/package.json +1 -1
  145. package/react-native-spike-sdk.podspec +2 -2
  146. package/src/{SpikeWorkoutResultData.ts → DataModels/SpikeActivitiesStreamDataEntry.ts} +14 -12
  147. package/src/{SpikeResultData.ts → DataModels/SpikeActivitiesSummaryDataEntry.ts} +4 -4
  148. package/src/DataModels/SpikeBreathingDataEntry.ts +12 -0
  149. package/src/DataModels/SpikeCaloriesDataEntry.ts +13 -0
  150. package/src/DataModels/SpikeData.ts +35 -0
  151. package/src/DataModels/SpikeDataTypes.ts +27 -0
  152. package/src/DataModels/SpikeDistanceDataEntry.ts +12 -0
  153. package/src/DataModels/SpikeGlucoseDataEntry.ts +3 -0
  154. package/src/DataModels/SpikeHeartDataEntry.ts +34 -0
  155. package/src/DataModels/SpikeOxygenSaturationDataEntry.ts +14 -0
  156. package/src/{SpikeSleepAnalysisResultData.ts → DataModels/SpikeSleepDataEntry.ts} +9 -7
  157. package/src/DataModels/SpikeStepsDataEntry.ts +11 -0
  158. package/src/DataModels/SpikeWebhookJob.ts +10 -0
  159. package/src/DataTypes/SpikeDataType.ts +87 -0
  160. package/src/Spike.ts +132 -73
  161. package/src/SpikeConnection.ts +151 -0
  162. package/src/SpikeException.ts +11 -0
  163. package/src/SpikeLogger.ts +11 -0
  164. package/src/SpikeSdk.ts +1 -3
  165. package/src/SpikeWebhookConnection.ts +201 -0
  166. package/src/SpikeWebhookConnectionListener.ts +9 -0
  167. package/src/index.ts +32 -20
  168. package/lib/commonjs/SpikeDataType.js +0 -2
  169. package/lib/commonjs/SpikeInterface.js.map +0 -1
  170. package/lib/commonjs/SpikeResultData.js +0 -2
  171. package/lib/commonjs/SpikeSleepAnalysisResultData.js +0 -2
  172. package/lib/commonjs/SpikeWorkoutResultData.js +0 -2
  173. package/lib/commonjs/SpikeWorkoutResultData.js.map +0 -1
  174. package/lib/commonjs/useSpikeEvents.js +0 -69
  175. package/lib/commonjs/useSpikeEvents.js.map +0 -1
  176. package/lib/module/SpikeDataType.js +0 -2
  177. package/lib/module/SpikeInterface.js +0 -2
  178. package/lib/module/SpikeInterface.js.map +0 -1
  179. package/lib/module/SpikeResultData.js +0 -2
  180. package/lib/module/SpikeResultData.js.map +0 -1
  181. package/lib/module/SpikeSleepAnalysisResultData.js +0 -2
  182. package/lib/module/SpikeSleepAnalysisResultData.js.map +0 -1
  183. package/lib/module/SpikeWorkoutResultData.js +0 -2
  184. package/lib/module/SpikeWorkoutResultData.js.map +0 -1
  185. package/lib/module/useSpikeEvents.js +0 -62
  186. package/lib/module/useSpikeEvents.js.map +0 -1
  187. package/lib/typescript/SpikeDataType.d.ts +0 -2
  188. package/lib/typescript/SpikeDataType.d.ts.map +0 -1
  189. package/lib/typescript/SpikeInterface.d.ts +0 -13
  190. package/lib/typescript/SpikeInterface.d.ts.map +0 -1
  191. package/lib/typescript/SpikeResultData.d.ts.map +0 -1
  192. package/lib/typescript/SpikeSleepAnalysisResultData.d.ts.map +0 -1
  193. package/lib/typescript/SpikeWorkoutResultData.d.ts.map +0 -1
  194. package/lib/typescript/useSpikeEvents.d.ts +0 -17
  195. package/lib/typescript/useSpikeEvents.d.ts.map +0 -1
  196. package/src/SpikeDataType.ts +0 -12
  197. package/src/SpikeInterface.ts +0 -30
  198. package/src/useSpikeEvents.ts +0 -89
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-spike-sdk",
3
- "version": "0.2.10",
3
+ "version": "1.0.0",
4
4
  "description": "Spike API for health and productivity data from wearables and IoT devices",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
@@ -5,7 +5,7 @@ folly_compiler_flags = '-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1
5
5
 
6
6
  Pod::Spec.new do |s|
7
7
  s.name = "react-native-spike-sdk"
8
- s.version = "0.2.10"
8
+ s.version = "1.0.0"
9
9
  s.summary = "Spike API for health and productivity data from wearables and IoT devices"
10
10
 
11
11
  s.description = <<-DESC
@@ -25,7 +25,7 @@ Pod::Spec.new do |s|
25
25
  s.swift_version = "5"
26
26
 
27
27
  s.dependency "React-Core"
28
- s.dependency "SpikeSDK", "0.2.14"
28
+ s.dependency "SpikeSDK", "1.0.1"
29
29
 
30
30
  # Don't install the dependencies when we run `pod install` in the old architecture.
31
31
  if ENV['RCT_NEW_ARCH_ENABLED'] == '1' then
@@ -1,22 +1,15 @@
1
- export type SpikeWorkoutResult =
2
- | { status: string }
3
- | { data: SpikeWorkoutResultData[] };
4
-
5
- export interface SpikeWorkoutResultData {
1
+ export type SpikeActivitiesStreamDataEntry = {
6
2
  time_start?: string;
7
3
  time_end?: string;
8
4
  timezone_offset?: number;
9
5
  activity_name?: string;
10
- activity_type_id?: string;
11
- provider_activity_name?: string;
12
- provider_activity_type_id?: number;
6
+ activity_type_id?: number;
13
7
  avg_hr?: number;
14
8
  max_hr?: number;
15
9
  min_hr?: number;
16
10
  avg_hr_variability?: number;
17
11
  calories?: number;
18
- source?: string;
19
- hr_zones?: string[];
12
+ hr_zones?: HRZone[];
20
13
  moving_time?: number;
21
14
  total_elevation_gain?: number;
22
15
  elev_high?: number;
@@ -29,5 +22,14 @@ export interface SpikeWorkoutResultData {
29
22
  device_watts?: boolean;
30
23
  max_watts?: number;
31
24
  weighted_average_watts?: number;
32
- map?: any;
33
- }
25
+ map?: string;
26
+ source?: string;
27
+ data_type?: string;
28
+ };
29
+
30
+ type HRZone = {
31
+ max?: number;
32
+ min?: number;
33
+ minutes?: number;
34
+ name?: string;
35
+ };
@@ -1,12 +1,11 @@
1
- export type SpikeResult = { status: string } | { data: SpikeResultData[] };
2
-
3
- export interface SpikeResultData {
1
+ export type SpikeActivitiesSummaryDataEntry = {
4
2
  date?: string;
5
3
  calories_bmr?: number;
6
4
  calories_total?: number;
7
5
  calories_active?: number;
8
6
  steps?: number;
9
7
  daily_movement?: number;
8
+ distance?: number;
10
9
  low?: number;
11
10
  medium?: number;
12
11
  high?: number;
@@ -24,4 +23,5 @@ export interface SpikeResultData {
24
23
  medium_stress_duration?: number;
25
24
  high_stress_duration?: number;
26
25
  source?: string;
27
- }
26
+ data_type?: string;
27
+ };
@@ -0,0 +1,12 @@
1
+ export type SpikeBreathingDataEntry = {
2
+ date?: string;
3
+ avg_value?: number;
4
+ intraday_data?: IntradayData[];
5
+ source?: string;
6
+ data_type?: string;
7
+ };
8
+
9
+ type IntradayData = {
10
+ endTime: string;
11
+ value: number;
12
+ };
@@ -0,0 +1,13 @@
1
+ export type SpikeCaloriesDataEntry = {
2
+ date?: string;
3
+ value?: number;
4
+ intraday_data?: IntradayData[];
5
+ source?: string;
6
+ data_type?: string;
7
+ };
8
+ type IntradayData = {
9
+ level: number;
10
+ mets: number;
11
+ time: string;
12
+ value: number;
13
+ };
@@ -0,0 +1,35 @@
1
+ import type { SpikeActivitiesStreamDataEntry } from './SpikeActivitiesStreamDataEntry';
2
+ import type { SpikeActivitiesSummaryDataEntry } from './SpikeActivitiesSummaryDataEntry';
3
+ import type { SpikeBreathingDataEntry } from './SpikeBreathingDataEntry';
4
+ import type { SpikeCaloriesDataEntry } from './SpikeCaloriesDataEntry';
5
+ import type { SpikeDistanceDataEntry } from './SpikeDistanceDataEntry';
6
+ import type { SpikeGlucoseDataEntry } from './SpikeGlucoseDataEntry';
7
+ import type { SpikeHeartDataEntry } from './SpikeHeartDataEntry';
8
+ import type { SpikeOxygenSaturationDataEntry } from './SpikeOxygenSaturationDataEntry';
9
+ import type { SpikeSleepDataEntry } from './SpikeSleepDataEntry';
10
+ import type { SpikeStepsDataEntry } from './SpikeStepsDataEntry';
11
+
12
+ export type SpikeDataEntry =
13
+ | SpikeActivitiesSummaryDataEntry
14
+ | SpikeActivitiesStreamDataEntry
15
+ | SpikeBreathingDataEntry
16
+ | SpikeCaloriesDataEntry
17
+ | SpikeDistanceDataEntry
18
+ | SpikeGlucoseDataEntry
19
+ | SpikeHeartDataEntry
20
+ | SpikeOxygenSaturationDataEntry
21
+ | SpikeSleepDataEntry
22
+ | SpikeStepsDataEntry;
23
+ export interface SpikeData<DataEntry extends SpikeDataEntry> {
24
+ from: Date;
25
+ to: Date;
26
+ endUserId: string;
27
+ collectedAt: Date;
28
+ sources: SpikeSource[];
29
+ entries: DataEntry[];
30
+ }
31
+
32
+ interface SpikeSource {
33
+ name: string;
34
+ status: string;
35
+ }
@@ -0,0 +1,27 @@
1
+ import {
2
+ SpikeActivitiesStreamDataType,
3
+ SpikeActivitiesSummaryDataType,
4
+ SpikeBreathingDataType,
5
+ SpikeCaloriesDataType,
6
+ SpikeDistanceDataType,
7
+ SpikeGlucoseDataType,
8
+ SpikeHeartDataType,
9
+ SpikeOxygenSaturationDataType,
10
+ SpikeSleepDataType,
11
+ SpikeStepsDataType,
12
+ SpikeBodyDataType,
13
+ } from '../DataTypes/SpikeDataType';
14
+
15
+ export const SpikeDataTypes = {
16
+ activitiesSummary: new SpikeActivitiesSummaryDataType(),
17
+ activitiesStream: new SpikeActivitiesStreamDataType(),
18
+ breathing: new SpikeBreathingDataType(),
19
+ calories: new SpikeCaloriesDataType(),
20
+ distance: new SpikeDistanceDataType(),
21
+ glucose: new SpikeGlucoseDataType(),
22
+ heart: new SpikeHeartDataType(),
23
+ oxygenSaturation: new SpikeOxygenSaturationDataType(),
24
+ sleep: new SpikeSleepDataType(),
25
+ steps: new SpikeStepsDataType(),
26
+ body: new SpikeBodyDataType(),
27
+ };
@@ -0,0 +1,12 @@
1
+ export type SpikeDistanceDataEntry = {
2
+ date?: string;
3
+ value?: number;
4
+ intraday_data?: IntradayData[];
5
+ source?: string;
6
+ data_type?: string;
7
+ };
8
+
9
+ type IntradayData = {
10
+ time: string;
11
+ value: number;
12
+ };
@@ -0,0 +1,3 @@
1
+ export type SpikeGlucoseDataEntry = {
2
+ date?: string;
3
+ };
@@ -0,0 +1,34 @@
1
+ export type SpikeHeartDataEntry = {
2
+ date?: string;
3
+ resting_hr?: number;
4
+ min_hr?: number;
5
+ avg_hr?: number;
6
+ max_hr?: number;
7
+ heart_rate_samples?: Sample[];
8
+ heart_rate_variability?: Variability;
9
+ intraday_hrv?: IntradayHrv[];
10
+ source?: string;
11
+ data_type?: string;
12
+ };
13
+
14
+ type Sample = {
15
+ time: string;
16
+ value: number;
17
+ };
18
+
19
+ type Variability = {
20
+ day_hrv?: number;
21
+ sleep_hrv?: number;
22
+ };
23
+
24
+ type IntradayHrv = {
25
+ time: string;
26
+ value?: Value;
27
+ };
28
+
29
+ type Value = {
30
+ rmssd?: number;
31
+ coverage?: number;
32
+ hf?: number;
33
+ lf?: number;
34
+ };
@@ -0,0 +1,14 @@
1
+ export type SpikeOxygenSaturationDataEntry = {
2
+ date?: string;
3
+ avg?: number;
4
+ min?: number;
5
+ max?: number;
6
+ intraday_data?: IntradayData[];
7
+ source?: string;
8
+ data_type?: string;
9
+ };
10
+
11
+ type IntradayData = {
12
+ time: string;
13
+ value: number;
14
+ };
@@ -1,8 +1,4 @@
1
- export type SpikeSleepAnalysisResult =
2
- | { status: string }
3
- | { data: SpikeSleepAnalysisResultData[] };
4
-
5
- export interface SpikeSleepAnalysisResultData {
1
+ export type SpikeSleepDataEntry = {
6
2
  date?: string;
7
3
  bedtime_start?: string;
8
4
  bedtime_end?: string;
@@ -23,5 +19,11 @@ export interface SpikeSleepAnalysisResultData {
23
19
  standardized_sleep_score?: number;
24
20
  source_specific_sleep_score?: number;
25
21
  source?: string;
26
- levels?: { date_time?: string; level?: string; seconds?: number }[];
27
- }
22
+ levels?: Levels[];
23
+ };
24
+
25
+ type Levels = {
26
+ date_time?: string;
27
+ level?: string;
28
+ seconds?: number;
29
+ };
@@ -0,0 +1,11 @@
1
+ export type SpikeStepsDataEntry = {
2
+ date?: string;
3
+ value?: number;
4
+ intraday_data?: IntradayData[];
5
+ source?: string;
6
+ data_type?: string;
7
+ };
8
+ type IntradayData = {
9
+ time: String;
10
+ value: number;
11
+ };
@@ -0,0 +1,10 @@
1
+ export interface SpikeWebhookJob {
2
+ notificationId?: string;
3
+ dataType: string;
4
+ payloadSize: number;
5
+ callbackUrl: URL;
6
+ dateFrom: Date;
7
+ dateTo: Date;
8
+ collectedAt: Date;
9
+ submittedAt?: Date;
10
+ }
@@ -0,0 +1,87 @@
1
+ import type { SpikeActivitiesStreamDataEntry } from '../DataModels/SpikeActivitiesStreamDataEntry';
2
+ import type { SpikeDataEntry } from '../DataModels/SpikeData';
3
+ import type { SpikeActivitiesSummaryDataEntry } from '../DataModels/SpikeActivitiesSummaryDataEntry';
4
+ import type { SpikeBreathingDataEntry } from '../DataModels/SpikeBreathingDataEntry';
5
+ import type { SpikeCaloriesDataEntry } from '../DataModels/SpikeCaloriesDataEntry';
6
+ import type { SpikeDistanceDataEntry } from '../DataModels/SpikeDistanceDataEntry';
7
+ import type { SpikeGlucoseDataEntry } from '../DataModels/SpikeGlucoseDataEntry';
8
+ import type { SpikeHeartDataEntry } from '../DataModels/SpikeHeartDataEntry';
9
+ import type { SpikeOxygenSaturationDataEntry } from '../DataModels/SpikeOxygenSaturationDataEntry';
10
+ import type { SpikeSleepDataEntry } from '../DataModels/SpikeSleepDataEntry';
11
+ import type { SpikeStepsDataEntry } from '../DataModels/SpikeStepsDataEntry';
12
+
13
+ type SpikeDataTypeValues =
14
+ | 'activities_summary'
15
+ | 'activities_stream'
16
+ | 'breathing'
17
+ | 'calories'
18
+ | 'distance'
19
+ | 'glucose'
20
+ | 'heart'
21
+ | 'oxygen_saturation'
22
+ | 'sleep'
23
+ | 'steps'
24
+ | 'body';
25
+
26
+ // @ts-ignore
27
+ export interface SpikeDataType<DataEntryType extends SpikeDataEntry> {
28
+ rawValue: SpikeDataTypeValues;
29
+ }
30
+
31
+ export class SpikeActivitiesStreamDataType
32
+ implements SpikeDataType<SpikeActivitiesStreamDataEntry>
33
+ {
34
+ rawValue: SpikeDataTypeValues = 'activities_stream';
35
+ }
36
+
37
+ export class SpikeActivitiesSummaryDataType
38
+ implements SpikeDataType<SpikeActivitiesSummaryDataEntry>
39
+ {
40
+ rawValue: SpikeDataTypeValues = 'activities_summary';
41
+ }
42
+
43
+ export class SpikeBreathingDataType
44
+ implements SpikeDataType<SpikeBreathingDataEntry>
45
+ {
46
+ rawValue: SpikeDataTypeValues = 'breathing';
47
+ }
48
+
49
+ export class SpikeCaloriesDataType
50
+ implements SpikeDataType<SpikeCaloriesDataEntry>
51
+ {
52
+ rawValue: SpikeDataTypeValues = 'calories';
53
+ }
54
+
55
+ export class SpikeDistanceDataType
56
+ implements SpikeDataType<SpikeDistanceDataEntry>
57
+ {
58
+ rawValue: SpikeDataTypeValues = 'distance';
59
+ }
60
+
61
+ export class SpikeGlucoseDataType
62
+ implements SpikeDataType<SpikeGlucoseDataEntry>
63
+ {
64
+ rawValue: SpikeDataTypeValues = 'glucose';
65
+ }
66
+
67
+ export class SpikeHeartDataType implements SpikeDataType<SpikeHeartDataEntry> {
68
+ rawValue: SpikeDataTypeValues = 'heart';
69
+ }
70
+
71
+ export class SpikeOxygenSaturationDataType
72
+ implements SpikeDataType<SpikeOxygenSaturationDataEntry>
73
+ {
74
+ rawValue: SpikeDataTypeValues = 'oxygen_saturation';
75
+ }
76
+
77
+ export class SpikeSleepDataType implements SpikeDataType<SpikeSleepDataEntry> {
78
+ rawValue: SpikeDataTypeValues = 'sleep';
79
+ }
80
+
81
+ export class SpikeStepsDataType implements SpikeDataType<SpikeStepsDataEntry> {
82
+ rawValue: SpikeDataTypeValues = 'steps';
83
+ }
84
+
85
+ export class SpikeBodyDataType implements SpikeDataType<SpikeDataEntry> {
86
+ rawValue: SpikeDataTypeValues = 'body';
87
+ }
package/src/Spike.ts CHANGED
@@ -1,77 +1,136 @@
1
- import type { SpikeDataType } from './SpikeDataType';
2
- import type { SpikeInterface } from './SpikeInterface';
1
+ import type { SpikeDataEntry } from './DataModels/SpikeData';
2
+ import type { SpikeDataType } from './DataTypes/SpikeDataType';
3
+ import { SpikeConnection } from './SpikeConnection';
4
+ import { SpikeException } from './SpikeException';
5
+ import type { SpikeLogger } from './SpikeLogger';
3
6
  import { SpikeSdk } from './SpikeSdk';
4
-
5
- export class Spike implements SpikeInterface {
6
- async isBackgroundUpdateEnabled(): Promise<boolean> {
7
- if (!SpikeSdk) return false;
8
-
9
- return SpikeSdk.isBackgroundUpdateEnabled();
10
- }
11
-
12
- enableDebug(): void {
13
- if (!SpikeSdk) return;
14
-
15
- SpikeSdk.enableDebug();
16
- }
17
-
18
- setup(
19
- clientId: string,
20
- authToken: string,
21
- userId: string,
22
- postbackURL?: string
23
- ): void {
24
- if (!SpikeSdk) return;
25
-
26
- if (postbackURL !== undefined) {
27
- SpikeSdk.setupWithURL(clientId, authToken, userId, postbackURL);
28
- } else {
29
- SpikeSdk.setup(clientId, authToken, userId);
30
- }
7
+ import { SpikeWebhookConnection } from './SpikeWebhookConnection';
8
+
9
+ const createConnection = async (
10
+ appId: string,
11
+ authToken: string,
12
+ customerEndUserId: string,
13
+ logger: SpikeLogger | null = null
14
+ ): Promise<SpikeConnection> => {
15
+ if (!SpikeSdk) throw new SpikeException();
16
+
17
+ const connectionUUID = generateUUID();
18
+ const spikeConnection = new SpikeConnection(connectionUUID, logger);
19
+
20
+ await SpikeSdk.createConnection(
21
+ connectionUUID,
22
+ appId,
23
+ authToken,
24
+ customerEndUserId,
25
+ !!logger
26
+ );
27
+
28
+ return spikeConnection;
29
+ };
30
+
31
+ const createWebhookConnection = async (
32
+ appId: string,
33
+ authToken: string,
34
+ customerEndUserId: string,
35
+ callbackUrl: string,
36
+ logger: SpikeLogger | null = null
37
+ ): Promise<SpikeWebhookConnection> => {
38
+ if (!SpikeSdk) throw new SpikeException();
39
+
40
+ const connectionUUID = generateUUID();
41
+ const spikeConnection = new SpikeWebhookConnection(connectionUUID, logger);
42
+
43
+ await SpikeSdk.createWebhookConnection(
44
+ connectionUUID,
45
+ appId,
46
+ authToken,
47
+ customerEndUserId,
48
+ callbackUrl,
49
+ !!logger
50
+ );
51
+
52
+ return spikeConnection;
53
+ };
54
+
55
+ const unpackConnection = async (
56
+ connection: string,
57
+ logger: SpikeLogger | null = null
58
+ ): Promise<SpikeConnection> => {
59
+ if (!SpikeSdk) throw new SpikeException();
60
+
61
+ const connectionUUID = generateUUID();
62
+ const webhookConnection = new SpikeWebhookConnection(connectionUUID, logger);
63
+
64
+ await SpikeSdk.unpackConnection(connectionUUID, connection, !!logger);
65
+
66
+ try {
67
+ await webhookConnection.getCallbackUrl();
68
+ return new SpikeWebhookConnection(connectionUUID, logger);
69
+ } catch (error) {
70
+ return new SpikeConnection(connectionUUID, logger);
31
71
  }
32
-
33
- async getCurrentUUID(): Promise<string | undefined> {
34
- if (!SpikeSdk) return undefined;
35
-
36
- const uuid: string = await SpikeSdk.getCurrentUUID();
37
- if (uuid) {
38
- return uuid;
39
- } else {
40
- return undefined;
72
+ };
73
+
74
+ const getBackgroundConnections = async (): Promise<
75
+ SpikeWebhookConnection[]
76
+ > => {
77
+ if (!SpikeSdk) throw new SpikeException();
78
+
79
+ const connectionUUIDs: string[] = await SpikeSdk.getBackgroundConnections();
80
+
81
+ const connections = connectionUUIDs.map(
82
+ (uuid) => new SpikeWebhookConnection(uuid)
83
+ );
84
+ return connections;
85
+ };
86
+
87
+ const ensurePermissionsAreGranted = async <DataEntry extends SpikeDataEntry>(
88
+ permissions: SpikeDataType<DataEntry>[]
89
+ ): Promise<void> => {
90
+ if (!SpikeSdk) throw new SpikeException();
91
+
92
+ await SpikeSdk.ensurePermissionsAreGranted(
93
+ permissions.map((permissionType) => permissionType.rawValue)
94
+ );
95
+ };
96
+
97
+ const initialize = () => {
98
+ if (!SpikeSdk) throw new SpikeException();
99
+
100
+ SpikeSdk.initialize();
101
+ };
102
+
103
+ function generateUUID() {
104
+ const S4 = function () {
105
+ let str = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVXZ';
106
+ let uuid = [];
107
+ for (let i = 0; i < 4; i++) {
108
+ uuid.push(str[Math.floor(Math.random() * str.length)]);
41
109
  }
42
- }
43
-
44
- clearData(): void {
45
- if (!SpikeSdk) return;
46
-
47
- SpikeSdk.clearData();
48
- }
49
-
50
- getData(dataTypes: SpikeDataType[]): void {
51
- if (!SpikeSdk) return;
52
-
53
- SpikeSdk.getData(dataTypes);
54
- }
55
-
56
- getDataInRange(
57
- dataTypes: SpikeDataType[],
58
- startDate: Date,
59
- endDate: Date
60
- ): void {
61
- if (!SpikeSdk) return;
62
-
63
- SpikeSdk.getDataInRange(dataTypes, startDate.getTime(), endDate.getTime());
64
- }
65
-
66
- async enableBackgroundDelivery(dataTypes: SpikeDataType[]): Promise<void> {
67
- if (!SpikeSdk) return;
68
-
69
- return SpikeSdk.enableBackgroundDelivery(dataTypes);
70
- }
71
-
72
- async disableAllBackgroundDelivery(): Promise<void> {
73
- if (!SpikeSdk) return;
74
-
75
- return SpikeSdk.disableAllBackgroundDelivery();
76
- }
110
+ return uuid.join('');
111
+ };
112
+
113
+ return (
114
+ S4() +
115
+ S4() +
116
+ '-' +
117
+ S4() +
118
+ '-' +
119
+ S4() +
120
+ '-' +
121
+ S4() +
122
+ '-' +
123
+ S4() +
124
+ S4() +
125
+ S4()
126
+ );
77
127
  }
128
+
129
+ export {
130
+ createConnection,
131
+ createWebhookConnection,
132
+ unpackConnection,
133
+ getBackgroundConnections,
134
+ ensurePermissionsAreGranted,
135
+ initialize,
136
+ };