@seamapi/http 0.31.0 → 0.32.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +39 -33
- package/dist/connect.cjs +1 -1
- package/dist/connect.cjs.map +1 -1
- package/lib/seam/connect/parse-options.js +1 -1
- package/lib/seam/connect/parse-options.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
- package/src/lib/seam/connect/parse-options.ts +1 -1
- package/src/lib/version.ts +1 -1
package/README.md
CHANGED
|
@@ -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
|
|
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
|
|
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
|
-
|
|
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.
|
|
224
|
-
|
|
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:
|
|
243
|
+
waitForActionAttempt: false,
|
|
227
244
|
},
|
|
228
245
|
)
|
|
229
246
|
```
|
|
230
247
|
|
|
231
|
-
|
|
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:
|
|
253
|
+
waitForActionAttempt: false,
|
|
237
254
|
})
|
|
238
255
|
|
|
239
256
|
await seam.locks.unlockDoor({ device_id })
|
|
240
257
|
```
|
|
241
258
|
|
|
242
|
-
|
|
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.
|
|
247
|
-
{
|
|
262
|
+
await seam.locks.unlockDoor(
|
|
263
|
+
{ device_id },
|
|
248
264
|
{
|
|
249
|
-
waitForActionAttempt:
|
|
265
|
+
waitForActionAttempt: false,
|
|
250
266
|
},
|
|
251
267
|
)
|
|
252
268
|
```
|
|
253
269
|
|
|
254
|
-
|
|
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)) {
|
package/dist/connect.cjs
CHANGED
|
@@ -57,7 +57,7 @@ var parseOptions = (apiKeyOrOptions) => {
|
|
|
57
57
|
var getNormalizedOptions = (apiKeyOrOptions) => {
|
|
58
58
|
const options = typeof apiKeyOrOptions === "string" ? { apiKey: apiKeyOrOptions } : apiKeyOrOptions;
|
|
59
59
|
const requestOptions = {
|
|
60
|
-
waitForActionAttempt: options.waitForActionAttempt ??
|
|
60
|
+
waitForActionAttempt: options.waitForActionAttempt ?? true
|
|
61
61
|
};
|
|
62
62
|
if (isSeamHttpOptionsWithClient(options)) {
|
|
63
63
|
return {
|