@seamapi/http 0.10.0 → 0.10.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 (58) hide show
  1. package/README.md +49 -1
  2. package/dist/connect.cjs +40 -20
  3. package/dist/connect.cjs.map +1 -1
  4. package/dist/connect.d.cts +11 -3
  5. package/lib/params-serializer.js +12 -14
  6. package/lib/params-serializer.js.map +1 -1
  7. package/lib/seam/connect/auth.js.map +1 -1
  8. package/lib/seam/connect/client.js +0 -2
  9. package/lib/seam/connect/client.js.map +1 -1
  10. package/lib/seam/connect/error-interceptor.js +11 -3
  11. package/lib/seam/connect/error-interceptor.js.map +1 -1
  12. package/lib/seam/connect/options.js.map +1 -1
  13. package/lib/seam/connect/parse-options.js.map +1 -1
  14. package/lib/seam/connect/resolve-action-attempt.js.map +1 -1
  15. package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
  16. package/lib/seam/connect/routes/access-codes.js.map +1 -1
  17. package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
  18. package/lib/seam/connect/routes/acs-credential-pools.js.map +1 -1
  19. package/lib/seam/connect/routes/acs-credential-provisioning-automations.js.map +1 -1
  20. package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
  21. package/lib/seam/connect/routes/acs-entrances.d.ts +4 -0
  22. package/lib/seam/connect/routes/acs-entrances.js +7 -0
  23. package/lib/seam/connect/routes/acs-entrances.js.map +1 -1
  24. package/lib/seam/connect/routes/acs-systems.js.map +1 -1
  25. package/lib/seam/connect/routes/acs-users.js.map +1 -1
  26. package/lib/seam/connect/routes/acs.js.map +1 -1
  27. package/lib/seam/connect/routes/action-attempts.js.map +1 -1
  28. package/lib/seam/connect/routes/client-sessions.js.map +1 -1
  29. package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
  30. package/lib/seam/connect/routes/connected-accounts.d.ts +4 -0
  31. package/lib/seam/connect/routes/connected-accounts.js +8 -0
  32. package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
  33. package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -1
  34. package/lib/seam/connect/routes/devices.js.map +1 -1
  35. package/lib/seam/connect/routes/events.js.map +1 -1
  36. package/lib/seam/connect/routes/locks.js.map +1 -1
  37. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
  38. package/lib/seam/connect/routes/noise-sensors.js.map +1 -1
  39. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -1
  40. package/lib/seam/connect/routes/thermostats.js.map +1 -1
  41. package/lib/seam/connect/routes/user-identities.js.map +1 -1
  42. package/lib/seam/connect/routes/webhooks.js.map +1 -1
  43. package/lib/seam/connect/routes/workspaces.js.map +1 -1
  44. package/lib/seam/connect/seam-http-multi-workspace.d.ts +1 -1
  45. package/lib/seam/connect/seam-http-multi-workspace.js.map +1 -1
  46. package/lib/seam/connect/seam-http.d.ts +1 -1
  47. package/lib/seam/connect/seam-http.js.map +1 -1
  48. package/lib/version.d.ts +1 -1
  49. package/lib/version.js +1 -1
  50. package/package.json +10 -10
  51. package/src/lib/params-serializer.ts +8 -19
  52. package/src/lib/seam/connect/client.ts +0 -2
  53. package/src/lib/seam/connect/error-interceptor.ts +11 -3
  54. package/src/lib/seam/connect/routes/acs-entrances.ts +17 -0
  55. package/src/lib/seam/connect/routes/connected-accounts.ts +23 -0
  56. package/src/lib/seam/connect/seam-http-multi-workspace.ts +1 -1
  57. package/src/lib/seam/connect/seam-http.ts +1 -1
  58. package/src/lib/version.ts +1 -1
package/README.md CHANGED
@@ -261,10 +261,58 @@ try {
261
261
 
262
262
  [action attempt]: https://docs.seam.co/latest/core-concepts/action-attempts
263
263
 
264
+ ### Interacting with Multiple Workspaces
265
+
266
+ Some Seam API endpoints interact with multiple workspaces.
267
+ The `SeamHttpMultiWorkspace` client is not bound to a specific workspace
268
+ and may use those endpoints with an appropriate authentication method.
269
+
270
+ #### Personal Access Token
271
+
272
+ A Personal Access Token is scoped to a Seam Console user.
273
+ Obtain one from the Seam Console.
274
+
275
+ ```ts
276
+ // Pass as an option the constructor
277
+ const seam = new SeamHttpMultiWorkspace({
278
+ personalAccessToken: 'your-personal-access-token',
279
+ })
280
+
281
+ // Use the factory method
282
+ const seam = SeamHttpMultiWorkspace.fromPersonalAccessToken(
283
+ 'some-console-session-token',
284
+ )
285
+
286
+ // List workspaces authorized for this Personal Access Token
287
+ const workspaces = await seam.workspaces.list()
288
+ ```
289
+
290
+ #### Console Session Token
291
+
292
+ A Console Session Token is used by the Seam Console.
293
+ This authentication method is only used by internal Seam applications.
294
+
295
+ ```ts
296
+ // Pass as an option the constructor
297
+ const seam = new SeamHttpMultiWorkspace({
298
+ consoleSessionToken: 'some-console-session-token',
299
+ })
300
+
301
+ // Use the factory method
302
+ const seam = SeamHttpMultiWorkspace.fromConsoleSessionToken(
303
+ 'some-console-session-token',
304
+ )
305
+
306
+ // List workspaces authorized for this Seam Console user
307
+ const workspaces = await seam.workspaces.list()
308
+ ```
309
+
264
310
  ### Advanced Usage
265
311
 
312
+ #### Additional Options
313
+
266
314
  In addition the various authentication options,
267
- the constructor takes some additional options that affect behavior.
315
+ the constructor takes some advanced options that affect behavior.
268
316
 
269
317
  ```ts
270
318
  const seam = new SeamHttp({
package/dist/connect.cjs CHANGED
@@ -476,8 +476,7 @@ var errorInterceptor = async (err) => {
476
476
  throw err;
477
477
  const { response } = err;
478
478
  const status = response?.status;
479
- const headers = response?.headers;
480
- const requestId = headers?.["seam-request-id"] ?? "";
479
+ const requestId = getRequestId(err);
481
480
  if (status == null)
482
481
  throw err;
483
482
  if (status === 401) {
@@ -497,7 +496,7 @@ var isApiErrorResponse = (response) => {
497
496
  const { headers, data } = response;
498
497
  if (headers == null)
499
498
  return false;
500
- const contentType = headers["content-type"];
499
+ const contentType = headers["Content-Type"];
501
500
  if (typeof contentType === "string" && !contentType.startsWith("application/json")) {
502
501
  return false;
503
502
  }
@@ -506,6 +505,15 @@ var isApiErrorResponse = (response) => {
506
505
  }
507
506
  return false;
508
507
  };
508
+ var getRequestId = (err) => {
509
+ const headers = err.response?.headers;
510
+ if (headers == null)
511
+ return "";
512
+ const requestId = headers["seam-request-id"];
513
+ if (requestId == null)
514
+ return "";
515
+ return requestId;
516
+ };
509
517
 
510
518
  // src/lib/seam/connect/resolve-action-attempt.ts
511
519
  var resolveActionAttempt = async (actionAttempt, actionAttempts, { timeout = 5e3, pollingInterval = 500 }) => {
@@ -598,30 +606,25 @@ var paramsSerializer = (params) => {
598
606
  );
599
607
  }
600
608
  for (const v of value) {
601
- throwIfUnserializable(name, v);
602
- searchParams.append(name, v);
609
+ searchParams.append(name, serialize(name, v));
603
610
  }
604
611
  continue;
605
612
  }
606
- throwIfUnserializable(name, value);
607
- searchParams.set(name, value);
613
+ searchParams.set(name, serialize(name, value));
608
614
  }
609
615
  searchParams.sort();
610
616
  return searchParams.toString();
611
617
  };
612
- var throwIfUnserializable = (k, v) => {
613
- if (v == null) {
614
- throw new UnserializableParamError(k, `is ${v} or contains ${v}`);
615
- }
616
- if (typeof v === "function") {
617
- throw new UnserializableParamError(
618
- k,
619
- "is a function or contains a function"
620
- );
621
- }
622
- if (typeof v === "object") {
623
- throw new UnserializableParamError(k, "is an object or contains an object");
624
- }
618
+ var serialize = (k, v) => {
619
+ if (typeof v === "string")
620
+ return v.toString();
621
+ if (typeof v === "number")
622
+ return v.toString();
623
+ if (typeof v === "bigint")
624
+ return v.toString();
625
+ if (typeof v === "boolean")
626
+ return v.toString();
627
+ throw new UnserializableParamError(k, `is a ${typeof v}`);
625
628
  };
626
629
  var UnserializableParamError = class extends Error {
627
630
  constructor(name, message) {
@@ -1431,6 +1434,13 @@ var SeamHttpAcsEntrances = class _SeamHttpAcsEntrances {
1431
1434
  });
1432
1435
  return data.acs_entrance;
1433
1436
  }
1437
+ async grantAccess(body) {
1438
+ await this.client.request({
1439
+ url: "/acs/entrances/grant_access",
1440
+ method: "post",
1441
+ data: body
1442
+ });
1443
+ }
1434
1444
  async list(body) {
1435
1445
  const { data } = await this.client.request({
1436
1446
  url: "/acs/entrances/list",
@@ -2011,6 +2021,16 @@ var SeamHttpConnectedAccounts = class _SeamHttpConnectedAccounts {
2011
2021
  });
2012
2022
  return data.connected_accounts;
2013
2023
  }
2024
+ async update(body) {
2025
+ const { data } = await this.client.request(
2026
+ {
2027
+ url: "/connected_accounts/update",
2028
+ method: "post",
2029
+ data: body
2030
+ }
2031
+ );
2032
+ return data.connected_account;
2033
+ }
2014
2034
  };
2015
2035
 
2016
2036
  // src/lib/seam/connect/routes/devices-unmanaged.ts