@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.
Files changed (75) hide show
  1. package/README.md +17 -2
  2. package/dist/elements.js +22049 -18031
  3. package/dist/elements.js.map +1 -1
  4. package/lib/index.d.ts +1 -0
  5. package/lib/index.js +1 -0
  6. package/lib/index.js.map +1 -1
  7. package/lib/seam/SeamProvider.d.ts +7 -16
  8. package/lib/seam/SeamProvider.js +12 -101
  9. package/lib/seam/SeamProvider.js.map +1 -1
  10. package/lib/seam/SeamQueryProvider.d.ts +32 -0
  11. package/lib/seam/SeamQueryProvider.js +127 -0
  12. package/lib/seam/SeamQueryProvider.js.map +1 -0
  13. package/lib/seam/access-codes/use-access-code.d.ts +2 -2
  14. package/lib/seam/access-codes/use-access-codes.d.ts +2 -2
  15. package/lib/seam/access-codes/use-create-access-code.d.ts +2 -7
  16. package/lib/seam/access-codes/use-create-access-code.js +3 -9
  17. package/lib/seam/access-codes/use-create-access-code.js.map +1 -1
  18. package/lib/seam/access-codes/use-generate-access-code-code.d.ts +2 -2
  19. package/lib/seam/client-sessions/use-client-session.d.ts +2 -2
  20. package/lib/seam/components/SupportedDeviceTable/use-device-model.d.ts +2 -2
  21. package/lib/seam/components/SupportedDeviceTable/use-device-models.d.ts +2 -2
  22. package/lib/seam/components/SupportedDeviceTable/use-manufacturer.d.ts +2 -2
  23. package/lib/seam/components/SupportedDeviceTable/use-manufacturers.d.ts +2 -2
  24. package/lib/seam/connected-accounts/use-connected-account.d.ts +2 -2
  25. package/lib/seam/devices/use-device-providers.d.ts +2 -2
  26. package/lib/seam/devices/use-device.d.ts +2 -2
  27. package/lib/seam/devices/use-devices.d.ts +2 -2
  28. package/lib/seam/events/use-events.d.ts +2 -2
  29. package/lib/seam/index.d.ts +2 -0
  30. package/lib/seam/index.js +2 -0
  31. package/lib/seam/index.js.map +1 -1
  32. package/lib/seam/noise-sensors/use-noise-thresholds.d.ts +2 -2
  33. package/lib/seam/thermostats/use-delete-thermostat-climate-preset.d.ts +2 -2
  34. package/lib/seam/use-seam-client.d.ts +2 -1
  35. package/lib/seam/use-seam-client.js +23 -9
  36. package/lib/seam/use-seam-client.js.map +1 -1
  37. package/lib/seam/use-seam-mutation.d.ts +8 -0
  38. package/lib/seam/use-seam-mutation.js +17 -0
  39. package/lib/seam/use-seam-mutation.js.map +1 -0
  40. package/lib/seam/use-seam-query-result.d.ts +1 -1
  41. package/lib/seam/use-seam-query.d.ts +8 -0
  42. package/lib/seam/use-seam-query.js +19 -0
  43. package/lib/seam/use-seam-query.js.map +1 -0
  44. package/lib/telemetry/hooks.js +2 -2
  45. package/lib/telemetry/hooks.js.map +1 -1
  46. package/lib/ui/DateTimePicker/DateTimePicker.d.ts +1 -1
  47. package/lib/version.d.ts +1 -1
  48. package/lib/version.js +1 -1
  49. package/package.json +3 -2
  50. package/src/lib/index.ts +1 -0
  51. package/src/lib/seam/SeamProvider.tsx +28 -183
  52. package/src/lib/seam/SeamQueryProvider.tsx +248 -0
  53. package/src/lib/seam/access-codes/use-access-code.ts +2 -2
  54. package/src/lib/seam/access-codes/use-access-codes.ts +2 -2
  55. package/src/lib/seam/access-codes/use-create-access-code.ts +7 -32
  56. package/src/lib/seam/access-codes/use-generate-access-code-code.ts +2 -2
  57. package/src/lib/seam/client-sessions/use-client-session.ts +2 -2
  58. package/src/lib/seam/components/SupportedDeviceTable/use-device-model.ts +2 -2
  59. package/src/lib/seam/components/SupportedDeviceTable/use-device-models.ts +2 -2
  60. package/src/lib/seam/components/SupportedDeviceTable/use-manufacturer.ts +2 -2
  61. package/src/lib/seam/components/SupportedDeviceTable/use-manufacturers.ts +2 -2
  62. package/src/lib/seam/connected-accounts/use-connected-account.ts +2 -2
  63. package/src/lib/seam/devices/use-device-providers.ts +2 -2
  64. package/src/lib/seam/devices/use-device.ts +2 -2
  65. package/src/lib/seam/devices/use-devices.ts +2 -2
  66. package/src/lib/seam/events/use-events.ts +2 -2
  67. package/src/lib/seam/index.ts +2 -0
  68. package/src/lib/seam/noise-sensors/use-noise-thresholds.ts +2 -2
  69. package/src/lib/seam/thermostats/use-delete-thermostat-climate-preset.ts +2 -2
  70. package/src/lib/seam/use-seam-client.ts +29 -10
  71. package/src/lib/seam/use-seam-mutation.ts +50 -0
  72. package/src/lib/seam/use-seam-query-result.ts +6 -4
  73. package/src/lib/seam/use-seam-query.ts +45 -0
  74. package/src/lib/telemetry/hooks.ts +2 -2
  75. package/src/lib/version.ts +1 -1
@@ -0,0 +1,50 @@
1
+ import type {
2
+ SeamHttpApiError,
3
+ SeamHttpEndpointMutationPaths,
4
+ SeamHttpEndpoints,
5
+ } from '@seamapi/http/connect'
6
+ import {
7
+ useMutation,
8
+ type UseMutationOptions,
9
+ type UseMutationResult,
10
+ } from '@tanstack/react-query'
11
+
12
+ import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
13
+
14
+ export type UseSeamMutationVariables<T extends SeamHttpEndpointMutationPaths> =
15
+ Parameters<SeamHttpEndpoints[T]>[0]
16
+
17
+ export type UseSeamMutationResult<T extends SeamHttpEndpointMutationPaths> =
18
+ UseMutationResult<
19
+ MutationData<T>,
20
+ SeamHttpApiError,
21
+ UseSeamMutationVariables<T>
22
+ >
23
+
24
+ export function useSeamMutation<T extends SeamHttpEndpointMutationPaths>(
25
+ endpointPath: T,
26
+ options: Parameters<SeamHttpEndpoints[T]>[1] &
27
+ MutationOptions<
28
+ MutationData<T>,
29
+ SeamHttpApiError,
30
+ UseSeamMutationVariables<T>
31
+ > = {}
32
+ ): UseSeamMutationResult<T> {
33
+ const { endpointClient: client } = useSeamClient()
34
+ return useMutation({
35
+ ...options,
36
+ mutationFn: async (variables) => {
37
+ if (client === null) throw new NullSeamClientError()
38
+ // Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
39
+ // Type assertion is needed here for performance reasons. The types are correct at runtime.
40
+ const endpoint = client[endpointPath] as (...args: any) => Promise<any>
41
+ return await endpoint(variables, options)
42
+ },
43
+ })
44
+ }
45
+
46
+ type MutationData<T extends SeamHttpEndpointMutationPaths> = Awaited<
47
+ ReturnType<SeamHttpEndpoints[T]>
48
+ >
49
+
50
+ type MutationOptions<X, Y, Z> = Omit<UseMutationOptions<X, Y, Z>, 'mutationFn'>
@@ -1,7 +1,9 @@
1
1
  import type { SeamHttpApiError } from '@seamapi/http/connect'
2
2
  import type { UseQueryResult } from '@tanstack/react-query'
3
3
 
4
- export type UseSeamQueryResult<Field extends string, ResponsePayload> = Omit<
5
- UseQueryResult<ResponsePayload, SeamHttpApiError>,
6
- 'data'
7
- > & { [key in Field]?: ResponsePayload }
4
+ export type UseSeamQueryResultLegacy<
5
+ Field extends string,
6
+ ResponsePayload,
7
+ > = Omit<UseQueryResult<ResponsePayload, SeamHttpApiError>, 'data'> & {
8
+ [key in Field]?: ResponsePayload
9
+ }
@@ -0,0 +1,45 @@
1
+ import type {
2
+ SeamHttpApiError,
3
+ SeamHttpEndpointQueryPaths,
4
+ SeamHttpEndpoints,
5
+ } from '@seamapi/http/connect'
6
+ import {
7
+ useQuery,
8
+ type UseQueryOptions,
9
+ type UseQueryResult,
10
+ } from '@tanstack/react-query'
11
+
12
+ import { useSeamClient } from 'lib/seam/use-seam-client.js'
13
+
14
+ export type UseSeamQueryParameters<T extends SeamHttpEndpointQueryPaths> =
15
+ Parameters<SeamHttpEndpoints[T]>[0]
16
+
17
+ export type UseSeamQueryResult<T extends SeamHttpEndpointQueryPaths> =
18
+ UseQueryResult<QueryData<T>, SeamHttpApiError>
19
+
20
+ export function useSeamQuery<T extends SeamHttpEndpointQueryPaths>(
21
+ endpointPath: T,
22
+ parameters?: UseSeamQueryParameters<T>,
23
+ options: Parameters<SeamHttpEndpoints[T]>[1] &
24
+ QueryOptions<QueryData<T>, SeamHttpApiError> = {}
25
+ ): UseSeamQueryResult<T> {
26
+ const { endpointClient: client } = useSeamClient()
27
+ return useQuery({
28
+ enabled: client != null,
29
+ ...options,
30
+ queryKey: [endpointPath, parameters],
31
+ queryFn: async () => {
32
+ if (client == null) return null
33
+ // Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
34
+ // Type assertion is needed here for performance reasons. The types are correct at runtime.
35
+ const endpoint = client[endpointPath] as (...args: any) => Promise<any>
36
+ return await endpoint(parameters, options)
37
+ },
38
+ })
39
+ }
40
+
41
+ type QueryData<T extends SeamHttpEndpointQueryPaths> = Awaited<
42
+ ReturnType<SeamHttpEndpoints[T]>
43
+ >
44
+
45
+ type QueryOptions<X, Y> = Omit<UseQueryOptions<X, Y>, 'queryKey' | 'queryFn'>
@@ -1,7 +1,7 @@
1
1
  import { useEffect, useLayoutEffect } from 'react'
2
2
 
3
3
  import { useClientSession } from 'lib/seam/client-sessions/use-client-session.js'
4
- import { useSeamContext } from 'lib/seam/SeamProvider.js'
4
+ import { useSeamQueryContext } from 'lib/seam/SeamQueryProvider.js'
5
5
 
6
6
  import type { TelemetryClient } from './client.js'
7
7
  import { useTelemetryContext } from './TelemetryProvider.js'
@@ -23,7 +23,7 @@ export function useComponentTelemetry(name: string): void {
23
23
 
24
24
  export function useUserTelemetry(): void {
25
25
  const telemetry = useTelemetryClient()
26
- const { publishableKey } = useSeamContext()
26
+ const { publishableKey } = useSeamQueryContext()
27
27
  const { clientSession } = useClientSession()
28
28
 
29
29
  // Ensure identify runs earlier than other effects to avoid anonymous telemetry data.
@@ -1,3 +1,3 @@
1
- const seamapiReactVersion = '4.8.2'
1
+ const seamapiReactVersion = '4.9.0'
2
2
 
3
3
  export default seamapiReactVersion