@@ -170,7 +170,7 @@ or create a new empty client session.
170
170
171
171
A Personal Access Token is scoped to a Seam Console user.
172
172
Obtain one from the Seam Console.
173
- A workspace id must be provided when using this method
173
+ A workspace ID must be provided when using this method
174
174
and all requests will be scoped to that workspace.
175
175
176
176
``` ts
@@ -192,7 +192,7 @@ const seam = SeamHttp.fromPersonalAccessToken(
192
192
193
193
A Console Session Token is used by the Seam Console.
194
194
This authentication method is only used by internal Seam applications.
195
- A workspace id must be provided when using this method
195
+ A workspace ID must be provided when using this method
196
196
and all requests will be scoped to that workspace.
197
197
198
198
``` ts
@@ -212,53 +212,62 @@ const seam = SeamHttp.fromConsoleSessionToken(
212
212
### Action Attempts
213
213
214
214
Some asynchronous operations, e.g., unlocking a door, return an [ action attempt] .
215
- Seam tracks the progress of requested operation and updates the action attempt.
215
+ Seam tracks the progress of the requested operation and updates the action attempt
216
+ when it succeeds or fails.
216
217
217
218
To make working with action attempts more convenient for applications,
218
- this library provides the ` waitForActionAttempt ` option.
219
+ this library provides the ` waitForActionAttempt ` option and enables it by default .
219
220
220
- Pass the option per-request,
221
+ When the ` waitForActionAttempt ` option is enabled, the SDK:
222
+
223
+ - Polls the action attempt up to the ` timeout `
224
+ at the ` pollingInterval ` (both in milliseconds).
225
+ - Resolves with a fresh copy of the successful action attempt.
226
+ - Rejects with a ` SeamActionAttemptFailedError ` if the action attempt is unsuccessful.
227
+ - Rejects with a ` SeamActionAttemptTimeoutError ` if the action attempt is still pending when the ` timeout ` is reached.
228
+ - Both errors expose an ` actionAttempt ` property.
229
+
230
+ If you already have an action attempt ID
231
+ and want to wait for it to resolve, simply use
221
232
222
233
``` ts
223
- await seam .locks .unlockDoor (
224
- { device_id },
234
+ await seam .actionAttempts .get ({ action_attempt_id })
235
+ ```
236
+
237
+ Or, to get the current state of an action attempt by ID without waiting,
238
+
239
+ ``` ts
240
+ await seam .actionAttempts .get (
241
+ { action_attempt_id },
225
242
{
226
- waitForActionAttempt: true ,
243
+ waitForActionAttempt: false ,
227
244
},
228
245
)
229
246
```
230
247
231
- or set the default option for the client:
248
+ To disable this behavior, set the default option for the client,
232
249
233
250
``` ts
234
251
const seam = new SeamHttp ({
235
252
apiKey: ' your-api-key' ,
236
- waitForActionAttempt: true ,
253
+ waitForActionAttempt: false ,
237
254
})
238
255
239
256
await seam .locks .unlockDoor ({ device_id })
240
257
```
241
258
242
- If you have already have an action attempt id
243
- and want to wait for it to resolve, simply use
259
+ or the behavior may be configured per-request,
244
260
245
261
``` ts
246
- await seam .actionAttempts . get (
247
- { action_attempt_id },
262
+ await seam .locks . unlockDoor (
263
+ { device_id },
248
264
{
249
- waitForActionAttempt: true ,
265
+ waitForActionAttempt: false ,
250
266
},
251
267
)
252
268
```
253
269
254
- Using the ` waitForActionAttempt ` option:
255
-
256
- - Polls the action attempt up to the ` timeout `
257
- at the ` pollingInterval ` (both in milliseconds).
258
- - Resolves with a fresh copy of the successful action attempt.
259
- - Rejects with a ` SeamActionAttemptFailedError ` if the action attempt is unsuccessful.
260
- - Rejects with a ` SeamActionAttemptTimeoutError ` if the action attempt is still pending when the ` timeout ` is reached.
261
- - Both errors expose an ` actionAttempt ` property.
270
+ The ` pollingInterval ` and ` timeout ` may be configured for the client or per-request, for example
262
271
263
272
``` ts
264
273
import {
@@ -267,22 +276,19 @@ import {
267
276
isSeamActionAttemptTimeoutError ,
268
277
} from ' @seamapi/http/connect'
269
278
270
- const seam = new SeamHttp (' your-api-key' )
279
+ const seam = new SeamHttp (' your-api-key' , {
280
+ waitForActionAttempt: {
281
+ pollingInterval: 1000 ,
282
+ timeout: 5000 ,
283
+ },
284
+ })
271
285
272
286
const [lock] = await seam .locks .list ()
273
287
274
288
if (lock == null ) throw new Error (' No locks in this workspace' )
275
289
276
290
try {
277
- await seam .locks .unlockDoor (
278
- { device_id: lock .device_id },
279
- {
280
- waitForActionAttempt: {
281
- pollingInterval: 1000 ,
282
- timeout: 5000 ,
283
- },
284
- },
285
- )
291
+ await seam .locks .unlockDoor ({ device_id: lock .device_id })
286
292
console .log (' Door unlocked' )
287
293
} catch (err : unknown ) {
288
294
if (isSeamActionAttemptFailedError (err )) {
0 commit comments