@seamapi/http 1.0.0-rc.0 → 1.0.0-rc.2

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.
Files changed (72) hide show
  1. package/LICENSE.txt +1 -1
  2. package/README.md +40 -34
  3. package/dist/connect.cjs +49 -67
  4. package/dist/connect.cjs.map +1 -1
  5. package/dist/connect.d.cts +1003 -59
  6. package/lib/seam/connect/parse-options.js +1 -1
  7. package/lib/seam/connect/parse-options.js.map +1 -1
  8. package/lib/seam/connect/resolve-action-attempt.d.ts +1273 -5
  9. package/lib/seam/connect/resolve-action-attempt.js.map +1 -1
  10. package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +2 -2
  11. package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
  12. package/lib/seam/connect/routes/access-codes.d.ts +2 -2
  13. package/lib/seam/connect/routes/access-codes.js.map +1 -1
  14. package/lib/seam/connect/routes/acs-access-groups.d.ts +2 -2
  15. package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
  16. package/lib/seam/connect/routes/acs-credentials.d.ts +6 -2
  17. package/lib/seam/connect/routes/acs-credentials.js +8 -0
  18. package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
  19. package/lib/seam/connect/routes/acs-systems.d.ts +4 -0
  20. package/lib/seam/connect/routes/acs-systems.js +8 -0
  21. package/lib/seam/connect/routes/acs-systems.js.map +1 -1
  22. package/lib/seam/connect/routes/acs-users.d.ts +6 -6
  23. package/lib/seam/connect/routes/acs-users.js.map +1 -1
  24. package/lib/seam/connect/routes/client-sessions.d.ts +4 -4
  25. package/lib/seam/connect/routes/client-sessions.js.map +1 -1
  26. package/lib/seam/connect/routes/connect-webviews.d.ts +2 -2
  27. package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
  28. package/lib/seam/connect/routes/connected-accounts.d.ts +2 -2
  29. package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
  30. package/lib/seam/connect/routes/devices-simulate.d.ts +2 -2
  31. package/lib/seam/connect/routes/devices-simulate.js.map +1 -1
  32. package/lib/seam/connect/routes/devices.d.ts +2 -2
  33. package/lib/seam/connect/routes/devices.js.map +1 -1
  34. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +2 -2
  35. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
  36. package/lib/seam/connect/routes/phones.d.ts +2 -2
  37. package/lib/seam/connect/routes/phones.js.map +1 -1
  38. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +2 -2
  39. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -1
  40. package/lib/seam/connect/routes/user-identities-enrollment-automations.d.ts +2 -2
  41. package/lib/seam/connect/routes/user-identities-enrollment-automations.js.map +1 -1
  42. package/lib/seam/connect/routes/user-identities.d.ts +6 -6
  43. package/lib/seam/connect/routes/user-identities.js.map +1 -1
  44. package/lib/seam/connect/routes/webhooks.d.ts +2 -2
  45. package/lib/seam/connect/routes/webhooks.js.map +1 -1
  46. package/lib/version.d.ts +1 -1
  47. package/lib/version.js +1 -1
  48. package/package.json +6 -6
  49. package/src/lib/seam/connect/parse-options.ts +1 -1
  50. package/src/lib/seam/connect/resolve-action-attempt.ts +16 -9
  51. package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +2 -2
  52. package/src/lib/seam/connect/routes/access-codes.ts +2 -2
  53. package/src/lib/seam/connect/routes/acs-access-groups.ts +2 -2
  54. package/src/lib/seam/connect/routes/acs-credentials.ts +25 -2
  55. package/src/lib/seam/connect/routes/acs-systems.ts +26 -0
  56. package/src/lib/seam/connect/routes/acs-users.ts +6 -6
  57. package/src/lib/seam/connect/routes/client-sessions.ts +4 -4
  58. package/src/lib/seam/connect/routes/connect-webviews.ts +2 -2
  59. package/src/lib/seam/connect/routes/connected-accounts.ts +4 -2
  60. package/src/lib/seam/connect/routes/devices-simulate.ts +2 -2
  61. package/src/lib/seam/connect/routes/devices.ts +2 -2
  62. package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +2 -2
  63. package/src/lib/seam/connect/routes/phones.ts +2 -2
  64. package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +2 -2
  65. package/src/lib/seam/connect/routes/user-identities-enrollment-automations.ts +2 -2
  66. package/src/lib/seam/connect/routes/user-identities.ts +6 -6
  67. package/src/lib/seam/connect/routes/webhooks.ts +2 -2
  68. package/src/lib/version.ts +1 -1
  69. package/lib/seam/connect/action-attempt-types.d.ts +0 -17
  70. package/lib/seam/connect/action-attempt-types.js +0 -3
  71. package/lib/seam/connect/action-attempt-types.js.map +0 -1
  72. package/src/lib/seam/connect/action-attempt-types.ts +0 -22
package/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2021-2023 Seam Labs, Inc.
3
+ Copyright (c) 2021-2024 Seam Labs, Inc.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
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 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)) {
@@ -351,7 +357,7 @@ const workspaces = await seam.workspaces.list()
351
357
 
352
358
  #### Additional Options
353
359
 
354
- In addition the various authentication options,
360
+ In addition to the various authentication options,
355
361
  the constructor takes some advanced options that affect behavior.
356
362
 
357
363
  ```ts
package/dist/connect.cjs CHANGED
@@ -11,24 +11,13 @@ var axios__default = /*#__PURE__*/_interopDefault(axios);
11
11
  var axiosBetterStacktrace__default = /*#__PURE__*/_interopDefault(axiosBetterStacktrace);
12
12
  var axiosRetry__default = /*#__PURE__*/_interopDefault(axiosRetry);
13
13
 
14
- var __accessCheck = (obj, member, msg) => {
15
- if (!member.has(obj))
16
- throw TypeError("Cannot " + msg);
17
- };
18
- var __privateGet = (obj, member, getter) => {
19
- __accessCheck(obj, member, "read from private field");
20
- return getter ? getter.call(obj) : member.get(obj);
21
- };
22
- var __privateAdd = (obj, member, value) => {
23
- if (member.has(obj))
24
- throw TypeError("Cannot add the same private member more than once");
25
- member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
26
- };
27
- var __privateSet = (obj, member, value, setter) => {
28
- __accessCheck(obj, member, "write to private field");
29
- setter ? setter.call(obj, value) : member.set(obj, value);
30
- return value;
14
+ var __typeError = (msg) => {
15
+ throw TypeError(msg);
31
16
  };
17
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
18
+ var __privateGet = (obj, member, getter) => (__accessCheck(obj, member, "read from private field"), getter ? getter.call(obj) : member.get(obj));
19
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
20
+ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "write to private field"), member.set(obj, value), value);
32
21
 
33
22
  // src/lib/lts-version.ts
34
23
  var seamApiLtsVersion = "1.0.0";
@@ -46,10 +35,8 @@ var sdkHeaders = {
46
35
  };
47
36
  var parseOptions = (apiKeyOrOptions) => {
48
37
  const options = getNormalizedOptions(apiKeyOrOptions);
49
- if (isSeamHttpOptionsWithClient(options))
50
- return options;
51
- if (isSeamHttpMultiWorkspaceOptionsWithClient(options))
52
- return options;
38
+ if (isSeamHttpOptionsWithClient(options)) return options;
39
+ if (isSeamHttpMultiWorkspaceOptionsWithClient(options)) return options;
53
40
  return {
54
41
  ...options,
55
42
  axiosOptions: {
@@ -70,7 +57,7 @@ var parseOptions = (apiKeyOrOptions) => {
70
57
  var getNormalizedOptions = (apiKeyOrOptions) => {
71
58
  const options = typeof apiKeyOrOptions === "string" ? { apiKey: apiKeyOrOptions } : apiKeyOrOptions;
72
59
  const requestOptions = {
73
- waitForActionAttempt: options.waitForActionAttempt ?? false
60
+ waitForActionAttempt: options.waitForActionAttempt ?? true
74
61
  };
75
62
  if (isSeamHttpOptionsWithClient(options)) {
76
63
  return {
@@ -129,10 +116,8 @@ var isSeamHttpRequestOption = (key) => {
129
116
  // src/lib/seam/connect/options.ts
130
117
  var isSeamHttpMultiWorkspaceOptionsWithClient = (options) => isSeamHttpOptionsWithClient(options);
131
118
  var isSeamHttpOptionsWithClient = (options) => {
132
- if (!("client" in options))
133
- return false;
134
- if (options.client == null)
135
- return false;
119
+ if (!("client" in options)) return false;
120
+ if (options.client == null) return false;
136
121
  const keys = Object.keys(options).filter((k) => k !== "client");
137
122
  if (keys.filter((k) => !isSeamHttpRequestOption(k)).length > 0) {
138
123
  throw new SeamHttpInvalidOptionsError(
@@ -144,10 +129,8 @@ var isSeamHttpOptionsWithClient = (options) => {
144
129
  return true;
145
130
  };
146
131
  var isSeamHttpOptionsWithApiKey = (options) => {
147
- if (!("apiKey" in options))
148
- return false;
149
- if (options.apiKey == null)
150
- return false;
132
+ if (!("apiKey" in options)) return false;
133
+ if (options.apiKey == null) return false;
151
134
  if ("clientSessionToken" in options && options.clientSessionToken != null) {
152
135
  throw new SeamHttpInvalidOptionsError(
153
136
  "The clientSessionToken option cannot be used with the apiKey option"
@@ -166,10 +149,8 @@ var isSeamHttpOptionsWithApiKey = (options) => {
166
149
  return true;
167
150
  };
168
151
  var isSeamHttpOptionsWithClientSessionToken = (options) => {
169
- if (!("clientSessionToken" in options))
170
- return false;
171
- if (options.clientSessionToken == null)
172
- return false;
152
+ if (!("clientSessionToken" in options)) return false;
153
+ if (options.clientSessionToken == null) return false;
173
154
  if ("apiKey" in options && options.apiKey != null) {
174
155
  throw new SeamHttpInvalidOptionsError(
175
156
  "The apiKey option cannot be used with the clientSessionToken option"
@@ -188,10 +169,8 @@ var isSeamHttpOptionsWithClientSessionToken = (options) => {
188
169
  return true;
189
170
  };
190
171
  var isSeamHttpMultiWorkspaceOptionsWithConsoleSessionToken = (options) => {
191
- if (!("consoleSessionToken" in options))
192
- return false;
193
- if (options.consoleSessionToken == null)
194
- return false;
172
+ if (!("consoleSessionToken" in options)) return false;
173
+ if (options.consoleSessionToken == null) return false;
195
174
  if ("apiKey" in options && options.apiKey != null) {
196
175
  throw new SeamHttpInvalidOptionsError(
197
176
  "The apiKey option cannot be used with the consoleSessionToken option"
@@ -221,10 +200,8 @@ var isSeamHttpOptionsWithConsoleSessionToken = (options) => {
221
200
  return true;
222
201
  };
223
202
  var isSeamHttpMultiWorkspaceOptionsWithPersonalAccessToken = (options) => {
224
- if (!("personalAccessToken" in options))
225
- return false;
226
- if (options.personalAccessToken == null)
227
- return false;
203
+ if (!("personalAccessToken" in options)) return false;
204
+ if (options.personalAccessToken == null) return false;
228
205
  if ("apiKey" in options && options.apiKey != null) {
229
206
  throw new SeamHttpInvalidOptionsError(
230
207
  "The apiKey option cannot be used with the personalAccessToken option"
@@ -479,8 +456,7 @@ var SeamHttpApiError = class extends Error {
479
456
  this.code = type;
480
457
  this.statusCode = statusCode;
481
458
  this.requestId = requestId;
482
- if (data != null)
483
- this.data = data;
459
+ if (data != null) this.data = data;
484
460
  }
485
461
  };
486
462
  var isSeamHttpApiError = (error) => {
@@ -513,30 +489,24 @@ var isSeamHttpInvalidInputError = (error) => {
513
489
 
514
490
  // src/lib/seam/connect/error-interceptor.ts
515
491
  var errorInterceptor = async (err) => {
516
- if (!axios.isAxiosError(err))
517
- throw err;
492
+ if (!axios.isAxiosError(err)) throw err;
518
493
  const { response } = err;
519
494
  const status = response?.status;
520
495
  const requestId = getRequestId(err);
521
- if (status == null)
522
- throw err;
496
+ if (status == null) throw err;
523
497
  if (status === 401) {
524
498
  throw new SeamHttpUnauthorizedError(requestId);
525
499
  }
526
- if (!isApiErrorResponse(response))
527
- throw err;
500
+ if (!isApiErrorResponse(response)) throw err;
528
501
  const { type } = response.data.error;
529
502
  const args = [response.data.error, status, requestId];
530
- if (type === "invalid_input")
531
- throw new SeamHttpInvalidInputError(...args);
503
+ if (type === "invalid_input") throw new SeamHttpInvalidInputError(...args);
532
504
  throw new SeamHttpApiError(...args);
533
505
  };
534
506
  var isApiErrorResponse = (response) => {
535
- if (response == null)
536
- return false;
507
+ if (response == null) return false;
537
508
  const { headers, data } = response;
538
- if (headers == null)
539
- return false;
509
+ if (headers == null) return false;
540
510
  const contentType = headers["Content-Type"];
541
511
  if (typeof contentType === "string" && !contentType.startsWith("application/json")) {
542
512
  return false;
@@ -548,11 +518,9 @@ var isApiErrorResponse = (response) => {
548
518
  };
549
519
  var getRequestId = (err) => {
550
520
  const headers = err.response?.headers;
551
- if (headers == null)
552
- return "";
521
+ if (headers == null) return "";
553
522
  const requestId = headers["seam-request-id"];
554
- if (requestId == null)
555
- return "";
523
+ if (requestId == null) return "";
556
524
  return requestId;
557
525
  };
558
526
  var createClient = (options) => {
@@ -598,8 +566,7 @@ var resolveActionAttempt = async (actionAttempt, actionAttempts, { timeout = 5e3
598
566
  timeoutPromise
599
567
  ]);
600
568
  } finally {
601
- if (timeoutRef != null)
602
- globalThis.clearTimeout(timeoutRef);
569
+ if (timeoutRef != null) globalThis.clearTimeout(timeoutRef);
603
570
  }
604
571
  };
605
572
  var pollActionAttempt = async (actionAttempt, actionAttempts, options) => {
@@ -654,11 +621,12 @@ var SeamActionAttemptTimeoutError = class extends SeamActionAttemptError {
654
621
  var isSuccessfulActionAttempt = (actionAttempt) => actionAttempt.status === "success";
655
622
  var isFailedActionAttempt = (actionAttempt) => actionAttempt.status === "error";
656
623
  var _a, _parent, _config;
624
+ _a = Symbol.toStringTag;
657
625
  var SeamHttpRequest = class {
658
626
  constructor(parent, config) {
659
627
  this[_a] = "SeamHttpRequest";
660
- __privateAdd(this, _parent, void 0);
661
- __privateAdd(this, _config, void 0);
628
+ __privateAdd(this, _parent);
629
+ __privateAdd(this, _config);
662
630
  __privateSet(this, _parent, parent);
663
631
  __privateSet(this, _config, config);
664
632
  }
@@ -717,14 +685,12 @@ var SeamHttpRequest = class {
717
685
  return await this.execute().finally(onfinally);
718
686
  }
719
687
  };
720
- _a = Symbol.toStringTag;
721
688
  _parent = new WeakMap();
722
689
  _config = new WeakMap();
723
690
  var getUrlPrefix = (input) => {
724
691
  if (canParseUrl(input)) {
725
692
  const url = new URL(input).toString();
726
- if (url.endsWith("/"))
727
- return url.slice(0, -1);
693
+ if (url.endsWith("/")) return url.slice(0, -1);
728
694
  return url;
729
695
  }
730
696
  if (globalThis.location != null) {
@@ -1646,6 +1612,14 @@ var SeamHttpAcsCredentials = class _SeamHttpAcsCredentials {
1646
1612
  responseKey: "acs_credentials"
1647
1613
  });
1648
1614
  }
1615
+ listAccessibleEntrances(body) {
1616
+ return new SeamHttpRequest(this, {
1617
+ path: "/acs/credentials/list_accessible_entrances",
1618
+ method: "post",
1619
+ body,
1620
+ responseKey: "acs_entrances"
1621
+ });
1622
+ }
1649
1623
  unassign(body) {
1650
1624
  return new SeamHttpRequest(this, {
1651
1625
  path: "/acs/credentials/unassign",
@@ -1868,6 +1842,14 @@ var SeamHttpAcsSystems = class _SeamHttpAcsSystems {
1868
1842
  responseKey: "acs_systems"
1869
1843
  });
1870
1844
  }
1845
+ listCompatibleCredentialManagerAcsSystems(body) {
1846
+ return new SeamHttpRequest(this, {
1847
+ path: "/acs/systems/list_compatible_credential_manager_acs_systems",
1848
+ method: "post",
1849
+ body,
1850
+ responseKey: "acs_systems"
1851
+ });
1852
+ }
1871
1853
  };
1872
1854
 
1873
1855
  // src/lib/seam/connect/routes/acs-users.ts