@seamapi/http 0.22.0 → 0.24.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.
@@ -0,0 +1,172 @@
1
+ /*
2
+ * Automatically generated by generate-routes.ts.
3
+ * Do not edit this file or add other files to this directory.
4
+ */
5
+
6
+ import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
7
+ import type { SetNonNullable } from 'type-fest'
8
+
9
+ import {
10
+ getAuthHeadersForClientSessionToken,
11
+ warnOnInsecureuserIdentifierKey,
12
+ } from 'lib/seam/connect/auth.js'
13
+ import { type Client, createClient } from 'lib/seam/connect/client.js'
14
+ import {
15
+ isSeamHttpOptionsWithApiKey,
16
+ isSeamHttpOptionsWithClient,
17
+ isSeamHttpOptionsWithClientSessionToken,
18
+ isSeamHttpOptionsWithConsoleSessionToken,
19
+ isSeamHttpOptionsWithPersonalAccessToken,
20
+ type SeamHttpFromPublishableKeyOptions,
21
+ SeamHttpInvalidOptionsError,
22
+ type SeamHttpOptions,
23
+ type SeamHttpOptionsWithApiKey,
24
+ type SeamHttpOptionsWithClient,
25
+ type SeamHttpOptionsWithClientSessionToken,
26
+ type SeamHttpOptionsWithConsoleSessionToken,
27
+ type SeamHttpOptionsWithPersonalAccessToken,
28
+ type SeamHttpRequestOptions,
29
+ } from 'lib/seam/connect/options.js'
30
+ import {
31
+ limitToSeamHttpRequestOptions,
32
+ parseOptions,
33
+ } from 'lib/seam/connect/parse-options.js'
34
+
35
+ import { SeamHttpClientSessions } from './client-sessions.js'
36
+
37
+ export class SeamHttpDevicesSimulate {
38
+ client: Client
39
+ readonly defaults: Required<SeamHttpRequestOptions>
40
+
41
+ constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
42
+ const options = parseOptions(apiKeyOrOptions)
43
+ this.client = 'client' in options ? options.client : createClient(options)
44
+ this.defaults = limitToSeamHttpRequestOptions(options)
45
+ }
46
+
47
+ static fromClient(
48
+ client: SeamHttpOptionsWithClient['client'],
49
+ options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
50
+ ): SeamHttpDevicesSimulate {
51
+ const constructorOptions = { ...options, client }
52
+ if (!isSeamHttpOptionsWithClient(constructorOptions)) {
53
+ throw new SeamHttpInvalidOptionsError('Missing client')
54
+ }
55
+ return new SeamHttpDevicesSimulate(constructorOptions)
56
+ }
57
+
58
+ static fromApiKey(
59
+ apiKey: SeamHttpOptionsWithApiKey['apiKey'],
60
+ options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
61
+ ): SeamHttpDevicesSimulate {
62
+ const constructorOptions = { ...options, apiKey }
63
+ if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
64
+ throw new SeamHttpInvalidOptionsError('Missing apiKey')
65
+ }
66
+ return new SeamHttpDevicesSimulate(constructorOptions)
67
+ }
68
+
69
+ static fromClientSessionToken(
70
+ clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
71
+ options: Omit<
72
+ SeamHttpOptionsWithClientSessionToken,
73
+ 'clientSessionToken'
74
+ > = {},
75
+ ): SeamHttpDevicesSimulate {
76
+ const constructorOptions = { ...options, clientSessionToken }
77
+ if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
78
+ throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
79
+ }
80
+ return new SeamHttpDevicesSimulate(constructorOptions)
81
+ }
82
+
83
+ static async fromPublishableKey(
84
+ publishableKey: string,
85
+ userIdentifierKey: string,
86
+ options: SeamHttpFromPublishableKeyOptions = {},
87
+ ): Promise<SeamHttpDevicesSimulate> {
88
+ warnOnInsecureuserIdentifierKey(userIdentifierKey)
89
+ const clientOptions = parseOptions({ ...options, publishableKey })
90
+ if (isSeamHttpOptionsWithClient(clientOptions)) {
91
+ throw new SeamHttpInvalidOptionsError(
92
+ 'The client option cannot be used with SeamHttp.fromPublishableKey',
93
+ )
94
+ }
95
+ const client = createClient(clientOptions)
96
+ const clientSessions = SeamHttpClientSessions.fromClient(client)
97
+ const { token } = await clientSessions.getOrCreate({
98
+ user_identifier_key: userIdentifierKey,
99
+ })
100
+ return SeamHttpDevicesSimulate.fromClientSessionToken(token, options)
101
+ }
102
+
103
+ static fromConsoleSessionToken(
104
+ consoleSessionToken: SeamHttpOptionsWithConsoleSessionToken['consoleSessionToken'],
105
+ workspaceId: SeamHttpOptionsWithConsoleSessionToken['workspaceId'],
106
+ options: Omit<
107
+ SeamHttpOptionsWithConsoleSessionToken,
108
+ 'consoleSessionToken' | 'workspaceId'
109
+ > = {},
110
+ ): SeamHttpDevicesSimulate {
111
+ const constructorOptions = { ...options, consoleSessionToken, workspaceId }
112
+ if (!isSeamHttpOptionsWithConsoleSessionToken(constructorOptions)) {
113
+ throw new SeamHttpInvalidOptionsError(
114
+ 'Missing consoleSessionToken or workspaceId',
115
+ )
116
+ }
117
+ return new SeamHttpDevicesSimulate(constructorOptions)
118
+ }
119
+
120
+ static fromPersonalAccessToken(
121
+ personalAccessToken: SeamHttpOptionsWithPersonalAccessToken['personalAccessToken'],
122
+ workspaceId: SeamHttpOptionsWithPersonalAccessToken['workspaceId'],
123
+ options: Omit<
124
+ SeamHttpOptionsWithPersonalAccessToken,
125
+ 'personalAccessToken' | 'workspaceId'
126
+ > = {},
127
+ ): SeamHttpDevicesSimulate {
128
+ const constructorOptions = { ...options, personalAccessToken, workspaceId }
129
+ if (!isSeamHttpOptionsWithPersonalAccessToken(constructorOptions)) {
130
+ throw new SeamHttpInvalidOptionsError(
131
+ 'Missing personalAccessToken or workspaceId',
132
+ )
133
+ }
134
+ return new SeamHttpDevicesSimulate(constructorOptions)
135
+ }
136
+
137
+ async updateClientSessionToken(
138
+ clientSessionToken: SeamHttpOptionsWithClientSessionToken['clientSessionToken'],
139
+ ): Promise<void> {
140
+ const { headers } = this.client.defaults
141
+ const authHeaders = getAuthHeadersForClientSessionToken({
142
+ clientSessionToken,
143
+ })
144
+ for (const key of Object.keys(authHeaders)) {
145
+ if (headers[key] == null) {
146
+ throw new Error(
147
+ 'Cannot update a clientSessionToken on a client created without a clientSessionToken',
148
+ )
149
+ }
150
+ }
151
+ this.client.defaults.headers = { ...headers, ...authHeaders }
152
+ const clientSessions = SeamHttpClientSessions.fromClient(this.client)
153
+ await clientSessions.get()
154
+ }
155
+
156
+ async remove(body?: DevicesSimulateRemoveBody): Promise<void> {
157
+ await this.client.request<DevicesSimulateRemoveResponse>({
158
+ url: '/devices/simulate/remove',
159
+ method: 'post',
160
+ data: body,
161
+ })
162
+ }
163
+ }
164
+
165
+ export type DevicesSimulateRemoveBody =
166
+ RouteRequestBody<'/devices/simulate/remove'>
167
+
168
+ export type DevicesSimulateRemoveResponse = SetNonNullable<
169
+ Required<RouteResponse<'/devices/simulate/remove'>>
170
+ >
171
+
172
+ export type DevicesSimulateRemoveOptions = never
@@ -33,6 +33,7 @@ import {
33
33
  } from 'lib/seam/connect/parse-options.js'
34
34
 
35
35
  import { SeamHttpClientSessions } from './client-sessions.js'
36
+ import { SeamHttpDevicesSimulate } from './devices-simulate.js'
36
37
  import { SeamHttpDevicesUnmanaged } from './devices-unmanaged.js'
37
38
 
38
39
  export class SeamHttpDevices {
@@ -158,6 +159,10 @@ export class SeamHttpDevices {
158
159
  return SeamHttpDevicesUnmanaged.fromClient(this.client, this.defaults)
159
160
  }
160
161
 
162
+ get simulate(): SeamHttpDevicesSimulate {
163
+ return SeamHttpDevicesSimulate.fromClient(this.client, this.defaults)
164
+ }
165
+
161
166
  async delete(body?: DevicesDeleteBody): Promise<void> {
162
167
  await this.client.request<DevicesDeleteResponse>({
163
168
  url: '/devices/delete',
@@ -13,6 +13,7 @@ export * from './client-sessions.js'
13
13
  export * from './connect-webviews.js'
14
14
  export * from './connected-accounts.js'
15
15
  export * from './devices.js'
16
+ export * from './devices-simulate.js'
16
17
  export * from './devices-unmanaged.js'
17
18
  export * from './events.js'
18
19
  export * from './locks.js'
@@ -31,7 +31,9 @@ import {
31
31
  limitToSeamHttpRequestOptions,
32
32
  parseOptions,
33
33
  } from 'lib/seam/connect/parse-options.js'
34
+ import { resolveActionAttempt } from 'lib/seam/connect/resolve-action-attempt.js'
34
35
 
36
+ import { SeamHttpActionAttempts } from './action-attempts.js'
35
37
  import { SeamHttpClientSessions } from './client-sessions.js'
36
38
  import { SeamHttpThermostatsClimateSettingSchedules } from './thermostats-climate-setting-schedules.js'
37
39
 
@@ -161,12 +163,28 @@ export class SeamHttpThermostats {
161
163
  )
162
164
  }
163
165
 
164
- async cool(body?: ThermostatsCoolBody): Promise<void> {
165
- await this.client.request<ThermostatsCoolResponse>({
166
+ async cool(
167
+ body?: ThermostatsCoolBody,
168
+ options: Pick<SeamHttpRequestOptions, 'waitForActionAttempt'> = {},
169
+ ): Promise<ThermostatsCoolResponse['action_attempt']> {
170
+ const { data } = await this.client.request<ThermostatsCoolResponse>({
166
171
  url: '/thermostats/cool',
167
172
  method: 'post',
168
173
  data: body,
169
174
  })
175
+ const waitForActionAttempt =
176
+ options.waitForActionAttempt ?? this.defaults.waitForActionAttempt
177
+ if (waitForActionAttempt !== false) {
178
+ return await resolveActionAttempt(
179
+ data.action_attempt,
180
+ SeamHttpActionAttempts.fromClient(this.client, {
181
+ ...this.defaults,
182
+ waitForActionAttempt: false,
183
+ }),
184
+ typeof waitForActionAttempt === 'boolean' ? {} : waitForActionAttempt,
185
+ )
186
+ }
187
+ return data.action_attempt
170
188
  }
171
189
 
172
190
  async get(
@@ -181,20 +199,52 @@ export class SeamHttpThermostats {
181
199
  return data.thermostat
182
200
  }
183
201
 
184
- async heat(body?: ThermostatsHeatBody): Promise<void> {
185
- await this.client.request<ThermostatsHeatResponse>({
202
+ async heat(
203
+ body?: ThermostatsHeatBody,
204
+ options: Pick<SeamHttpRequestOptions, 'waitForActionAttempt'> = {},
205
+ ): Promise<ThermostatsHeatResponse['action_attempt']> {
206
+ const { data } = await this.client.request<ThermostatsHeatResponse>({
186
207
  url: '/thermostats/heat',
187
208
  method: 'post',
188
209
  data: body,
189
210
  })
211
+ const waitForActionAttempt =
212
+ options.waitForActionAttempt ?? this.defaults.waitForActionAttempt
213
+ if (waitForActionAttempt !== false) {
214
+ return await resolveActionAttempt(
215
+ data.action_attempt,
216
+ SeamHttpActionAttempts.fromClient(this.client, {
217
+ ...this.defaults,
218
+ waitForActionAttempt: false,
219
+ }),
220
+ typeof waitForActionAttempt === 'boolean' ? {} : waitForActionAttempt,
221
+ )
222
+ }
223
+ return data.action_attempt
190
224
  }
191
225
 
192
- async heatCool(body?: ThermostatsHeatCoolBody): Promise<void> {
193
- await this.client.request<ThermostatsHeatCoolResponse>({
226
+ async heatCool(
227
+ body?: ThermostatsHeatCoolBody,
228
+ options: Pick<SeamHttpRequestOptions, 'waitForActionAttempt'> = {},
229
+ ): Promise<ThermostatsHeatCoolResponse['action_attempt']> {
230
+ const { data } = await this.client.request<ThermostatsHeatCoolResponse>({
194
231
  url: '/thermostats/heat_cool',
195
232
  method: 'post',
196
233
  data: body,
197
234
  })
235
+ const waitForActionAttempt =
236
+ options.waitForActionAttempt ?? this.defaults.waitForActionAttempt
237
+ if (waitForActionAttempt !== false) {
238
+ return await resolveActionAttempt(
239
+ data.action_attempt,
240
+ SeamHttpActionAttempts.fromClient(this.client, {
241
+ ...this.defaults,
242
+ waitForActionAttempt: false,
243
+ }),
244
+ typeof waitForActionAttempt === 'boolean' ? {} : waitForActionAttempt,
245
+ )
246
+ }
247
+ return data.action_attempt
198
248
  }
199
249
 
200
250
  async list(
@@ -209,20 +259,52 @@ export class SeamHttpThermostats {
209
259
  return data.thermostats
210
260
  }
211
261
 
212
- async off(body?: ThermostatsOffBody): Promise<void> {
213
- await this.client.request<ThermostatsOffResponse>({
262
+ async off(
263
+ body?: ThermostatsOffBody,
264
+ options: Pick<SeamHttpRequestOptions, 'waitForActionAttempt'> = {},
265
+ ): Promise<ThermostatsOffResponse['action_attempt']> {
266
+ const { data } = await this.client.request<ThermostatsOffResponse>({
214
267
  url: '/thermostats/off',
215
268
  method: 'post',
216
269
  data: body,
217
270
  })
271
+ const waitForActionAttempt =
272
+ options.waitForActionAttempt ?? this.defaults.waitForActionAttempt
273
+ if (waitForActionAttempt !== false) {
274
+ return await resolveActionAttempt(
275
+ data.action_attempt,
276
+ SeamHttpActionAttempts.fromClient(this.client, {
277
+ ...this.defaults,
278
+ waitForActionAttempt: false,
279
+ }),
280
+ typeof waitForActionAttempt === 'boolean' ? {} : waitForActionAttempt,
281
+ )
282
+ }
283
+ return data.action_attempt
218
284
  }
219
285
 
220
- async setFanMode(body?: ThermostatsSetFanModeBody): Promise<void> {
221
- await this.client.request<ThermostatsSetFanModeResponse>({
286
+ async setFanMode(
287
+ body?: ThermostatsSetFanModeBody,
288
+ options: Pick<SeamHttpRequestOptions, 'waitForActionAttempt'> = {},
289
+ ): Promise<ThermostatsSetFanModeResponse['action_attempt']> {
290
+ const { data } = await this.client.request<ThermostatsSetFanModeResponse>({
222
291
  url: '/thermostats/set_fan_mode',
223
292
  method: 'post',
224
293
  data: body,
225
294
  })
295
+ const waitForActionAttempt =
296
+ options.waitForActionAttempt ?? this.defaults.waitForActionAttempt
297
+ if (waitForActionAttempt !== false) {
298
+ return await resolveActionAttempt(
299
+ data.action_attempt,
300
+ SeamHttpActionAttempts.fromClient(this.client, {
301
+ ...this.defaults,
302
+ waitForActionAttempt: false,
303
+ }),
304
+ typeof waitForActionAttempt === 'boolean' ? {} : waitForActionAttempt,
305
+ )
306
+ }
307
+ return data.action_attempt
226
308
  }
227
309
 
228
310
  async update(body?: ThermostatsUpdateBody): Promise<void> {
@@ -240,7 +322,10 @@ export type ThermostatsCoolResponse = SetNonNullable<
240
322
  Required<RouteResponse<'/thermostats/cool'>>
241
323
  >
242
324
 
243
- export type ThermostatsCoolOptions = never
325
+ export type ThermostatsCoolOptions = Pick<
326
+ SeamHttpRequestOptions,
327
+ 'waitForActionAttempt'
328
+ >
244
329
 
245
330
  export type ThermostatsGetParams = RouteRequestBody<'/thermostats/get'>
246
331
 
@@ -256,7 +341,10 @@ export type ThermostatsHeatResponse = SetNonNullable<
256
341
  Required<RouteResponse<'/thermostats/heat'>>
257
342
  >
258
343
 
259
- export type ThermostatsHeatOptions = never
344
+ export type ThermostatsHeatOptions = Pick<
345
+ SeamHttpRequestOptions,
346
+ 'waitForActionAttempt'
347
+ >
260
348
 
261
349
  export type ThermostatsHeatCoolBody = RouteRequestBody<'/thermostats/heat_cool'>
262
350
 
@@ -264,7 +352,10 @@ export type ThermostatsHeatCoolResponse = SetNonNullable<
264
352
  Required<RouteResponse<'/thermostats/heat_cool'>>
265
353
  >
266
354
 
267
- export type ThermostatsHeatCoolOptions = never
355
+ export type ThermostatsHeatCoolOptions = Pick<
356
+ SeamHttpRequestOptions,
357
+ 'waitForActionAttempt'
358
+ >
268
359
 
269
360
  export type ThermostatsListParams = RouteRequestBody<'/thermostats/list'>
270
361
 
@@ -280,7 +371,10 @@ export type ThermostatsOffResponse = SetNonNullable<
280
371
  Required<RouteResponse<'/thermostats/off'>>
281
372
  >
282
373
 
283
- export type ThermostatsOffOptions = never
374
+ export type ThermostatsOffOptions = Pick<
375
+ SeamHttpRequestOptions,
376
+ 'waitForActionAttempt'
377
+ >
284
378
 
285
379
  export type ThermostatsSetFanModeBody =
286
380
  RouteRequestBody<'/thermostats/set_fan_mode'>
@@ -289,7 +383,10 @@ export type ThermostatsSetFanModeResponse = SetNonNullable<
289
383
  Required<RouteResponse<'/thermostats/set_fan_mode'>>
290
384
  >
291
385
 
292
- export type ThermostatsSetFanModeOptions = never
386
+ export type ThermostatsSetFanModeOptions = Pick<
387
+ SeamHttpRequestOptions,
388
+ 'waitForActionAttempt'
389
+ >
293
390
 
294
391
  export type ThermostatsUpdateBody = RouteRequestBody<'/thermostats/update'>
295
392
 
@@ -1,3 +1,3 @@
1
- const seamapiJavascriptHttpVersion = '0.22.0'
1
+ const seamapiJavascriptHttpVersion = '0.24.0'
2
2
 
3
3
  export default seamapiJavascriptHttpVersion