Skip to content

Commit

Permalink
Document resolveActionAttempt
Browse files Browse the repository at this point in the history
  • Loading branch information
razor-x committed Nov 11, 2023
1 parent edd66c1 commit 87b70e1
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,57 @@ const seam = SeamHttp.fromConsoleSessionToken(
)
```

### Action Attempts

Some asynchronous operations, e.g., unlocking a door, return an [action attempt].
Seam tracks the progress the requested operation and updates the action attempts.

To make working with action attempts more convenient for applications,
this library provides the `resolveActionAttempt` function:

- Polls the action attempt up to the `timeout` (in milliseconds).
- Polls at the `pollingInterval` (in milliseconds).
- Resolves with a fresh copy of the successful action attempt.
- Reject with a `SeamActionAttemptFailedError` if the action attempt is unsuccessful.
- Reject with a `isSeamActionAttemptTimeoutError` if the action attempt is still pending when the `timeout` is reached.

```ts
import {
SeamHttp,
resolveActionAttempt,
isSeamActionAttemptFailedError,
isSeamActionAttemptTimeoutError,
} from '@seamapi/http/connect'

const seam = new SeamHttp('your-api-key')

const [lock] = await seam.locks.list()

if (lock == null) throw new Error('No locks in this workspace')

const actionAttempt = await seam.locks.unlockDoor({
device_id: lock.device_id,
})

try {
await resolveActionAttempt(actionAttempt, seam)
} catch (err: unknown) {
if (isSeamActionAttemptFailedError(err)) {
console.log('Could not unlock the door')
return
}

if (isSeamActionAttemptTimeoutError(err)) {
console.log('Door took too long to unlock')
return
}

throw err
}
```

[action attempt]: https://docs.seam.co/latest/core-concepts/action-attempts

### Advanced Usage

In addition the various authentication options,
Expand Down

0 comments on commit 87b70e1

Please sign in to comment.