@kingstinct/react-native-healthkit 5.1.2 → 5.2.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 +28 -23
- package/android/.project +18 -1
- package/android/.settings/org.eclipse.buildship.core.prefs +4 -4
- package/ios/ReactNativeHealthkit.m +9 -0
- package/ios/ReactNativeHealthkit.swift +23 -7
- package/lib/commonjs/hooks/useHealthkitAuthorization.js.map +1 -1
- package/lib/commonjs/hooks/useHealthkitAuthorization.test.js +57 -0
- package/lib/commonjs/hooks/useHealthkitAuthorization.test.js.map +1 -0
- package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js +12 -19
- package/lib/commonjs/hooks/useIsHealthDataAvailable.test.js.map +1 -1
- package/lib/commonjs/index.ios.js +1 -0
- package/lib/commonjs/index.ios.js.map +1 -1
- package/lib/commonjs/index.js +3 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/jest.setup.js +29 -2
- package/lib/commonjs/jest.setup.js.map +1 -1
- package/lib/commonjs/native-types.js +27 -27
- package/lib/commonjs/native-types.js.map +1 -1
- package/lib/commonjs/test-utils.js +21 -0
- package/lib/commonjs/test-utils.js.map +1 -0
- package/lib/commonjs/utils/getPreferredUnit.js.map +1 -1
- package/lib/commonjs/utils/subscribeToChanges.js +4 -4
- package/lib/commonjs/utils/subscribeToChanges.js.map +1 -1
- package/lib/module/hooks/useHealthkitAuthorization.js.map +1 -1
- package/lib/module/hooks/useHealthkitAuthorization.test.js +45 -0
- package/lib/module/hooks/useHealthkitAuthorization.test.js.map +1 -0
- package/lib/module/hooks/useIsHealthDataAvailable.test.js +8 -16
- package/lib/module/hooks/useIsHealthDataAvailable.test.js.map +1 -1
- package/lib/module/index.ios.js +1 -0
- package/lib/module/index.ios.js.map +1 -1
- package/lib/module/index.js +3 -1
- package/lib/module/index.js.map +1 -1
- package/lib/module/jest.setup.js +29 -2
- package/lib/module/jest.setup.js.map +1 -1
- package/lib/module/native-types.js +27 -27
- package/lib/module/native-types.js.map +1 -1
- package/lib/module/test-utils.js +13 -0
- package/lib/module/test-utils.js.map +1 -0
- package/lib/module/utils/getPreferredUnit.js.map +1 -1
- package/lib/module/utils/subscribeToChanges.js +1 -2
- package/lib/module/utils/subscribeToChanges.js.map +1 -1
- package/lib/{src/types.js → typescript/src/hooks/useHealthkitAuthorization.test.d.ts} +0 -0
- package/lib/typescript/src/index.ios.d.ts +1 -0
- package/lib/typescript/src/native-types.d.ts +48 -46
- package/lib/typescript/src/test-utils.d.ts +2 -0
- package/lib/typescript/src/utils/getPreferredUnit.d.ts +1 -1
- package/package.json +8 -4
- package/src/hooks/useHealthkitAuthorization.test.ts +54 -0
- package/src/hooks/useHealthkitAuthorization.ts +1 -0
- package/src/hooks/useIsHealthDataAvailable.test.ts +9 -14
- package/src/index.ios.tsx +3 -1
- package/src/index.tsx +2 -0
- package/src/jest.setup.ts +32 -2
- package/src/native-types.ts +349 -159
- package/src/test-utils.ts +10 -0
- package/src/utils/getPreferredUnit.ts +2 -2
- package/src/utils/subscribeToChanges.ts +1 -2
- package/lib/example/App.js +0 -197
- package/lib/index.ios.js +0 -310
- package/lib/index.js +0 -44
- package/lib/native-types.js +0 -447
- package/lib/src/index.ios.js +0 -314
- package/lib/src/index.js +0 -45
- package/lib/src/native-types.js +0 -453
- package/lib/types.js +0 -1
|
File without changes
|
|
@@ -13,6 +13,7 @@ import saveWorkoutSample from './utils/saveWorkoutSample';
|
|
|
13
13
|
declare const Healthkit: {
|
|
14
14
|
authorizationStatusFor: (type: import("./native-types").HealthkitReadAuthorization) => Promise<boolean>;
|
|
15
15
|
isHealthDataAvailable: () => Promise<boolean>;
|
|
16
|
+
canAccessProtectedData: () => Promise<boolean>;
|
|
16
17
|
disableAllBackgroundDelivery: () => Promise<boolean>;
|
|
17
18
|
disableBackgroundDelivery: (typeIdentifier: import("./native-types").HKSampleTypeIdentifier) => Promise<boolean>;
|
|
18
19
|
enableBackgroundDelivery: (typeIdentifier: import("./native-types").HKSampleTypeIdentifier, updateFrequency: import("./native-types").HKUpdateFrequency) => Promise<boolean>;
|
|
@@ -445,7 +445,7 @@ export declare type MetadataMapperForCorrelationIdentifier<TCorrelationTypeIdent
|
|
|
445
445
|
readonly HKFoodType?: string;
|
|
446
446
|
} : HKGenericMetadata;
|
|
447
447
|
export declare type UnitForIdentifier<T extends HKQuantityTypeIdentifier> = T extends HKQuantityTypeIdentifier.bloodGlucose ? BloodGlucoseUnit : T extends HKQuantityTypeIdentifier.appleExerciseTime | HKQuantityTypeIdentifier.appleMoveTime | HKQuantityTypeIdentifier.appleStandTime ? TimeUnit : T extends HKQuantityTypeIdentifier.activeEnergyBurned | HKQuantityTypeIdentifier.basalEnergyBurned | HKQuantityTypeIdentifier.dietaryEnergyConsumed ? EnergyUnit : T extends HKQuantityTypeIdentifier.distanceCycling | HKQuantityTypeIdentifier.distanceDownhillSnowSports | HKQuantityTypeIdentifier.distanceSwimming | HKQuantityTypeIdentifier.distanceWalkingRunning | HKQuantityTypeIdentifier.distanceWheelchair | HKQuantityTypeIdentifier.sixMinuteWalkTestDistance | HKQuantityTypeIdentifier.waistCircumference ? LengthUnit : T extends HKQuantityTypeIdentifier.bodyFatPercentage | HKQuantityTypeIdentifier.oxygenSaturation | HKQuantityTypeIdentifier.walkingAsymmetryPercentage | HKQuantityTypeIdentifier.walkingDoubleSupportPercentage ? HKUnits.Percent : T extends HKQuantityTypeIdentifier.basalBodyTemperature | HKQuantityTypeIdentifier.basalBodyTemperature ? TemperatureUnit : T extends HKQuantityTypeIdentifier.stairAscentSpeed | HKQuantityTypeIdentifier.stairDescentSpeed | HKQuantityTypeIdentifier.walkingSpeed | HKQuantityTypeIdentifier.walkingSpeed ? SpeedUnit<LengthUnit, TimeUnit> : T extends HKQuantityTypeIdentifier.flightsClimbed | HKQuantityTypeIdentifier.numberOfAlcoholicBeverages | HKQuantityTypeIdentifier.numberOfTimesFallen | HKQuantityTypeIdentifier.pushCount | HKQuantityTypeIdentifier.stepCount | HKQuantityTypeIdentifier.swimmingStrokeCount ? HKUnits.Count : T extends HKQuantityTypeIdentifier.dietaryBiotin | HKQuantityTypeIdentifier.dietaryCaffeine | HKQuantityTypeIdentifier.dietaryCalcium | HKQuantityTypeIdentifier.dietaryCarbohydrates | HKQuantityTypeIdentifier.dietaryChloride | HKQuantityTypeIdentifier.dietaryCholesterol | HKQuantityTypeIdentifier.dietaryChromium | HKQuantityTypeIdentifier.dietaryCopper | HKQuantityTypeIdentifier.dietaryFatMonounsaturated | HKQuantityTypeIdentifier.dietaryFatPolyunsaturated | HKQuantityTypeIdentifier.dietaryFatSaturated | HKQuantityTypeIdentifier.dietaryFatTotal | HKQuantityTypeIdentifier.dietaryFiber | HKQuantityTypeIdentifier.dietaryFolate | HKQuantityTypeIdentifier.dietaryIodine | HKQuantityTypeIdentifier.dietaryIodine | HKQuantityTypeIdentifier.dietaryIron | HKQuantityTypeIdentifier.dietaryMagnesium | HKQuantityTypeIdentifier.dietaryManganese | HKQuantityTypeIdentifier.dietaryMolybdenum | HKQuantityTypeIdentifier.dietaryNiacin | HKQuantityTypeIdentifier.dietaryPantothenicAcid | HKQuantityTypeIdentifier.dietaryPhosphorus | HKQuantityTypeIdentifier.dietaryPotassium | HKQuantityTypeIdentifier.dietaryProtein | HKQuantityTypeIdentifier.dietaryRiboflavin | HKQuantityTypeIdentifier.dietarySelenium | HKQuantityTypeIdentifier.dietarySodium | HKQuantityTypeIdentifier.dietarySugar | HKQuantityTypeIdentifier.dietaryThiamin | HKQuantityTypeIdentifier.dietaryVitaminA | HKQuantityTypeIdentifier.dietaryVitaminB6 | HKQuantityTypeIdentifier.dietaryVitaminB12 | HKQuantityTypeIdentifier.dietaryVitaminC | HKQuantityTypeIdentifier.dietaryVitaminD | HKQuantityTypeIdentifier.dietaryVitaminE | HKQuantityTypeIdentifier.dietaryVitaminK | HKQuantityTypeIdentifier.dietaryZinc ? MassUnit : T extends HKQuantityTypeIdentifier.dietaryWater ? VolumeUnit : T extends HKQuantityTypeIdentifier.insulinDelivery ? HKUnits.InternationalUnit | `${HKUnits.InternationalUnit}` : T extends HKQuantityTypeIdentifier.heartRate | HKQuantityTypeIdentifier.restingHeartRate | HKQuantityTypeIdentifier.walkingHeartRateAverage ? CountPerTime<TimeUnit> : HKUnit;
|
|
448
|
-
export declare type HKCategoryValueForIdentifier<T extends HKCategoryTypeIdentifier> = T extends HKCategoryTypeIdentifier.cervicalMucusQuality ? HKCategoryValueCervicalMucusQuality : T extends HKCategoryTypeIdentifier.menstrualFlow ? HKCategoryValueMenstrualFlow : T extends HKCategoryTypeIdentifier.ovulationTestResult ? HKCategoryValueOvulationTestResult : T extends HKCategoryTypeIdentifier.sleepAnalysis ? HKCategoryValueSleepAnalysis : T extends
|
|
448
|
+
export declare type HKCategoryValueForIdentifier<T extends HKCategoryTypeIdentifier> = T extends HKCategoryTypeIdentifier.cervicalMucusQuality ? HKCategoryValueCervicalMucusQuality : T extends HKCategoryTypeIdentifier.menstrualFlow ? HKCategoryValueMenstrualFlow : T extends HKCategoryTypeIdentifier.ovulationTestResult ? HKCategoryValueOvulationTestResult : T extends HKCategoryTypeIdentifier.sleepAnalysis ? HKCategoryValueSleepAnalysis : T extends HKCategoryTypeIdentifier.highHeartRateEvent | HKCategoryTypeIdentifier.intermenstrualBleeding | HKCategoryTypeIdentifier.mindfulSession | HKCategoryTypeIdentifier.sexualActivity ? HKCategoryValueNotApplicable : T extends HKCategoryTypeIdentifier.abdominalCramps | HKCategoryTypeIdentifier.abdominalCramps | HKCategoryTypeIdentifier.acne | HKCategoryTypeIdentifier.bladderIncontinence | HKCategoryTypeIdentifier.bloating | HKCategoryTypeIdentifier.breastPain | HKCategoryTypeIdentifier.chestTightnessOrPain | HKCategoryTypeIdentifier.chills | HKCategoryTypeIdentifier.constipation | HKCategoryTypeIdentifier.coughing | HKCategoryTypeIdentifier.diarrhea | HKCategoryTypeIdentifier.dizziness | HKCategoryTypeIdentifier.drySkin | HKCategoryTypeIdentifier.fainting | HKCategoryTypeIdentifier.fatigue | HKCategoryTypeIdentifier.fever | HKCategoryTypeIdentifier.generalizedBodyAche | HKCategoryTypeIdentifier.hairLoss | HKCategoryTypeIdentifier.headache | HKCategoryTypeIdentifier.heartburn | HKCategoryTypeIdentifier.hotFlashes | HKCategoryTypeIdentifier.lossOfSmell | HKCategoryTypeIdentifier.lossOfTaste | HKCategoryTypeIdentifier.lowerBackPain | HKCategoryTypeIdentifier.memoryLapse | HKCategoryTypeIdentifier.moodChanges | HKCategoryTypeIdentifier.nausea | HKCategoryTypeIdentifier.nightSweats | HKCategoryTypeIdentifier.pelvicPain | HKCategoryTypeIdentifier.rapidPoundingOrFlutteringHeartbeat | HKCategoryTypeIdentifier.runnyNose | HKCategoryTypeIdentifier.shortnessOfBreath | HKCategoryTypeIdentifier.sinusCongestion | HKCategoryTypeIdentifier.skippedHeartbeat | HKCategoryTypeIdentifier.soreThroat | HKCategoryTypeIdentifier.vaginalDryness | HKCategoryTypeIdentifier.vomiting | HKCategoryTypeIdentifier.wheezing ? HKCategoryValueSeverity : T extends HKCategoryTypeIdentifier.appetiteChanges | HKCategoryTypeIdentifier.sleepChanges ? HKCategoryValuePresence : T extends HKCategoryTypeIdentifier.lowCardioFitnessEvent ? HKCategoryValueLowCardioFitnessEvent : T extends HKCategoryTypeIdentifier.pregnancyTestResult ? HKCategoryValuePregnancyTestResult : T extends HKCategoryTypeIdentifier.pregnancyTestResult ? HKCategoryValuePregnancyTestResult : T extends HKCategoryTypeIdentifier.appleStandHour ? HKCategoryValueAppleStandHour : number;
|
|
449
449
|
declare enum HKCategoryValuePregnancyTestResult {
|
|
450
450
|
positive = 2,
|
|
451
451
|
negative = 1,
|
|
@@ -509,15 +509,15 @@ export declare type MoleUnit<MolarMass extends number> = `mol<${MolarMass}>`;
|
|
|
509
509
|
export declare type MoleUnitWith<MolarMass extends number, Prefix extends HKMetricPrefix = HKMetricPrefix.None> = `${Prefix}mol<${MolarMass}>`;
|
|
510
510
|
export declare type FrequencyUnit = HertzUnit<HKMetricPrefix>;
|
|
511
511
|
/**
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
512
|
+
* More SI prefixes also available as literals, just type the string
|
|
513
|
+
* @example 'cm', 'km'
|
|
514
|
+
*/
|
|
515
515
|
export declare enum UnitOfLength {
|
|
516
516
|
Feet = "ft",
|
|
517
517
|
/**
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
518
|
+
* More SI prefixes also available as literals, just type the string
|
|
519
|
+
* @example 'cm', 'km'
|
|
520
|
+
*/
|
|
521
521
|
Meter = "m",
|
|
522
522
|
Inches = "in",
|
|
523
523
|
Yards = "yd",
|
|
@@ -525,9 +525,9 @@ export declare enum UnitOfLength {
|
|
|
525
525
|
}
|
|
526
526
|
export declare type LengthUnit = MeterUnit<HKMetricPrefix> | UnitOfLength;
|
|
527
527
|
/**
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
528
|
+
* More SI prefixes also available as literals, just type the string
|
|
529
|
+
* @example 'ml', 'cl'
|
|
530
|
+
*/
|
|
531
531
|
export declare enum UnitOfVolume {
|
|
532
532
|
ImperialCup = "cup_imp",
|
|
533
533
|
ImperialFluidOunces = "fl_oz_imp",
|
|
@@ -536,35 +536,35 @@ export declare enum UnitOfVolume {
|
|
|
536
536
|
USFluidOunces = "fl_oz_us",
|
|
537
537
|
USPint = "pt_us",
|
|
538
538
|
/**
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
539
|
+
* More SI prefixes also available as literals, just type the string
|
|
540
|
+
* @example 'ml', 'cl'
|
|
541
|
+
*/
|
|
542
542
|
Liter = "l"
|
|
543
543
|
}
|
|
544
544
|
export declare type VolumeUnit = LiterUnit<HKMetricPrefix> | UnitOfVolume;
|
|
545
545
|
/**
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
546
|
+
* More SI prefixes also available as literals, just type the string
|
|
547
|
+
* @example 'mg', 'kg'
|
|
548
|
+
*/
|
|
549
549
|
export declare enum UnitOfMass {
|
|
550
550
|
Ounces = "oz",
|
|
551
551
|
Stones = "st",
|
|
552
552
|
Pounds = "lb",
|
|
553
553
|
/**
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
554
|
+
* More SI prefixes also available as literals, just type the string
|
|
555
|
+
* @example 'mg', 'kg'
|
|
556
|
+
*/
|
|
557
557
|
Gram = "g"
|
|
558
558
|
}
|
|
559
559
|
/**
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
560
|
+
* More SI prefixes also available as literals, just type the string
|
|
561
|
+
* @example 'mg', 'kg'
|
|
562
|
+
*/
|
|
563
563
|
export declare type MassUnit = GramUnit<HKMetricPrefix> | UnitOfMass;
|
|
564
564
|
/**
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
565
|
+
* More SI prefixes also available as literals, just type the string
|
|
566
|
+
* @example 'kPa', 'hPa'
|
|
567
|
+
*/
|
|
568
568
|
export declare enum UnitOfPressure {
|
|
569
569
|
Atmospheres = "atm",
|
|
570
570
|
CentimetersOfWater = "cmAq",
|
|
@@ -572,34 +572,34 @@ export declare enum UnitOfPressure {
|
|
|
572
572
|
InchesOfMercury = "inHg",
|
|
573
573
|
DecibelAWeightedSoundPressureLevel = "dBASPL",
|
|
574
574
|
/**
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
575
|
+
* More SI prefixes also available as literals, just type the string
|
|
576
|
+
* @example 'kPa', 'hPa'
|
|
577
|
+
*/
|
|
578
578
|
Pascals = "Pa"
|
|
579
579
|
}
|
|
580
580
|
/**
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
581
|
+
* More SI prefixes also available as literals, just type the string
|
|
582
|
+
* @example 'kPa', 'hPa'
|
|
583
|
+
*/
|
|
584
584
|
export declare type PressureUnit = PascalUnit<HKMetricPrefix> | UnitOfPressure;
|
|
585
585
|
/**
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
586
|
+
* More SI prefixes also available as literals, just type the string
|
|
587
|
+
* @example 'ms'
|
|
588
|
+
*/
|
|
589
589
|
export declare enum UnitOfTime {
|
|
590
590
|
Days = "d",
|
|
591
591
|
Minutes = "min",
|
|
592
592
|
Hours = "hr",
|
|
593
593
|
/**
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
594
|
+
* More SI prefixes also available as literals, just type the string
|
|
595
|
+
* @example 'ms'
|
|
596
|
+
*/
|
|
597
597
|
Seconds = "s"
|
|
598
598
|
}
|
|
599
599
|
/**
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
600
|
+
* More SI prefixes also available as literals, just type the string
|
|
601
|
+
* @example 'ms'
|
|
602
|
+
*/
|
|
603
603
|
export declare type TimeUnit = SecondUnit<HKMetricPrefix> | UnitOfTime;
|
|
604
604
|
export declare enum TemperatureUnit {
|
|
605
605
|
DegreesCelsius = "degC",
|
|
@@ -607,17 +607,17 @@ export declare enum TemperatureUnit {
|
|
|
607
607
|
Kelvin = "K"
|
|
608
608
|
}
|
|
609
609
|
/**
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
610
|
+
* More SI prefixes also available as literals, just type the string
|
|
611
|
+
* @example 'kJ'
|
|
612
|
+
*/
|
|
613
613
|
export declare enum UnitOfEnergy {
|
|
614
614
|
Kilocalories = "kcal",
|
|
615
615
|
LargeCalories = "Cal",
|
|
616
616
|
SmallCalories = "cal",
|
|
617
617
|
/**
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
618
|
+
* More SI prefixes also available as literals, just type the string
|
|
619
|
+
* @example 'kJ'
|
|
620
|
+
*/
|
|
621
621
|
Joules = "J"
|
|
622
622
|
}
|
|
623
623
|
export declare type EnergyUnit = JouleUnit<HKMetricPrefix> | UnitOfEnergy;
|
|
@@ -721,6 +721,7 @@ export declare type WorkoutLocation = {
|
|
|
721
721
|
readonly horizontalAccuracy: number;
|
|
722
722
|
readonly speedAccuracy: number;
|
|
723
723
|
readonly verticalAccuracy: number;
|
|
724
|
+
readonly distance: number | null;
|
|
724
725
|
};
|
|
725
726
|
export declare type WorkoutRoute = {
|
|
726
727
|
readonly locations: readonly WorkoutLocation[];
|
|
@@ -729,6 +730,7 @@ export declare type WorkoutRoute = {
|
|
|
729
730
|
};
|
|
730
731
|
declare type ReactNativeHealthkitTypeNative = {
|
|
731
732
|
isHealthDataAvailable(): Promise<boolean>;
|
|
733
|
+
canAccessProtectedData(): Promise<boolean>;
|
|
732
734
|
getBloodType(): Promise<HKBloodType>;
|
|
733
735
|
getDateOfBirth(): Promise<string>;
|
|
734
736
|
getBiologicalSex(): Promise<HKBiologicalSex>;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import type { HKQuantityTypeIdentifier, HKUnit } from '../native-types';
|
|
2
|
-
export declare type GetPreferredUnitFn = (identifier: HKQuantityTypeIdentifier) => Promise<HKUnit>;
|
|
2
|
+
export declare type GetPreferredUnitFn = (identifier: HKQuantityTypeIdentifier) => Promise<HKUnit | undefined>;
|
|
3
3
|
declare const getPreferredUnit: GetPreferredUnitFn;
|
|
4
4
|
export default getPreferredUnit;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingstinct/react-native-healthkit",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "React Native bindings for HealthKit",
|
|
5
5
|
"main": "lib/commonjs/index",
|
|
6
6
|
"module": "lib/module/index",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"test-only": "jest",
|
|
24
24
|
"test": "concurrently \"yarn test-only\" \"yarn typecheck\" \"yarn lint\"",
|
|
25
25
|
"typecheck": "tsc --noEmit",
|
|
26
|
-
"lint": "eslint \"**/*.{js,ts,tsx}\"",
|
|
26
|
+
"lint": "eslint \"**/*.{js,ts,tsx}\" --cache",
|
|
27
27
|
"prepare": "bob build",
|
|
28
28
|
"release": "release-it",
|
|
29
29
|
"example": "yarn --cwd example",
|
|
@@ -46,11 +46,13 @@
|
|
|
46
46
|
"homepage": "https://github.com/kingstinct/react-native-healthkit#readme",
|
|
47
47
|
"devDependencies": {
|
|
48
48
|
"@babel/core": ">=7",
|
|
49
|
+
"@babel/preset-env": "^7.18.10",
|
|
49
50
|
"@commitlint/config-conventional": "12",
|
|
50
51
|
"@graphql-eslint/eslint-plugin": ">=3",
|
|
51
52
|
"@release-it/conventional-changelog": "2",
|
|
52
|
-
"@testing-library/react-
|
|
53
|
+
"@testing-library/react-native": "^11.0.0",
|
|
53
54
|
"@types/jest": ">=26",
|
|
55
|
+
"@types/node": "^18.7.14",
|
|
54
56
|
"@types/react": "17",
|
|
55
57
|
"@types/react-native": "0.67",
|
|
56
58
|
"@typescript-eslint/eslint-plugin": ">=5",
|
|
@@ -78,13 +80,15 @@
|
|
|
78
80
|
"graphql": ">=16",
|
|
79
81
|
"husky": "8",
|
|
80
82
|
"jest": ">=26",
|
|
83
|
+
"jest-environment-jsdom": "^29.0.2",
|
|
81
84
|
"metro-react-native-babel-preset": "^0.70.3",
|
|
82
85
|
"pod-install": "^0.1.0",
|
|
83
86
|
"react": "17",
|
|
84
87
|
"react-native": "0.68",
|
|
85
88
|
"react-native-builder-bob": "^0.18.1",
|
|
86
|
-
"react-test-renderer": "
|
|
89
|
+
"react-test-renderer": "17",
|
|
87
90
|
"release-it": "14",
|
|
91
|
+
"ts-node": "^10.9.1",
|
|
88
92
|
"typescript": ">=4"
|
|
89
93
|
},
|
|
90
94
|
"peerDependencies": {
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { renderHook, act } from '@testing-library/react-native'
|
|
2
|
+
|
|
3
|
+
import Native, { HKAuthorizationRequestStatus, HKCategoryTypeIdentifier } from '../native-types'
|
|
4
|
+
import waitForNextUpdate from '../test-utils'
|
|
5
|
+
import useHealthkitAuthorization from './useHealthkitAuthorization'
|
|
6
|
+
|
|
7
|
+
describe('useHealthkitAuthorization', () => {
|
|
8
|
+
test('should return shouldRequest', async () => {
|
|
9
|
+
jest.spyOn(Native, 'getRequestStatusForAuthorization').mockReturnValue(Promise.resolve(HKAuthorizationRequestStatus.shouldRequest))
|
|
10
|
+
|
|
11
|
+
const { result } = renderHook(() => useHealthkitAuthorization([HKCategoryTypeIdentifier.abdominalCramps]))
|
|
12
|
+
|
|
13
|
+
await waitForNextUpdate()
|
|
14
|
+
|
|
15
|
+
expect(result.current[0]).toBe(HKAuthorizationRequestStatus.shouldRequest)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
test('should request permissions', async () => {
|
|
19
|
+
const spy = jest.spyOn(Native, 'getRequestStatusForAuthorization').mockReturnValue(Promise.resolve(HKAuthorizationRequestStatus.shouldRequest))
|
|
20
|
+
jest.spyOn(Native, 'requestAuthorization').mockReturnValue(Promise.resolve(true))
|
|
21
|
+
|
|
22
|
+
const { result } = renderHook(() => useHealthkitAuthorization([HKCategoryTypeIdentifier.abdominalCramps]))
|
|
23
|
+
|
|
24
|
+
await waitForNextUpdate()
|
|
25
|
+
|
|
26
|
+
spy.mockReturnValue(Promise.resolve(HKAuthorizationRequestStatus.unnecessary))
|
|
27
|
+
|
|
28
|
+
let retVal: HKAuthorizationRequestStatus | undefined
|
|
29
|
+
await act(async () => {
|
|
30
|
+
retVal = await result.current[1]()
|
|
31
|
+
})
|
|
32
|
+
|
|
33
|
+
expect(result.current[0]).toBe(HKAuthorizationRequestStatus.unnecessary)
|
|
34
|
+
expect(retVal).toBe(HKAuthorizationRequestStatus.unnecessary)
|
|
35
|
+
})
|
|
36
|
+
|
|
37
|
+
test('should return unnecessary', async () => {
|
|
38
|
+
jest.spyOn(Native, 'getRequestStatusForAuthorization').mockReturnValue(Promise.resolve(HKAuthorizationRequestStatus.unnecessary))
|
|
39
|
+
|
|
40
|
+
const { result } = renderHook(() => useHealthkitAuthorization([HKCategoryTypeIdentifier.abdominalCramps]))
|
|
41
|
+
|
|
42
|
+
await waitForNextUpdate()
|
|
43
|
+
|
|
44
|
+
expect(result.current[0]).toBe(HKAuthorizationRequestStatus.unnecessary)
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
test('should return null before initalizing', async () => {
|
|
48
|
+
const { result } = renderHook(() => useHealthkitAuthorization([HKCategoryTypeIdentifier.abdominalCramps]))
|
|
49
|
+
|
|
50
|
+
expect(result.current[0]).toBe(null)
|
|
51
|
+
|
|
52
|
+
await waitForNextUpdate()
|
|
53
|
+
})
|
|
54
|
+
})
|
|
@@ -20,6 +20,7 @@ const useHealthkitAuthorization = (read: readonly HealthkitReadAuthorization[],
|
|
|
20
20
|
|
|
21
21
|
const refreshAuthStatus = useCallback(async () => {
|
|
22
22
|
const auth = await getRequestStatusForAuthorization(readMemo.current, writeMemo.current)
|
|
23
|
+
|
|
23
24
|
setStatus(auth)
|
|
24
25
|
return auth
|
|
25
26
|
}, [])
|
|
@@ -1,40 +1,35 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { renderHook } from '@testing-library/react-native'
|
|
2
2
|
|
|
3
3
|
import Native from '../native-types'
|
|
4
|
+
import waitForNextUpdate from '../test-utils'
|
|
4
5
|
import useIsHealthDataAvailable from './useIsHealthDataAvailable'
|
|
5
6
|
|
|
6
7
|
describe('useIsHealthDataAvailable', () => {
|
|
7
8
|
test('should return false', async () => {
|
|
8
9
|
jest.spyOn(Native, 'isHealthDataAvailable').mockReturnValue(Promise.resolve(false))
|
|
9
10
|
|
|
10
|
-
const { result
|
|
11
|
+
const { result } = renderHook(useIsHealthDataAvailable)
|
|
11
12
|
|
|
12
|
-
await
|
|
13
|
-
await waitForNextUpdate()
|
|
14
|
-
})
|
|
13
|
+
await waitForNextUpdate()
|
|
15
14
|
|
|
16
15
|
expect(result.current).toBe(false)
|
|
17
|
-
|
|
18
|
-
unmount()
|
|
19
16
|
})
|
|
20
17
|
|
|
21
18
|
test('should return true', async () => {
|
|
22
19
|
jest.spyOn(Native, 'isHealthDataAvailable').mockReturnValue(Promise.resolve(true))
|
|
23
20
|
|
|
24
|
-
const { result
|
|
21
|
+
const { result } = renderHook(useIsHealthDataAvailable)
|
|
25
22
|
|
|
26
|
-
await
|
|
27
|
-
await waitForNextUpdate()
|
|
28
|
-
})
|
|
23
|
+
await waitForNextUpdate()
|
|
29
24
|
|
|
30
25
|
expect(result.current).toBe(true)
|
|
31
|
-
|
|
32
|
-
unmount()
|
|
33
26
|
})
|
|
34
27
|
|
|
35
|
-
test('should return null before initalizing', () => {
|
|
28
|
+
test('should return null before initalizing', async () => {
|
|
36
29
|
const { result } = renderHook(useIsHealthDataAvailable)
|
|
37
30
|
|
|
38
31
|
expect(result.current).toBe(null)
|
|
32
|
+
|
|
33
|
+
await waitForNextUpdate()
|
|
39
34
|
})
|
|
40
35
|
})
|
package/src/index.ios.tsx
CHANGED
|
@@ -29,8 +29,10 @@ const Healthkit = {
|
|
|
29
29
|
authorizationStatusFor: Native.authorizationStatusFor.bind(Native),
|
|
30
30
|
|
|
31
31
|
isHealthDataAvailable: Native.isHealthDataAvailable.bind(Native),
|
|
32
|
+
canAccessProtectedData: Native.canAccessProtectedData.bind(Native),
|
|
32
33
|
|
|
33
|
-
disableAllBackgroundDelivery:
|
|
34
|
+
disableAllBackgroundDelivery:
|
|
35
|
+
Native.disableAllBackgroundDelivery.bind(Native),
|
|
34
36
|
disableBackgroundDelivery: Native.disableBackgroundDelivery.bind(Native),
|
|
35
37
|
enableBackgroundDelivery: Native.enableBackgroundDelivery.bind(Native),
|
|
36
38
|
|
package/src/index.tsx
CHANGED
|
@@ -15,6 +15,7 @@ let hasWarned = false
|
|
|
15
15
|
function UnavailableFn<T = unknown>(retVal: T) {
|
|
16
16
|
return () => {
|
|
17
17
|
if (!hasWarned) {
|
|
18
|
+
// eslint-disable-next-line no-console
|
|
18
19
|
console.warn(notAvailableError)
|
|
19
20
|
hasWarned = true
|
|
20
21
|
}
|
|
@@ -66,6 +67,7 @@ const Healthkit: typeof ReactNativeHealthkit = {
|
|
|
66
67
|
useSubscribeToChanges: UnavailableFn([null, () => null]),
|
|
67
68
|
useHealthkitAuthorization: UnavailableFn([null, async () => Promise.resolve(HKAuthorizationRequestStatus.unknown)] as const),
|
|
68
69
|
useIsHealthDataAvailable: () => false,
|
|
70
|
+
canAccessProtectedData: async () => Promise.resolve(false),
|
|
69
71
|
}
|
|
70
72
|
|
|
71
73
|
export * from './types'
|
package/src/jest.setup.ts
CHANGED
|
@@ -1,7 +1,37 @@
|
|
|
1
|
-
import { NativeModules } from 'react-native'
|
|
1
|
+
import { NativeModule, NativeModules } from 'react-native'
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import type Native from './native-types'
|
|
4
|
+
|
|
5
|
+
const mockModule: (NativeModule & typeof Native) = {
|
|
4
6
|
isHealthDataAvailable: jest.fn(),
|
|
5
7
|
addListener: jest.fn(),
|
|
6
8
|
removeListeners: jest.fn(),
|
|
9
|
+
authorizationStatusFor: jest.fn(),
|
|
10
|
+
requestAuthorization: jest.fn(),
|
|
11
|
+
saveQuantitySample: jest.fn(),
|
|
12
|
+
deleteQuantitySample: jest.fn(),
|
|
13
|
+
disableAllBackgroundDelivery: jest.fn(),
|
|
14
|
+
disableBackgroundDelivery: jest.fn(),
|
|
15
|
+
enableBackgroundDelivery: jest.fn(),
|
|
16
|
+
getBiologicalSex: jest.fn(),
|
|
17
|
+
getBloodType: jest.fn(),
|
|
18
|
+
getDateOfBirth: jest.fn(),
|
|
19
|
+
getFitzpatrickSkinType: jest.fn(),
|
|
20
|
+
getPreferredUnits: jest.fn(),
|
|
21
|
+
getRequestStatusForAuthorization: jest.fn(),
|
|
22
|
+
getWheelchairUse: jest.fn(),
|
|
23
|
+
getWorkoutRoutes: jest.fn(),
|
|
24
|
+
queryCategorySamples: jest.fn(),
|
|
25
|
+
queryCorrelationSamples: jest.fn(),
|
|
26
|
+
queryQuantitySamples: jest.fn(),
|
|
27
|
+
queryStatisticsForQuantity: jest.fn(),
|
|
28
|
+
queryWorkoutSamples: jest.fn(),
|
|
29
|
+
saveCategorySample: jest.fn(),
|
|
30
|
+
saveCorrelationSample: jest.fn(),
|
|
31
|
+
saveWorkoutSample: jest.fn(),
|
|
32
|
+
subscribeToObserverQuery: jest.fn(),
|
|
33
|
+
unsubscribeQuery: jest.fn(),
|
|
34
|
+
canAccessProtectedData: jest.fn(),
|
|
7
35
|
}
|
|
36
|
+
|
|
37
|
+
NativeModules.ReactNativeHealthkit = mockModule
|