@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
|
@@ -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 SeamHttpDevicesUnmanaged {
|
|
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
|
): SeamHttpDevicesUnmanaged {
|
|
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 SeamHttpDevicesUnmanaged(
|
|
42
|
+
return new SeamHttpDevicesUnmanaged(constructorOptions)
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
static fromApiKey(
|
|
43
46
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
44
47
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
45
48
|
): SeamHttpDevicesUnmanaged {
|
|
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 SeamHttpDevicesUnmanaged(
|
|
53
|
+
return new SeamHttpDevicesUnmanaged(constructorOptions)
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
static fromClientSessionToken(
|
|
@@ -57,11 +60,26 @@ export class SeamHttpDevicesUnmanaged {
|
|
|
57
60
|
'clientSessionToken'
|
|
58
61
|
> = {},
|
|
59
62
|
): SeamHttpDevicesUnmanaged {
|
|
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 SeamHttpDevicesUnmanaged(
|
|
67
|
+
return new SeamHttpDevicesUnmanaged(constructorOptions)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static async fromPublishableKey(
|
|
71
|
+
publishableKey: string,
|
|
72
|
+
userIdentifierKey: string,
|
|
73
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
74
|
+
): Promise<SeamHttpDevicesUnmanaged> {
|
|
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 SeamHttpDevicesUnmanaged.fromClientSessionToken(token, options)
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
async get(
|
|
@@ -95,25 +113,21 @@ export class SeamHttpDevicesUnmanaged {
|
|
|
95
113
|
}
|
|
96
114
|
}
|
|
97
115
|
|
|
98
|
-
export type DevicesUnmanagedGetBody =
|
|
99
|
-
Required<RouteRequestBody<'/devices/unmanaged/get'>>
|
|
100
|
-
>
|
|
116
|
+
export type DevicesUnmanagedGetBody = RouteRequestBody<'/devices/unmanaged/get'>
|
|
101
117
|
|
|
102
118
|
export type DevicesUnmanagedGetResponse = SetNonNullable<
|
|
103
119
|
Required<RouteResponse<'/devices/unmanaged/get'>>
|
|
104
120
|
>
|
|
105
121
|
|
|
106
|
-
export type DevicesUnmanagedListBody =
|
|
107
|
-
|
|
108
|
-
>
|
|
122
|
+
export type DevicesUnmanagedListBody =
|
|
123
|
+
RouteRequestBody<'/devices/unmanaged/list'>
|
|
109
124
|
|
|
110
125
|
export type DevicesUnmanagedListResponse = SetNonNullable<
|
|
111
126
|
Required<RouteResponse<'/devices/unmanaged/list'>>
|
|
112
127
|
>
|
|
113
128
|
|
|
114
|
-
export type DevicesUnmanagedUpdateBody =
|
|
115
|
-
|
|
116
|
-
>
|
|
129
|
+
export type DevicesUnmanagedUpdateBody =
|
|
130
|
+
RouteRequestBody<'/devices/unmanaged/update'>
|
|
117
131
|
|
|
118
132
|
export type DevicesUnmanagedUpdateResponse = SetNonNullable<
|
|
119
133
|
Required<RouteResponse<'/devices/unmanaged/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 { SeamHttpDevicesUnmanaged } from './devices-unmanaged.js'
|
|
24
26
|
|
|
25
27
|
export class SeamHttpDevices {
|
|
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
|
): SeamHttpDevices {
|
|
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 SeamHttpDevices(
|
|
43
|
+
return new SeamHttpDevices(constructorOptions)
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
static fromApiKey(
|
|
45
47
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
46
48
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
47
49
|
): SeamHttpDevices {
|
|
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 SeamHttpDevices(
|
|
54
|
+
return new SeamHttpDevices(constructorOptions)
|
|
53
55
|
}
|
|
54
56
|
|
|
55
57
|
static fromClientSessionToken(
|
|
@@ -59,11 +61,26 @@ export class SeamHttpDevices {
|
|
|
59
61
|
'clientSessionToken'
|
|
60
62
|
> = {},
|
|
61
63
|
): SeamHttpDevices {
|
|
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 SeamHttpDevices(
|
|
68
|
+
return new SeamHttpDevices(constructorOptions)
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
static async fromPublishableKey(
|
|
72
|
+
publishableKey: string,
|
|
73
|
+
userIdentifierKey: string,
|
|
74
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
75
|
+
): Promise<SeamHttpDevices> {
|
|
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 SeamHttpDevices.fromClientSessionToken(token, options)
|
|
67
84
|
}
|
|
68
85
|
|
|
69
86
|
get unmanaged(): SeamHttpDevicesUnmanaged {
|
|
@@ -117,41 +134,32 @@ export class SeamHttpDevices {
|
|
|
117
134
|
}
|
|
118
135
|
}
|
|
119
136
|
|
|
120
|
-
export type DevicesDeleteBody =
|
|
121
|
-
Required<RouteRequestBody<'/devices/delete'>>
|
|
122
|
-
>
|
|
137
|
+
export type DevicesDeleteBody = RouteRequestBody<'/devices/delete'>
|
|
123
138
|
|
|
124
139
|
export type DevicesDeleteResponse = SetNonNullable<
|
|
125
140
|
Required<RouteResponse<'/devices/delete'>>
|
|
126
141
|
>
|
|
127
142
|
|
|
128
|
-
export type DevicesGetBody =
|
|
129
|
-
Required<RouteRequestBody<'/devices/get'>>
|
|
130
|
-
>
|
|
143
|
+
export type DevicesGetBody = RouteRequestBody<'/devices/get'>
|
|
131
144
|
|
|
132
145
|
export type DevicesGetResponse = SetNonNullable<
|
|
133
146
|
Required<RouteResponse<'/devices/get'>>
|
|
134
147
|
>
|
|
135
148
|
|
|
136
|
-
export type DevicesListBody =
|
|
137
|
-
Required<RouteRequestBody<'/devices/list'>>
|
|
138
|
-
>
|
|
149
|
+
export type DevicesListBody = RouteRequestBody<'/devices/list'>
|
|
139
150
|
|
|
140
151
|
export type DevicesListResponse = SetNonNullable<
|
|
141
152
|
Required<RouteResponse<'/devices/list'>>
|
|
142
153
|
>
|
|
143
154
|
|
|
144
|
-
export type DevicesListDeviceProvidersBody =
|
|
145
|
-
|
|
146
|
-
>
|
|
155
|
+
export type DevicesListDeviceProvidersBody =
|
|
156
|
+
RouteRequestBody<'/devices/list_device_providers'>
|
|
147
157
|
|
|
148
158
|
export type DevicesListDeviceProvidersResponse = SetNonNullable<
|
|
149
159
|
Required<RouteResponse<'/devices/list_device_providers'>>
|
|
150
160
|
>
|
|
151
161
|
|
|
152
|
-
export type DevicesUpdateBody =
|
|
153
|
-
Required<RouteRequestBody<'/devices/update'>>
|
|
154
|
-
>
|
|
162
|
+
export type DevicesUpdateBody = RouteRequestBody<'/devices/update'>
|
|
155
163
|
|
|
156
164
|
export type DevicesUpdateResponse = SetNonNullable<
|
|
157
165
|
Required<RouteResponse<'/devices/update'>>
|
|
@@ -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 SeamHttpEvents {
|
|
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
|
): SeamHttpEvents {
|
|
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 SeamHttpEvents(
|
|
42
|
+
return new SeamHttpEvents(constructorOptions)
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
static fromApiKey(
|
|
43
46
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
44
47
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
45
48
|
): SeamHttpEvents {
|
|
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 SeamHttpEvents(
|
|
53
|
+
return new SeamHttpEvents(constructorOptions)
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
static fromClientSessionToken(
|
|
@@ -57,11 +60,26 @@ export class SeamHttpEvents {
|
|
|
57
60
|
'clientSessionToken'
|
|
58
61
|
> = {},
|
|
59
62
|
): SeamHttpEvents {
|
|
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 SeamHttpEvents(
|
|
67
|
+
return new SeamHttpEvents(constructorOptions)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static async fromPublishableKey(
|
|
71
|
+
publishableKey: string,
|
|
72
|
+
userIdentifierKey: string,
|
|
73
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
74
|
+
): Promise<SeamHttpEvents> {
|
|
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 SeamHttpEvents.fromClientSessionToken(token, options)
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
async get(body: EventsGetBody): Promise<EventsGetResponse['event']> {
|
|
@@ -83,17 +101,13 @@ export class SeamHttpEvents {
|
|
|
83
101
|
}
|
|
84
102
|
}
|
|
85
103
|
|
|
86
|
-
export type EventsGetBody =
|
|
87
|
-
Required<RouteRequestBody<'/events/get'>>
|
|
88
|
-
>
|
|
104
|
+
export type EventsGetBody = RouteRequestBody<'/events/get'>
|
|
89
105
|
|
|
90
106
|
export type EventsGetResponse = SetNonNullable<
|
|
91
107
|
Required<RouteResponse<'/events/get'>>
|
|
92
108
|
>
|
|
93
109
|
|
|
94
|
-
export type EventsListBody =
|
|
95
|
-
Required<RouteRequestBody<'/events/list'>>
|
|
96
|
-
>
|
|
110
|
+
export type EventsListBody = RouteRequestBody<'/events/list'>
|
|
97
111
|
|
|
98
112
|
export type EventsListResponse = SetNonNullable<
|
|
99
113
|
Required<RouteResponse<'/events/list'>>
|
|
@@ -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 SeamHttpLocks {
|
|
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
|
): SeamHttpLocks {
|
|
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 SeamHttpLocks(
|
|
42
|
+
return new SeamHttpLocks(constructorOptions)
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
static fromApiKey(
|
|
43
46
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
44
47
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
45
48
|
): SeamHttpLocks {
|
|
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 SeamHttpLocks(
|
|
53
|
+
return new SeamHttpLocks(constructorOptions)
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
static fromClientSessionToken(
|
|
@@ -57,11 +60,26 @@ export class SeamHttpLocks {
|
|
|
57
60
|
'clientSessionToken'
|
|
58
61
|
> = {},
|
|
59
62
|
): SeamHttpLocks {
|
|
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 SeamHttpLocks(
|
|
67
|
+
return new SeamHttpLocks(constructorOptions)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static async fromPublishableKey(
|
|
71
|
+
publishableKey: string,
|
|
72
|
+
userIdentifierKey: string,
|
|
73
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
74
|
+
): Promise<SeamHttpLocks> {
|
|
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 SeamHttpLocks.fromClientSessionToken(token, options)
|
|
65
83
|
}
|
|
66
84
|
|
|
67
85
|
async get(body: LocksGetBody): Promise<LocksGetResponse['device']> {
|
|
@@ -105,33 +123,25 @@ export class SeamHttpLocks {
|
|
|
105
123
|
}
|
|
106
124
|
}
|
|
107
125
|
|
|
108
|
-
export type LocksGetBody =
|
|
109
|
-
Required<RouteRequestBody<'/locks/get'>>
|
|
110
|
-
>
|
|
126
|
+
export type LocksGetBody = RouteRequestBody<'/locks/get'>
|
|
111
127
|
|
|
112
128
|
export type LocksGetResponse = SetNonNullable<
|
|
113
129
|
Required<RouteResponse<'/locks/get'>>
|
|
114
130
|
>
|
|
115
131
|
|
|
116
|
-
export type LocksListBody =
|
|
117
|
-
Required<RouteRequestBody<'/locks/list'>>
|
|
118
|
-
>
|
|
132
|
+
export type LocksListBody = RouteRequestBody<'/locks/list'>
|
|
119
133
|
|
|
120
134
|
export type LocksListResponse = SetNonNullable<
|
|
121
135
|
Required<RouteResponse<'/locks/list'>>
|
|
122
136
|
>
|
|
123
137
|
|
|
124
|
-
export type LocksLockDoorBody =
|
|
125
|
-
Required<RouteRequestBody<'/locks/lock_door'>>
|
|
126
|
-
>
|
|
138
|
+
export type LocksLockDoorBody = RouteRequestBody<'/locks/lock_door'>
|
|
127
139
|
|
|
128
140
|
export type LocksLockDoorResponse = SetNonNullable<
|
|
129
141
|
Required<RouteResponse<'/locks/lock_door'>>
|
|
130
142
|
>
|
|
131
143
|
|
|
132
|
-
export type LocksUnlockDoorBody =
|
|
133
|
-
Required<RouteRequestBody<'/locks/unlock_door'>>
|
|
134
|
-
>
|
|
144
|
+
export type LocksUnlockDoorBody = RouteRequestBody<'/locks/unlock_door'>
|
|
135
145
|
|
|
136
146
|
export type LocksUnlockDoorResponse = SetNonNullable<
|
|
137
147
|
Required<RouteResponse<'/locks/unlock_door'>>
|
|
@@ -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 SeamHttpNoiseSensorsNoiseThresholds {
|
|
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
|
): SeamHttpNoiseSensorsNoiseThresholds {
|
|
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 SeamHttpNoiseSensorsNoiseThresholds(
|
|
42
|
+
return new SeamHttpNoiseSensorsNoiseThresholds(constructorOptions)
|
|
40
43
|
}
|
|
41
44
|
|
|
42
45
|
static fromApiKey(
|
|
43
46
|
apiKey: SeamHttpOptionsWithApiKey['apiKey'],
|
|
44
47
|
options: Omit<SeamHttpOptionsWithApiKey, 'apiKey'> = {},
|
|
45
48
|
): SeamHttpNoiseSensorsNoiseThresholds {
|
|
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 SeamHttpNoiseSensorsNoiseThresholds(
|
|
53
|
+
return new SeamHttpNoiseSensorsNoiseThresholds(constructorOptions)
|
|
51
54
|
}
|
|
52
55
|
|
|
53
56
|
static fromClientSessionToken(
|
|
@@ -57,11 +60,29 @@ export class SeamHttpNoiseSensorsNoiseThresholds {
|
|
|
57
60
|
'clientSessionToken'
|
|
58
61
|
> = {},
|
|
59
62
|
): SeamHttpNoiseSensorsNoiseThresholds {
|
|
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 SeamHttpNoiseSensorsNoiseThresholds(
|
|
67
|
+
return new SeamHttpNoiseSensorsNoiseThresholds(constructorOptions)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
static async fromPublishableKey(
|
|
71
|
+
publishableKey: string,
|
|
72
|
+
userIdentifierKey: string,
|
|
73
|
+
options: SeamHttpFromPublishableKeyOptions = {},
|
|
74
|
+
): Promise<SeamHttpNoiseSensorsNoiseThresholds> {
|
|
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 SeamHttpNoiseSensorsNoiseThresholds.fromClientSessionToken(
|
|
83
|
+
token,
|
|
84
|
+
options,
|
|
85
|
+
)
|
|
65
86
|
}
|
|
66
87
|
|
|
67
88
|
async create(body: NoiseSensorsNoiseThresholdsCreateBody): Promise<void> {
|
|
@@ -113,41 +134,36 @@ export class SeamHttpNoiseSensorsNoiseThresholds {
|
|
|
113
134
|
}
|
|
114
135
|
}
|
|
115
136
|
|
|
116
|
-
export type NoiseSensorsNoiseThresholdsCreateBody =
|
|
117
|
-
|
|
118
|
-
>
|
|
137
|
+
export type NoiseSensorsNoiseThresholdsCreateBody =
|
|
138
|
+
RouteRequestBody<'/noise_sensors/noise_thresholds/create'>
|
|
119
139
|
|
|
120
140
|
export type NoiseSensorsNoiseThresholdsCreateResponse = SetNonNullable<
|
|
121
141
|
Required<RouteResponse<'/noise_sensors/noise_thresholds/create'>>
|
|
122
142
|
>
|
|
123
143
|
|
|
124
|
-
export type NoiseSensorsNoiseThresholdsDeleteBody =
|
|
125
|
-
|
|
126
|
-
>
|
|
144
|
+
export type NoiseSensorsNoiseThresholdsDeleteBody =
|
|
145
|
+
RouteRequestBody<'/noise_sensors/noise_thresholds/delete'>
|
|
127
146
|
|
|
128
147
|
export type NoiseSensorsNoiseThresholdsDeleteResponse = SetNonNullable<
|
|
129
148
|
Required<RouteResponse<'/noise_sensors/noise_thresholds/delete'>>
|
|
130
149
|
>
|
|
131
150
|
|
|
132
|
-
export type NoiseSensorsNoiseThresholdsGetBody =
|
|
133
|
-
|
|
134
|
-
>
|
|
151
|
+
export type NoiseSensorsNoiseThresholdsGetBody =
|
|
152
|
+
RouteRequestBody<'/noise_sensors/noise_thresholds/get'>
|
|
135
153
|
|
|
136
154
|
export type NoiseSensorsNoiseThresholdsGetResponse = SetNonNullable<
|
|
137
155
|
Required<RouteResponse<'/noise_sensors/noise_thresholds/get'>>
|
|
138
156
|
>
|
|
139
157
|
|
|
140
|
-
export type NoiseSensorsNoiseThresholdsListBody =
|
|
141
|
-
|
|
142
|
-
>
|
|
158
|
+
export type NoiseSensorsNoiseThresholdsListBody =
|
|
159
|
+
RouteRequestBody<'/noise_sensors/noise_thresholds/list'>
|
|
143
160
|
|
|
144
161
|
export type NoiseSensorsNoiseThresholdsListResponse = SetNonNullable<
|
|
145
162
|
Required<RouteResponse<'/noise_sensors/noise_thresholds/list'>>
|
|
146
163
|
>
|
|
147
164
|
|
|
148
|
-
export type NoiseSensorsNoiseThresholdsUpdateBody =
|
|
149
|
-
|
|
150
|
-
>
|
|
165
|
+
export type NoiseSensorsNoiseThresholdsUpdateBody =
|
|
166
|
+
RouteRequestBody<'/noise_sensors/noise_thresholds/update'>
|
|
151
167
|
|
|
152
168
|
export type NoiseSensorsNoiseThresholdsUpdateResponse = SetNonNullable<
|
|
153
169
|
Required<RouteResponse<'/noise_sensors/noise_thresholds/update'>>
|