@kingstinct/react-native-healthkit 8.2.0 → 8.4.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 (52) hide show
  1. package/README.md +28 -7
  2. package/ios/Constants.swift +5 -0
  3. package/ios/Helpers.swift +87 -0
  4. package/ios/ReactNativeHealthkit.m +22 -0
  5. package/ios/ReactNativeHealthkit.swift +184 -0
  6. package/ios/Serializers.swift +18 -0
  7. package/lib/commonjs/index.ios.js +28 -1
  8. package/lib/commonjs/index.ios.js.map +1 -1
  9. package/lib/commonjs/index.native.js +21 -4
  10. package/lib/commonjs/index.native.js.map +1 -1
  11. package/lib/commonjs/native-types.js +107 -1
  12. package/lib/commonjs/native-types.js.map +1 -1
  13. package/lib/commonjs/test-setup.js +4 -1
  14. package/lib/commonjs/test-setup.js.map +1 -1
  15. package/lib/commonjs/utils/queryStateOfMindSamples.js +22 -0
  16. package/lib/commonjs/utils/queryStateOfMindSamples.js.map +1 -0
  17. package/lib/commonjs/utils/queryStatisticsCollectionForQuantity.js +16 -0
  18. package/lib/commonjs/utils/queryStatisticsCollectionForQuantity.js.map +1 -0
  19. package/lib/commonjs/utils/startWatchApp.js +11 -0
  20. package/lib/commonjs/utils/startWatchApp.js.map +1 -0
  21. package/lib/module/index.ios.js +9 -3
  22. package/lib/module/index.ios.js.map +1 -1
  23. package/lib/module/index.native.js +17 -3
  24. package/lib/module/index.native.js.map +1 -1
  25. package/lib/module/native-types.js +111 -0
  26. package/lib/module/native-types.js.map +1 -1
  27. package/lib/module/test-setup.js +4 -1
  28. package/lib/module/test-setup.js.map +1 -1
  29. package/lib/module/utils/queryStateOfMindSamples.js +14 -0
  30. package/lib/module/utils/queryStateOfMindSamples.js.map +1 -0
  31. package/lib/module/utils/queryStatisticsCollectionForQuantity.js +9 -0
  32. package/lib/module/utils/queryStatisticsCollectionForQuantity.js.map +1 -0
  33. package/lib/module/utils/startWatchApp.js +4 -0
  34. package/lib/module/utils/startWatchApp.js.map +1 -0
  35. package/lib/typescript/src/index.ios.d.ts +13 -2
  36. package/lib/typescript/src/index.native.d.ts +11 -3
  37. package/lib/typescript/src/native-types.d.ts +146 -2
  38. package/lib/typescript/src/utils/queryStateOfMindSamples.d.ts +7 -0
  39. package/lib/typescript/src/utils/queryStatisticsCollectionForQuantity.d.ts +3 -0
  40. package/lib/typescript/src/utils/startWatchApp.d.ts +3 -0
  41. package/package.json +1 -1
  42. package/src/index.ios.tsx +10 -0
  43. package/src/index.native.tsx +20 -1
  44. package/src/native-types.ts +176 -1
  45. package/src/test-setup.ts +3 -0
  46. package/src/utils/queryStateOfMindSamples.ts +14 -0
  47. package/src/utils/queryStatisticsCollectionForQuantity.ts +38 -0
  48. package/src/utils/startWatchApp.ts +7 -0
  49. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  50. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  51. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcuserdata/robertherber.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  52. package/ios/ReactNativeHealthkit.xcodeproj/xcuserdata/robertherber.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
@@ -26,6 +26,12 @@ export const HKAudiogramTypeIdentifier = 'HKAudiogramSampleType' as const
26
26
  */
27
27
  export const HKWorkoutRouteTypeIdentifier = 'HKWorkoutRouteTypeIdentifier' as const
28
28
 
29
+ /**
30
+ * Represents a state of mind type identifier.
31
+ * @see {@link https://developer.apple.com/documentation/healthkit/hkstateofmindtype Apple Docs HKStateOfMindType}
32
+ */
33
+ export const HKStateOfMindTypeIdentifier = 'HKStateOfMindTypeIdentifier' as const
34
+
29
35
  /**
30
36
  * Represents a series sample containing heartbeat data..
31
37
  * @see {@link https://developer.apple.com/documentation/healthkit/HKDataTypeIdentifierHeartbeatSeries Apple Docs HKDataTypeIdentifierHeartbeatSeries}
@@ -899,6 +905,7 @@ export type HKSampleTypeIdentifier =
899
905
  | HKCategoryTypeIdentifier
900
906
  | HKCorrelationTypeIdentifier
901
907
  | HKQuantityTypeIdentifier
908
+ | typeof HKStateOfMindTypeIdentifier
902
909
  | typeof HKActivitySummaryTypeIdentifier
903
910
  | typeof HKAudiogramTypeIdentifier
904
911
  | typeof HKDataTypeIdentifierHeartbeatSeries
@@ -1172,6 +1179,14 @@ export type QueryStatisticsResponseRaw<
1172
1179
  readonly duration?: HKQuantity<HKQuantityTypeIdentifier, TimeUnit>;
1173
1180
  };
1174
1181
 
1182
+ export interface IntervalComponents {
1183
+ readonly minute?: number;
1184
+ readonly hour?: number;
1185
+ readonly day?: number;
1186
+ readonly month?: number;
1187
+ readonly year?: number;
1188
+ }
1189
+
1175
1190
  /**
1176
1191
  * @see {@link https://developer.apple.com/documentation/healthkit/hkcategoryvaluecervicalmucusquality Apple Docs }
1177
1192
  */
@@ -1545,10 +1560,10 @@ export enum HKUnitMetric {
1545
1560
  export enum HKUnits {
1546
1561
  DecibelHearingLevel = 'dBHL',
1547
1562
  DecibelSoundPressureLevel = 'dBASPL',
1548
-
1549
1563
  Percent = '%',
1550
1564
  Count = 'count',
1551
1565
  InternationalUnit = 'IU',
1566
+ AppleEffortScore = 'appleEffortScore'
1552
1567
  }
1553
1568
 
1554
1569
  export type MeterUnit<Prefix extends HKMetricPrefix = HKMetricPrefix.None> =
@@ -2008,6 +2023,23 @@ type QueryWorkoutSamplesWithAnchorResponseRaw<
2008
2023
  readonly newAnchor: string
2009
2024
  }
2010
2025
 
2026
+ /**
2027
+ * @see {@link https://developer.apple.com/documentation/healthkit/hkworkoutconfiguration Apple Docs }
2028
+ */
2029
+ export type HKWorkoutConfiguration = {
2030
+ readonly activityType: HKWorkoutActivityType;
2031
+ readonly locationType?: HKWorkoutSessionLocationType;
2032
+ };
2033
+
2034
+ /**
2035
+ * @see {@link https://developer.apple.com/documentation/healthkit/hkworkoutsessionlocationtype Apple Docs }
2036
+ */
2037
+ export enum HKWorkoutSessionLocationType {
2038
+ unknown = 1,
2039
+ indoor = 2,
2040
+ outdoor = 3
2041
+ }
2042
+
2011
2043
  type ReactNativeHealthkitTypeNative = {
2012
2044
  /**
2013
2045
  * @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1614180-ishealthdataavailable Apple Docs }
@@ -2212,6 +2244,18 @@ type ReactNativeHealthkitTypeNative = {
2212
2244
  to: string,
2213
2245
  options: readonly HKStatisticsOptions[]
2214
2246
  ) => Promise<QueryStatisticsResponseRaw<TIdentifier, TUnit>>;
2247
+ readonly queryStatisticsCollectionForQuantity: <
2248
+ TIdentifier extends HKQuantityTypeIdentifier,
2249
+ TUnit extends UnitForIdentifier<TIdentifier>
2250
+ >(
2251
+ identifier: TIdentifier,
2252
+ unit: TUnit,
2253
+ options: readonly HKStatisticsOptions[],
2254
+ anchorDate: string,
2255
+ intervalComponents: IntervalComponents,
2256
+ startDate: string,
2257
+ endDate: string
2258
+ ) => Promise<readonly QueryStatisticsResponseRaw<TIdentifier, TUnit>[]>;
2215
2259
  readonly getPreferredUnits: (
2216
2260
  identifiers: readonly HKQuantityTypeIdentifier[]
2217
2261
  ) => Promise<TypeToUnitMapping>;
@@ -2219,8 +2263,61 @@ type ReactNativeHealthkitTypeNative = {
2219
2263
  workoutUUID: string
2220
2264
  ) => Promise<readonly WorkoutRoute[]>;
2221
2265
  readonly getWorkoutPlanById: (workoutUUID: string) => Promise<{readonly id: string, readonly activityType: HKWorkoutActivityType} | null>;
2266
+
2267
+ /**
2268
+ * @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1648358-startwatchapp Apple Docs }
2269
+ */
2270
+ readonly startWatchAppWithWorkoutConfiguration: (
2271
+ workoutConfiguration: HKWorkoutConfiguration
2272
+ ) => Promise<boolean>;
2273
+
2274
+ /**
2275
+ * Query state of mind samples from HealthKit
2276
+ * @param from Start date to query from
2277
+ * @param to End date to query to
2278
+ * @param limit Maximum number of samples to return
2279
+ * @param ascending Sort order of samples
2280
+ * @returns Promise resolving to array of state of mind samples
2281
+ * @platform ios
2282
+ * @requires iOS 17.0+
2283
+ */
2284
+ readonly queryStateOfMindSamples: (
2285
+ from: string | null,
2286
+ to: string | null,
2287
+ limit: number,
2288
+ ascending: boolean
2289
+ ) => Promise<readonly HKStateOfMindSampleRaw[]>;
2222
2290
  };
2223
2291
 
2292
+ export enum HKStateOfMindValenceClassification {
2293
+ veryUnpleasant = 1,
2294
+ unpleasant = 2,
2295
+ slightlyUnpleasant = 3,
2296
+ neutral = 4,
2297
+ slightlyPleasant = 5,
2298
+ pleasant = 6,
2299
+ veryPleasant = 7,
2300
+ }
2301
+
2302
+ export type HKStateOfMindSampleRaw = {
2303
+ readonly uuid: string;
2304
+ readonly device?: HKDevice;
2305
+ readonly startDate: string;
2306
+ readonly endDate: string;
2307
+ readonly metadata?: HKHeartbeatSeriesSampleMetadata;
2308
+ readonly sourceRevision?: HKSourceRevision;
2309
+ // State of mind sample properties
2310
+ /**
2311
+ * @see {@link https://developer.apple.com/documentation/healthkit/hkstateofmind/4337998-valence Apple Docs }
2312
+ * Value between -1 and 1
2313
+ */
2314
+ readonly valence: number;
2315
+ readonly kind: HKStateOfMindKind;
2316
+ readonly valenceClassification: HKStateOfMindValenceClassification;
2317
+ readonly associations: readonly HKStateOfMindAssociation[];
2318
+ readonly labels: readonly HKStateOfMindLabel[];
2319
+ }
2320
+
2224
2321
  const Native = NativeModules.ReactNativeHealthkit as ReactNativeHealthkitTypeNative
2225
2322
 
2226
2323
  type OnChangeCallback = ({
@@ -2241,3 +2338,81 @@ export const EventEmitter = new NativeEventEmitter(
2241
2338
  ) as HealthkitEventEmitter
2242
2339
 
2243
2340
  export default Native
2341
+
2342
+ /**
2343
+ * @see {@link https://developer.apple.com/documentation/healthkit/hkstateofmind/label Apple Docs}
2344
+ */
2345
+ export enum HKStateOfMindLabel {
2346
+ amazed = 1,
2347
+ amused = 2,
2348
+ angry = 3,
2349
+ anxious = 4,
2350
+ ashamed = 5,
2351
+ brave = 6,
2352
+ calm = 7,
2353
+ content = 8,
2354
+ disappointed = 9,
2355
+ discouraged = 10,
2356
+ disgusted = 11,
2357
+ embarrassed = 12,
2358
+ excited = 13,
2359
+ frustrated = 14,
2360
+ grateful = 15,
2361
+ guilty = 16,
2362
+ happy = 17,
2363
+ hopeless = 18,
2364
+ irritated = 19,
2365
+ jealous = 20,
2366
+ joyful = 21,
2367
+ lonely = 22,
2368
+ passionate = 23,
2369
+ peaceful = 24,
2370
+ proud = 25,
2371
+ relieved = 26,
2372
+ sad = 27,
2373
+ scared = 28,
2374
+ stressed = 29,
2375
+ surprised = 30,
2376
+ worried = 31,
2377
+
2378
+ annoyed = 32,
2379
+ confident = 33,
2380
+ drained = 34,
2381
+ hopeful = 35,
2382
+ indifferent = 36,
2383
+ overwhelmed = 37,
2384
+ satisfied = 38,
2385
+ }
2386
+
2387
+ /**
2388
+ * @see {@link https://developer.apple.com/documentation/healthkit/hkstateofmind/kind Apple Docs}
2389
+ */
2390
+ export enum HKStateOfMindKind {
2391
+ dailyMood = 2,
2392
+ momentaryEmotion = 1
2393
+ }
2394
+
2395
+ /**
2396
+ * @see {@link https://developer.apple.com/documentation/healthkit/hkstateofmind/association Apple Docs}
2397
+ * @since iOS 17.0+
2398
+ */
2399
+ export enum HKStateOfMindAssociation {
2400
+ community = 1,
2401
+ currentEvents = 2,
2402
+ dating = 3,
2403
+ education = 4,
2404
+ family = 5,
2405
+ fitness = 6,
2406
+ friends = 7,
2407
+ health = 8,
2408
+ hobbies = 9,
2409
+ identity = 10,
2410
+ money = 11,
2411
+ partner = 12,
2412
+ selfCare = 13,
2413
+ spirituality = 14,
2414
+ tasks = 15,
2415
+ travel = 16,
2416
+ work = 17,
2417
+ weather = 18,
2418
+ }
package/src/test-setup.ts CHANGED
@@ -33,6 +33,7 @@ beforeAll(async () => {
33
33
  queryQuantitySamples: jest.fn(),
34
34
  querySources: jest.fn(),
35
35
  queryStatisticsForQuantity: jest.fn(),
36
+ queryStatisticsCollectionForQuantity: jest.fn(),
36
37
  queryWorkoutSamples: jest.fn(),
37
38
  saveCategorySample: jest.fn(),
38
39
  saveCorrelationSample: jest.fn(),
@@ -41,6 +42,8 @@ beforeAll(async () => {
41
42
  unsubscribeQuery: jest.fn(),
42
43
  saveWorkoutRoute: jest.fn(),
43
44
  getWorkoutPlanById: jest.fn(),
45
+ startWatchAppWithWorkoutConfiguration: jest.fn(),
46
+ queryStateOfMindSamples: jest.fn(),
44
47
  }
45
48
 
46
49
  await mock.module('react-native', () => ({
@@ -0,0 +1,14 @@
1
+ import Native from '../native-types'
2
+
3
+ export const queryStateOfMindSamples = async ({
4
+ from, to, limit, ascending,
5
+ }: { readonly from?: Date; readonly to?: Date; readonly limit?: number; readonly ascending?: boolean } = {}) => {
6
+ const fromString = (from || new Date(0)).toISOString()
7
+ const toString = (to || new Date(0)).toISOString()
8
+
9
+ const res = await Native.queryStateOfMindSamples(fromString, toString, limit ?? 0, ascending ?? false)
10
+
11
+ return res
12
+ }
13
+
14
+ export default queryStateOfMindSamples
@@ -0,0 +1,38 @@
1
+ import ensureUnit from './ensureUnit'
2
+ import Native from '../native-types'
3
+
4
+ import type {
5
+ HKQuantityTypeIdentifier,
6
+ HKStatisticsOptions,
7
+ UnitForIdentifier,
8
+ IntervalComponents,
9
+ } from '../native-types'
10
+
11
+ async function queryStatisticsCollectionForQuantity<
12
+ TIdentifier extends HKQuantityTypeIdentifier,
13
+ TUnit extends UnitForIdentifier<TIdentifier> = UnitForIdentifier<TIdentifier>
14
+ >(
15
+ identifier: TIdentifier,
16
+ options: readonly HKStatisticsOptions[],
17
+ anchorDate: Date,
18
+ intervalComponents: IntervalComponents,
19
+ startDate: Date,
20
+ endDate: Date,
21
+ unit?: TUnit,
22
+ ) {
23
+ const actualUnit = await ensureUnit(identifier, unit)
24
+
25
+ const rawResponse = await Native.queryStatisticsCollectionForQuantity(
26
+ identifier,
27
+ actualUnit,
28
+ options,
29
+ anchorDate.toISOString(),
30
+ intervalComponents,
31
+ startDate.toISOString(),
32
+ endDate.toISOString(),
33
+ )
34
+
35
+ return rawResponse
36
+ }
37
+
38
+ export default queryStatisticsCollectionForQuantity
@@ -0,0 +1,7 @@
1
+ import Native from '../native-types'
2
+
3
+ import type { HKWorkoutConfiguration } from '..'
4
+
5
+ const startWatchApp = (configuration: HKWorkoutConfiguration) => async () => Native.startWatchAppWithWorkoutConfiguration(configuration)
6
+
7
+ export default startWatchApp
@@ -1,7 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <Workspace
3
- version = "1.0">
4
- <FileRef
5
- location = "self:">
6
- </FileRef>
7
- </Workspace>
@@ -1,8 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>IDEDidComputeMac32BitWarning</key>
6
- <true/>
7
- </dict>
8
- </plist>
@@ -1,14 +0,0 @@
1
- <?xml version="1.0" encoding="UTF-8"?>
2
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3
- <plist version="1.0">
4
- <dict>
5
- <key>SchemeUserState</key>
6
- <dict>
7
- <key>ReactNativeHealthkit.xcscheme_^#shared#^_</key>
8
- <dict>
9
- <key>orderHint</key>
10
- <integer>0</integer>
11
- </dict>
12
- </dict>
13
- </dict>
14
- </plist>