@kingstinct/react-native-healthkit 5.1.2 → 5.2.1
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 +37 -30
- 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 +37 -30
- 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 +60 -51
- 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 +364 -162
- 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
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kingstinct/react-native-healthkit",
|
|
3
|
-
"version": "5.1
|
|
3
|
+
"version": "5.2.1",
|
|
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
|