@kingstinct/react-native-healthkit 8.3.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 (39) hide show
  1. package/README.md +10 -3
  2. package/ios/Constants.swift +1 -0
  3. package/ios/Helpers.swift +6 -0
  4. package/ios/ReactNativeHealthkit.m +7 -0
  5. package/ios/ReactNativeHealthkit.swift +84 -2
  6. package/lib/commonjs/index.ios.js +10 -1
  7. package/lib/commonjs/index.ios.js.map +1 -1
  8. package/lib/commonjs/index.native.js +7 -4
  9. package/lib/commonjs/index.native.js.map +1 -1
  10. package/lib/commonjs/native-types.js +94 -1
  11. package/lib/commonjs/native-types.js.map +1 -1
  12. package/lib/commonjs/test-setup.js +2 -1
  13. package/lib/commonjs/test-setup.js.map +1 -1
  14. package/lib/commonjs/utils/queryStateOfMindSamples.js +22 -0
  15. package/lib/commonjs/utils/queryStateOfMindSamples.js.map +1 -0
  16. package/lib/module/index.ios.js +4 -2
  17. package/lib/module/index.ios.js.map +1 -1
  18. package/lib/module/index.native.js +5 -3
  19. package/lib/module/index.native.js.map +1 -1
  20. package/lib/module/native-types.js +96 -0
  21. package/lib/module/native-types.js.map +1 -1
  22. package/lib/module/test-setup.js +2 -1
  23. package/lib/module/test-setup.js.map +1 -1
  24. package/lib/module/utils/queryStateOfMindSamples.js +14 -0
  25. package/lib/module/utils/queryStateOfMindSamples.js.map +1 -0
  26. package/lib/typescript/src/index.ios.d.ts +8 -1
  27. package/lib/typescript/src/index.native.d.ts +2 -2
  28. package/lib/typescript/src/native-types.d.ts +117 -1
  29. package/lib/typescript/src/utils/queryStateOfMindSamples.d.ts +7 -0
  30. package/package.json +1 -1
  31. package/src/index.ios.tsx +3 -0
  32. package/src/index.native.tsx +4 -1
  33. package/src/native-types.ts +131 -0
  34. package/src/test-setup.ts +1 -0
  35. package/src/utils/queryStateOfMindSamples.ts +14 -0
  36. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/contents.xcworkspacedata +0 -7
  37. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist +0 -8
  38. package/ios/ReactNativeHealthkit.xcodeproj/project.xcworkspace/xcuserdata/robertherber.xcuserdatad/UserInterfaceState.xcuserstate +0 -0
  39. package/ios/ReactNativeHealthkit.xcodeproj/xcuserdata/robertherber.xcuserdatad/xcschemes/xcschememanagement.plist +0 -14
@@ -0,0 +1,14 @@
1
+ import Native from '../native-types';
2
+ export const queryStateOfMindSamples = async ({
3
+ from,
4
+ to,
5
+ limit,
6
+ ascending
7
+ } = {}) => {
8
+ const fromString = (from || new Date(0)).toISOString();
9
+ const toString = (to || new Date(0)).toISOString();
10
+ const res = await Native.queryStateOfMindSamples(fromString, toString, limit ?? 0, ascending ?? false);
11
+ return res;
12
+ };
13
+ export default queryStateOfMindSamples;
14
+ //# sourceMappingURL=queryStateOfMindSamples.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["Native","queryStateOfMindSamples","from","to","limit","ascending","fromString","Date","toISOString","toString","res"],"sources":["queryStateOfMindSamples.ts"],"sourcesContent":["import Native from '../native-types'\n\nexport const queryStateOfMindSamples = async ({\n from, to, limit, ascending,\n}: { readonly from?: Date; readonly to?: Date; readonly limit?: number; readonly ascending?: boolean } = {}) => {\n const fromString = (from || new Date(0)).toISOString()\n const toString = (to || new Date(0)).toISOString()\n\n const res = await Native.queryStateOfMindSamples(fromString, toString, limit ?? 0, ascending ?? false)\n\n return res\n}\n\nexport default queryStateOfMindSamples\n"],"mappings":"AAAA,OAAOA,MAAM,MAAM,iBAAiB;AAEpC,OAAO,MAAMC,uBAAuB,GAAG,MAAAA,CAAO;EAC5CC,IAAI;EAAEC,EAAE;EAAEC,KAAK;EAAEC;AACkF,CAAC,GAAG,CAAC,CAAC,KAAK;EAC9G,MAAMC,UAAU,GAAG,CAACJ,IAAI,IAAI,IAAIK,IAAI,CAAC,CAAC,CAAC,EAAEC,WAAW,CAAC,CAAC;EACtD,MAAMC,QAAQ,GAAG,CAACN,EAAE,IAAI,IAAII,IAAI,CAAC,CAAC,CAAC,EAAEC,WAAW,CAAC,CAAC;EAElD,MAAME,GAAG,GAAG,MAAMV,MAAM,CAACC,uBAAuB,CAACK,UAAU,EAAEG,QAAQ,EAAEL,KAAK,IAAI,CAAC,EAAEC,SAAS,IAAI,KAAK,CAAC;EAEtG,OAAOK,GAAG;AACZ,CAAC;AAED,eAAeT,uBAAuB","ignoreList":[]}
@@ -25,6 +25,7 @@ import queryHeartbeatSeriesSamplesWithAnchor from './utils/queryHeartbeatSeriesS
25
25
  import queryQuantitySamples from './utils/queryQuantitySamples';
26
26
  import queryQuantitySamplesWithAnchor from './utils/queryQuantitySamplesWithAnchor';
27
27
  import querySources from './utils/querySources';
28
+ import { queryStateOfMindSamples } from './utils/queryStateOfMindSamples';
28
29
  import queryStatisticsCollectionForQuantity from './utils/queryStatisticsCollectionForQuantity';
29
30
  import queryStatisticsForQuantity from './utils/queryStatisticsForQuantity';
30
31
  import queryWorkoutSamples from './utils/queryWorkouts';
@@ -176,6 +177,12 @@ declare const _default: {
176
177
  useHealthkitAuthorization: (read: readonly import("./native-types").HealthkitReadAuthorization[], write?: readonly import("./native-types").HKSampleTypeIdentifier[] | undefined) => readonly [import("./native-types").HKAuthorizationRequestStatus | null, () => Promise<import("./native-types").HKAuthorizationRequestStatus>];
177
178
  useSources: typeof useSources;
178
179
  useStatisticsForQuantity: typeof useStatisticsForQuantity;
180
+ queryStateOfMindSamples: ({ from, to, limit, ascending, }?: {
181
+ readonly from?: Date | undefined;
182
+ readonly to?: Date | undefined;
183
+ readonly limit?: number | undefined;
184
+ readonly ascending?: boolean | undefined;
185
+ }) => Promise<readonly import("./native-types").HKStateOfMindSampleRaw[]>;
179
186
  };
180
187
  export default _default;
181
188
  declare const queryWorkouts: typeof queryWorkoutSamples;
@@ -183,5 +190,5 @@ export { authorizationStatusFor, availableQuantityTypes, disableAllBackgroundDel
183
190
  /**
184
191
  * @deprecated Use queryWorkoutSamples instead
185
192
  */
186
- queryWorkouts, queryWorkoutSamples, queryWorkoutSamplesWithAnchor, querySources, requestAuthorization, deleteQuantitySample, deleteSamples, getWorkoutPlanById, saveCategorySample, saveCorrelationSample, saveQuantitySample, saveWorkoutSample, saveWorkoutRoute, subscribeToChanges, startWatchApp, useMostRecentCategorySample, useMostRecentQuantitySample, useMostRecentWorkout, useSubscribeToChanges, useHealthkitAuthorization, useIsHealthDataAvailable, useSources, useStatisticsForQuantity, isProtectedDataAvailable, };
193
+ queryWorkouts, queryWorkoutSamples, queryWorkoutSamplesWithAnchor, querySources, requestAuthorization, deleteQuantitySample, deleteSamples, getWorkoutPlanById, saveCategorySample, saveCorrelationSample, saveQuantitySample, saveWorkoutSample, saveWorkoutRoute, subscribeToChanges, startWatchApp, useMostRecentCategorySample, useMostRecentQuantitySample, useMostRecentWorkout, useSubscribeToChanges, useHealthkitAuthorization, useIsHealthDataAvailable, useSources, useStatisticsForQuantity, isProtectedDataAvailable, queryStateOfMindSamples, };
187
194
  export * from './types';
@@ -34,8 +34,8 @@ declare const authorizationStatusFor: () => Promise<HKAuthorizationStatus>, avai
34
34
  samples: never[];
35
35
  deletedSamples: never[];
36
36
  newAnchor: string;
37
- }>, querySources: () => Promise<never[]>, requestAuthorization: () => Promise<boolean>, deleteQuantitySample: () => Promise<boolean>, deleteSamples: () => Promise<boolean>, getWorkoutPlanById: () => Promise<null>, saveCategorySample: () => Promise<boolean>, saveCorrelationSample: () => Promise<boolean>, saveQuantitySample: () => Promise<boolean>, saveWorkoutSample: () => Promise<null>, saveWorkoutRoute: () => Promise<boolean>, subscribeToChanges: () => Promise<() => Promise<boolean>>, startWatchApp: () => () => Promise<boolean>, useMostRecentCategorySample: () => null, useMostRecentQuantitySample: () => null, useMostRecentWorkout: () => null, useSubscribeToChanges: () => ((() => null) | null)[], useHealthkitAuthorization: () => readonly [null, () => Promise<HKAuthorizationRequestStatus>], useIsHealthDataAvailable: () => boolean, isProtectedDataAvailable: () => Promise<boolean>;
37
+ }>, querySources: () => Promise<never[]>, requestAuthorization: () => Promise<boolean>, deleteQuantitySample: () => Promise<boolean>, deleteSamples: () => Promise<boolean>, getWorkoutPlanById: () => Promise<null>, saveCategorySample: () => Promise<boolean>, saveCorrelationSample: () => Promise<boolean>, saveQuantitySample: () => Promise<boolean>, saveWorkoutSample: () => Promise<null>, saveWorkoutRoute: () => Promise<boolean>, subscribeToChanges: () => Promise<() => Promise<boolean>>, startWatchApp: () => () => Promise<boolean>, useMostRecentCategorySample: () => null, useMostRecentQuantitySample: () => null, useMostRecentWorkout: () => null, useSubscribeToChanges: () => ((() => null) | null)[], useHealthkitAuthorization: () => readonly [null, () => Promise<HKAuthorizationRequestStatus>], useIsHealthDataAvailable: () => boolean, isProtectedDataAvailable: () => Promise<boolean>, queryStateOfMindSamples: () => Promise<never[]>;
38
38
  declare const Healthkit: typeof ReactNativeHealthkit;
39
- export { authorizationStatusFor, availableQuantityTypes, deleteQuantitySample, deleteSamples, disableAllBackgroundDelivery, disableBackgroundDelivery, enableBackgroundDelivery, getBiologicalSex, getBloodType, getDateOfBirth, getFitzpatrickSkinType, getMostRecentCategorySample, getMostRecentQuantitySample, getMostRecentWorkout, getPreferredUnit, getPreferredUnits, getRequestStatusForAuthorization, getWheelchairUse, getWorkoutPlanById, getWorkoutRoutes, isHealthDataAvailable, isProtectedDataAvailable, queryCategorySamples, queryCategorySamplesWithAnchor, queryCorrelationSamples, queryHeartbeatSeriesSamples, queryHeartbeatSeriesSamplesWithAnchor, queryQuantitySamples, queryQuantitySamplesWithAnchor, querySources, queryStatisticsForQuantity, queryStatisticsCollectionForQuantity, queryWorkouts, queryWorkoutSamples, queryWorkoutSamplesWithAnchor, requestAuthorization, saveCategorySample, saveCorrelationSample, saveQuantitySample, saveWorkoutRoute, saveWorkoutSample, subscribeToChanges, startWatchApp, useHealthkitAuthorization, useIsHealthDataAvailable, useMostRecentCategorySample, useMostRecentQuantitySample, useMostRecentWorkout, useSources, useStatisticsForQuantity, useSubscribeToChanges, };
39
+ export { authorizationStatusFor, availableQuantityTypes, deleteQuantitySample, deleteSamples, disableAllBackgroundDelivery, disableBackgroundDelivery, enableBackgroundDelivery, getBiologicalSex, getBloodType, getDateOfBirth, getFitzpatrickSkinType, getMostRecentCategorySample, getMostRecentQuantitySample, getMostRecentWorkout, getPreferredUnit, getPreferredUnits, getRequestStatusForAuthorization, getWheelchairUse, getWorkoutPlanById, getWorkoutRoutes, isHealthDataAvailable, isProtectedDataAvailable, queryCategorySamples, queryCategorySamplesWithAnchor, queryCorrelationSamples, queryHeartbeatSeriesSamples, queryHeartbeatSeriesSamplesWithAnchor, queryQuantitySamples, queryQuantitySamplesWithAnchor, querySources, queryStatisticsForQuantity, queryStatisticsCollectionForQuantity, queryWorkouts, queryWorkoutSamples, queryWorkoutSamplesWithAnchor, requestAuthorization, saveCategorySample, saveCorrelationSample, saveQuantitySample, saveWorkoutRoute, saveWorkoutSample, subscribeToChanges, startWatchApp, useHealthkitAuthorization, useIsHealthDataAvailable, useMostRecentCategorySample, useMostRecentQuantitySample, useMostRecentWorkout, useSources, useStatisticsForQuantity, useSubscribeToChanges, queryStateOfMindSamples, };
40
40
  export * from './types';
41
41
  export default Healthkit;
@@ -20,6 +20,11 @@ export declare const HKAudiogramTypeIdentifier: "HKAudiogramSampleType";
20
20
  * @see {@link https://developer.apple.com/documentation/healthkit/hkworkoutroutetypeidentifier Apple Docs HKWorkoutRouteTypeIdentifier}
21
21
  */
22
22
  export declare const HKWorkoutRouteTypeIdentifier: "HKWorkoutRouteTypeIdentifier";
23
+ /**
24
+ * Represents a state of mind type identifier.
25
+ * @see {@link https://developer.apple.com/documentation/healthkit/hkstateofmindtype Apple Docs HKStateOfMindType}
26
+ */
27
+ export declare const HKStateOfMindTypeIdentifier: "HKStateOfMindTypeIdentifier";
23
28
  /**
24
29
  * Represents a series sample containing heartbeat data..
25
30
  * @see {@link https://developer.apple.com/documentation/healthkit/HKDataTypeIdentifierHeartbeatSeries Apple Docs HKDataTypeIdentifierHeartbeatSeries}
@@ -783,7 +788,7 @@ export declare enum HKCategoryTypeIdentifier {
783
788
  */
784
789
  bleedingDuringPregnancy = "HKCategoryTypeIdentifierBleedingDuringPregnancy"
785
790
  }
786
- export type HKSampleTypeIdentifier = HKCategoryTypeIdentifier | HKCorrelationTypeIdentifier | HKQuantityTypeIdentifier | typeof HKActivitySummaryTypeIdentifier | typeof HKAudiogramTypeIdentifier | typeof HKDataTypeIdentifierHeartbeatSeries | typeof HKWorkoutRouteTypeIdentifier | typeof HKWorkoutTypeIdentifier | `${HKCategoryTypeIdentifier}` | `${HKCorrelationTypeIdentifier}` | `${HKQuantityTypeIdentifier}`;
791
+ export type HKSampleTypeIdentifier = HKCategoryTypeIdentifier | HKCorrelationTypeIdentifier | HKQuantityTypeIdentifier | typeof HKStateOfMindTypeIdentifier | typeof HKActivitySummaryTypeIdentifier | typeof HKAudiogramTypeIdentifier | typeof HKDataTypeIdentifierHeartbeatSeries | typeof HKWorkoutRouteTypeIdentifier | typeof HKWorkoutTypeIdentifier | `${HKCategoryTypeIdentifier}` | `${HKCorrelationTypeIdentifier}` | `${HKQuantityTypeIdentifier}`;
787
792
  export type HealthkitReadAuthorization = HKCharacteristicTypeIdentifier | HKSampleTypeIdentifier | `${HKCharacteristicTypeIdentifier}` | `${HKSampleTypeIdentifier}`;
788
793
  export type HealthkitWriteAuthorization = HKSampleTypeIdentifier;
789
794
  export declare enum HKCategoryValueAppleStandHour {
@@ -1598,6 +1603,43 @@ type ReactNativeHealthkitTypeNative = {
1598
1603
  * @see {@link https://developer.apple.com/documentation/healthkit/hkhealthstore/1648358-startwatchapp Apple Docs }
1599
1604
  */
1600
1605
  readonly startWatchAppWithWorkoutConfiguration: (workoutConfiguration: HKWorkoutConfiguration) => Promise<boolean>;
1606
+ /**
1607
+ * Query state of mind samples from HealthKit
1608
+ * @param from Start date to query from
1609
+ * @param to End date to query to
1610
+ * @param limit Maximum number of samples to return
1611
+ * @param ascending Sort order of samples
1612
+ * @returns Promise resolving to array of state of mind samples
1613
+ * @platform ios
1614
+ * @requires iOS 17.0+
1615
+ */
1616
+ readonly queryStateOfMindSamples: (from: string | null, to: string | null, limit: number, ascending: boolean) => Promise<readonly HKStateOfMindSampleRaw[]>;
1617
+ };
1618
+ export declare enum HKStateOfMindValenceClassification {
1619
+ veryUnpleasant = 1,
1620
+ unpleasant = 2,
1621
+ slightlyUnpleasant = 3,
1622
+ neutral = 4,
1623
+ slightlyPleasant = 5,
1624
+ pleasant = 6,
1625
+ veryPleasant = 7
1626
+ }
1627
+ export type HKStateOfMindSampleRaw = {
1628
+ readonly uuid: string;
1629
+ readonly device?: HKDevice;
1630
+ readonly startDate: string;
1631
+ readonly endDate: string;
1632
+ readonly metadata?: HKHeartbeatSeriesSampleMetadata;
1633
+ readonly sourceRevision?: HKSourceRevision;
1634
+ /**
1635
+ * @see {@link https://developer.apple.com/documentation/healthkit/hkstateofmind/4337998-valence Apple Docs }
1636
+ * Value between -1 and 1
1637
+ */
1638
+ readonly valence: number;
1639
+ readonly kind: HKStateOfMindKind;
1640
+ readonly valenceClassification: HKStateOfMindValenceClassification;
1641
+ readonly associations: readonly HKStateOfMindAssociation[];
1642
+ readonly labels: readonly HKStateOfMindLabel[];
1601
1643
  };
1602
1644
  declare const Native: ReactNativeHealthkitTypeNative;
1603
1645
  type OnChangeCallback = ({ typeIdentifier, }: {
@@ -1608,3 +1650,77 @@ interface HealthkitEventEmitter extends NativeEventEmitter {
1608
1650
  }
1609
1651
  export declare const EventEmitter: HealthkitEventEmitter;
1610
1652
  export default Native;
1653
+ /**
1654
+ * @see {@link https://developer.apple.com/documentation/healthkit/hkstateofmind/label Apple Docs}
1655
+ */
1656
+ export declare enum HKStateOfMindLabel {
1657
+ amazed = 1,
1658
+ amused = 2,
1659
+ angry = 3,
1660
+ anxious = 4,
1661
+ ashamed = 5,
1662
+ brave = 6,
1663
+ calm = 7,
1664
+ content = 8,
1665
+ disappointed = 9,
1666
+ discouraged = 10,
1667
+ disgusted = 11,
1668
+ embarrassed = 12,
1669
+ excited = 13,
1670
+ frustrated = 14,
1671
+ grateful = 15,
1672
+ guilty = 16,
1673
+ happy = 17,
1674
+ hopeless = 18,
1675
+ irritated = 19,
1676
+ jealous = 20,
1677
+ joyful = 21,
1678
+ lonely = 22,
1679
+ passionate = 23,
1680
+ peaceful = 24,
1681
+ proud = 25,
1682
+ relieved = 26,
1683
+ sad = 27,
1684
+ scared = 28,
1685
+ stressed = 29,
1686
+ surprised = 30,
1687
+ worried = 31,
1688
+ annoyed = 32,
1689
+ confident = 33,
1690
+ drained = 34,
1691
+ hopeful = 35,
1692
+ indifferent = 36,
1693
+ overwhelmed = 37,
1694
+ satisfied = 38
1695
+ }
1696
+ /**
1697
+ * @see {@link https://developer.apple.com/documentation/healthkit/hkstateofmind/kind Apple Docs}
1698
+ */
1699
+ export declare enum HKStateOfMindKind {
1700
+ dailyMood = 2,
1701
+ momentaryEmotion = 1
1702
+ }
1703
+ /**
1704
+ * @see {@link https://developer.apple.com/documentation/healthkit/hkstateofmind/association Apple Docs}
1705
+ * @since iOS 17.0+
1706
+ */
1707
+ export declare enum HKStateOfMindAssociation {
1708
+ community = 1,
1709
+ currentEvents = 2,
1710
+ dating = 3,
1711
+ education = 4,
1712
+ family = 5,
1713
+ fitness = 6,
1714
+ friends = 7,
1715
+ health = 8,
1716
+ hobbies = 9,
1717
+ identity = 10,
1718
+ money = 11,
1719
+ partner = 12,
1720
+ selfCare = 13,
1721
+ spirituality = 14,
1722
+ tasks = 15,
1723
+ travel = 16,
1724
+ work = 17,
1725
+ weather = 18
1726
+ }
@@ -0,0 +1,7 @@
1
+ export declare const queryStateOfMindSamples: ({ from, to, limit, ascending, }?: {
2
+ readonly from?: Date | undefined;
3
+ readonly to?: Date | undefined;
4
+ readonly limit?: number | undefined;
5
+ readonly ascending?: boolean | undefined;
6
+ }) => Promise<readonly import("../native-types").HKStateOfMindSampleRaw[]>;
7
+ export default queryStateOfMindSamples;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kingstinct/react-native-healthkit",
3
- "version": "8.3.0",
3
+ "version": "8.4.0",
4
4
  "description": "React Native bindings for HealthKit",
5
5
  "main": "lib/commonjs/index",
6
6
  "module": "lib/module/index",
package/src/index.ios.tsx CHANGED
@@ -27,6 +27,7 @@ import queryHeartbeatSeriesSamplesWithAnchor from './utils/queryHeartbeatSeriesS
27
27
  import queryQuantitySamples from './utils/queryQuantitySamples'
28
28
  import queryQuantitySamplesWithAnchor from './utils/queryQuantitySamplesWithAnchor'
29
29
  import querySources from './utils/querySources'
30
+ import { queryStateOfMindSamples } from './utils/queryStateOfMindSamples'
30
31
  import queryStatisticsCollectionForQuantity from './utils/queryStatisticsCollectionForQuantity'
31
32
  import queryStatisticsForQuantity from './utils/queryStatisticsForQuantity'
32
33
  import queryWorkoutSamples from './utils/queryWorkouts'
@@ -219,6 +220,7 @@ export default {
219
220
  useHealthkitAuthorization,
220
221
  useSources,
221
222
  useStatisticsForQuantity,
223
+ queryStateOfMindSamples,
222
224
  }
223
225
 
224
226
  const queryWorkouts = queryWorkoutSamples
@@ -278,6 +280,7 @@ export {
278
280
  useSources,
279
281
  useStatisticsForQuantity,
280
282
  isProtectedDataAvailable,
283
+ queryStateOfMindSamples,
281
284
  }
282
285
 
283
286
  export * from './types'
@@ -109,7 +109,8 @@ const authorizationStatusFor = UnavailableFn(Promise.resolve(HKAuthorizationStat
109
109
  useSubscribeToChanges = UnavailableFn([null, () => null]),
110
110
  useHealthkitAuthorization = UnavailableFn([null, async () => Promise.resolve(HKAuthorizationRequestStatus.unknown)] as const),
111
111
  useIsHealthDataAvailable = () => false,
112
- isProtectedDataAvailable = async () => Promise.resolve(false)
112
+ isProtectedDataAvailable = async () => Promise.resolve(false),
113
+ queryStateOfMindSamples = UnavailableFn(Promise.resolve([]))
113
114
 
114
115
  const Healthkit: typeof ReactNativeHealthkit = {
115
116
  authorizationStatusFor,
@@ -163,6 +164,7 @@ const Healthkit: typeof ReactNativeHealthkit = {
163
164
  useSources,
164
165
  useStatisticsForQuantity,
165
166
  useSubscribeToChanges,
167
+ queryStateOfMindSamples,
166
168
  }
167
169
 
168
170
  export {
@@ -217,6 +219,7 @@ export {
217
219
  useSources,
218
220
  useStatisticsForQuantity,
219
221
  useSubscribeToChanges,
222
+ queryStateOfMindSamples,
220
223
  }
221
224
 
222
225
  export * from './types'
@@ -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
@@ -2263,8 +2270,54 @@ type ReactNativeHealthkitTypeNative = {
2263
2270
  readonly startWatchAppWithWorkoutConfiguration: (
2264
2271
  workoutConfiguration: HKWorkoutConfiguration
2265
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[]>;
2266
2290
  };
2267
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
+
2268
2321
  const Native = NativeModules.ReactNativeHealthkit as ReactNativeHealthkitTypeNative
2269
2322
 
2270
2323
  type OnChangeCallback = ({
@@ -2285,3 +2338,81 @@ export const EventEmitter = new NativeEventEmitter(
2285
2338
  ) as HealthkitEventEmitter
2286
2339
 
2287
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
@@ -43,6 +43,7 @@ beforeAll(async () => {
43
43
  saveWorkoutRoute: jest.fn(),
44
44
  getWorkoutPlanById: jest.fn(),
45
45
  startWatchAppWithWorkoutConfiguration: jest.fn(),
46
+ queryStateOfMindSamples: jest.fn(),
46
47
  }
47
48
 
48
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
@@ -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>