@seamapi/http 0.3.0 → 0.5.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.
Files changed (122) hide show
  1. package/README.md +212 -1
  2. package/dist/connect.cjs +643 -4
  3. package/dist/connect.cjs.map +1 -1
  4. package/dist/connect.d.cts +84 -2
  5. package/lib/seam/connect/api-error-type.d.ts +8 -0
  6. package/lib/seam/connect/api-error-type.js +3 -0
  7. package/lib/seam/connect/api-error-type.js.map +1 -0
  8. package/lib/seam/connect/auth.js +55 -4
  9. package/lib/seam/connect/auth.js.map +1 -1
  10. package/lib/seam/connect/client.js +5 -0
  11. package/lib/seam/connect/client.js.map +1 -1
  12. package/lib/seam/connect/error-interceptor.d.ts +1 -0
  13. package/lib/seam/connect/error-interceptor.js +43 -0
  14. package/lib/seam/connect/error-interceptor.js.map +1 -0
  15. package/lib/seam/connect/index.d.ts +3 -1
  16. package/lib/seam/connect/index.js +3 -1
  17. package/lib/seam/connect/index.js.map +1 -1
  18. package/lib/seam/connect/options.d.ts +11 -1
  19. package/lib/seam/connect/options.js +51 -1
  20. package/lib/seam/connect/options.js.map +1 -1
  21. package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +3 -1
  22. package/lib/seam/connect/routes/access-codes-unmanaged.js +15 -1
  23. package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
  24. package/lib/seam/connect/routes/access-codes.d.ts +3 -1
  25. package/lib/seam/connect/routes/access-codes.js +15 -1
  26. package/lib/seam/connect/routes/access-codes.js.map +1 -1
  27. package/lib/seam/connect/routes/acs-access-groups.d.ts +3 -1
  28. package/lib/seam/connect/routes/acs-access-groups.js +15 -1
  29. package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
  30. package/lib/seam/connect/routes/acs-credentials.d.ts +3 -1
  31. package/lib/seam/connect/routes/acs-credentials.js +15 -1
  32. package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
  33. package/lib/seam/connect/routes/acs-systems.d.ts +3 -1
  34. package/lib/seam/connect/routes/acs-systems.js +15 -1
  35. package/lib/seam/connect/routes/acs-systems.js.map +1 -1
  36. package/lib/seam/connect/routes/acs-users.d.ts +3 -1
  37. package/lib/seam/connect/routes/acs-users.js +15 -1
  38. package/lib/seam/connect/routes/acs-users.js.map +1 -1
  39. package/lib/seam/connect/routes/acs.d.ts +3 -1
  40. package/lib/seam/connect/routes/acs.js +15 -1
  41. package/lib/seam/connect/routes/acs.js.map +1 -1
  42. package/lib/seam/connect/routes/action-attempts.d.ts +3 -1
  43. package/lib/seam/connect/routes/action-attempts.js +15 -1
  44. package/lib/seam/connect/routes/action-attempts.js.map +1 -1
  45. package/lib/seam/connect/routes/client-sessions.d.ts +3 -1
  46. package/lib/seam/connect/routes/client-sessions.js +15 -1
  47. package/lib/seam/connect/routes/client-sessions.js.map +1 -1
  48. package/lib/seam/connect/routes/connect-webviews.d.ts +3 -1
  49. package/lib/seam/connect/routes/connect-webviews.js +15 -1
  50. package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
  51. package/lib/seam/connect/routes/connected-accounts.d.ts +3 -1
  52. package/lib/seam/connect/routes/connected-accounts.js +15 -1
  53. package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
  54. package/lib/seam/connect/routes/devices-unmanaged.d.ts +3 -1
  55. package/lib/seam/connect/routes/devices-unmanaged.js +15 -1
  56. package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -1
  57. package/lib/seam/connect/routes/devices.d.ts +3 -1
  58. package/lib/seam/connect/routes/devices.js +15 -1
  59. package/lib/seam/connect/routes/devices.js.map +1 -1
  60. package/lib/seam/connect/routes/events.d.ts +3 -1
  61. package/lib/seam/connect/routes/events.js +15 -1
  62. package/lib/seam/connect/routes/events.js.map +1 -1
  63. package/lib/seam/connect/routes/locks.d.ts +3 -1
  64. package/lib/seam/connect/routes/locks.js +15 -1
  65. package/lib/seam/connect/routes/locks.js.map +1 -1
  66. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +3 -1
  67. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +15 -1
  68. package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
  69. package/lib/seam/connect/routes/noise-sensors.d.ts +3 -1
  70. package/lib/seam/connect/routes/noise-sensors.js +15 -1
  71. package/lib/seam/connect/routes/noise-sensors.js.map +1 -1
  72. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +3 -1
  73. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js +15 -1
  74. package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -1
  75. package/lib/seam/connect/routes/thermostats.d.ts +3 -1
  76. package/lib/seam/connect/routes/thermostats.js +15 -1
  77. package/lib/seam/connect/routes/thermostats.js.map +1 -1
  78. package/lib/seam/connect/routes/webhooks.d.ts +3 -1
  79. package/lib/seam/connect/routes/webhooks.js +15 -1
  80. package/lib/seam/connect/routes/webhooks.js.map +1 -1
  81. package/lib/seam/connect/routes/workspaces.d.ts +3 -1
  82. package/lib/seam/connect/routes/workspaces.js +15 -1
  83. package/lib/seam/connect/routes/workspaces.js.map +1 -1
  84. package/lib/seam/connect/seam-http-error.d.ts +20 -0
  85. package/lib/seam/connect/seam-http-error.js +43 -0
  86. package/lib/seam/connect/seam-http-error.js.map +1 -0
  87. package/lib/seam/connect/seam-http.d.ts +3 -1
  88. package/lib/seam/connect/seam-http.js +15 -1
  89. package/lib/seam/connect/seam-http.js.map +1 -1
  90. package/lib/version.d.ts +1 -1
  91. package/lib/version.js +1 -1
  92. package/package.json +3 -2
  93. package/src/lib/seam/connect/api-error-type.ts +11 -0
  94. package/src/lib/seam/connect/auth.ts +95 -3
  95. package/src/lib/seam/connect/client.ts +8 -0
  96. package/src/lib/seam/connect/error-interceptor.ts +61 -0
  97. package/src/lib/seam/connect/index.ts +3 -1
  98. package/src/lib/seam/connect/options.ts +105 -1
  99. package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +38 -0
  100. package/src/lib/seam/connect/routes/access-codes.ts +38 -0
  101. package/src/lib/seam/connect/routes/acs-access-groups.ts +38 -0
  102. package/src/lib/seam/connect/routes/acs-credentials.ts +38 -0
  103. package/src/lib/seam/connect/routes/acs-systems.ts +38 -0
  104. package/src/lib/seam/connect/routes/acs-users.ts +38 -0
  105. package/src/lib/seam/connect/routes/acs.ts +38 -0
  106. package/src/lib/seam/connect/routes/action-attempts.ts +38 -0
  107. package/src/lib/seam/connect/routes/client-sessions.ts +38 -0
  108. package/src/lib/seam/connect/routes/connect-webviews.ts +38 -0
  109. package/src/lib/seam/connect/routes/connected-accounts.ts +38 -0
  110. package/src/lib/seam/connect/routes/devices-unmanaged.ts +38 -0
  111. package/src/lib/seam/connect/routes/devices.ts +38 -0
  112. package/src/lib/seam/connect/routes/events.ts +38 -0
  113. package/src/lib/seam/connect/routes/locks.ts +38 -0
  114. package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +38 -0
  115. package/src/lib/seam/connect/routes/noise-sensors.ts +38 -0
  116. package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +38 -0
  117. package/src/lib/seam/connect/routes/thermostats.ts +38 -0
  118. package/src/lib/seam/connect/routes/webhooks.ts +38 -0
  119. package/src/lib/seam/connect/routes/workspaces.ts +38 -0
  120. package/src/lib/seam/connect/seam-http-error.ts +64 -0
  121. package/src/lib/seam/connect/seam-http.ts +38 -0
  122. package/src/lib/version.ts +1 -1
package/README.md CHANGED
@@ -7,7 +7,23 @@ JavaScript HTTP client for the Seam API written in TypeScript.
7
7
 
8
8
  ## Description
9
9
 
10
- TODO
10
+ [Seam] makes it easy to integrate IoT devices with your applications.
11
+ This is an official SDK for the Seam API.
12
+ Please refer to the official [Seam Docs] to get started.
13
+
14
+ Parts of this SDK are generated from always up-to-date type information
15
+ provided by [@seamapi/types].
16
+ This ensures all API methods, request shapes, and response shapes are
17
+ accurate and fully typed.
18
+
19
+ The SDK contains minimal dependencies, is fully tree-shakeable,
20
+ and optimized for use in both client and server applications.
21
+ The underlying HTTP client is [Axios].
22
+
23
+ [Seam]: https://www.seam.co/
24
+ [Seam Docs]: https://docs.seam.co/latest/
25
+ [@seamapi/types]: https://github.com/seamapi/types/
26
+ [Axios]: https://axios-http.com/
11
27
 
12
28
  ## Installation
13
29
 
@@ -19,6 +35,201 @@ $ npm install @seamapi/http
19
35
 
20
36
  [npm]: https://www.npmjs.com/
21
37
 
38
+ ## Usage
39
+
40
+ ```ts
41
+ import { SeamHttp } from '@seamapi/http'
42
+
43
+ const seam = new SeamHttp('your-api-key')
44
+ const devices = await seam.devices.list()
45
+ ```
46
+
47
+ ### Authentication Methods
48
+
49
+ The SDK supports several authentication mechanisms.
50
+ Authentication may be configured by passing the corresponding
51
+ options directly to the `SeamHttp` constructor,
52
+ or with the more ergonomic static factory methods.
53
+
54
+ > Publishable Key authentication is not supported by the constructor
55
+ > and must be configured using `SeamHttp.fromPublishableKey`.
56
+
57
+ #### API Key
58
+
59
+ An API key is scoped to a single workspace and should only be used on the server.
60
+ Obtain one from the Seam Console.
61
+
62
+ ##### Set the `SEAM_API_KEY` environment variable
63
+
64
+ ```ts
65
+ const seam = new SeamHttp()
66
+ ```
67
+
68
+ ##### Pass as the first argument to the constructor
69
+
70
+ ```ts
71
+ const seam = new SeamHttp('your-api-key')
72
+ ```
73
+
74
+ ##### Pass as an option the constructor
75
+
76
+ ```ts
77
+ const seam = new SeamHttp({ apiKey: 'your-api-key' })
78
+ ```
79
+
80
+ ##### Use the factory method
81
+
82
+ ```ts
83
+ const seam = SeamHttp.fromApiKey('your-api-key')
84
+ ```
85
+
86
+ #### Client Session Token
87
+
88
+ A Client Session Token is scoped to a client session and should only be used on the client.
89
+
90
+ ##### Pass as an option the constructor
91
+
92
+ ```ts
93
+ const seam = new SeamHttp({ clientSessionToken: 'some-client-session-token' })
94
+ ```
95
+
96
+ ##### Use the factory method
97
+
98
+ ```ts
99
+ const seam = SeamHttp.fromClientSessionToken('some-client-session-token')
100
+ ```
101
+
102
+ #### Publishable Key
103
+
104
+ A Publishable Key is used by the client to acquire Client Session Token for a workspace.
105
+ Obtain one from the Seam Console.
106
+
107
+ Use the async factory method to return a client authenticated with a client session token:
108
+
109
+ ```ts
110
+ const seam = await SeamHttp.fromPublishableKey(
111
+ 'your-publishable-key',
112
+ 'some-user-identifier-key',
113
+ )
114
+ ```
115
+
116
+ This will get an existing client session matching the user identifier key,
117
+ or create a new empty client session.
118
+
119
+ #### Personal Access Token
120
+
121
+ A Personal Access Token is scoped to a Seam Console user.
122
+ Obtain one from the Seam Console.
123
+ A workspace id must be provided when using this method
124
+ and all requests will be scoped to that workspace.
125
+
126
+ ##### Pass as an option the constructor
127
+
128
+ ```ts
129
+ const seam = new SeamHttp({
130
+ personalAccessToken: 'your-personal-access-token',
131
+ workspaceId: 'your-workspace-id',
132
+ })
133
+ ```
134
+
135
+ ##### Use the factory method
136
+
137
+ ```ts
138
+ const seam = SeamHttp.fromPersonalAccessToken(
139
+ 'some-console-session-token',
140
+ 'your-workspace-id',
141
+ )
142
+ ```
143
+
144
+ #### Console Session Token
145
+
146
+ A Console Session Token is used by the Seam Console.
147
+ This authentication method is only used by internal Seam applications.
148
+ A workspace id must be provided when using this method
149
+ and all requests will be scoped to that workspace.
150
+
151
+ ##### Pass as an option the constructor
152
+
153
+ ```ts
154
+ const seam = new SeamHttp({
155
+ consoleSessionToken: 'some-console-session-token',
156
+ workspaceId: 'your-workspace-id',
157
+ })
158
+ ```
159
+
160
+ ##### Use the factory method
161
+
162
+ ```ts
163
+ const seam = SeamHttp.fromConsoleSessionToken(
164
+ 'some-console-session-token',
165
+ 'your-workspace-id',
166
+ )
167
+ ```
168
+
169
+ ### Advanced Usage
170
+
171
+ In addition the various authentication options,
172
+ the constructor takes some additional options that affect behavior.
173
+
174
+ ```ts
175
+ const seam = new SeamHttp({
176
+ apiKey: 'your-api-key',
177
+ endpoint: 'https://example.com',
178
+ axiosOptions: {},
179
+ axiosRetryOptions: {},
180
+ })
181
+ ```
182
+
183
+ When using the static factory methods,
184
+ these options may be passed in as the last argument.
185
+
186
+ ```ts
187
+ const seam = SeamHttp.fromApiKey('some-api-key', {
188
+ endpoint: 'https://example.com',
189
+ axiosOptions: {},
190
+ axiosRetryOptions: {},
191
+ })
192
+ ```
193
+
194
+ #### Setting the endpoint
195
+
196
+ Some contexts may need to override the API endpoint,
197
+ e.g., testing or proxy setups.
198
+ This option corresponds to the Axios `baseURL` setting.
199
+
200
+ Either pass the `endpoint` option, or set the `SEAM_ENDPOINT` environment variable.
201
+
202
+ #### Configuring the Axios Client
203
+
204
+ The Axios client and retry behavior may be configured with custom initiation options
205
+ via [`axiosOptions`] and [`axiosRetryOptions`][axiosRetryOptions].
206
+ Options are deep merged with the default options.
207
+
208
+ [axiosOptions]: https://axios-http.com/docs/config_defaults
209
+ [axiosRetryOptions]: https://github.com/softonic/axios-retry
210
+
211
+ #### Using the Axios Client
212
+
213
+ The Axios client is exposed and may be used or configured directly:
214
+
215
+ ```ts
216
+ import { SeamHttp, DevicesListResponse } from '@seamapi/http'
217
+
218
+ const seam = new SeamHttp()
219
+
220
+ seam.client.interceptors.response.use((response) => {
221
+ console.log(response)
222
+ return response
223
+ })
224
+
225
+ const devices = await seam.client.get<DevicesListResponse>('/devices/list')
226
+ ```
227
+
228
+ #### Overriding the Client
229
+
230
+ An Axios compatible client may be provided to create a `SeamHttp` instance.
231
+ This API is used internally and is not directly supported.
232
+
22
233
  ## Development and Testing
23
234
 
24
235
  ### Quickstart