@seamapi/http 0.1.0 → 0.2.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/dist/connect.cjs +752 -366
- package/dist/connect.cjs.map +1 -1
- package/dist/connect.d.cts +186 -142
- package/lib/params-serializer.d.ts +5 -0
- package/lib/params-serializer.js +42 -0
- package/lib/params-serializer.js.map +1 -0
- package/lib/seam/connect/auth.d.ts +3 -2
- package/lib/seam/connect/auth.js +55 -4
- package/lib/seam/connect/auth.js.map +1 -1
- package/lib/seam/connect/client.d.ts +10 -22
- package/lib/seam/connect/client.js +17 -77
- package/lib/seam/connect/client.js.map +1 -1
- package/lib/seam/connect/index.d.ts +2 -1
- package/lib/seam/connect/index.js +2 -1
- package/lib/seam/connect/index.js.map +1 -1
- package/lib/seam/connect/{client-options.d.ts → options.d.ts} +7 -7
- package/lib/seam/connect/{client-options.js → options.js} +5 -10
- package/lib/seam/connect/options.js.map +1 -0
- package/lib/seam/connect/parse-options.d.ts +6 -2
- package/lib/seam/connect/parse-options.js +34 -16
- package/lib/seam/connect/parse-options.js.map +1 -1
- package/lib/seam/connect/routes/access-codes-unmanaged.d.ts +10 -9
- package/lib/seam/connect/routes/access-codes-unmanaged.js +26 -14
- package/lib/seam/connect/routes/access-codes-unmanaged.js.map +1 -1
- package/lib/seam/connect/routes/access-codes.d.ts +15 -14
- package/lib/seam/connect/routes/access-codes.js +29 -17
- package/lib/seam/connect/routes/access-codes.js.map +1 -1
- package/lib/seam/connect/routes/acs-access-groups.d.ts +13 -12
- package/lib/seam/connect/routes/acs-access-groups.js +26 -14
- package/lib/seam/connect/routes/acs-access-groups.js.map +1 -1
- package/lib/seam/connect/routes/acs-credentials.d.ts +9 -8
- package/lib/seam/connect/routes/acs-credentials.js +26 -14
- package/lib/seam/connect/routes/acs-credentials.js.map +1 -1
- package/lib/seam/connect/routes/acs-systems.d.ts +9 -8
- package/lib/seam/connect/routes/acs-systems.js +29 -17
- package/lib/seam/connect/routes/acs-systems.js.map +1 -1
- package/lib/seam/connect/routes/acs-users.d.ts +18 -11
- package/lib/seam/connect/routes/acs-users.js +40 -14
- package/lib/seam/connect/routes/acs-users.js.map +1 -1
- package/lib/seam/connect/routes/acs.d.ts +5 -4
- package/lib/seam/connect/routes/acs.js +26 -14
- package/lib/seam/connect/routes/acs.js.map +1 -1
- package/lib/seam/connect/routes/action-attempts.d.ts +7 -6
- package/lib/seam/connect/routes/action-attempts.js +26 -14
- package/lib/seam/connect/routes/action-attempts.js.map +1 -1
- package/lib/seam/connect/routes/client-sessions.d.ts +13 -9
- package/lib/seam/connect/routes/client-sessions.js +33 -14
- package/lib/seam/connect/routes/client-sessions.js.map +1 -1
- package/lib/seam/connect/routes/connect-webviews.d.ts +11 -10
- package/lib/seam/connect/routes/connect-webviews.js +29 -17
- package/lib/seam/connect/routes/connect-webviews.js.map +1 -1
- package/lib/seam/connect/routes/connected-accounts.d.ts +8 -7
- package/lib/seam/connect/routes/connected-accounts.js +26 -14
- package/lib/seam/connect/routes/connected-accounts.js.map +1 -1
- package/lib/seam/connect/routes/devices-unmanaged.d.ts +8 -7
- package/lib/seam/connect/routes/devices-unmanaged.js +26 -14
- package/lib/seam/connect/routes/devices-unmanaged.js.map +1 -1
- package/lib/seam/connect/routes/devices.d.ts +10 -9
- package/lib/seam/connect/routes/devices.js +26 -14
- package/lib/seam/connect/routes/devices.js.map +1 -1
- package/lib/seam/connect/routes/events.d.ts +7 -6
- package/lib/seam/connect/routes/events.js +26 -14
- package/lib/seam/connect/routes/events.js.map +1 -1
- package/lib/seam/connect/routes/locks.d.ts +9 -8
- package/lib/seam/connect/routes/locks.js +26 -14
- package/lib/seam/connect/routes/locks.js.map +1 -1
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.d.ts +10 -9
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js +26 -14
- package/lib/seam/connect/routes/noise-sensors-noise-thresholds.js.map +1 -1
- package/lib/seam/connect/routes/noise-sensors.d.ts +5 -4
- package/lib/seam/connect/routes/noise-sensors.js +26 -14
- package/lib/seam/connect/routes/noise-sensors.js.map +1 -1
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.d.ts +10 -9
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js +26 -14
- package/lib/seam/connect/routes/thermostats-climate-setting-schedules.js.map +1 -1
- package/lib/seam/connect/routes/thermostats.d.ts +13 -12
- package/lib/seam/connect/routes/thermostats.js +26 -14
- package/lib/seam/connect/routes/thermostats.js.map +1 -1
- package/lib/seam/connect/routes/webhooks.d.ts +9 -8
- package/lib/seam/connect/routes/webhooks.js +26 -14
- package/lib/seam/connect/routes/webhooks.js.map +1 -1
- package/lib/seam/connect/routes/workspaces.d.ts +8 -7
- package/lib/seam/connect/routes/workspaces.js +26 -14
- package/lib/seam/connect/routes/workspaces.js.map +1 -1
- package/lib/seam/connect/seam-http.d.ts +24 -0
- package/lib/seam/connect/seam-http.js +82 -0
- package/lib/seam/connect/seam-http.js.map +1 -0
- package/package.json +7 -4
- package/src/lib/params-serializer.ts +55 -0
- package/src/lib/seam/connect/auth.ts +94 -6
- package/src/lib/seam/connect/client.ts +22 -127
- package/src/lib/seam/connect/env.d.ts +11 -0
- package/src/lib/seam/connect/index.ts +2 -1
- package/src/lib/seam/connect/{client-options.ts → options.ts} +13 -19
- package/src/lib/seam/connect/parse-options.ts +50 -23
- package/src/lib/seam/connect/routes/access-codes-unmanaged.ts +44 -31
- package/src/lib/seam/connect/routes/access-codes.ts +48 -48
- package/src/lib/seam/connect/routes/acs-access-groups.ts +49 -40
- package/src/lib/seam/connect/routes/acs-credentials.ts +40 -28
- package/src/lib/seam/connect/routes/acs-systems.ts +40 -30
- package/src/lib/seam/connect/routes/acs-users.ts +70 -36
- package/src/lib/seam/connect/routes/acs.ts +33 -17
- package/src/lib/seam/connect/routes/action-attempts.ts +36 -22
- package/src/lib/seam/connect/routes/client-sessions.ts +58 -30
- package/src/lib/seam/connect/routes/connect-webviews.ts +45 -34
- package/src/lib/seam/connect/routes/connected-accounts.ts +40 -25
- package/src/lib/seam/connect/routes/devices-unmanaged.ts +39 -25
- package/src/lib/seam/connect/routes/devices.ts +39 -31
- package/src/lib/seam/connect/routes/events.ts +36 -22
- package/src/lib/seam/connect/routes/locks.ts +38 -28
- package/src/lib/seam/connect/routes/noise-sensors-noise-thresholds.ts +47 -31
- package/src/lib/seam/connect/routes/noise-sensors.ts +33 -17
- package/src/lib/seam/connect/routes/thermostats-climate-setting-schedules.ts +47 -31
- package/src/lib/seam/connect/routes/thermostats.ts +42 -40
- package/src/lib/seam/connect/routes/webhooks.ts +38 -28
- package/src/lib/seam/connect/routes/workspaces.ts +38 -25
- package/src/lib/seam/connect/seam-http.ts +141 -0
- package/lib/seam/connect/axios.d.ts +0 -3
- package/lib/seam/connect/axios.js +0 -19
- package/lib/seam/connect/axios.js.map +0 -1
- package/lib/seam/connect/client-options.js.map +0 -1
- package/src/lib/seam/connect/axios.ts +0 -25
|
@@ -3,51 +3,52 @@
|
|
|
3
3
|
* Do not edit this file or add other files to this directory.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
|
|
8
|
-
import { createAxiosClient } from 'lib/seam/connect/axios.js'
|
|
6
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
7
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
9
8
|
import {
|
|
10
9
|
isSeamHttpOptionsWithApiKey,
|
|
11
10
|
isSeamHttpOptionsWithClient,
|
|
12
11
|
isSeamHttpOptionsWithClientSessionToken,
|
|
12
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
13
13
|
SeamHttpInvalidOptionsError,
|
|
14
14
|
type SeamHttpOptions,
|
|
15
15
|
type SeamHttpOptionsWithApiKey,
|
|
16
16
|
type SeamHttpOptionsWithClient,
|
|
17
17
|
type SeamHttpOptionsWithClientSessionToken,
|
|
18
|
-
} from 'lib/seam/connect/
|
|
18
|
+
} from 'lib/seam/connect/options.js'
|
|
19
19
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
20
20
|
|
|
21
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
21
22
|
import { SeamHttpNoiseSensorsNoiseThresholds } from './noise-sensors-noise-thresholds.js'
|
|
22
23
|
|
|
23
24
|
export class SeamHttpNoiseSensors {
|
|
24
|
-
client:
|
|
25
|
+
client: Client
|
|
25
26
|
|
|
26
|
-
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
27
|
-
const
|
|
28
|
-
this.client =
|
|
27
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
28
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
29
|
+
this.client = createClient(clientOptions)
|
|
29
30
|
}
|
|
30
31
|
|
|
31
32
|
static fromClient(
|
|
32
33
|
client: SeamHttpOptionsWithClient['client'],
|
|
33
34
|
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
34
35
|
): SeamHttpNoiseSensors {
|
|
35
|
-
const
|
|
36
|
-
if (!isSeamHttpOptionsWithClient(
|
|
36
|
+
const constructorOptions = { ...options, client }
|
|
37
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
37
38
|
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
38
39
|
}
|
|
39
|
-
return new SeamHttpNoiseSensors(
|
|
40
|
+
return new SeamHttpNoiseSensors(constructorOptions)
|
|
40
41
|
}
|
|
41
42
|
|
|
42
43
|
static fromApiKey(
|
|
43
44
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
44
45
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
45
46
|
): SeamHttpNoiseSensors {
|
|
46
|
-
const
|
|
47
|
-
if (!isSeamHttpOptionsWithApiKey(
|
|
47
|
+
const constructorOptions = { ...options, apiKey }
|
|
48
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
48
49
|
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
49
50
|
}
|
|
50
|
-
return new SeamHttpNoiseSensors(
|
|
51
|
+
return new SeamHttpNoiseSensors(constructorOptions)
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
static fromClientSessionToken(
|
|
@@ -57,11 +58,26 @@ export class SeamHttpNoiseSensors {
|
|
|
57
58
|
'clientSessionToken'
|
|
58
59
|
> = {},
|
|
59
60
|
): SeamHttpNoiseSensors {
|
|
60
|
-
const
|
|
61
|
-
if (!isSeamHttpOptionsWithClientSessionToken(
|
|
61
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
62
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
62
63
|
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
63
64
|
}
|
|
64
|
-
return new SeamHttpNoiseSensors(
|
|
65
|
+
return new SeamHttpNoiseSensors(constructorOptions)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static async fromPublishableKey(
|
|
69
|
+
publishableKey: string,
|
|
70
|
+
userIdentifierKey: string,
|
|
71
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
72
|
+
): Promise<SeamHttpNoiseSensors> {
|
|
73
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
74
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
75
|
+
const client = createClient(clientOptions)
|
|
76
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
77
|
+
const { token } = await clientSessions.getOrCreate({
|
|
78
|
+
user_identifier_key: userIdentifierKey,
|
|
79
|
+
})
|
|
80
|
+
return SeamHttpNoiseSensors.fromClientSessionToken(token, options)
|
|
65
81
|
}
|
|
66
82
|
|
|
67
83
|
get noiseThresholds(): SeamHttpNoiseSensorsNoiseThresholds {
|
|
@@ -4,50 +4,53 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
|
|
7
|
-
import type { Axios } from 'axios'
|
|
8
7
|
import type { SetNonNullable } from 'type-fest'
|
|
9
8
|
|
|
10
|
-
import {
|
|
9
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
10
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
11
11
|
import {
|
|
12
12
|
isSeamHttpOptionsWithApiKey,
|
|
13
13
|
isSeamHttpOptionsWithClient,
|
|
14
14
|
isSeamHttpOptionsWithClientSessionToken,
|
|
15
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
15
16
|
SeamHttpInvalidOptionsError,
|
|
16
17
|
type SeamHttpOptions,
|
|
17
18
|
type SeamHttpOptionsWithApiKey,
|
|
18
19
|
type SeamHttpOptionsWithClient,
|
|
19
20
|
type SeamHttpOptionsWithClientSessionToken,
|
|
20
|
-
} from 'lib/seam/connect/
|
|
21
|
+
} from 'lib/seam/connect/options.js'
|
|
21
22
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
22
23
|
|
|
24
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
25
|
+
|
|
23
26
|
export class SeamHttpThermostatsClimateSettingSchedules {
|
|
24
|
-
client:
|
|
27
|
+
client: Client
|
|
25
28
|
|
|
26
|
-
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
27
|
-
const
|
|
28
|
-
this.client =
|
|
29
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
30
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
31
|
+
this.client = createClient(clientOptions)
|
|
29
32
|
}
|
|
30
33
|
|
|
31
34
|
static fromClient(
|
|
32
35
|
client: SeamHttpOptionsWithClient['client'],
|
|
33
36
|
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
34
37
|
): SeamHttpThermostatsClimateSettingSchedules {
|
|
35
|
-
const
|
|
36
|
-
if (!isSeamHttpOptionsWithClient(
|
|
38
|
+
const constructorOptions = { ...options, client }
|
|
39
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
37
40
|
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
38
41
|
}
|
|
39
|
-
return new SeamHttpThermostatsClimateSettingSchedules(
|
|
42
|
+
return new SeamHttpThermostatsClimateSettingSchedules(constructorOptions)
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
static fromApiKey(
|
|
43
46
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
44
47
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
45
48
|
): SeamHttpThermostatsClimateSettingSchedules {
|
|
46
|
-
const
|
|
47
|
-
if (!isSeamHttpOptionsWithApiKey(
|
|
49
|
+
const constructorOptions = { ...options, apiKey }
|
|
50
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
48
51
|
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
49
52
|
}
|
|
50
|
-
return new SeamHttpThermostatsClimateSettingSchedules(
|
|
53
|
+
return new SeamHttpThermostatsClimateSettingSchedules(constructorOptions)
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
static fromClientSessionToken(
|
|
@@ -57,11 +60,29 @@ export class SeamHttpThermostatsClimateSettingSchedules {
|
|
|
57
60
|
'clientSessionToken'
|
|
58
61
|
> = {},
|
|
59
62
|
): SeamHttpThermostatsClimateSettingSchedules {
|
|
60
|
-
const
|
|
61
|
-
if (!isSeamHttpOptionsWithClientSessionToken(
|
|
63
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
64
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
62
65
|
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
63
66
|
}
|
|
64
|
-
return new SeamHttpThermostatsClimateSettingSchedules(
|
|
67
|
+
return new SeamHttpThermostatsClimateSettingSchedules(constructorOptions)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static async fromPublishableKey(
|
|
71
|
+
publishableKey: string,
|
|
72
|
+
userIdentifierKey: string,
|
|
73
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
74
|
+
): Promise<SeamHttpThermostatsClimateSettingSchedules> {
|
|
75
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
76
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
77
|
+
const client = createClient(clientOptions)
|
|
78
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
79
|
+
const { token } = await clientSessions.getOrCreate({
|
|
80
|
+
user_identifier_key: userIdentifierKey,
|
|
81
|
+
})
|
|
82
|
+
return SeamHttpThermostatsClimateSettingSchedules.fromClientSessionToken(
|
|
83
|
+
token,
|
|
84
|
+
options,
|
|
85
|
+
)
|
|
65
86
|
}
|
|
66
87
|
|
|
67
88
|
async create(
|
|
@@ -135,41 +156,36 @@ export class SeamHttpThermostatsClimateSettingSchedules {
|
|
|
135
156
|
}
|
|
136
157
|
}
|
|
137
158
|
|
|
138
|
-
export type ThermostatsClimateSettingSchedulesCreateBody =
|
|
139
|
-
|
|
140
|
-
>
|
|
159
|
+
export type ThermostatsClimateSettingSchedulesCreateBody =
|
|
160
|
+
RouteRequestBody<'/thermostats/climate_setting_schedules/create'>
|
|
141
161
|
|
|
142
162
|
export type ThermostatsClimateSettingSchedulesCreateResponse = SetNonNullable<
|
|
143
163
|
Required<RouteResponse<'/thermostats/climate_setting_schedules/create'>>
|
|
144
164
|
>
|
|
145
165
|
|
|
146
|
-
export type ThermostatsClimateSettingSchedulesDeleteBody =
|
|
147
|
-
|
|
148
|
-
>
|
|
166
|
+
export type ThermostatsClimateSettingSchedulesDeleteBody =
|
|
167
|
+
RouteRequestBody<'/thermostats/climate_setting_schedules/delete'>
|
|
149
168
|
|
|
150
169
|
export type ThermostatsClimateSettingSchedulesDeleteResponse = SetNonNullable<
|
|
151
170
|
Required<RouteResponse<'/thermostats/climate_setting_schedules/delete'>>
|
|
152
171
|
>
|
|
153
172
|
|
|
154
|
-
export type ThermostatsClimateSettingSchedulesGetBody =
|
|
155
|
-
|
|
156
|
-
>
|
|
173
|
+
export type ThermostatsClimateSettingSchedulesGetBody =
|
|
174
|
+
RouteRequestBody<'/thermostats/climate_setting_schedules/get'>
|
|
157
175
|
|
|
158
176
|
export type ThermostatsClimateSettingSchedulesGetResponse = SetNonNullable<
|
|
159
177
|
Required<RouteResponse<'/thermostats/climate_setting_schedules/get'>>
|
|
160
178
|
>
|
|
161
179
|
|
|
162
|
-
export type ThermostatsClimateSettingSchedulesListBody =
|
|
163
|
-
|
|
164
|
-
>
|
|
180
|
+
export type ThermostatsClimateSettingSchedulesListBody =
|
|
181
|
+
RouteRequestBody<'/thermostats/climate_setting_schedules/list'>
|
|
165
182
|
|
|
166
183
|
export type ThermostatsClimateSettingSchedulesListResponse = SetNonNullable<
|
|
167
184
|
Required<RouteResponse<'/thermostats/climate_setting_schedules/list'>>
|
|
168
185
|
>
|
|
169
186
|
|
|
170
|
-
export type ThermostatsClimateSettingSchedulesUpdateBody =
|
|
171
|
-
|
|
172
|
-
>
|
|
187
|
+
export type ThermostatsClimateSettingSchedulesUpdateBody =
|
|
188
|
+
RouteRequestBody<'/thermostats/climate_setting_schedules/update'>
|
|
173
189
|
|
|
174
190
|
export type ThermostatsClimateSettingSchedulesUpdateResponse = SetNonNullable<
|
|
175
191
|
Required<RouteResponse<'/thermostats/climate_setting_schedules/update'>>
|
|
@@ -4,52 +4,54 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import type { RouteRequestBody, RouteResponse } from '@seamapi/types/connect'
|
|
7
|
-
import type { Axios } from 'axios'
|
|
8
7
|
import type { SetNonNullable } from 'type-fest'
|
|
9
8
|
|
|
10
|
-
import {
|
|
9
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
10
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
11
11
|
import {
|
|
12
12
|
isSeamHttpOptionsWithApiKey,
|
|
13
13
|
isSeamHttpOptionsWithClient,
|
|
14
14
|
isSeamHttpOptionsWithClientSessionToken,
|
|
15
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
15
16
|
SeamHttpInvalidOptionsError,
|
|
16
17
|
type SeamHttpOptions,
|
|
17
18
|
type SeamHttpOptionsWithApiKey,
|
|
18
19
|
type SeamHttpOptionsWithClient,
|
|
19
20
|
type SeamHttpOptionsWithClientSessionToken,
|
|
20
|
-
} from 'lib/seam/connect/
|
|
21
|
+
} from 'lib/seam/connect/options.js'
|
|
21
22
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
22
23
|
|
|
24
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
23
25
|
import { SeamHttpThermostatsClimateSettingSchedules } from './thermostats-climate-setting-schedules.js'
|
|
24
26
|
|
|
25
27
|
export class SeamHttpThermostats {
|
|
26
|
-
client:
|
|
28
|
+
client: Client
|
|
27
29
|
|
|
28
|
-
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
29
|
-
const
|
|
30
|
-
this.client =
|
|
30
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
31
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
32
|
+
this.client = createClient(clientOptions)
|
|
31
33
|
}
|
|
32
34
|
|
|
33
35
|
static fromClient(
|
|
34
36
|
client: SeamHttpOptionsWithClient['client'],
|
|
35
37
|
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
36
38
|
): SeamHttpThermostats {
|
|
37
|
-
const
|
|
38
|
-
if (!isSeamHttpOptionsWithClient(
|
|
39
|
+
const constructorOptions = { ...options, client }
|
|
40
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
39
41
|
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
40
42
|
}
|
|
41
|
-
return new SeamHttpThermostats(
|
|
43
|
+
return new SeamHttpThermostats(constructorOptions)
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
static fromApiKey(
|
|
45
47
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
46
48
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
47
49
|
): SeamHttpThermostats {
|
|
48
|
-
const
|
|
49
|
-
if (!isSeamHttpOptionsWithApiKey(
|
|
50
|
+
const constructorOptions = { ...options, apiKey }
|
|
51
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
50
52
|
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
51
53
|
}
|
|
52
|
-
return new SeamHttpThermostats(
|
|
54
|
+
return new SeamHttpThermostats(constructorOptions)
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
static fromClientSessionToken(
|
|
@@ -59,11 +61,26 @@ export class SeamHttpThermostats {
|
|
|
59
61
|
'clientSessionToken'
|
|
60
62
|
> = {},
|
|
61
63
|
): SeamHttpThermostats {
|
|
62
|
-
const
|
|
63
|
-
if (!isSeamHttpOptionsWithClientSessionToken(
|
|
64
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
65
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
64
66
|
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
65
67
|
}
|
|
66
|
-
return new SeamHttpThermostats(
|
|
68
|
+
return new SeamHttpThermostats(constructorOptions)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static async fromPublishableKey(
|
|
72
|
+
publishableKey: string,
|
|
73
|
+
userIdentifierKey: string,
|
|
74
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
75
|
+
): Promise<SeamHttpThermostats> {
|
|
76
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
77
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
78
|
+
const client = createClient(clientOptions)
|
|
79
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
80
|
+
const { token } = await clientSessions.getOrCreate({
|
|
81
|
+
user_identifier_key: userIdentifierKey,
|
|
82
|
+
})
|
|
83
|
+
return SeamHttpThermostats.fromClientSessionToken(token, options)
|
|
67
84
|
}
|
|
68
85
|
|
|
69
86
|
get climateSettingSchedules(): SeamHttpThermostatsClimateSettingSchedules {
|
|
@@ -141,65 +158,50 @@ export class SeamHttpThermostats {
|
|
|
141
158
|
}
|
|
142
159
|
}
|
|
143
160
|
|
|
144
|
-
export type ThermostatsCoolBody =
|
|
145
|
-
Required<RouteRequestBody<'/thermostats/cool'>>
|
|
146
|
-
>
|
|
161
|
+
export type ThermostatsCoolBody = RouteRequestBody<'/thermostats/cool'>
|
|
147
162
|
|
|
148
163
|
export type ThermostatsCoolResponse = SetNonNullable<
|
|
149
164
|
Required<RouteResponse<'/thermostats/cool'>>
|
|
150
165
|
>
|
|
151
166
|
|
|
152
|
-
export type ThermostatsGetBody =
|
|
153
|
-
Required<RouteRequestBody<'/thermostats/get'>>
|
|
154
|
-
>
|
|
167
|
+
export type ThermostatsGetBody = RouteRequestBody<'/thermostats/get'>
|
|
155
168
|
|
|
156
169
|
export type ThermostatsGetResponse = SetNonNullable<
|
|
157
170
|
Required<RouteResponse<'/thermostats/get'>>
|
|
158
171
|
>
|
|
159
172
|
|
|
160
|
-
export type ThermostatsHeatBody =
|
|
161
|
-
Required<RouteRequestBody<'/thermostats/heat'>>
|
|
162
|
-
>
|
|
173
|
+
export type ThermostatsHeatBody = RouteRequestBody<'/thermostats/heat'>
|
|
163
174
|
|
|
164
175
|
export type ThermostatsHeatResponse = SetNonNullable<
|
|
165
176
|
Required<RouteResponse<'/thermostats/heat'>>
|
|
166
177
|
>
|
|
167
178
|
|
|
168
|
-
export type ThermostatsHeatCoolBody =
|
|
169
|
-
Required<RouteRequestBody<'/thermostats/heat_cool'>>
|
|
170
|
-
>
|
|
179
|
+
export type ThermostatsHeatCoolBody = RouteRequestBody<'/thermostats/heat_cool'>
|
|
171
180
|
|
|
172
181
|
export type ThermostatsHeatCoolResponse = SetNonNullable<
|
|
173
182
|
Required<RouteResponse<'/thermostats/heat_cool'>>
|
|
174
183
|
>
|
|
175
184
|
|
|
176
|
-
export type ThermostatsListBody =
|
|
177
|
-
Required<RouteRequestBody<'/thermostats/list'>>
|
|
178
|
-
>
|
|
185
|
+
export type ThermostatsListBody = RouteRequestBody<'/thermostats/list'>
|
|
179
186
|
|
|
180
187
|
export type ThermostatsListResponse = SetNonNullable<
|
|
181
188
|
Required<RouteResponse<'/thermostats/list'>>
|
|
182
189
|
>
|
|
183
190
|
|
|
184
|
-
export type ThermostatsOffBody =
|
|
185
|
-
Required<RouteRequestBody<'/thermostats/off'>>
|
|
186
|
-
>
|
|
191
|
+
export type ThermostatsOffBody = RouteRequestBody<'/thermostats/off'>
|
|
187
192
|
|
|
188
193
|
export type ThermostatsOffResponse = SetNonNullable<
|
|
189
194
|
Required<RouteResponse<'/thermostats/off'>>
|
|
190
195
|
>
|
|
191
196
|
|
|
192
|
-
export type ThermostatsSetFanModeBody =
|
|
193
|
-
|
|
194
|
-
>
|
|
197
|
+
export type ThermostatsSetFanModeBody =
|
|
198
|
+
RouteRequestBody<'/thermostats/set_fan_mode'>
|
|
195
199
|
|
|
196
200
|
export type ThermostatsSetFanModeResponse = SetNonNullable<
|
|
197
201
|
Required<RouteResponse<'/thermostats/set_fan_mode'>>
|
|
198
202
|
>
|
|
199
203
|
|
|
200
|
-
export type ThermostatsUpdateBody =
|
|
201
|
-
Required<RouteRequestBody<'/thermostats/update'>>
|
|
202
|
-
>
|
|
204
|
+
export type ThermostatsUpdateBody = RouteRequestBody<'/thermostats/update'>
|
|
203
205
|
|
|
204
206
|
export type ThermostatsUpdateResponse = SetNonNullable<
|
|
205
207
|
Required<RouteResponse<'/thermostats/update'>>
|
|
@@ -8,50 +8,53 @@ import type {
|
|
|
8
8
|
RouteRequestParams,
|
|
9
9
|
RouteResponse,
|
|
10
10
|
} from '@seamapi/types/connect'
|
|
11
|
-
import type { Axios } from 'axios'
|
|
12
11
|
import type { SetNonNullable } from 'type-fest'
|
|
13
12
|
|
|
14
|
-
import {
|
|
13
|
+
import { warnOnInsecureuserIdentifierKey } from 'lib/seam/connect/auth.js'
|
|
14
|
+
import { type Client, createClient } from 'lib/seam/connect/client.js'
|
|
15
15
|
import {
|
|
16
16
|
isSeamHttpOptionsWithApiKey,
|
|
17
17
|
isSeamHttpOptionsWithClient,
|
|
18
18
|
isSeamHttpOptionsWithClientSessionToken,
|
|
19
|
+
type SeamHttpFromPublishableKeyOptions,
|
|
19
20
|
SeamHttpInvalidOptionsError,
|
|
20
21
|
type SeamHttpOptions,
|
|
21
22
|
type SeamHttpOptionsWithApiKey,
|
|
22
23
|
type SeamHttpOptionsWithClient,
|
|
23
24
|
type SeamHttpOptionsWithClientSessionToken,
|
|
24
|
-
} from 'lib/seam/connect/
|
|
25
|
+
} from 'lib/seam/connect/options.js'
|
|
25
26
|
import { parseOptions } from 'lib/seam/connect/parse-options.js'
|
|
26
27
|
|
|
28
|
+
import { SeamHttpClientSessions } from './client-sessions.js'
|
|
29
|
+
|
|
27
30
|
export class SeamHttpWebhooks {
|
|
28
|
-
client:
|
|
31
|
+
client: Client
|
|
29
32
|
|
|
30
|
-
constructor(apiKeyOrOptions: string | SeamHttpOptions) {
|
|
31
|
-
const
|
|
32
|
-
this.client =
|
|
33
|
+
constructor(apiKeyOrOptions: string | SeamHttpOptions = {}) {
|
|
34
|
+
const clientOptions = parseOptions(apiKeyOrOptions)
|
|
35
|
+
this.client = createClient(clientOptions)
|
|
33
36
|
}
|
|
34
37
|
|
|
35
38
|
static fromClient(
|
|
36
39
|
client: SeamHttpOptionsWithClient['client'],
|
|
37
40
|
options: Omit<SeamHttpOptionsWithClient, 'client'> = {},
|
|
38
41
|
): SeamHttpWebhooks {
|
|
39
|
-
const
|
|
40
|
-
if (!isSeamHttpOptionsWithClient(
|
|
42
|
+
const constructorOptions = { ...options, client }
|
|
43
|
+
if (!isSeamHttpOptionsWithClient(constructorOptions)) {
|
|
41
44
|
throw new SeamHttpInvalidOptionsError('Missing client')
|
|
42
45
|
}
|
|
43
|
-
return new SeamHttpWebhooks(
|
|
46
|
+
return new SeamHttpWebhooks(constructorOptions)
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
static fromApiKey(
|
|
47
50
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
48
51
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
49
52
|
): SeamHttpWebhooks {
|
|
50
|
-
const
|
|
51
|
-
if (!isSeamHttpOptionsWithApiKey(
|
|
53
|
+
const constructorOptions = { ...options, apiKey }
|
|
54
|
+
if (!isSeamHttpOptionsWithApiKey(constructorOptions)) {
|
|
52
55
|
throw new SeamHttpInvalidOptionsError('Missing apiKey')
|
|
53
56
|
}
|
|
54
|
-
return new SeamHttpWebhooks(
|
|
57
|
+
return new SeamHttpWebhooks(constructorOptions)
|
|
55
58
|
}
|
|
56
59
|
|
|
57
60
|
static fromClientSessionToken(
|
|
@@ -61,11 +64,26 @@ export class SeamHttpWebhooks {
|
|
|
61
64
|
'clientSessionToken'
|
|
62
65
|
> = {},
|
|
63
66
|
): SeamHttpWebhooks {
|
|
64
|
-
const
|
|
65
|
-
if (!isSeamHttpOptionsWithClientSessionToken(
|
|
67
|
+
const constructorOptions = { ...options, clientSessionToken }
|
|
68
|
+
if (!isSeamHttpOptionsWithClientSessionToken(constructorOptions)) {
|
|
66
69
|
throw new SeamHttpInvalidOptionsError('Missing clientSessionToken')
|
|
67
70
|
}
|
|
68
|
-
return new SeamHttpWebhooks(
|
|
71
|
+
return new SeamHttpWebhooks(constructorOptions)
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
static async fromPublishableKey(
|
|
75
|
+
publishableKey: string,
|
|
76
|
+
userIdentifierKey: string,
|
|
77
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
78
|
+
): Promise<SeamHttpWebhooks> {
|
|
79
|
+
warnOnInsecureuserIdentifierKey(userIdentifierKey)
|
|
80
|
+
const clientOptions = parseOptions({ ...options, publishableKey })
|
|
81
|
+
const client = createClient(clientOptions)
|
|
82
|
+
const clientSessions = SeamHttpClientSessions.fromClient(client)
|
|
83
|
+
const { token } = await clientSessions.getOrCreate({
|
|
84
|
+
user_identifier_key: userIdentifierKey,
|
|
85
|
+
})
|
|
86
|
+
return SeamHttpWebhooks.fromClientSessionToken(token, options)
|
|
69
87
|
}
|
|
70
88
|
|
|
71
89
|
async create(
|
|
@@ -108,33 +126,25 @@ export class SeamHttpWebhooks {
|
|
|
108
126
|
}
|
|
109
127
|
}
|
|
110
128
|
|
|
111
|
-
export type WebhooksCreateBody =
|
|
112
|
-
Required<RouteRequestBody<'/webhooks/create'>>
|
|
113
|
-
>
|
|
129
|
+
export type WebhooksCreateBody = RouteRequestBody<'/webhooks/create'>
|
|
114
130
|
|
|
115
131
|
export type WebhooksCreateResponse = SetNonNullable<
|
|
116
132
|
Required<RouteResponse<'/webhooks/create'>>
|
|
117
133
|
>
|
|
118
134
|
|
|
119
|
-
export type WebhooksDeleteBody =
|
|
120
|
-
Required<RouteRequestBody<'/webhooks/delete'>>
|
|
121
|
-
>
|
|
135
|
+
export type WebhooksDeleteBody = RouteRequestBody<'/webhooks/delete'>
|
|
122
136
|
|
|
123
137
|
export type WebhooksDeleteResponse = SetNonNullable<
|
|
124
138
|
Required<RouteResponse<'/webhooks/delete'>>
|
|
125
139
|
>
|
|
126
140
|
|
|
127
|
-
export type WebhooksGetBody =
|
|
128
|
-
Required<RouteRequestBody<'/webhooks/get'>>
|
|
129
|
-
>
|
|
141
|
+
export type WebhooksGetBody = RouteRequestBody<'/webhooks/get'>
|
|
130
142
|
|
|
131
143
|
export type WebhooksGetResponse = SetNonNullable<
|
|
132
144
|
Required<RouteResponse<'/webhooks/get'>>
|
|
133
145
|
>
|
|
134
146
|
|
|
135
|
-
export type WebhooksListParams =
|
|
136
|
-
Required<RouteRequestParams<'/webhooks/list'>>
|
|
137
|
-
>
|
|
147
|
+
export type WebhooksListParams = RouteRequestParams<'/webhooks/list'>
|
|
138
148
|
|
|
139
149
|
export type WebhooksListResponse = SetNonNullable<
|
|
140
150
|
Required<RouteResponse<'/webhooks/list'>>
|