# Outbox store

Canonical page: https://docs.ovok.com/flutter-sdk/reference/ovok_sdk/outbox-store

{/* Generated by scripts/generate_reference.dart; do not edit. */}

## OfflineMeasurementFailure [#offlinemeasurementfailure]

```dart
class OfflineMeasurementFailure
```

Why a queued save last failed.

### Constructors [#constructors]

#### OfflineMeasurementFailure.new [#offlinemeasurementfailurenew]

```dart
OfflineMeasurementFailure({
  required String name,
  String? code,
  int? status,
})
```

A failure named [`name`](#offlinemeasurementfailurename), with the server's [`code`](#offlinemeasurementfailurecode) and [`status`](#offlinemeasurementfailurestatus) when known.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `name` | `String` | required named |  |
| `code` | `String?` | named |  |
| `status` | `int?` | named |  |

#### OfflineMeasurementFailure.fromJson [#offlinemeasurementfailurefromjson]

```dart
OfflineMeasurementFailure.fromJson(JsonMap json)
```

Reads a failure stored by [`toJson`](#offlinemeasurementfailuretojson).

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `json` | `JsonMap` | positional |  |

### Properties [#properties]

#### OfflineMeasurementFailure.name [#offlinemeasurementfailurename]

```dart
final String name
```

The error's type, e.g. `OvokServiceException`.

#### OfflineMeasurementFailure.code [#offlinemeasurementfailurecode]

```dart
final String? code
```

The condition the server named, when known.

#### OfflineMeasurementFailure.status [#offlinemeasurementfailurestatus]

```dart
final int? status
```

The HTTP status, when known.

### Methods [#methods]

#### OfflineMeasurementFailure.toJson [#offlinemeasurementfailuretojson]

```dart
JsonMap toJson()
```

The failure as stored in the queue.

Returns `JsonMap`.


## OutboxItem [#outboxitem]

```dart
class OutboxItem extends OutboxItemSummary
```

One reading waiting to be sent: the bundle entries that save it, with their state.

### Constructors [#constructors-1]

#### OutboxItem.new [#outboxitemnew]

```dart
OutboxItem({
  required String id,
  required String ownerKey,
  required OutboxState state,
  required int attempts,
  required int nextAttemptAt,
  required int createdAt,
  required int recordedAt,
  OfflineMeasurementFailure? lastFailure,
  required List<JsonMap> entries,
})
```

An item that sends [`entries`](#outboxitementries) in one FHIR transaction.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `id` | `String` | required named |  |
| `ownerKey` | `String` | required named |  |
| `state` | `OutboxState` | required named |  |
| `attempts` | `int` | required named |  |
| `nextAttemptAt` | `int` | required named |  |
| `createdAt` | `int` | required named |  |
| `recordedAt` | `int` | required named |  |
| `lastFailure` | `OfflineMeasurementFailure?` | named |  |
| `entries` | `List<Map<String, dynamic>>` | required named |  |

### Properties [#properties-1]

#### OutboxItem.entries [#outboxitementries]

```dart
final List<Map<String, dynamic>> entries
```

The bundle entries to send.

### Methods [#methods-1]

#### OutboxItem.copyWith [#outboxitemcopywith]

```dart
OutboxItem copyWith({
  OutboxState? state,
  int? attempts,
  int? nextAttemptAt,
  OfflineMeasurementFailure? lastFailure,
})
```

This item with the given fields replaced.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `state` | `OutboxState?` | named |  |
| `attempts` | `int?` | named |  |
| `nextAttemptAt` | `int?` | named |  |
| `lastFailure` | `OfflineMeasurementFailure?` | named |  |

Returns `OutboxItem`.


## OutboxItemSummary [#outboxitemsummary]

```dart
class OutboxItemSummary
```

An outbox item without its entries: what the outbox lists and counts.

### Constructors [#constructors-2]

#### OutboxItemSummary.new [#outboxitemsummarynew]

```dart
OutboxItemSummary({
  required String id,
  required String ownerKey,
  required OutboxState state,
  required int attempts,
  required int nextAttemptAt,
  required int createdAt,
  required int recordedAt,
  OfflineMeasurementFailure? lastFailure,
})
```

A summary of the item [`id`](#outboxitemsummaryid) that the account [`ownerKey`](#outboxitemsummaryownerkey) queued.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `id` | `String` | required named |  |
| `ownerKey` | `String` | required named |  |
| `state` | `OutboxState` | required named |  |
| `attempts` | `int` | required named |  |
| `nextAttemptAt` | `int` | required named |  |
| `createdAt` | `int` | required named |  |
| `recordedAt` | `int` | required named |  |
| `lastFailure` | `OfflineMeasurementFailure?` | named |  |

### Properties [#properties-2]

#### OutboxItemSummary.id [#outboxitemsummaryid]

```dart
final String id
```

Unique id: the reading's entry `fullUrl`s, joined by `|`.

#### OutboxItemSummary.ownerKey [#outboxitemsummaryownerkey]

```dart
final String ownerKey
```

Account that owns the item; only that account's session sends it.

#### OutboxItemSummary.state [#outboxitemsummarystate]

```dart
final OutboxState state
```

Whether the item is still being sent.

#### OutboxItemSummary.attempts [#outboxitemsummaryattempts]

```dart
final int attempts
```

Attempts that failed.

#### OutboxItemSummary.nextAttemptAt [#outboxitemsummarynextattemptat]

```dart
final int nextAttemptAt
```

Earliest time to try again, in epoch milliseconds.

#### OutboxItemSummary.createdAt [#outboxitemsummarycreatedat]

```dart
final int createdAt
```

When the item entered the outbox, in epoch milliseconds.

#### OutboxItemSummary.recordedAt [#outboxitemsummaryrecordedat]

```dart
final int recordedAt
```

When the reading was taken, in epoch milliseconds; the outbox sends the newest first.

#### OutboxItemSummary.lastFailure [#outboxitemsummarylastfailure]

```dart
final OfflineMeasurementFailure? lastFailure
```

The last failure, when there was one.


## OutboxState [#outboxstate]

```dart
enum OutboxState
```

Whether an outbox item is still being sent.

### Values [#values]

#### OutboxState.pending [#outboxstatepending]

```dart
static const OutboxState pending
```

Waiting to be sent, now or after its backoff.

#### OutboxState.rejected [#outboxstaterejected]

```dart
static const OutboxState rejected
```

Used up its attempts; sent again only by a flush that includes or resets it.


## OutboxStore [#outboxstore]

```dart
abstract interface class OutboxStore
```

Where the outbox keeps its items so they survive a restart.

Every method must be atomic, so a crash leaves an item either stored or not.

### Methods [#methods-2]

#### OutboxStore.put [#outboxstoreput]

```dart
Future<void> put(OutboxItem item)
```

Stores `item`, replacing the one with the same id.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `item` | `OutboxItem` | positional |  |

Returns `Future<void>`.

#### OutboxStore.get [#outboxstoreget]

```dart
Future<OutboxItem?> get(String id)
```

The item `id`, or null when there is none.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `id` | `String` | positional |  |

Returns `Future<OutboxItem?>`.

#### OutboxStore.remove [#outboxstoreremove]

```dart
Future<void> remove(String id)
```

Deletes the item `id`; an unknown id is not an error.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `id` | `String` | positional |  |

Returns `Future<void>`.

#### OutboxStore.due [#outboxstoredue]

```dart
Future<List<OutboxItem>> due(
  String ownerKey,
  int now,
  int limit,
)
```

The owner's pending items whose `nextAttemptAt` is not after `now`, newest `recordedAt` first, at most `limit`.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `ownerKey` | `String` | positional |  |
| `now` | `int` | positional |  |
| `limit` | `int` | positional |  |

Returns `Future<List<OutboxItem>>`.

#### OutboxStore.summaries [#outboxstoresummaries]

```dart
Future<List<OutboxItemSummary>> summaries(String ownerKey)
```

Every item of the owner, in any state, without its entries.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `ownerKey` | `String` | positional |  |

Returns `Future<List<OutboxItemSummary>>`.

#### OutboxStore.count [#outboxstorecount]

```dart
Future<int> count(String ownerKey, OutboxState state)
```

How many of the owner's items are in `state`.

| Parameter | Type | Kind | Default |
| ------ | ------ | ------ | ------ |
| `ownerKey` | `String` | positional |  |
| `state` | `OutboxState` | positional |  |

Returns `Future<int>`.
