# @ovok/native/helpers

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

Shared helpers: form fields, conditional rendering, formatting utilities, logging and telemetry.

Import from `@ovok/native/helpers`.

## Components [#components]

### Conditional [#conditional]

```ts
const Conditional: React.FunctionComponent<ConditionalProps>;
```

Renders its children only when `condition` is true.

***

### FormDateField [#formdatefield]

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

Formik form field that opens a date, time or date-time picker.

***

### FormField [#formfield]

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

Formik form field that renders a text input with its validation message.

***

### FormSelect [#formselect]

```ts
const FormSelect: <T>(props) => ReactElement;
```

Formik form field that renders a dropdown over `options`.

#### Type Parameters [#type-parameters]

| Type Parameter |
| ------ |
| <a id="type-parameter-__typet"></a> `T` *extends* `object` |

#### Parameters [#parameters]

| Parameter | Type |
| ------ | ------ |
| `props` | `FormSelectProps`\<`T`\> |

#### Returns [#returns]

`ReactElement`

## Functions [#functions]

### addOvokSpanEvent() [#addovokspanevent]

```ts
function addOvokSpanEvent(
   name,
   attributes?,
   span?
): void;
```

Adds an event with sanitized attributes to the given or active span; never throws.

#### Parameters [#parameters-1]

| Parameter | Type |
| ------ | ------ |
| `name` | `string` |
| `attributes?` | `Record`\<`string`, `unknown`\> |
| `span?` | [`OvokSpan`](#ovokspan) |

#### Returns [#returns-1]

`void`

***

### configureOvokLogger() [#configureovoklogger]

```ts
function configureOvokLogger(logger?): void;
```

Configure the SDK logger. The default is the console and OpenTelemetry when present.

#### Parameters [#parameters-2]

| Parameter | Type |
| ------ | ------ |
| `logger?` | `OvokLogger` |

#### Returns [#returns-2]

`void`

***

### configureOvokTelemetry() [#configureovoktelemetry]

```ts
function configureOvokTelemetry(options?): void;
```

Sets the telemetry providers and resets cached instruments.

#### Parameters [#parameters-3]

| Parameter | Type |
| ------ | ------ |
| `options?` | [`OvokTelemetryOptions`](#ovoktelemetryoptions) |

#### Returns [#returns-3]

`void`

***

### emitOvokLog() [#emitovoklog]

```ts
function emitOvokLog(
   severityText,
   body,
   attributes?
): void;
```

Emits a scrubbed log record when a logger is available; never throws.

#### Parameters [#parameters-4]

| Parameter | Type |
| ------ | ------ |
| `severityText` | `string` |
| `body` | `string` |
| `attributes?` | `Record`\<`string`, `unknown`\> |

#### Returns [#returns-4]

`void`

***

### ovokLogger() [#ovoklogger]

```ts
function ovokLogger(
   type,
   message,
   extra?
): void;
```

Logs a message through the configured logger and OpenTelemetry; error and fatal levels also count toward the `ovok.errors` metric.

#### Parameters [#parameters-5]

| Parameter | Type |
| ------ | ------ |
| `type` | `OvokLogLevel` |
| `message` | `string` |
| `extra?` | `Record`\<`string`, `unknown`\> |

#### Returns [#returns-5]

`void`

***

### parseDatePickerValue() [#parsedatepickervalue]

```ts
function parseDatePickerValue(value, fallback): Date;
```

Parses a `YYYY-MM-DD` string as a local date, other strings via `Date`; returns `fallback` when the value is not a valid date.

#### Parameters [#parameters-6]

| Parameter | Type |
| ------ | ------ |
| `value` | `string` |
| `fallback` | `Date` |

#### Returns [#returns-6]

`Date`

***

### recordOvokDuration() [#recordovokduration]

```ts
function recordOvokDuration(
   name,
   durationMs,
   attributes?
): void;
```

Records a duration in milliseconds on the named histogram; never throws.

#### Parameters [#parameters-7]

| Parameter | Type |
| ------ | ------ |
| `name` | `string` |
| `durationMs` | `number` |
| `attributes?` | `Record`\<`string`, `unknown`\> |

#### Returns [#returns-7]

`void`

***

### recordOvokMetric() [#recordovokmetric]

```ts
function recordOvokMetric(
   name,
   value,
   attributes?
): void;
```

Adds a value to the named counter; never throws.

#### Parameters [#parameters-8]

| Parameter | Type |
| ------ | ------ |
| `name` | `string` |
| `value` | `number` |
| `attributes?` | `Record`\<`string`, `unknown`\> |

#### Returns [#returns-8]

`void`

***

### sanitizeOvokTelemetryAttributes() [#sanitizeovoktelemetryattributes]

```ts
function sanitizeOvokTelemetryAttributes(attributes?): OvokTelemetryAttributes;
```

Keeps identifiers useful for operations while excluding readings and patient data.

#### Parameters [#parameters-9]

| Parameter | Type |
| ------ | ------ |
| `attributes?` | `Record`\<`string`, `unknown`\> |

#### Returns [#returns-9]

[`OvokTelemetryAttributes`](#ovoktelemetryattributes)

***

### scrubOvokError() [#scrubovokerror]

```ts
function scrubOvokError(error): object;
```

Returns error text without the identifiers commonly echoed by the Ovok API.

#### Parameters [#parameters-10]

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

#### Returns [#returns-10]

| Name | Type | Description |
| ------ | ------ | ------ |
| `message` | `string` | Error message with ids, emails and numbers replaced by placeholders, capped at 500 characters. |
| `name` | `string` | Error class name. |

***

### slog() [#slog]

```ts
function slog(
   error,
   scope,
   additionalData?,
   level?
): void;
```

Logs an error with a scope name and extra data through `ovokLogger`; level defaults to `"error"`.

#### Parameters [#parameters-11]

| Parameter | Type | Default value |
| ------ | ------ | ------ |
| `error` | `any` | `undefined` |
| `scope` | `string` | `undefined` |
| `additionalData?` | `Record`\<`string`, `any`\> | `{}` |
| `level?` | `"error"` \| `"warning"` \| `"info"` \| `"debug"` | `"error"` |

#### Returns [#returns-11]

`void`

***

### startOvokSpan() [#startovokspan]

```ts
function startOvokSpan(name, attributes?): OvokSpan | undefined;
```

Starts a span with sanitized attributes; returns `undefined` when no tracer is available.

#### Parameters [#parameters-12]

| Parameter | Type |
| ------ | ------ |
| `name` | `string` |
| `attributes?` | `Record`\<`string`, `unknown`\> |

#### Returns [#returns-12]

[`OvokSpan`](#ovokspan) \| `undefined`

***

### withAnimated() [#withanimated]

```ts
function withAnimated<T>(WrappedComponent): ComponentType<AnimatedProps<T>>;
```

Wraps a component in a class so Reanimated can animate it; function components cannot take the ref that animation needs.

#### Type Parameters [#type-parameters-1]

| Type Parameter |
| ------ |
| <a id="type-parameter-t"></a> `T` *extends* `object` |

#### Parameters [#parameters-13]

| Parameter | Type |
| ------ | ------ |
| `WrappedComponent` | `ComponentType`\<`T`\> |

#### Returns [#returns-13]

`ComponentType`\<`AnimatedProps`\<`T`\>\>

***

### withOvokSpan() [#withovokspan]

```ts
function withOvokSpan<T>(
   name,
   attributes,
   operation
): Promise<T>;
```

Runs the operation inside a span, recording its outcome and rethrowing any error.

#### Type Parameters [#type-parameters-2]

| Type Parameter |
| ------ |
| <a id="type-parameter-t-1"></a> `T` |

#### Parameters [#parameters-14]

| Parameter | Type |
| ------ | ------ |
| `name` | `string` |
| `attributes` | `Record`\<`string`, `unknown`\> |
| `operation` | () => `T` \| `Promise`\<`T`\> |

#### Returns [#returns-14]

`Promise`\<`T`\>

## Interfaces [#interfaces]

### OvokLoggerProvider [#ovokloggerprovider]

Source of loggers, compatible with the OpenTelemetry logger provider.

#### Properties [#properties]

| Property | Type | Description |
| ------ | ------ | ------ |
| <a id="property-getlogger"></a> `getLogger` | (`name`, `version?`) => `OvokLogEmitter` | Returns the logger for the given instrumentation name and version. |

***

### OvokMeterProvider [#ovokmeterprovider]

Source of meters, compatible with the OpenTelemetry meter provider.

#### Properties [#properties-1]

| Property | Type | Description |
| ------ | ------ | ------ |
| <a id="property-getmeter"></a> `getMeter` | (`name`, `version?`) => `OvokMeter` | Returns the meter for the given instrumentation name and version. |

***

### OvokSpan [#ovokspan]

Minimal OpenTelemetry-compatible span the SDK records to.

#### Properties [#properties-2]

| Property | Type | Description |
| ------ | ------ | ------ |
| <a id="property-addevent"></a> `addEvent?` | (`name`, `attributes?`) => `void` | Adds a named event to the span. |
| <a id="property-end"></a> `end` | () => `void` | Ends the span. |
| <a id="property-recordexception"></a> `recordException?` | (`error`) => `void` | Records an error on the span. |
| <a id="property-setattribute"></a> `setAttribute?` | (`name`, `value`) => `void` | Sets one attribute on the span. |
| <a id="property-setattributes"></a> `setAttributes?` | (`attributes`) => `void` | Sets several attributes on the span. |
| <a id="property-setstatus"></a> `setStatus?` | (`status`) => `void` | Sets the span status; code 1 is OK, 2 is an error. |

***

### OvokTelemetryOptions [#ovoktelemetryoptions]

Telemetry providers to use instead of the global OpenTelemetry API.

#### Properties [#properties-3]

| Property | Type | Description |
| ------ | ------ | ------ |
| <a id="property-loggerprovider"></a> `loggerProvider?` | [`OvokLoggerProvider`](#ovokloggerprovider) | Use this when the app does not register a provider globally. |
| <a id="property-meterprovider"></a> `meterProvider?` | [`OvokMeterProvider`](#ovokmeterprovider) | Use this when the app does not register a provider globally. |
| <a id="property-tracerprovider"></a> `tracerProvider?` | [`OvokTracerProvider`](#ovoktracerprovider) | Use this when the app does not register a provider globally. |

***

### OvokTracerProvider [#ovoktracerprovider]

Source of tracers, compatible with the OpenTelemetry tracer provider.

#### Properties [#properties-4]

| Property | Type | Description |
| ------ | ------ | ------ |
| <a id="property-getactivespan"></a> `getActiveSpan?` | () => [`OvokSpan`](#ovokspan) \| `undefined` | Returns the currently active span, if any. |
| <a id="property-gettracer"></a> `getTracer` | (`name`, `version?`) => `OvokTracer` | Returns the tracer for the given instrumentation name and version. |

## Type Aliases [#type-aliases]

### OvokTelemetryAttribute [#ovoktelemetryattribute]

```ts
type OvokTelemetryAttribute = string | number | boolean;
```

A single telemetry attribute value.

***

### OvokTelemetryAttributes [#ovoktelemetryattributes]

```ts
type OvokTelemetryAttributes = Record<string, OvokTelemetryAttribute>;
```

Telemetry attributes keyed by name.
