@seamapi/react 4.8.2 → 4.9.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 +17 -2
- package/dist/elements.js +22049 -18031
- package/dist/elements.js.map +1 -1
- package/lib/index.d.ts +1 -0
- package/lib/index.js +1 -0
- package/lib/index.js.map +1 -1
- package/lib/seam/SeamProvider.d.ts +7 -16
- package/lib/seam/SeamProvider.js +12 -101
- package/lib/seam/SeamProvider.js.map +1 -1
- package/lib/seam/SeamQueryProvider.d.ts +32 -0
- package/lib/seam/SeamQueryProvider.js +127 -0
- package/lib/seam/SeamQueryProvider.js.map +1 -0
- package/lib/seam/access-codes/use-access-code.d.ts +2 -2
- package/lib/seam/access-codes/use-access-codes.d.ts +2 -2
- package/lib/seam/access-codes/use-create-access-code.d.ts +2 -7
- package/lib/seam/access-codes/use-create-access-code.js +3 -9
- package/lib/seam/access-codes/use-create-access-code.js.map +1 -1
- package/lib/seam/access-codes/use-generate-access-code-code.d.ts +2 -2
- package/lib/seam/client-sessions/use-client-session.d.ts +2 -2
- package/lib/seam/components/SupportedDeviceTable/use-device-model.d.ts +2 -2
- package/lib/seam/components/SupportedDeviceTable/use-device-models.d.ts +2 -2
- package/lib/seam/components/SupportedDeviceTable/use-manufacturer.d.ts +2 -2
- package/lib/seam/components/SupportedDeviceTable/use-manufacturers.d.ts +2 -2
- package/lib/seam/connected-accounts/use-connected-account.d.ts +2 -2
- package/lib/seam/devices/use-device-providers.d.ts +2 -2
- package/lib/seam/devices/use-device.d.ts +2 -2
- package/lib/seam/devices/use-devices.d.ts +2 -2
- package/lib/seam/events/use-events.d.ts +2 -2
- package/lib/seam/index.d.ts +2 -0
- package/lib/seam/index.js +2 -0
- package/lib/seam/index.js.map +1 -1
- package/lib/seam/noise-sensors/use-noise-thresholds.d.ts +2 -2
- package/lib/seam/thermostats/use-delete-thermostat-climate-preset.d.ts +2 -2
- package/lib/seam/use-seam-client.d.ts +2 -1
- package/lib/seam/use-seam-client.js +23 -9
- package/lib/seam/use-seam-client.js.map +1 -1
- package/lib/seam/use-seam-mutation.d.ts +8 -0
- package/lib/seam/use-seam-mutation.js +17 -0
- package/lib/seam/use-seam-mutation.js.map +1 -0
- package/lib/seam/use-seam-query-result.d.ts +1 -1
- package/lib/seam/use-seam-query.d.ts +8 -0
- package/lib/seam/use-seam-query.js +19 -0
- package/lib/seam/use-seam-query.js.map +1 -0
- package/lib/telemetry/hooks.js +2 -2
- package/lib/telemetry/hooks.js.map +1 -1
- package/lib/ui/DateTimePicker/DateTimePicker.d.ts +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +3 -2
- package/src/lib/index.ts +1 -0
- package/src/lib/seam/SeamProvider.tsx +28 -183
- package/src/lib/seam/SeamQueryProvider.tsx +248 -0
- package/src/lib/seam/access-codes/use-access-code.ts +2 -2
- package/src/lib/seam/access-codes/use-access-codes.ts +2 -2
- package/src/lib/seam/access-codes/use-create-access-code.ts +7 -32
- package/src/lib/seam/access-codes/use-generate-access-code-code.ts +2 -2
- package/src/lib/seam/client-sessions/use-client-session.ts +2 -2
- package/src/lib/seam/components/SupportedDeviceTable/use-device-model.ts +2 -2
- package/src/lib/seam/components/SupportedDeviceTable/use-device-models.ts +2 -2
- package/src/lib/seam/components/SupportedDeviceTable/use-manufacturer.ts +2 -2
- package/src/lib/seam/components/SupportedDeviceTable/use-manufacturers.ts +2 -2
- package/src/lib/seam/connected-accounts/use-connected-account.ts +2 -2
- package/src/lib/seam/devices/use-device-providers.ts +2 -2
- package/src/lib/seam/devices/use-device.ts +2 -2
- package/src/lib/seam/devices/use-devices.ts +2 -2
- package/src/lib/seam/events/use-events.ts +2 -2
- package/src/lib/seam/index.ts +2 -0
- package/src/lib/seam/noise-sensors/use-noise-thresholds.ts +2 -2
- package/src/lib/seam/thermostats/use-delete-thermostat-climate-preset.ts +2 -2
- package/src/lib/seam/use-seam-client.ts +29 -10
- package/src/lib/seam/use-seam-mutation.ts +50 -0
- package/src/lib/seam/use-seam-query-result.ts +6 -4
- package/src/lib/seam/use-seam-query.ts +45 -0
- package/src/lib/telemetry/hooks.ts +2 -2
- package/src/lib/version.ts +1 -1
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SeamHttp,
|
|
3
|
+
SeamHttpEndpoints,
|
|
4
|
+
SeamHttpOptionsWithClientSessionToken,
|
|
5
|
+
} from '@seamapi/http/connect'
|
|
6
|
+
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
7
|
+
import {
|
|
8
|
+
createContext,
|
|
9
|
+
type PropsWithChildren,
|
|
10
|
+
useContext,
|
|
11
|
+
useEffect,
|
|
12
|
+
useMemo,
|
|
13
|
+
} from 'react'
|
|
14
|
+
|
|
15
|
+
import { useSeamClient } from './use-seam-client.js'
|
|
16
|
+
|
|
17
|
+
export interface SeamQueryContext {
|
|
18
|
+
client: SeamHttp | null
|
|
19
|
+
endpointClient: SeamHttpEndpoints | null
|
|
20
|
+
clientOptions?: SeamQueryProviderClientOptions | undefined
|
|
21
|
+
publishableKey?: string | undefined
|
|
22
|
+
userIdentifierKey?: string | undefined
|
|
23
|
+
clientSessionToken?: string | undefined
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export type SeamQueryProviderProps =
|
|
27
|
+
| SeamQueryProviderPropsWithClient
|
|
28
|
+
| SeamQueryProviderPropsWithPublishableKey
|
|
29
|
+
| SeamQueryProviderPropsWithClientSessionToken
|
|
30
|
+
|
|
31
|
+
export interface SeamQueryProviderPropsWithClient
|
|
32
|
+
extends SeamQueryProviderBaseProps {
|
|
33
|
+
client: SeamHttp
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export interface SeamQueryProviderPropsWithPublishableKey
|
|
37
|
+
extends SeamQueryProviderBaseProps,
|
|
38
|
+
SeamQueryProviderClientOptions {
|
|
39
|
+
publishableKey: string
|
|
40
|
+
userIdentifierKey?: string
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface SeamQueryProviderPropsWithClientSessionToken
|
|
44
|
+
extends SeamQueryProviderBaseProps,
|
|
45
|
+
SeamQueryProviderClientOptions {
|
|
46
|
+
clientSessionToken: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface SeamQueryProviderBaseProps extends PropsWithChildren {
|
|
50
|
+
queryClient?: QueryClient | undefined
|
|
51
|
+
onSessionUpdate?: (client: SeamHttp) => void
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
type SeamClientOptions = SeamHttpOptionsWithClientSessionToken
|
|
55
|
+
|
|
56
|
+
export type SeamQueryProviderClientOptions = Pick<SeamClientOptions, 'endpoint'>
|
|
57
|
+
|
|
58
|
+
const defaultQueryClient = new QueryClient()
|
|
59
|
+
|
|
60
|
+
export function SeamQueryProvider({
|
|
61
|
+
children,
|
|
62
|
+
onSessionUpdate = () => {},
|
|
63
|
+
queryClient,
|
|
64
|
+
...props
|
|
65
|
+
}: SeamQueryProviderProps): JSX.Element {
|
|
66
|
+
const value = useMemo(() => {
|
|
67
|
+
const context = createSeamQueryContextValue(props)
|
|
68
|
+
if (
|
|
69
|
+
context.client == null &&
|
|
70
|
+
context.publishableKey == null &&
|
|
71
|
+
context.clientSessionToken == null
|
|
72
|
+
) {
|
|
73
|
+
return defaultSeamQueryContextValue
|
|
74
|
+
}
|
|
75
|
+
return context
|
|
76
|
+
}, [props])
|
|
77
|
+
|
|
78
|
+
if (
|
|
79
|
+
value.client == null &&
|
|
80
|
+
value.publishableKey == null &&
|
|
81
|
+
value.clientSessionToken == null
|
|
82
|
+
) {
|
|
83
|
+
throw new Error(
|
|
84
|
+
`Must provide either a Seam client, clientSessionToken, or a publishableKey.`
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
const { Provider } = seamContext
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<QueryClientProvider
|
|
92
|
+
client={queryClient ?? globalThis.seamQueryClient ?? defaultQueryClient}
|
|
93
|
+
>
|
|
94
|
+
<Provider value={value}>
|
|
95
|
+
<Session onSessionUpdate={onSessionUpdate}>{children}</Session>
|
|
96
|
+
</Provider>
|
|
97
|
+
</QueryClientProvider>
|
|
98
|
+
)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
function Session({
|
|
102
|
+
onSessionUpdate,
|
|
103
|
+
children,
|
|
104
|
+
}: Required<Pick<SeamQueryProviderProps, 'onSessionUpdate'>> &
|
|
105
|
+
PropsWithChildren): JSX.Element | null {
|
|
106
|
+
const { client } = useSeamClient()
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
if (client != null) onSessionUpdate(client)
|
|
109
|
+
}, [onSessionUpdate, client])
|
|
110
|
+
|
|
111
|
+
return <>{children}</>
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
const createDefaultSeamQueryContextValue = (): SeamQueryContext => {
|
|
115
|
+
try {
|
|
116
|
+
if (globalThis.seam == null) {
|
|
117
|
+
return { client: null, endpointClient: null }
|
|
118
|
+
}
|
|
119
|
+
return createSeamQueryContextValue(globalThis.seam)
|
|
120
|
+
} catch (err) {
|
|
121
|
+
// eslint-disable-next-line no-console
|
|
122
|
+
console.warn(err)
|
|
123
|
+
return { client: null, endpointClient: null }
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
const createSeamQueryContextValue = (
|
|
128
|
+
options: SeamQueryProviderProps
|
|
129
|
+
): SeamQueryContext => {
|
|
130
|
+
if (isSeamQueryProviderPropsWithClient(options)) {
|
|
131
|
+
return {
|
|
132
|
+
...options,
|
|
133
|
+
endpointClient: null,
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if (isSeamQueryProviderPropsWithClientSessionToken(options)) {
|
|
138
|
+
const { clientSessionToken, ...clientOptions } = options
|
|
139
|
+
return {
|
|
140
|
+
clientSessionToken,
|
|
141
|
+
clientOptions,
|
|
142
|
+
client: null,
|
|
143
|
+
endpointClient: null,
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
if (isSeamQueryProviderPropsWithPublishableKey(options)) {
|
|
148
|
+
const { publishableKey, userIdentifierKey, ...clientOptions } = options
|
|
149
|
+
return {
|
|
150
|
+
publishableKey,
|
|
151
|
+
userIdentifierKey,
|
|
152
|
+
clientOptions,
|
|
153
|
+
client: null,
|
|
154
|
+
endpointClient: null,
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return { client: null, endpointClient: null }
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const defaultSeamQueryContextValue = createDefaultSeamQueryContextValue()
|
|
162
|
+
|
|
163
|
+
export const seamContext = createContext<SeamQueryContext>(
|
|
164
|
+
defaultSeamQueryContextValue
|
|
165
|
+
)
|
|
166
|
+
|
|
167
|
+
export function useSeamQueryContext(): SeamQueryContext {
|
|
168
|
+
return useContext(seamContext)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
const isSeamQueryProviderPropsWithClient = (
|
|
172
|
+
props: SeamQueryProviderProps
|
|
173
|
+
): props is SeamQueryProviderPropsWithClient => {
|
|
174
|
+
if (!('client' in props)) return false
|
|
175
|
+
|
|
176
|
+
const { client, ...otherProps } = props
|
|
177
|
+
if (client == null) return false
|
|
178
|
+
|
|
179
|
+
const otherNonNullProps = Object.values(otherProps).filter((v) => v != null)
|
|
180
|
+
if (otherNonNullProps.length > 0) {
|
|
181
|
+
throw new InvalidSeamQueryProviderProps(
|
|
182
|
+
`The client prop cannot be used with ${otherNonNullProps.join(' or ')}.`
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return true
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const isSeamQueryProviderPropsWithPublishableKey = (
|
|
190
|
+
props: SeamQueryProviderProps
|
|
191
|
+
): props is SeamQueryProviderPropsWithPublishableKey &
|
|
192
|
+
SeamQueryProviderClientOptions => {
|
|
193
|
+
if (!('publishableKey' in props)) return false
|
|
194
|
+
|
|
195
|
+
const { publishableKey } = props
|
|
196
|
+
if (publishableKey == null) return false
|
|
197
|
+
|
|
198
|
+
if ('client' in props && props.client != null) {
|
|
199
|
+
throw new InvalidSeamQueryProviderProps(
|
|
200
|
+
'The client prop cannot be used with the publishableKey prop.'
|
|
201
|
+
)
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
if ('clientSessionToken' in props && props.clientSessionToken != null) {
|
|
205
|
+
throw new InvalidSeamQueryProviderProps(
|
|
206
|
+
'The clientSessionToken prop cannot be used with the publishableKey prop.'
|
|
207
|
+
)
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
return true
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const isSeamQueryProviderPropsWithClientSessionToken = (
|
|
214
|
+
props: SeamQueryProviderProps
|
|
215
|
+
): props is SeamQueryProviderPropsWithClientSessionToken &
|
|
216
|
+
SeamQueryProviderClientOptions => {
|
|
217
|
+
if (!('clientSessionToken' in props)) return false
|
|
218
|
+
|
|
219
|
+
const { clientSessionToken } = props
|
|
220
|
+
if (clientSessionToken == null) return false
|
|
221
|
+
|
|
222
|
+
if ('client' in props && props.client != null) {
|
|
223
|
+
throw new InvalidSeamQueryProviderProps(
|
|
224
|
+
'The client prop cannot be used with the clientSessionToken prop.'
|
|
225
|
+
)
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
if ('publishableKey' in props && props.publishableKey != null) {
|
|
229
|
+
throw new InvalidSeamQueryProviderProps(
|
|
230
|
+
'The publishableKey prop cannot be used with the clientSessionToken prop.'
|
|
231
|
+
)
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
if ('userIdentifierKey' in props && props.userIdentifierKey != null) {
|
|
235
|
+
throw new InvalidSeamQueryProviderProps(
|
|
236
|
+
'The userIdentifierKey prop cannot be used with the clientSessionToken prop.'
|
|
237
|
+
)
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return true
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
class InvalidSeamQueryProviderProps extends Error {
|
|
244
|
+
constructor(message: string) {
|
|
245
|
+
super(`SeamQueryProvider received invalid props: ${message}`)
|
|
246
|
+
this.name = this.constructor.name
|
|
247
|
+
}
|
|
248
|
+
}
|
|
@@ -6,7 +6,7 @@ import type { AccessCode } from '@seamapi/types/connect'
|
|
|
6
6
|
import { useQuery } from '@tanstack/react-query'
|
|
7
7
|
|
|
8
8
|
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
9
|
-
import type {
|
|
9
|
+
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
10
10
|
|
|
11
11
|
export type UseAccessCodeParams = AccessCodesGetParams
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ export type UseAccessCodeData = AccessCode | null
|
|
|
14
14
|
|
|
15
15
|
export function useAccessCode(
|
|
16
16
|
params: UseAccessCodeParams
|
|
17
|
-
):
|
|
17
|
+
): UseSeamQueryResultLegacy<'accessCode', UseAccessCodeData> {
|
|
18
18
|
const { client } = useSeamClient()
|
|
19
19
|
const { data, ...rest } = useQuery<UseAccessCodeData, SeamHttpApiError>({
|
|
20
20
|
enabled: client != null,
|
|
@@ -6,7 +6,7 @@ import type { AccessCode } from '@seamapi/types/connect'
|
|
|
6
6
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
7
7
|
|
|
8
8
|
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
9
|
-
import type {
|
|
9
|
+
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
10
10
|
|
|
11
11
|
export type UseAccessCodesParams = AccessCodesListParams
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ export type UseAccessCodesData = AccessCode[]
|
|
|
14
14
|
|
|
15
15
|
export function useAccessCodes(
|
|
16
16
|
params: UseAccessCodesParams
|
|
17
|
-
):
|
|
17
|
+
): UseSeamQueryResultLegacy<'accessCodes', UseAccessCodesData> {
|
|
18
18
|
const { client } = useSeamClient()
|
|
19
19
|
const queryClient = useQueryClient()
|
|
20
20
|
|
|
@@ -1,39 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
AccessCodesCreateBody,
|
|
3
|
-
SeamHttpApiError,
|
|
4
|
-
} from '@seamapi/http/connect'
|
|
5
|
-
import type { AccessCode } from '@seamapi/types/connect'
|
|
6
|
-
import {
|
|
7
|
-
useMutation,
|
|
8
|
-
type UseMutationResult,
|
|
9
|
-
useQueryClient,
|
|
10
|
-
} from '@tanstack/react-query'
|
|
11
|
-
|
|
12
|
-
import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
13
|
-
|
|
14
|
-
export type UseCreateAccessCodeParams = never
|
|
1
|
+
import { useQueryClient } from '@tanstack/react-query'
|
|
15
2
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
3
|
+
import {
|
|
4
|
+
useSeamMutation,
|
|
5
|
+
type UseSeamMutationResult,
|
|
6
|
+
} from '../use-seam-mutation.js'
|
|
19
7
|
|
|
20
|
-
export function useCreateAccessCode():
|
|
21
|
-
UseCreateAccessCodeData,
|
|
22
|
-
SeamHttpApiError,
|
|
23
|
-
UseCreateAccessCodeMutationVariables
|
|
24
|
-
> {
|
|
25
|
-
const { client } = useSeamClient()
|
|
8
|
+
export function useCreateAccessCode(): UseSeamMutationResult<'/access_codes/create'> {
|
|
26
9
|
const queryClient = useQueryClient()
|
|
27
10
|
|
|
28
|
-
return
|
|
29
|
-
UseCreateAccessCodeData,
|
|
30
|
-
SeamHttpApiError,
|
|
31
|
-
UseCreateAccessCodeMutationVariables
|
|
32
|
-
>({
|
|
33
|
-
mutationFn: async (variables) => {
|
|
34
|
-
if (client === null) throw new NullSeamClientError()
|
|
35
|
-
return await client.accessCodes.create(variables)
|
|
36
|
-
},
|
|
11
|
+
return useSeamMutation('/access_codes/create', {
|
|
37
12
|
onSuccess: (data) => {
|
|
38
13
|
queryClient.setQueryData(
|
|
39
14
|
['access_codes', 'get', { access_code_id: data.access_code_id }],
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
2
|
+
AccessCodesGenerateCodeParams,
|
|
3
3
|
SeamHttpApiError,
|
|
4
4
|
} from '@seamapi/http/connect'
|
|
5
5
|
import { useMutation, type UseMutationResult } from '@tanstack/react-query'
|
|
@@ -11,7 +11,7 @@ export type UseGenerateAccessCodeCodeParams = never
|
|
|
11
11
|
export type UseGenerateAccessCodeCodeData = string
|
|
12
12
|
|
|
13
13
|
export type UseGenerateAccessCodeCodeMutationVariables =
|
|
14
|
-
|
|
14
|
+
AccessCodesGenerateCodeParams
|
|
15
15
|
|
|
16
16
|
export function useGenerateAccessCodeCode(): UseMutationResult<
|
|
17
17
|
UseGenerateAccessCodeCodeData,
|
|
@@ -3,13 +3,13 @@ import type { ClientSession } from '@seamapi/types/connect'
|
|
|
3
3
|
import { useQuery } from '@tanstack/react-query'
|
|
4
4
|
|
|
5
5
|
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
6
|
-
import type {
|
|
6
|
+
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
7
7
|
|
|
8
8
|
export type UseClientSessionParams = never
|
|
9
9
|
|
|
10
10
|
export type UseClientSessionData = ClientSession | null
|
|
11
11
|
|
|
12
|
-
export function useClientSession():
|
|
12
|
+
export function useClientSession(): UseSeamQueryResultLegacy<
|
|
13
13
|
'clientSession',
|
|
14
14
|
UseClientSessionData
|
|
15
15
|
> {
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
import { useQuery } from '@tanstack/react-query'
|
|
8
8
|
|
|
9
9
|
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
10
|
-
import type {
|
|
10
|
+
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
11
11
|
|
|
12
12
|
export type UseDeviceModelParams = DeviceModelsGetParams
|
|
13
13
|
|
|
@@ -15,7 +15,7 @@ export type UseDeviceModelData = DeviceModel | null
|
|
|
15
15
|
|
|
16
16
|
export function useDeviceModel(
|
|
17
17
|
params: UseDeviceModelParams
|
|
18
|
-
):
|
|
18
|
+
): UseSeamQueryResultLegacy<'deviceModel', UseDeviceModelData> {
|
|
19
19
|
const { client: seam } = useSeamClient()
|
|
20
20
|
const { data, ...rest } = useQuery<UseDeviceModelData, SeamHttpApiError>({
|
|
21
21
|
enabled: seam != null,
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
8
8
|
|
|
9
9
|
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
10
|
-
import type {
|
|
10
|
+
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
11
11
|
|
|
12
12
|
export type UseDeviceModelsParams = DeviceModelsListParams
|
|
13
13
|
|
|
@@ -15,7 +15,7 @@ export type UseDeviceModelsData = DeviceModel[]
|
|
|
15
15
|
|
|
16
16
|
export function useDeviceModels(
|
|
17
17
|
params?: UseDeviceModelsParams
|
|
18
|
-
):
|
|
18
|
+
): UseSeamQueryResultLegacy<'deviceModels', UseDeviceModelsData> {
|
|
19
19
|
const { client: seam } = useSeamClient()
|
|
20
20
|
const queryClient = useQueryClient()
|
|
21
21
|
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
import { useQuery } from '@tanstack/react-query'
|
|
8
8
|
|
|
9
9
|
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
10
|
-
import type {
|
|
10
|
+
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
11
11
|
|
|
12
12
|
export type UseManufacturerParams = ManufacturersGetParams
|
|
13
13
|
|
|
@@ -15,7 +15,7 @@ export type UseManufacturerData = Manufacturer | null
|
|
|
15
15
|
|
|
16
16
|
export function useManufacturer(
|
|
17
17
|
params: UseManufacturerParams
|
|
18
|
-
):
|
|
18
|
+
): UseSeamQueryResultLegacy<'manufacturer', UseManufacturerData> {
|
|
19
19
|
const { client: seam } = useSeamClient()
|
|
20
20
|
const { data, ...rest } = useQuery<UseManufacturerData, SeamHttpApiError>({
|
|
21
21
|
enabled: seam != null,
|
|
@@ -7,7 +7,7 @@ import type {
|
|
|
7
7
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
8
8
|
|
|
9
9
|
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
10
|
-
import type {
|
|
10
|
+
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
11
11
|
|
|
12
12
|
export type UseManufacturersParams = ManufacturersListParams
|
|
13
13
|
|
|
@@ -15,7 +15,7 @@ export type UseManufacturersData = Manufacturer[]
|
|
|
15
15
|
|
|
16
16
|
export function useManufacturers(
|
|
17
17
|
params?: UseManufacturersParams
|
|
18
|
-
):
|
|
18
|
+
): UseSeamQueryResultLegacy<'manufacturers', UseManufacturersData> {
|
|
19
19
|
const { client: seam } = useSeamClient()
|
|
20
20
|
const queryClient = useQueryClient()
|
|
21
21
|
|
|
@@ -6,7 +6,7 @@ import type { ConnectedAccount } from '@seamapi/types/connect'
|
|
|
6
6
|
import { useQuery } from '@tanstack/react-query'
|
|
7
7
|
|
|
8
8
|
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
9
|
-
import type {
|
|
9
|
+
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
10
10
|
|
|
11
11
|
export type UseConnectedAccountParams = ConnectedAccountsGetParams
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ export type UseConnectedAccountData = ConnectedAccount | null
|
|
|
14
14
|
|
|
15
15
|
export function useConnectedAccount(
|
|
16
16
|
params: UseConnectedAccountParams
|
|
17
|
-
):
|
|
17
|
+
): UseSeamQueryResultLegacy<'connectedAccount', UseConnectedAccountData> {
|
|
18
18
|
const { client } = useSeamClient()
|
|
19
19
|
const { data, ...rest } = useQuery<UseConnectedAccountData, SeamHttpApiError>(
|
|
20
20
|
{
|
|
@@ -6,7 +6,7 @@ import type { DeviceProvider } from '@seamapi/types/connect'
|
|
|
6
6
|
import { useQuery } from '@tanstack/react-query'
|
|
7
7
|
|
|
8
8
|
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
9
|
-
import type {
|
|
9
|
+
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
10
10
|
|
|
11
11
|
export type UseDeviceProvidersParams = DevicesListDeviceProvidersParams
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ export type UseDeviceProvidersData = DeviceProvider[]
|
|
|
14
14
|
|
|
15
15
|
export function useDeviceProviders(
|
|
16
16
|
params?: UseDeviceProvidersParams
|
|
17
|
-
):
|
|
17
|
+
): UseSeamQueryResultLegacy<'deviceProviders', UseDeviceProvidersData> {
|
|
18
18
|
const { client } = useSeamClient()
|
|
19
19
|
|
|
20
20
|
const { data, ...rest } = useQuery<UseDeviceProvidersData, SeamHttpApiError>({
|
|
@@ -3,7 +3,7 @@ import type { Device } from '@seamapi/types/connect'
|
|
|
3
3
|
import { useQuery } from '@tanstack/react-query'
|
|
4
4
|
|
|
5
5
|
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
6
|
-
import type {
|
|
6
|
+
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
7
7
|
|
|
8
8
|
export type UseDeviceParams = DevicesGetParams
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ export type UseDeviceData = Device | null
|
|
|
11
11
|
|
|
12
12
|
export function useDevice(
|
|
13
13
|
params: UseDeviceParams
|
|
14
|
-
):
|
|
14
|
+
): UseSeamQueryResultLegacy<'device', UseDeviceData> {
|
|
15
15
|
const { client } = useSeamClient()
|
|
16
16
|
const { data, ...rest } = useQuery<UseDeviceData, SeamHttpApiError>({
|
|
17
17
|
enabled: client != null,
|
|
@@ -3,7 +3,7 @@ import type { Device } from '@seamapi/types/connect'
|
|
|
3
3
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
4
4
|
|
|
5
5
|
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
6
|
-
import type {
|
|
6
|
+
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
7
7
|
|
|
8
8
|
export type UseDevicesParams = DevicesListParams
|
|
9
9
|
|
|
@@ -11,7 +11,7 @@ export type UseDevicesData = Device[]
|
|
|
11
11
|
|
|
12
12
|
export function useDevices(
|
|
13
13
|
params?: UseDevicesParams
|
|
14
|
-
):
|
|
14
|
+
): UseSeamQueryResultLegacy<'devices', UseDevicesData> {
|
|
15
15
|
const { client } = useSeamClient()
|
|
16
16
|
const queryClient = useQueryClient()
|
|
17
17
|
|
|
@@ -3,7 +3,7 @@ import type { SeamEvent } from '@seamapi/types/connect'
|
|
|
3
3
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
4
4
|
|
|
5
5
|
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
6
|
-
import type {
|
|
6
|
+
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
7
7
|
|
|
8
8
|
export type UseEventsParams = EventsListParams
|
|
9
9
|
|
|
@@ -16,7 +16,7 @@ export interface UseEventsOptions {
|
|
|
16
16
|
export function useEvents(
|
|
17
17
|
params?: UseEventsParams,
|
|
18
18
|
{ refetchInterval }: UseEventsOptions = {}
|
|
19
|
-
):
|
|
19
|
+
): UseSeamQueryResultLegacy<'events', UseEventsData> {
|
|
20
20
|
const { client } = useSeamClient()
|
|
21
21
|
const queryClient = useQueryClient()
|
|
22
22
|
|
package/src/lib/seam/index.ts
CHANGED
|
@@ -12,4 +12,6 @@ export * from './devices/use-device-providers.js'
|
|
|
12
12
|
export * from './devices/use-devices.js'
|
|
13
13
|
export * from './SeamProvider.js'
|
|
14
14
|
export * from './use-seam-client.js'
|
|
15
|
+
export * from './use-seam-mutation.js'
|
|
16
|
+
export * from './use-seam-query.js'
|
|
15
17
|
export * from './use-seam-query-result.js'
|
|
@@ -6,7 +6,7 @@ import type { NoiseThreshold } from '@seamapi/types/connect'
|
|
|
6
6
|
import { useQuery, useQueryClient } from '@tanstack/react-query'
|
|
7
7
|
|
|
8
8
|
import { useSeamClient } from 'lib/seam/use-seam-client.js'
|
|
9
|
-
import type {
|
|
9
|
+
import type { UseSeamQueryResultLegacy } from 'lib/seam/use-seam-query-result.js'
|
|
10
10
|
|
|
11
11
|
export type UseNoiseThresholdsParams = NoiseSensorsNoiseThresholdsListParams
|
|
12
12
|
|
|
@@ -14,7 +14,7 @@ export type UseNoiseThresholdsData = NoiseThreshold[]
|
|
|
14
14
|
|
|
15
15
|
export function useNoiseThresholds(
|
|
16
16
|
params: UseNoiseThresholdsParams
|
|
17
|
-
):
|
|
17
|
+
): UseSeamQueryResultLegacy<'noiseThresholds', UseNoiseThresholdsData> {
|
|
18
18
|
const { client } = useSeamClient()
|
|
19
19
|
const queryClient = useQueryClient()
|
|
20
20
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type {
|
|
2
2
|
SeamHttpApiError,
|
|
3
|
-
|
|
3
|
+
ThermostatsDeleteClimatePresetParams,
|
|
4
4
|
} from '@seamapi/http/connect'
|
|
5
5
|
import {
|
|
6
6
|
useMutation,
|
|
@@ -16,7 +16,7 @@ export type UseDeleteThermostatClimatePresetParams = never
|
|
|
16
16
|
export type UseDeleteThermostatClimatePresetData = undefined
|
|
17
17
|
|
|
18
18
|
export type UseDeleteThermostatClimatePresetVariables =
|
|
19
|
-
|
|
19
|
+
ThermostatsDeleteClimatePresetParams
|
|
20
20
|
|
|
21
21
|
export function useDeleteThermostatClimatePreset(): UseMutationResult<
|
|
22
22
|
UseDeleteThermostatClimatePresetData,
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { SeamHttp } from '@seamapi/http/connect'
|
|
1
|
+
import { SeamHttp, SeamHttpEndpoints } from '@seamapi/http/connect'
|
|
2
2
|
import { useQuery } from '@tanstack/react-query'
|
|
3
3
|
import { useEffect } from 'react'
|
|
4
4
|
import { v4 as uuidv4 } from 'uuid'
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { useSeamQueryContext } from './SeamQueryProvider.js'
|
|
7
7
|
|
|
8
8
|
export function useSeamClient(): {
|
|
9
9
|
client: SeamHttp | null
|
|
10
|
+
endpointClient: SeamHttpEndpoints | null
|
|
10
11
|
isPending: boolean
|
|
11
12
|
isError: boolean
|
|
12
13
|
error: unknown
|
|
@@ -17,12 +18,14 @@ export function useSeamClient(): {
|
|
|
17
18
|
publishableKey,
|
|
18
19
|
clientSessionToken,
|
|
19
20
|
...context
|
|
20
|
-
} =
|
|
21
|
+
} = useSeamQueryContext()
|
|
21
22
|
const userIdentifierKey = useUserIdentifierKeyOrFingerprint(
|
|
22
23
|
clientSessionToken != null ? '' : context.userIdentifierKey
|
|
23
24
|
)
|
|
24
25
|
|
|
25
|
-
const { isPending, isError, error, data } = useQuery<
|
|
26
|
+
const { isPending, isError, error, data } = useQuery<
|
|
27
|
+
[SeamHttp, SeamHttpEndpoints]
|
|
28
|
+
>({
|
|
26
29
|
queryKey: [
|
|
27
30
|
'client',
|
|
28
31
|
{
|
|
@@ -34,13 +37,19 @@ export function useSeamClient(): {
|
|
|
34
37
|
},
|
|
35
38
|
],
|
|
36
39
|
queryFn: async () => {
|
|
37
|
-
if (client != null)
|
|
40
|
+
if (client != null)
|
|
41
|
+
return [client, SeamHttpEndpoints.fromClient(client.client)]
|
|
38
42
|
|
|
39
43
|
if (clientSessionToken != null) {
|
|
40
|
-
|
|
44
|
+
const clientSessionTokenClient = SeamHttp.fromClientSessionToken(
|
|
41
45
|
clientSessionToken,
|
|
42
46
|
clientOptions
|
|
43
47
|
)
|
|
48
|
+
|
|
49
|
+
return [
|
|
50
|
+
clientSessionTokenClient,
|
|
51
|
+
SeamHttpEndpoints.fromClient(clientSessionTokenClient.client),
|
|
52
|
+
]
|
|
44
53
|
}
|
|
45
54
|
|
|
46
55
|
if (publishableKey == null) {
|
|
@@ -49,15 +58,25 @@ export function useSeamClient(): {
|
|
|
49
58
|
)
|
|
50
59
|
}
|
|
51
60
|
|
|
52
|
-
|
|
61
|
+
const publishableKeyClient = await SeamHttp.fromPublishableKey(
|
|
53
62
|
publishableKey,
|
|
54
63
|
userIdentifierKey,
|
|
55
64
|
clientOptions
|
|
56
65
|
)
|
|
66
|
+
return [
|
|
67
|
+
publishableKeyClient,
|
|
68
|
+
SeamHttpEndpoints.fromClient(publishableKeyClient.client),
|
|
69
|
+
]
|
|
57
70
|
},
|
|
58
71
|
})
|
|
59
72
|
|
|
60
|
-
return {
|
|
73
|
+
return {
|
|
74
|
+
client: data?.[0] ?? null,
|
|
75
|
+
endpointClient: data?.[1] ?? null,
|
|
76
|
+
isPending,
|
|
77
|
+
isError,
|
|
78
|
+
error,
|
|
79
|
+
}
|
|
61
80
|
}
|
|
62
81
|
|
|
63
82
|
export class NullSeamClientError extends Error {
|
|
@@ -65,7 +84,7 @@ export class NullSeamClientError extends Error {
|
|
|
65
84
|
super(
|
|
66
85
|
[
|
|
67
86
|
'Attempted to use a null Seam client.',
|
|
68
|
-
'Either a hook using useSeamClient was called outside of a SeamProvider,',
|
|
87
|
+
'Either a hook using useSeamClient was called outside of a SeamProvider or SeamQueryProvider,',
|
|
69
88
|
'or there was an error when creating the Seam client in useSeamClient,',
|
|
70
89
|
'or useSeamClient is still loading the client.',
|
|
71
90
|
].join(' ')
|
|
@@ -81,7 +100,7 @@ function useUserIdentifierKeyOrFingerprint(
|
|
|
81
100
|
useEffect(() => {
|
|
82
101
|
if (userIdentifierKey != null) return
|
|
83
102
|
// eslint-disable-next-line no-console
|
|
84
|
-
console.warn(`Using an automatically generated fingerprint for the
|
|
103
|
+
console.warn(`Using an automatically generated fingerprint for the Seam userIdentifierKey!
|
|
85
104
|
The user interface will show warnings when using a fingerprint.
|
|
86
105
|
This is not recommended because the client session is now bound to this machine and is effectively ephemeral.`)
|
|
87
106
|
}, [userIdentifierKey])
|