@kingstinct/react-native-healthkit 7.0.0 → 7.0.2

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 (37) hide show
  1. package/README.md +9 -3
  2. package/app.plugin.js +23 -4
  3. package/lib/commonjs/hooks/useMostRecentCategorySample.js.map +1 -1
  4. package/lib/commonjs/hooks/useMostRecentQuantitySample.js.map +1 -1
  5. package/lib/commonjs/native-types.js +87 -2
  6. package/lib/commonjs/native-types.js.map +1 -1
  7. package/lib/commonjs/utils/queryCategorySamples.js +2 -1
  8. package/lib/commonjs/utils/queryCategorySamples.js.map +1 -1
  9. package/lib/commonjs/utils/queryQuantitySamples.js +2 -1
  10. package/lib/commonjs/utils/queryQuantitySamples.js.map +1 -1
  11. package/lib/commonjs/utils/requestAuthorization.js +1 -0
  12. package/lib/commonjs/utils/requestAuthorization.js.map +1 -1
  13. package/lib/module/hooks/useMostRecentCategorySample.js.map +1 -1
  14. package/lib/module/hooks/useMostRecentQuantitySample.js.map +1 -1
  15. package/lib/module/native-types.js +107 -2
  16. package/lib/module/native-types.js.map +1 -1
  17. package/lib/module/utils/queryCategorySamples.js +2 -1
  18. package/lib/module/utils/queryCategorySamples.js.map +1 -1
  19. package/lib/module/utils/queryQuantitySamples.js +2 -1
  20. package/lib/module/utils/queryQuantitySamples.js.map +1 -1
  21. package/lib/module/utils/requestAuthorization.js +1 -0
  22. package/lib/module/utils/requestAuthorization.js.map +1 -1
  23. package/lib/typescript/src/hooks/useMostRecentCategorySample.d.ts +3 -2
  24. package/lib/typescript/src/hooks/useMostRecentQuantitySample.d.ts +3 -2
  25. package/lib/typescript/src/native-types.d.ts +96 -1
  26. package/lib/typescript/src/utils/getMostRecentCategorySample.d.ts +1 -1
  27. package/lib/typescript/src/utils/getMostRecentQuantitySample.d.ts +1 -1
  28. package/lib/typescript/src/utils/queryCategorySamples.d.ts +3 -3
  29. package/lib/typescript/src/utils/queryQuantitySamples.d.ts +3 -3
  30. package/lib/typescript/src/utils/requestAuthorization.d.ts +1 -0
  31. package/package.json +1 -1
  32. package/src/hooks/useMostRecentCategorySample.ts +3 -2
  33. package/src/hooks/useMostRecentQuantitySample.ts +3 -2
  34. package/src/native-types.ts +102 -1
  35. package/src/utils/queryCategorySamples.ts +5 -4
  36. package/src/utils/queryQuantitySamples.ts +5 -4
  37. package/src/utils/requestAuthorization.ts +1 -0
@@ -2,12 +2,21 @@ import { NativeEventEmitter, NativeModules } from 'react-native'
2
2
 
3
3
  import type { EmitterSubscription, NativeModule } from 'react-native'
4
4
 
5
+ /**
6
+ * See https://developer.apple.com/documentation/healthkit/hkworkouttypeidentifier
7
+ */
5
8
  export const HKWorkoutTypeIdentifier = 'HKWorkoutTypeIdentifier' as const
6
9
  export const HKAudiogramTypeIdentifier = 'HKAudiogramTypeIdentifier' as const
10
+
11
+ /**
12
+ * See https://developer.apple.com/documentation/healthkit/hkworkoutroutetypeidentifier
13
+ */
7
14
  export const HKWorkoutRouteTypeIdentifier = 'HKWorkoutRouteTypeIdentifier' as const
8
15
  export const HKDataTypeIdentifierHeartbeatSeries = 'HKDataTypeIdentifierHeartbeatSeries' as const
9
16
 
10
- // Straight mapping to https://developer.apple.com/documentation/healthkit/hkquantitytypeidentifier
17
+ /**
18
+ * See https://developer.apple.com/documentation/healthkit/hkquantitytypeidentifier
19
+ */
11
20
  export enum HKQuantityTypeIdentifier {
12
21
  bodyMassIndex = 'HKQuantityTypeIdentifierBodyMassIndex',
13
22
  bodyFatPercentage = 'HKQuantityTypeIdentifierBodyFatPercentage', // Scalar(Percent, 0.0 - 1.0), Discrete
@@ -127,6 +136,18 @@ export enum HKQuantityTypeIdentifier {
127
136
  waterTemperature = 'HKQuantityTypeIdentifierWaterTemperature', // Temperature, Discrete
128
137
 
129
138
  appleSleepingWristTemperature = 'HKQuantityTypeIdentifierAppleSleepingWristTemperature', // Temperature, Discrete
139
+
140
+ timeInDaylight = 'HKQuantityTypeIdentifierTimeInDaylight', // Time, Cumulative
141
+
142
+ physicalEffort = 'HKQuantityTypeIdentifierPhysicalEffort', // Scalar(Percent, 0.0 - 1.0), Discrete
143
+
144
+ cyclingSpeed = 'HKQuantityTypeIdentifierCyclingSpeed', // Length/Time, Discrete
145
+
146
+ cyclingPower = 'HKQuantityTypeIdentifierCyclingPower', // Power, Discrete
147
+
148
+ cyclingFunctionalThresholdPower = 'HKQuantityTypeIdentifierCyclingFunctionalThresholdPower', // Power, Discrete
149
+
150
+ cyclingCadence = 'HKQuantityTypeIdentifierCyclingCadence', // Scalar(Count)/Time, Discrete
130
151
  }
131
152
 
132
153
  export type TypeToUnitMapping = {
@@ -143,11 +164,17 @@ export enum HKHeartRateMotionContext {
143
164
  sedentary = 1,
144
165
  }
145
166
 
167
+ /**
168
+ * See https://developer.apple.com/documentation/healthkit/hkcorrelationtypeidentifier
169
+ */
146
170
  export enum HKCorrelationTypeIdentifier {
147
171
  bloodPressure = 'HKCorrelationTypeIdentifierBloodPressure',
148
172
  food = 'HKCorrelationTypeIdentifierFood',
149
173
  }
150
174
 
175
+ /**
176
+ * See https://developer.apple.com/documentation/healthkit/hkcategorytypeidentifier
177
+ */
151
178
  export enum HKCategoryTypeIdentifier {
152
179
  sleepAnalysis = 'HKCategoryTypeIdentifierSleepAnalysis',
153
180
  appleStandHour = 'HKCategoryTypeIdentifierAppleStandHour',
@@ -160,6 +187,9 @@ export enum HKCategoryTypeIdentifier {
160
187
  highHeartRateEvent = 'HKCategoryTypeIdentifierHighHeartRateEvent',
161
188
  lowHeartRateEvent = 'HKCategoryTypeIdentifierLowHeartRateEvent',
162
189
  irregularHeartRhythmEvent = 'HKCategoryTypeIdentifierIrregularHeartRhythmEvent',
190
+ /**
191
+ * @deprecated Use environmentalAudioExposureEvent instead.
192
+ */
163
193
  audioExposureEvent = 'HKCategoryTypeIdentifierAudioExposureEvent',
164
194
  toothbrushingEvent = 'HKCategoryTypeIdentifierToothbrushingEvent',
165
195
  lowCardioFitnessEvent = 'HKCategoryTypeIdentifierLowCardioFitnessEvent',
@@ -390,12 +420,18 @@ export interface HKWorkoutMetadata
390
420
  readonly HKIndoorWorkout?: HKIndoorWorkout;
391
421
  }
392
422
 
423
+ /**
424
+ * See https://developer.apple.com/documentation/healthkit/hkauthorizationrequeststatus
425
+ */
393
426
  export enum HKAuthorizationRequestStatus {
394
427
  unknown = 0,
395
428
  shouldRequest = 1,
396
429
  unnecessary = 2,
397
430
  }
398
431
 
432
+ /**
433
+ * See https://developer.apple.com/documentation/healthkit/hkauthorizationstatus
434
+ */
399
435
  export enum HKAuthorizationStatus {
400
436
  notDetermined = 0,
401
437
  sharingDenied = 1,
@@ -410,6 +446,9 @@ export type HKQuantity<
410
446
  readonly quantity: number;
411
447
  };
412
448
 
449
+ /**
450
+ * See https://developer.apple.com/documentation/healthkit/hkbloodtype
451
+ */
413
452
  export enum HKBloodType {
414
453
  notSet = 0,
415
454
  aPositive = 1,
@@ -422,6 +461,9 @@ export enum HKBloodType {
422
461
  oNegative = 8,
423
462
  }
424
463
 
464
+ /**
465
+ * See https://developer.apple.com/documentation/healthkit/hkbiologicalsex
466
+ */
425
467
  export enum HKBiologicalSex {
426
468
  notSet = 0,
427
469
  female = 1,
@@ -429,6 +471,9 @@ export enum HKBiologicalSex {
429
471
  other = 3,
430
472
  }
431
473
 
474
+ /**
475
+ * See https://developer.apple.com/documentation/healthkit/hkfitzpatrickskintype
476
+ */
432
477
  export enum HKFitzpatrickSkinType {
433
478
  notSet = 0,
434
479
  I = 1,
@@ -439,6 +484,9 @@ export enum HKFitzpatrickSkinType {
439
484
  VI = 6,
440
485
  }
441
486
 
487
+ /**
488
+ * See https://developer.apple.com/documentation/healthkit/hkstatisticsoptions
489
+ */
442
490
  export enum HKStatisticsOptions {
443
491
  cumulativeSum = 'cumulativeSum',
444
492
  discreteAverage = 'discreteAverage',
@@ -466,6 +514,9 @@ export type QueryStatisticsResponseRaw<
466
514
  readonly duration?: HKQuantity<HKQuantityTypeIdentifier, TimeUnit>;
467
515
  };
468
516
 
517
+ /**
518
+ * https://developer.apple.com/documentation/healthkit/hkcategoryvaluecervicalmucusquality
519
+ */
469
520
  export enum HKCategoryValueCervicalMucusQuality {
470
521
  dry = 1,
471
522
  sticky = 2,
@@ -474,6 +525,9 @@ export enum HKCategoryValueCervicalMucusQuality {
474
525
  eggWhite = 5,
475
526
  }
476
527
 
528
+ /**
529
+ * See https://developer.apple.com/documentation/healthkit/hkcategoryvaluemenstrualflow
530
+ */
477
531
  export enum HKCategoryValueMenstrualFlow {
478
532
  unspecified = 1,
479
533
  none = 5,
@@ -482,6 +536,9 @@ export enum HKCategoryValueMenstrualFlow {
482
536
  heavy = 4,
483
537
  }
484
538
 
539
+ /**
540
+ * See https://developer.apple.com/documentation/healthkit/hkcategoryvalueovulationtestresult
541
+ */
485
542
  export enum HKCategoryValueOvulationTestResult {
486
543
  negative = 1,
487
544
  luteinizingHormoneSurge = 2,
@@ -489,6 +546,9 @@ export enum HKCategoryValueOvulationTestResult {
489
546
  estrogenSurge = 4,
490
547
  }
491
548
 
549
+ /**
550
+ * See https://developer.apple.com/documentation/healthkit/hkcategoryvaluesleepanalysis
551
+ */
492
552
  export enum HKCategoryValueSleepAnalysis {
493
553
  inBed = 0,
494
554
  asleepUnspecified = 1,
@@ -498,6 +558,9 @@ export enum HKCategoryValueSleepAnalysis {
498
558
  asleepREM = 5
499
559
  }
500
560
 
561
+ /**
562
+ * https://developer.apple.com/documentation/healthkit/hkcategoryvalueappetitechanges
563
+ */
501
564
  export enum HKCategoryValueAppetiteChanges {
502
565
  decreased = 2,
503
566
  increased = 3,
@@ -505,11 +568,17 @@ export enum HKCategoryValueAppetiteChanges {
505
568
  unspecified = 0,
506
569
  }
507
570
 
571
+ /**
572
+ * https://developer.apple.com/documentation/healthkit/hkcategoryvaluepresence
573
+ */
508
574
  export enum HKCategoryValuePresence {
509
575
  notPresent = 1,
510
576
  present = 0,
511
577
  }
512
578
 
579
+ /**
580
+ * See https://developer.apple.com/documentation/healthkit/hkcategoryvalueseverity
581
+ */
513
582
  export enum HKCategoryValueSeverity {
514
583
  notPresent = 1,
515
584
  mild = 2,
@@ -518,10 +587,16 @@ export enum HKCategoryValueSeverity {
518
587
  unspecified = 0,
519
588
  }
520
589
 
590
+ /**
591
+ * See https://developer.apple.com/documentation/healthkit/hkcategoryvalue/notapplicable
592
+ */
521
593
  export enum HKCategoryValueNotApplicable {
522
594
  notApplicable = 0,
523
595
  }
524
596
 
597
+ /**
598
+ * See https://developer.apple.com/documentation/healthkit/hkcategoryvalue
599
+ */
525
600
  export type HKCategoryValue =
526
601
  | HKCategoryValueAppetiteChanges
527
602
  | HKCategoryValueCervicalMucusQuality
@@ -533,6 +608,9 @@ export type HKCategoryValue =
533
608
  | HKCategoryValueSleepAnalysis
534
609
  | number;
535
610
 
611
+ /**
612
+ * See https://developer.apple.com/documentation/healthkit/hkinsulindeliveryreason
613
+ */
536
614
  export enum HKInsulinDeliveryReason {
537
615
  basal = 1,
538
616
  bolus = 2,
@@ -728,6 +806,9 @@ export type HKCategoryValueForIdentifier<T extends HKCategoryTypeIdentifier> =
728
806
  ? HKCategoryValueAppleStandHour
729
807
  : number;
730
808
 
809
+ /**
810
+ * See https://developer.apple.com/documentation/healthkit/hkcategoryvaluepregnancytestresult
811
+ */
731
812
  enum HKCategoryValuePregnancyTestResult {
732
813
  positive = 2,
733
814
  negative = 1,
@@ -990,6 +1071,9 @@ export type HKUnit =
990
1071
  | `${TimeUnit}`
991
1072
  | `${VolumeUnit}`;
992
1073
 
1074
+ /**
1075
+ * See https://developer.apple.com/documentation/healthkit/hkdevice
1076
+ */
993
1077
  export type HKDevice = {
994
1078
  readonly name: string; // ex: "Apple Watch"
995
1079
  readonly firmwareVersion: string | null;
@@ -1001,11 +1085,17 @@ export type HKDevice = {
1001
1085
  readonly udiDeviceIdentifier: string | null
1002
1086
  };
1003
1087
 
1088
+ /**
1089
+ * See https://developer.apple.com/documentation/healthkit/hkobject/1615781-source
1090
+ */
1004
1091
  export type HKSource = {
1005
1092
  readonly name: string;
1006
1093
  readonly bundleIdentifier: string;
1007
1094
  };
1008
1095
 
1096
+ /**
1097
+ * See https://developer.apple.com/documentation/healthkit/hkobject/1615483-sourcerevision
1098
+ */
1009
1099
  export type HKSourceRevision = {
1010
1100
  readonly source: HKSource;
1011
1101
  readonly version: string;
@@ -1013,6 +1103,9 @@ export type HKSourceRevision = {
1013
1103
  readonly productType?: string;
1014
1104
  };
1015
1105
 
1106
+ /**
1107
+ * See https://developer.apple.com/documentation/healthkit/hkquantitysample
1108
+ */
1016
1109
  export type HKQuantitySampleRaw<
1017
1110
  TQuantityIdentifier extends HKQuantityTypeIdentifier = HKQuantityTypeIdentifier,
1018
1111
  TUnit extends UnitForIdentifier<TQuantityIdentifier> = UnitForIdentifier<TQuantityIdentifier>
@@ -1163,6 +1256,7 @@ export type HKCorrelationRaw<TIdentifier extends HKCorrelationTypeIdentifier> =
1163
1256
 
1164
1257
  type QueryId = string;
1165
1258
 
1259
+ /** See https://developer.apple.com/documentation/healthkit/hkupdatefrequency */
1166
1260
  export enum HKUpdateFrequency {
1167
1261
  immediate = 1,
1168
1262
  hourly = 2,
@@ -1189,6 +1283,7 @@ export type WorkoutRoute = {
1189
1283
  };
1190
1284
 
1191
1285
  type ReactNativeHealthkitTypeNative = {
1286
+ /** See https://developer.apple.com/documentation/healthkit/hkhealthstore/1614180-ishealthdataavailable */
1192
1287
  isHealthDataAvailable(): Promise<boolean>;
1193
1288
  canAccessProtectedData(): Promise<boolean>;
1194
1289
  getBloodType(): Promise<HKBloodType>;
@@ -1197,13 +1292,16 @@ type ReactNativeHealthkitTypeNative = {
1197
1292
  getFitzpatrickSkinType(): Promise<HKFitzpatrickSkinType>;
1198
1293
  readonly getWheelchairUse: () => Promise<HKWheelchairUse>;
1199
1294
 
1295
+ /** See https://developer.apple.com/documentation/healthkit/hkhealthstore/1614175-enablebackgrounddelivery */
1200
1296
  readonly enableBackgroundDelivery: (
1201
1297
  typeIdentifier: HKSampleTypeIdentifier,
1202
1298
  updateFrequency: HKUpdateFrequency
1203
1299
  ) => Promise<boolean>;
1300
+ /** https://developer.apple.com/documentation/healthkit/hkhealthstore/1614177-disablebackgrounddelivery */
1204
1301
  readonly disableBackgroundDelivery: (
1205
1302
  typeIdentifier: HKSampleTypeIdentifier
1206
1303
  ) => Promise<boolean>;
1304
+ /** See https://developer.apple.com/documentation/healthkit/hkhealthstore/1614158-disableallbackgrounddelivery */
1207
1305
  readonly disableAllBackgroundDelivery: () => Promise<boolean>;
1208
1306
 
1209
1307
  readonly saveCorrelationSample: <
@@ -1240,11 +1338,14 @@ type ReactNativeHealthkitTypeNative = {
1240
1338
  identifier: HKSampleTypeIdentifier
1241
1339
  ): Promise<QueryId>;
1242
1340
  unsubscribeQuery(queryId: QueryId): Promise<boolean>;
1341
+ /** See https://developer.apple.com/documentation/healthkit/hkhealthstore/1614154-authorizationstatus */
1243
1342
  authorizationStatusFor(type: HealthkitReadAuthorization): Promise<HKAuthorizationStatus>;
1343
+ /** See https://developer.apple.com/documentation/healthkit/hkhealthstore/2994346-getrequeststatusforauthorization */
1244
1344
  getRequestStatusForAuthorization(
1245
1345
  write: WritePermissions,
1246
1346
  read: ReadPermissions
1247
1347
  ): Promise<HKAuthorizationRequestStatus>;
1348
+ /** See https://developer.apple.com/documentation/healthkit/hkhealthstore/1614152-requestauthorization */
1248
1349
  requestAuthorization(
1249
1350
  write: WritePermissions,
1250
1351
  read: ReadPermissions
@@ -1,13 +1,14 @@
1
+ import deserializeCategorySample from './deserializeCategorySample'
1
2
  import prepareOptions from './prepareOptions'
2
3
  import Native from '../native-types'
3
4
 
4
- import type { HKCategoryTypeIdentifier, HKCategorySampleRaw } from '../native-types'
5
- import type { GenericQueryOptions } from '../types'
5
+ import type { HKCategoryTypeIdentifier } from '../native-types'
6
+ import type { GenericQueryOptions, HKCategorySample } from '../types'
6
7
 
7
8
  export type QueryCategorySamplesFn = <T extends HKCategoryTypeIdentifier>(
8
9
  identifier: T,
9
10
  options: Omit<GenericQueryOptions, 'anchor'>
10
- ) => Promise<readonly HKCategorySampleRaw<T>[]>;
11
+ ) => Promise<readonly HKCategorySample<T>[]>;
11
12
 
12
13
  const queryCategorySamples: QueryCategorySamplesFn = async (
13
14
  identifier,
@@ -22,7 +23,7 @@ const queryCategorySamples: QueryCategorySamplesFn = async (
22
23
  opts.ascending,
23
24
  )
24
25
 
25
- return raw
26
+ return raw.map(deserializeCategorySample)
26
27
  }
27
28
 
28
29
  export default queryCategorySamples
@@ -1,11 +1,12 @@
1
+ import deserializeQuantitySample from './deserializeSample'
1
2
  import ensureUnit from './ensureUnit'
2
3
  import prepareOptions from './prepareOptions'
3
4
  import Native from '../native-types'
4
5
 
5
6
  import type {
6
- HKQuantityTypeIdentifier, UnitForIdentifier, HKQuantitySampleRaw,
7
+ HKQuantityTypeIdentifier, UnitForIdentifier,
7
8
  } from '../native-types'
8
- import type { GenericQueryOptions } from '../types'
9
+ import type { GenericQueryOptions, HKQuantitySample } from '../types'
9
10
 
10
11
  export type QueryQuantitySamplesFn = <
11
12
  TIdentifier extends HKQuantityTypeIdentifier,
@@ -13,7 +14,7 @@ export type QueryQuantitySamplesFn = <
13
14
  >(
14
15
  identifier: TIdentifier,
15
16
  options: Omit<GenericQueryOptions, 'anchor'> & { readonly unit?: TUnit }
16
- ) => Promise<readonly HKQuantitySampleRaw<TIdentifier>[]>;
17
+ ) => Promise<readonly HKQuantitySample<TIdentifier>[]>;
17
18
 
18
19
  const queryQuantitySamples: QueryQuantitySamplesFn = async (
19
20
  identifier,
@@ -31,7 +32,7 @@ const queryQuantitySamples: QueryQuantitySamplesFn = async (
31
32
  opts.ascending,
32
33
  )
33
34
 
34
- return result
35
+ return result.map(deserializeQuantitySample)
35
36
  }
36
37
 
37
38
  export default queryQuantitySamples
@@ -4,6 +4,7 @@ import type {
4
4
  HealthkitReadAuthorization, HealthkitWriteAuthorization, ReadPermissions, WritePermissions,
5
5
  } from '../native-types'
6
6
 
7
+ /** See https://developer.apple.com/documentation/healthkit/hkhealthstore/1614152-requestauthorization */
7
8
  const requestAuthorization = async (
8
9
  read: readonly HealthkitReadAuthorization[],
9
10
  write: readonly HealthkitWriteAuthorization[] = [],