# @ovok/native/data-sync

Canonical page: https://docs.ovok.com/native-sdk/reference/data-sync

Apple Health and Health Connect import: authorization, sync progress and manual request UI.

Import from `@ovok/native/data-sync`.

## Components [#components]

### SyncProgressList [#syncprogresslist]

```ts
const SyncProgressList: MemoExoticComponent<(__namedParameters) => Element>;
```

Lists the sync progress of each data type with its status.

***

### DataSync() [#datasync]

```ts
function DataSync(__namedParameters): Element;
```

Namespace for the health data sync components; renders its children.

#### Parameters [#parameters]

| Parameter | Type |
| ------ | ------ |
| `__namedParameters` | \{ \} |

#### Returns [#returns]

`Element`

## Hooks [#hooks]

### useHealthAuthorization() [#usehealthauthorization]

```ts
function useHealthAuthorization(): HealthAuthorizationValue;
```

Returns the health authorization state; must be used inside an Apple Health or Health Connect authorization provider.

#### Returns [#returns-1]

[`HealthAuthorizationValue`](#healthauthorizationvalue)

## Classes [#classes]

### HealthSyncBatchError [#healthsyncbatcherror]

Error of a health import batch that did not save every entry, carrying the server response.

#### Extends [#extends]

- `Error`

#### Constructors [#constructors]

##### Constructor [#constructor]

```ts
new HealthSyncBatchError(
   message,
   bundle?,
   outcome?
): HealthSyncBatchError;
```

###### Parameters [#parameters-1]

| Parameter | Type | Description |
| ------ | ------ | ------ |
| `message` | `string` | - |
| `bundle?` | `Bundle`\<`Resource`\> | Transaction response bundle of the batch that failed to save every entry. |
| `outcome?` | `OperationOutcome` | Operation outcome the server returned for the batch. |

###### Returns [#returns-2]

[`HealthSyncBatchError`](#healthsyncbatcherror)

###### Overrides [#overrides]

`Error.constructor`

#### Properties [#properties]

| Property | Modifier | Type | Default value | Description | Overrides |
| ------ | ------ | ------ | ------ | ------ | ------ |
| <a id="property-bundle"></a> `bundle?` | `public readonly` | `Bundle`\<`Resource`\> | `undefined` | Transaction response bundle of the batch that failed to save every entry. | - |
| <a id="property-name"></a> `name` | `public readonly` | `"HealthSyncBatchError"` | `"HealthSyncBatchError"` | Error name. | `Error.name` |
| <a id="property-outcome"></a> `outcome?` | `public readonly` | `OperationOutcome` | `undefined` | Operation outcome the server returned for the batch. | - |

## Functions [#functions]

### getHealthDataCoding() [#gethealthdatacoding]

```ts
function getHealthDataCoding(
   provider,
   identifier,
   mode
): object;
```

Returns the coding for a health platform identifier and data mode.

#### Parameters [#parameters-2]

| Parameter | Type |
| ------ | ------ |
| `provider` | `HealthProvider` |
| `identifier` | `string` |
| `mode` | [`HealthDataMode`](#healthdatamode) |

#### Returns [#returns-3]

| Name | Type | Description |
| ------ | ------ | ------ |
| `code` | `string` | Code of the coding. |
| `display?` | `string` | Human readable name of the code, when known. |
| `system` | `string` | Code system of the coding. |

***

### getHealthDataMode() [#gethealthdatamode]

```ts
function getHealthDataMode(key, configuredMode?): HealthDataMode;
```

Returns the configured mode, or the default mode of the data type.

#### Parameters [#parameters-3]

| Parameter | Type |
| ------ | ------ |
| `key` | [`HealthSyncKey`](#healthsynckey) |
| `configuredMode?` | [`HealthDataMode`](#healthdatamode) |

#### Returns [#returns-4]

[`HealthDataMode`](#healthdatamode)

***

### toHealthSyncError() [#tohealthsyncerror]

```ts
function toHealthSyncError(error): Error;
```

Converts a failed batch response or error into an `Error`, keeping the bundle or outcome.

#### Parameters [#parameters-4]

| Parameter | Type |
| ------ | ------ |
| `error` | `unknown` |

#### Returns [#returns-5]

`Error`

## Type Aliases [#type-aliases]

### AndroidHealthConnectAuthorizationStatus [#androidhealthconnectauthorizationstatus]

```ts
type AndroidHealthConnectAuthorizationStatus = object;
```

Health Connect authorization state.

#### Properties [#properties-1]

##### backgroundAccess? [#backgroundaccess]

```ts
backgroundAccess?: "authorized" | "shouldRequest" | "refused" | "unsupported";
```

Background access is reported independently; it never blocks foreground import.

##### error? [#error]

```ts
error?: Error;
```

Error of the last authorization attempt.

##### missingTypes? [#missingtypes]

```ts
missingTypes?: readonly string[];
```

Record types that still need authorization.

##### state [#state]

```ts
state:
  | "unknown"
  | "shouldRequest"
  | "requesting"
  | "authorized"
  | "refused"
  | "error";
```

Current authorization stage.

***

### AndroidHealthSyncProps [#androidhealthsyncprops]

```ts
type AndroidHealthSyncProps = HealthSyncProps<RecordType>;
```

Props of `AndroidHealthSync`.

***

### AppleHealthAuthorizationStatus [#applehealthauthorizationstatus]

```ts
type AppleHealthAuthorizationStatus = object;
```

Apple Health authorization state.

#### Properties [#properties-2]

##### error? [#error-1]

```ts
error?: Error;
```

Error of the last authorization attempt.

##### notRequestedMeasurementTypes [#notrequestedmeasurementtypes]

```ts
notRequestedMeasurementTypes: HealthSyncKey[];
```

Configured measurement types with at least one unanswered read identifier.

##### notRequestedReadIdentifiers [#notrequestedreadidentifiers]

```ts
notRequestedReadIdentifiers: AppleHealthDataTypeIdentifier[];
```

HealthKit types that still need to be answered in Settings.

##### notRequestedWriteIdentifiers [#notrequestedwriteidentifiers]

```ts
notRequestedWriteIdentifiers: SampleTypeIdentifierWriteable[];
```

HealthKit write types that still need to be answered in Settings.

##### state [#state-1]

```ts
state: "unknown" | "shouldRequest" | "requesting" | "ready" | "error";
```

Current authorization stage.

***

### AppleHealthDataTypeIdentifier [#applehealthdatatypeidentifier]

```ts
type AppleHealthDataTypeIdentifier = SampleTypeIdentifier;
```

HealthKit sample type identifiers supported by the SDK.

***

### AppleHealthSyncProps [#applehealthsyncprops]

```ts
type AppleHealthSyncProps = HealthSyncProps<AppleHealthDataTypeIdentifier> & object;
```

Props of `AppleHealthSync`.

#### Type Declaration [#type-declaration]

| Name | Type | Description |
| ------ | ------ | ------ |
| `backgroundDelivery?` | `object` | Enables HealthKit observer delivery while the app is in the background. |
| `backgroundDelivery.frequency?` | `UpdateFrequency` | How often HealthKit delivers updates in the background. |

***

### HealthAuthorizationValue [#healthauthorizationvalue]

```ts
type HealthAuthorizationValue =
  | {
  missingTypes: readonly string[];
  platform: "apple-health";
  request: () => Promise<void>;
  status: AppleHealthAuthorizationStatus;
}
  | {
  missingTypes: readonly string[];
  platform: "health-connect";
  request: () => Promise<void>;
  status: AndroidHealthConnectAuthorizationStatus;
};
```

Authorization state and request action of the active health platform.

#### Union Members [#union-members]

##### Type Literal [#type-literal]

```ts
{
  missingTypes: readonly string[];
  platform: "apple-health";
  request: () => Promise<void>;
  status: AppleHealthAuthorizationStatus;
}
```

| Name | Type | Description |
| ------ | ------ | ------ |
| `missingTypes` | readonly `string`[] | Data types that have not been authorized. |
| `platform` | `"apple-health"` | Apple Health platform. |
| `request()` | () => `Promise`\<`void`\> | Requests the missing authorizations. |
| `status` | [`AppleHealthAuthorizationStatus`](#applehealthauthorizationstatus) | Authorization status. |

***

##### Type Literal [#type-literal-1]

```ts
{
  missingTypes: readonly string[];
  platform: "health-connect";
  request: () => Promise<void>;
  status: AndroidHealthConnectAuthorizationStatus;
}
```

| Name | Type | Description |
| ------ | ------ | ------ |
| `missingTypes` | readonly `string`[] | Data types that have not been authorized. |
| `platform` | `"health-connect"` | Health Connect platform. |
| `request()` | () => `Promise`\<`void`\> | Requests the missing authorizations. |
| `status` | [`AndroidHealthConnectAuthorizationStatus`](#androidhealthconnectauthorizationstatus) | Authorization status. |

***

### HealthDataMode [#healthdatamode]

```ts
type HealthDataMode = "point" | "daily-total" | "daily-summary" | "session" | "series";
```

How a data type is turned into observations.

***

### HealthSyncKey [#healthsynckey]

```ts
type HealthSyncKey = HealthSyncKeys | HealthDataType;
```

Measurement type or health-only data type that can be synced.

***

### HealthSyncKeys [#healthsynckeys]

```ts
type HealthSyncKeys = Exclude<MeasurementTypeKey,
  | MeasurementTypeKey.photoUpload
| MeasurementTypeKey.symptomQuestionnaire>;
```

Measurement types that can be synced, excluding photo upload and symptom questionnaire.

***

### SyncPauseReason [#syncpausereason]

```ts
type SyncPauseReason = "offline" | "wifi-only";
```

Why a sync is paused.

***

### SyncProgress [#syncprogress]

```ts
type SyncProgress = object;
```

Sync state of one data type.

#### Properties [#properties-3]

##### measurementTypeKey [#measurementtypekey]

```ts
measurementTypeKey: HealthSyncKey;
```

Data type being synced.

##### progress? [#progress]

```ts
progress?: object;
```

Records processed so far.

###### created? [#created]

```ts
created?: number;
```

Number of observations created instead of matched or updated.

###### done [#done]

```ts
done: number;
```

Records processed.

###### total [#total]

```ts
total: number;
```

Records to process.

##### reason? [#reason]

```ts
reason?: SyncPauseReason;
```

Why the sync is paused.

##### status [#status]

```ts
status: "started" | "completed" | "failed" | "idle" | "syncing" | "paused";
```

Current sync stage.

***

### SyncProgressListProps [#syncprogresslistprops]

```ts
type SyncProgressListProps = object;
```

Props of `SyncProgressList`.

#### Properties [#properties-4]

##### labelForType? [#labelfortype]

```ts
labelForType?: (type) => string;
```

Returns the display label of a data type.

###### Parameters [#parameters-5]

| Parameter | Type |
| ------ | ------ |
| `type` | `string` |

###### Returns [#returns-6]

`string`

##### progress [#progress-1]

```ts
progress:
  | Partial<Record<string, SyncProgress>>
  | null
  | undefined;
```

Sync progress per data type.

##### reasonLabels? [#reasonlabels]

```ts
reasonLabels?: Partial<Record<NonNullable<SyncProgress["reason"]>, string>>;
```

Overrides the pause reason texts.

##### statusLabels? [#statuslabels]

```ts
statusLabels?: Partial<Record<SyncProgress["status"], string>>;
```

Overrides the status texts.

##### Text? [#text]

```ts
Text?: React.ComponentType<React.ComponentProps<typeof PaperText>>;
```

Text component used to render labels.

## Enumerations [#enumerations]

### HealthDataType [#healthdatatype]

Health data that is not represented by a core measurement service.

#### Enumeration Members [#enumeration-members]

| Enumeration Member | Value | Description |
| ------ | ------ | ------ |
| <a id="enumeration-member-activeenergy"></a> `activeEnergy` | `"active-energy"` | Active energy burned. |
| <a id="enumeration-member-bloodalcohol"></a> `bloodAlcohol` | `"blood-alcohol"` | Blood alcohol content. |
| <a id="enumeration-member-bodyfatpercentage"></a> `bodyFatPercentage` | `"body-fat-percentage"` | Body fat percentage. |
| <a id="enumeration-member-bodymassindex"></a> `bodyMassIndex` | `"body-mass-index"` | Body mass index. |
| <a id="enumeration-member-calorieseaten"></a> `caloriesEaten` | `"calories-eaten"` | Food energy eaten. |
| <a id="enumeration-member-carbohydrates"></a> `carbohydrates` | `"carbohydrates"` | Carbohydrates eaten. |
| <a id="enumeration-member-distance"></a> `distance` | `"distance"` | Distance walked or run. |
| <a id="enumeration-member-exerciseminutes"></a> `exerciseMinutes` | `"exercise-minutes"` | Minutes of exercise. |
| <a id="enumeration-member-flightsclimbed"></a> `flightsClimbed` | `"flights-climbed"` | Flights of stairs climbed. |
| <a id="enumeration-member-heartratesummary"></a> `heartRateSummary` | `"heart-rate-summary"` | Summary of heart rate over a period. |
| <a id="enumeration-member-height"></a> `height` | `"height"` | Body height. |
| <a id="enumeration-member-insulin"></a> `insulin` | `"insulin"` | Insulin delivered. |
| <a id="enumeration-member-leanbodymass"></a> `leanBodyMass` | `"lean-body-mass"` | Lean body mass. |
| <a id="enumeration-member-sleep"></a> `sleep` | `"sleep"` | Sleep sessions. |
| <a id="enumeration-member-water"></a> `water` | `"water"` | Water drunk. |
| <a id="enumeration-member-workout"></a> `workout` | `"workout"` | Workout sessions. |

## Variables [#variables]

### HEALTH\_DATA\_CATALOG [#health_data_catalog]

```ts
const HEALTH_DATA_CATALOG: readonly HealthDataCatalogEntry[];
```

Supported Apple Health and Health Connect data types with their LOINC mappings.

***

### HealthAuthorizationContext [#healthauthorizationcontext]

```ts
const HealthAuthorizationContext: Context<HealthAuthorizationValue | null>;
```

Context carrying the health authorization state.

## References [#references]

### HealthImportAdapter [#healthimportadapter]

Re-exports [HealthImportAdapter](/native-sdk/reference/bt-management#healthimportadapter)

***

### useHealthImport [#usehealthimport]

Re-exports [useHealthImport](/native-sdk/reference/bt-management#usehealthimport)
