@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.
- package/README.md +212 -1
- package/dist/connect.cjs +643 -4
- package/dist/connect.cjs.map +1 -1
- package/dist/connect.d.cts +84 -2
- package/lib/seam/connect/api-error-type.d.ts +8 -0
- package/lib/seam/connect/api-error-type.js +3 -0
- package/lib/seam/connect/api-error-type.js.map +1 -0
- package/lib/seam/connect/auth.js +55 -4
- package/lib/seam/connect/auth.js.map +1 -1
- package/lib/seam/connect/client.js +5 -0
- package/lib/seam/connect/client.js.map +1 -1
- package/lib/seam/connect/error-interceptor.d.ts +1 -0
- package/lib/seam/connect/error-interceptor.js +43 -0
- package/lib/seam/connect/error-interceptor.js.map +1 -0
- package/lib/seam/connect/index.d.ts +3 -1
- package/lib/seam/connect/index.js +3 -1
- package/lib/seam/connect/index.js.map +1 -1
- package/lib/seam/connect/options.d.ts +11 -1
- package/lib/seam/connect/options.js +51 -1
- package/lib/seam/connect/options.js.map +1 -1
- package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +3 -1
- package/lib/seam/connect/routes/access-codes-unmanaged.js +15 -1
- package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
- package/lib/seam/connect/routes/access-codes.d.ts +3 -1
- package/lib/seam/connect/routes/access-codes.js +15 -1
- package/lib/seam/connect/routes/access-codes.js.map +1 -1
- package/lib/seam/connect/routes/acs-access-groups.d.ts +3 -1
- package/lib/seam/connect/routes/acs-access-groups.js +15 -1
- package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
- package/lib/seam/connect/routes/acs-credentials.d.ts +3 -1
- package/lib/seam/connect/routes/acs-credentials.js +15 -1
- package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
- package/lib/seam/connect/routes/acs-systems.d.ts +3 -1
- package/lib/seam/connect/routes/acs-systems.js +15 -1
- package/lib/seam/connect/routes/acs-systems.js.map +1 -1
- package/lib/seam/connect/routes/acs-users.d.ts +3 -1
- package/lib/seam/connect/routes/acs-users.js +15 -1
- package/lib/seam/connect/routes/acs-users.js.map +1 -1
- package/lib/seam/connect/routes/acs.d.ts +3 -1
- package/lib/seam/connect/routes/acs.js +15 -1
- package/lib/seam/connect/routes/acs.js.map +1 -1
- package/lib/seam/connect/routes/action-attempts.d.ts +3 -1
- package/lib/seam/connect/routes/action-attempts.js +15 -1
- package/lib/seam/connect/routes/action-attempts.js.map +1 -1
- package/lib/seam/connect/routes/client-sessions.d.ts +3 -1
- package/lib/seam/connect/routes/client-sessions.js +15 -1
- package/lib/seam/connect/routes/client-sessions.js.map +1 -1
- package/lib/seam/connect/routes/connect-webviews.d.ts +3 -1
- package/lib/seam/connect/routes/connect-webviews.js +15 -1
- package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
- package/lib/seam/connect/routes/connected-accounts.d.ts +3 -1
- package/lib/seam/connect/routes/connected-accounts.js +15 -1
- package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
- package/lib/seam/connect/routes/devices-unmanaged.d.ts +3 -1
- package/lib/seam/connect/routes/devices-unmanaged.js +15 -1
- package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -1
- package/lib/seam/connect/routes/devices.d.ts +3 -1
- package/lib/seam/connect/routes/devices.js +15 -1
- package/lib/seam/connect/routes/devices.js.map +1 -1
- package/lib/seam/connect/routes/events.d.ts +3 -1
- package/lib/seam/connect/routes/events.js +15 -1
- package/lib/seam/connect/routes/events.js.map +1 -1
- package/lib/seam/connect/routes/locks.d.ts +3 -1
- package/lib/seam/connect/routes/locks.js +15 -1
- package/lib/seam/connect/routes/locks.js.map +1 -1
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +3 -1
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +15 -1
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
- package/lib/seam/connect/routes/noise-sensors.d.ts +3 -1
- package/lib/seam/connect/routes/noise-sensors.js +15 -1
- package/lib/seam/connect/routes/noise-sensors.js.map +1 -1
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +3 -1
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js +15 -1
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -1
- package/lib/seam/connect/routes/thermostats.d.ts +3 -1
- package/lib/seam/connect/routes/thermostats.js +15 -1
- package/lib/seam/connect/routes/thermostats.js.map +1 -1
- package/lib/seam/connect/routes/webhooks.d.ts +3 -1
- package/lib/seam/connect/routes/webhooks.js +15 -1
- package/lib/seam/connect/routes/webhooks.js.map +1 -1
- package/lib/seam/connect/routes/workspaces.d.ts +3 -1
- package/lib/seam/connect/routes/workspaces.js +15 -1
- package/lib/seam/connect/routes/workspaces.js.map +1 -1
- package/lib/seam/connect/seam-http-error.d.ts +20 -0
- package/lib/seam/connect/seam-http-error.js +43 -0
- package/lib/seam/connect/seam-http-error.js.map +1 -0
- package/lib/seam/connect/seam-http.d.ts +3 -1
- package/lib/seam/connect/seam-http.js +15 -1
- package/lib/seam/connect/seam-http.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +3 -2
- package/src/lib/seam/connect/api-error-type.ts +11 -0
- package/src/lib/seam/connect/auth.ts +95 -3
- package/src/lib/seam/connect/client.ts +8 -0
- package/src/lib/seam/connect/error-interceptor.ts +61 -0
- package/src/lib/seam/connect/index.ts +3 -1
- package/src/lib/seam/connect/options.ts +105 -1
- package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +38 -0
- package/src/lib/seam/connect/routes/access-codes.ts +38 -0
- package/src/lib/seam/connect/routes/acs-access-groups.ts +38 -0
- package/src/lib/seam/connect/routes/acs-credentials.ts +38 -0
- package/src/lib/seam/connect/routes/acs-systems.ts +38 -0
- package/src/lib/seam/connect/routes/acs-users.ts +38 -0
- package/src/lib/seam/connect/routes/acs.ts +38 -0
- package/src/lib/seam/connect/routes/action-attempts.ts +38 -0
- package/src/lib/seam/connect/routes/client-sessions.ts +38 -0
- package/src/lib/seam/connect/routes/connect-webviews.ts +38 -0
- package/src/lib/seam/connect/routes/connected-accounts.ts +38 -0
- package/src/lib/seam/connect/routes/devices-unmanaged.ts +38 -0
- package/src/lib/seam/connect/routes/devices.ts +38 -0
- package/src/lib/seam/connect/routes/events.ts +38 -0
- package/src/lib/seam/connect/routes/locks.ts +38 -0
- package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +38 -0
- package/src/lib/seam/connect/routes/noise-sensors.ts +38 -0
- package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +38 -0
- package/src/lib/seam/connect/routes/thermostats.ts +38 -0
- package/src/lib/seam/connect/routes/webhooks.ts +38 -0
- package/src/lib/seam/connect/routes/workspaces.ts +38 -0
- package/src/lib/seam/connect/seam-http-error.ts +64 -0
- package/src/lib/seam/connect/seam-http.ts +38 -0
- 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
|
-
|
|
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
|