@seamapi/react 4.12.1 → 4.13.1

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 (160) hide show
  1. package/README.md +2 -17
  2. package/dist/elements.js +9445 -9053
  3. package/dist/elements.js.map +1 -1
  4. package/dist/index.css +1 -0
  5. package/dist/index.css.map +1 -1
  6. package/dist/index.min.css +1 -1
  7. package/dist/index.min.css.map +1 -1
  8. package/index.d.ts +1 -0
  9. package/index.js +1 -0
  10. package/index.js.map +1 -1
  11. package/lib/index.d.ts +0 -1
  12. package/lib/index.js +0 -1
  13. package/lib/index.js.map +1 -1
  14. package/lib/seam/SeamProvider.d.ts +1 -1
  15. package/lib/seam/SeamProvider.js +1 -1
  16. package/lib/seam/SeamProvider.js.map +1 -1
  17. package/lib/seam/access-codes/use-access-code.js +1 -1
  18. package/lib/seam/access-codes/use-access-code.js.map +1 -1
  19. package/lib/seam/access-codes/use-access-codes.js +1 -1
  20. package/lib/seam/access-codes/use-access-codes.js.map +1 -1
  21. package/lib/seam/access-codes/use-create-access-code.d.ts +1 -1
  22. package/lib/seam/access-codes/use-create-access-code.js +1 -1
  23. package/lib/seam/access-codes/use-create-access-code.js.map +1 -1
  24. package/lib/seam/access-codes/use-delete-access-code.js +1 -1
  25. package/lib/seam/access-codes/use-delete-access-code.js.map +1 -1
  26. package/lib/seam/access-codes/use-generate-access-code-code.js +1 -1
  27. package/lib/seam/access-codes/use-generate-access-code-code.js.map +1 -1
  28. package/lib/seam/access-codes/use-update-access-code.js +1 -1
  29. package/lib/seam/access-codes/use-update-access-code.js.map +1 -1
  30. package/lib/seam/client-sessions/use-client-session.js +1 -1
  31. package/lib/seam/client-sessions/use-client-session.js.map +1 -1
  32. package/lib/seam/components/DeviceDetails/LockDeviceDetails.js +2 -23
  33. package/lib/seam/components/DeviceDetails/LockDeviceDetails.js.map +1 -1
  34. package/lib/seam/components/DeviceDetails/LockDeviceLockButtons.d.ts +11 -0
  35. package/lib/seam/components/DeviceDetails/LockDeviceLockButtons.js +68 -0
  36. package/lib/seam/components/DeviceDetails/LockDeviceLockButtons.js.map +1 -0
  37. package/lib/seam/components/SupportedDeviceTable/use-device-model.js +1 -1
  38. package/lib/seam/components/SupportedDeviceTable/use-device-model.js.map +1 -1
  39. package/lib/seam/components/SupportedDeviceTable/use-device-models.js +1 -1
  40. package/lib/seam/components/SupportedDeviceTable/use-device-models.js.map +1 -1
  41. package/lib/seam/components/SupportedDeviceTable/use-manufacturer.js +1 -1
  42. package/lib/seam/components/SupportedDeviceTable/use-manufacturer.js.map +1 -1
  43. package/lib/seam/components/SupportedDeviceTable/use-manufacturers.js +1 -1
  44. package/lib/seam/components/SupportedDeviceTable/use-manufacturers.js.map +1 -1
  45. package/lib/seam/connect-webviews/use-create-connect-webview.js +1 -1
  46. package/lib/seam/connect-webviews/use-create-connect-webview.js.map +1 -1
  47. package/lib/seam/connected-accounts/use-connected-account.js +1 -1
  48. package/lib/seam/connected-accounts/use-connected-account.js.map +1 -1
  49. package/lib/seam/devices/use-device-providers.js +1 -1
  50. package/lib/seam/devices/use-device-providers.js.map +1 -1
  51. package/lib/seam/devices/use-device.js +1 -1
  52. package/lib/seam/devices/use-device.js.map +1 -1
  53. package/lib/seam/devices/use-devices.js +1 -1
  54. package/lib/seam/devices/use-devices.js.map +1 -1
  55. package/lib/seam/devices/use-update-device-name.js +1 -1
  56. package/lib/seam/devices/use-update-device-name.js.map +1 -1
  57. package/lib/seam/events/use-events.js +1 -1
  58. package/lib/seam/events/use-events.js.map +1 -1
  59. package/lib/seam/index.d.ts +0 -6
  60. package/lib/seam/index.js +0 -6
  61. package/lib/seam/index.js.map +1 -1
  62. package/lib/seam/locks/use-lock-door.d.ts +17 -0
  63. package/lib/seam/locks/use-lock-door.js +60 -0
  64. package/lib/seam/locks/use-lock-door.js.map +1 -0
  65. package/lib/seam/locks/use-toggle-lock.js +1 -1
  66. package/lib/seam/locks/use-toggle-lock.js.map +1 -1
  67. package/lib/seam/locks/use-unlock-door.d.ts +17 -0
  68. package/lib/seam/locks/use-unlock-door.js +60 -0
  69. package/lib/seam/locks/use-unlock-door.js.map +1 -0
  70. package/lib/seam/noise-sensors/use-noise-thresholds.js +1 -1
  71. package/lib/seam/noise-sensors/use-noise-thresholds.js.map +1 -1
  72. package/lib/seam/thermostats/use-cool-thermostat.js +1 -1
  73. package/lib/seam/thermostats/use-cool-thermostat.js.map +1 -1
  74. package/lib/seam/thermostats/use-create-thermostat-climate-preset.js +1 -1
  75. package/lib/seam/thermostats/use-create-thermostat-climate-preset.js.map +1 -1
  76. package/lib/seam/thermostats/use-delete-thermostat-climate-preset.js +1 -1
  77. package/lib/seam/thermostats/use-delete-thermostat-climate-preset.js.map +1 -1
  78. package/lib/seam/thermostats/use-heat-cool-thermostat.js +1 -1
  79. package/lib/seam/thermostats/use-heat-cool-thermostat.js.map +1 -1
  80. package/lib/seam/thermostats/use-heat-thermostat.js +1 -1
  81. package/lib/seam/thermostats/use-heat-thermostat.js.map +1 -1
  82. package/lib/seam/thermostats/use-set-thermostat-fan-mode.js +1 -1
  83. package/lib/seam/thermostats/use-set-thermostat-fan-mode.js.map +1 -1
  84. package/lib/seam/thermostats/use-set-thermostat-off.js +1 -1
  85. package/lib/seam/thermostats/use-set-thermostat-off.js.map +1 -1
  86. package/lib/seam/thermostats/use-update-thermostat-climate-preset.js +1 -1
  87. package/lib/seam/thermostats/use-update-thermostat-climate-preset.js.map +1 -1
  88. package/lib/telemetry/hooks.js +1 -1
  89. package/lib/telemetry/hooks.js.map +1 -1
  90. package/lib/ui/DateTimePicker/DateTimePicker.d.ts +1 -1
  91. package/lib/version.d.ts +1 -1
  92. package/lib/version.js +1 -1
  93. package/package.json +5 -5
  94. package/src/index.ts +1 -0
  95. package/src/lib/index.ts +0 -1
  96. package/src/lib/seam/SeamProvider.tsx +4 -4
  97. package/src/lib/seam/access-codes/use-access-code.ts +1 -1
  98. package/src/lib/seam/access-codes/use-access-codes.ts +1 -1
  99. package/src/lib/seam/access-codes/use-create-access-code.ts +2 -3
  100. package/src/lib/seam/access-codes/use-delete-access-code.ts +1 -2
  101. package/src/lib/seam/access-codes/use-generate-access-code-code.ts +1 -2
  102. package/src/lib/seam/access-codes/use-update-access-code.ts +1 -2
  103. package/src/lib/seam/client-sessions/use-client-session.ts +1 -1
  104. package/src/lib/seam/components/DeviceDetails/LockDeviceDetails.tsx +7 -43
  105. package/src/lib/seam/components/DeviceDetails/LockDeviceLockButtons.tsx +137 -0
  106. package/src/lib/seam/components/SupportedDeviceTable/use-device-model.ts +1 -1
  107. package/src/lib/seam/components/SupportedDeviceTable/use-device-models.ts +1 -1
  108. package/src/lib/seam/components/SupportedDeviceTable/use-manufacturer.ts +1 -1
  109. package/src/lib/seam/components/SupportedDeviceTable/use-manufacturers.ts +1 -1
  110. package/src/lib/seam/connect-webviews/use-create-connect-webview.ts +1 -1
  111. package/src/lib/seam/connected-accounts/use-connected-account.ts +1 -1
  112. package/src/lib/seam/devices/use-device-providers.ts +1 -1
  113. package/src/lib/seam/devices/use-device.ts +1 -1
  114. package/src/lib/seam/devices/use-devices.ts +1 -1
  115. package/src/lib/seam/devices/use-update-device-name.ts +1 -2
  116. package/src/lib/seam/events/use-events.ts +1 -1
  117. package/src/lib/seam/index.ts +0 -6
  118. package/src/lib/seam/locks/use-lock-door.ts +101 -0
  119. package/src/lib/seam/locks/use-toggle-lock.ts +1 -2
  120. package/src/lib/seam/locks/use-unlock-door.ts +104 -0
  121. package/src/lib/seam/noise-sensors/use-noise-thresholds.ts +1 -1
  122. package/src/lib/seam/thermostats/use-cool-thermostat.ts +1 -1
  123. package/src/lib/seam/thermostats/use-create-thermostat-climate-preset.ts +1 -1
  124. package/src/lib/seam/thermostats/use-delete-thermostat-climate-preset.ts +1 -1
  125. package/src/lib/seam/thermostats/use-heat-cool-thermostat.ts +1 -1
  126. package/src/lib/seam/thermostats/use-heat-thermostat.ts +1 -1
  127. package/src/lib/seam/thermostats/use-set-thermostat-fan-mode.ts +1 -2
  128. package/src/lib/seam/thermostats/use-set-thermostat-off.ts +1 -2
  129. package/src/lib/seam/thermostats/use-update-thermostat-climate-preset.ts +1 -1
  130. package/src/lib/telemetry/hooks.ts +1 -1
  131. package/src/lib/version.ts +1 -1
  132. package/src/styles/_device-details.scss +1 -0
  133. package/lib/seam/SeamQueryProvider.d.ts +0 -40
  134. package/lib/seam/SeamQueryProvider.js +0 -180
  135. package/lib/seam/SeamQueryProvider.js.map +0 -1
  136. package/lib/seam/use-seam-client.d.ts +0 -14
  137. package/lib/seam/use-seam-client.js +0 -134
  138. package/lib/seam/use-seam-client.js.map +0 -1
  139. package/lib/seam/use-seam-infinite-query.d.ts +0 -15
  140. package/lib/seam/use-seam-infinite-query.js +0 -47
  141. package/lib/seam/use-seam-infinite-query.js.map +0 -1
  142. package/lib/seam/use-seam-mutation-without-workspace.d.ts +0 -9
  143. package/lib/seam/use-seam-mutation-without-workspace.js +0 -17
  144. package/lib/seam/use-seam-mutation-without-workspace.js.map +0 -1
  145. package/lib/seam/use-seam-mutation.d.ts +0 -10
  146. package/lib/seam/use-seam-mutation.js +0 -17
  147. package/lib/seam/use-seam-mutation.js.map +0 -1
  148. package/lib/seam/use-seam-query-without-workspace.d.ts +0 -11
  149. package/lib/seam/use-seam-query-without-workspace.js +0 -25
  150. package/lib/seam/use-seam-query-without-workspace.js.map +0 -1
  151. package/lib/seam/use-seam-query.d.ts +0 -12
  152. package/lib/seam/use-seam-query.js +0 -25
  153. package/lib/seam/use-seam-query.js.map +0 -1
  154. package/src/lib/seam/SeamQueryProvider.tsx +0 -356
  155. package/src/lib/seam/use-seam-client.ts +0 -225
  156. package/src/lib/seam/use-seam-infinite-query.ts +0 -103
  157. package/src/lib/seam/use-seam-mutation-without-workspace.ts +0 -56
  158. package/src/lib/seam/use-seam-mutation.ts +0 -64
  159. package/src/lib/seam/use-seam-query-without-workspace.ts +0 -59
  160. package/src/lib/seam/use-seam-query.ts +0 -66
@@ -1,103 +0,0 @@
1
- import type {
2
- SeamActionAttemptFailedError,
3
- SeamActionAttemptTimeoutError,
4
- SeamHttpApiError,
5
- SeamHttpEndpointPaginatedQueryPaths,
6
- SeamHttpEndpoints,
7
- SeamHttpInvalidInputError,
8
- SeamHttpRequest,
9
- SeamPageCursor,
10
- } from '@seamapi/http/connect'
11
- import type { ActionAttempt } from '@seamapi/types/connect'
12
- import {
13
- type QueryKey,
14
- useInfiniteQuery,
15
- type UseInfiniteQueryOptions,
16
- type UseInfiniteQueryResult,
17
- } from '@tanstack/react-query'
18
-
19
- import { useSeamClient } from 'lib/seam/use-seam-client.js'
20
-
21
- export type UseSeamInfiniteQueryParameters<
22
- T extends SeamHttpEndpointPaginatedQueryPaths,
23
- > = Parameters<SeamHttpEndpoints[T]>[0]
24
-
25
- export type UseSeamInfiniteQueryResult<
26
- T extends SeamHttpEndpointPaginatedQueryPaths,
27
- > = UseInfiniteQueryResult<QueryData<T>, QueryError<T>>
28
-
29
- export function useSeamInfiniteQuery<
30
- T extends SeamHttpEndpointPaginatedQueryPaths,
31
- >(
32
- endpointPath: T,
33
- parameters: UseSeamInfiniteQueryParameters<T> = {},
34
- options: Parameters<SeamHttpEndpoints[T]>[1] &
35
- QueryOptions<QueryData<T>, QueryError<T>> = {}
36
- ): UseSeamInfiniteQueryResult<T> & { queryKey: QueryKey } {
37
- const { endpointClient: client, queryKeyPrefixes } = useSeamClient()
38
-
39
- if ('page_cursor' in (parameters ?? {})) {
40
- throw new Error('Cannot use page_cursor with useSeamInfiniteQuery')
41
- }
42
-
43
- const queryKey = [
44
- ...queryKeyPrefixes,
45
- ...endpointPath.split('/').filter((v) => v !== ''),
46
- parameters ?? {},
47
- ]
48
- const result = useInfiniteQuery({
49
- enabled: client != null,
50
- ...options,
51
- queryKey,
52
- initialPageParam: null,
53
- getNextPageParam: (lastPage) => lastPage.nextPageCursor,
54
- queryFn: async ({ pageParam }) => {
55
- if (client == null)
56
- return {
57
- data: [] as Awaited<ReturnType<SeamHttpEndpoints[T]>>,
58
- nextPageCursor: null,
59
- }
60
- // Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
61
- // Type assertion is needed here for performance reasons. The types are correct at runtime.
62
- const endpoint = client[endpointPath] as (...args: any) => any
63
- const request = endpoint(parameters, options)
64
- const pages = client.createPaginator(request as SeamHttpRequest<any, any>)
65
- if (pageParam == null) {
66
- const [data, { nextPageCursor }] = await pages.firstPage()
67
- return {
68
- data: data as Awaited<ReturnType<SeamHttpEndpoints[T]>>,
69
- nextPageCursor,
70
- }
71
- }
72
- // Type assertion is needed for pageParam since the Seam API expects a branded PageCursor type.
73
- const [data, { nextPageCursor }] = await pages.nextPage(
74
- pageParam as SeamPageCursor
75
- )
76
- return {
77
- data: data as Awaited<ReturnType<SeamHttpEndpoints[T]>>,
78
- nextPageCursor,
79
- }
80
- },
81
- })
82
- return { ...result, queryKey }
83
- }
84
-
85
- interface QueryData<T extends SeamHttpEndpointPaginatedQueryPaths> {
86
- data: Awaited<ReturnType<SeamHttpEndpoints[T]>>
87
- nextPageCursor: SeamPageCursor | null
88
- }
89
-
90
- type QueryError<T extends SeamHttpEndpointPaginatedQueryPaths> =
91
- | Error
92
- | SeamHttpApiError
93
- | SeamHttpInvalidInputError
94
- | (QueryData<T>['data'] extends ActionAttempt
95
- ?
96
- | SeamActionAttemptFailedError<QueryData<T>['data']>
97
- | SeamActionAttemptTimeoutError<QueryData<T>['data']>
98
- : never)
99
-
100
- type QueryOptions<X, Y> = Omit<
101
- UseInfiniteQueryOptions<X, Y>,
102
- 'queryKey' | 'queryFn' | 'initialPageParam' | 'getNextPageParam'
103
- >
@@ -1,56 +0,0 @@
1
- import type {
2
- SeamHttpApiError,
3
- SeamHttpEndpointsWithoutWorkspace,
4
- SeamHttpEndpointWithoutWorkspaceMutationPaths,
5
- SeamHttpInvalidInputError,
6
- } from '@seamapi/http/connect'
7
- import {
8
- useMutation,
9
- type UseMutationOptions,
10
- type UseMutationResult,
11
- } from '@tanstack/react-query'
12
-
13
- import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
14
-
15
- export type UseSeamMutationWithoutWorkspaceVariables<
16
- T extends SeamHttpEndpointWithoutWorkspaceMutationPaths,
17
- > = Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[0]
18
-
19
- export type UseSeamMutationWithoutWorkspaceResult<
20
- T extends SeamHttpEndpointWithoutWorkspaceMutationPaths,
21
- > = UseMutationResult<
22
- MutationData<T>,
23
- MutationError,
24
- UseSeamMutationWithoutWorkspaceVariables<T>
25
- >
26
-
27
- export function useSeamMutationWithoutWorkspace<
28
- T extends SeamHttpEndpointWithoutWorkspaceMutationPaths,
29
- >(
30
- endpointPath: T,
31
- options: Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[1] &
32
- MutationOptions<
33
- MutationData<T>,
34
- MutationError,
35
- UseSeamMutationWithoutWorkspaceVariables<T>
36
- > = {}
37
- ): UseSeamMutationWithoutWorkspaceResult<T> {
38
- const { endpointClient: client } = useSeamClient()
39
- return useMutation({
40
- ...options,
41
- mutationFn: async (variables) => {
42
- if (client === null) throw new NullSeamClientError()
43
- // Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
44
- // Type assertion is needed here for performance reasons. The types are correct at runtime.
45
- const endpoint = client[endpointPath] as (...args: any) => Promise<any>
46
- return await endpoint(variables, options)
47
- },
48
- })
49
- }
50
-
51
- type MutationData<T extends SeamHttpEndpointWithoutWorkspaceMutationPaths> =
52
- Awaited<ReturnType<SeamHttpEndpointsWithoutWorkspace[T]>>
53
-
54
- type MutationError = Error | SeamHttpApiError | SeamHttpInvalidInputError
55
-
56
- type MutationOptions<X, Y, Z> = Omit<UseMutationOptions<X, Y, Z>, 'mutationFn'>
@@ -1,64 +0,0 @@
1
- import type {
2
- SeamActionAttemptFailedError,
3
- SeamActionAttemptTimeoutError,
4
- SeamHttpApiError,
5
- SeamHttpEndpointMutationPaths,
6
- SeamHttpEndpoints,
7
- SeamHttpInvalidInputError,
8
- } from '@seamapi/http/connect'
9
- import type { ActionAttempt } from '@seamapi/types/connect'
10
- import {
11
- useMutation,
12
- type UseMutationOptions,
13
- type UseMutationResult,
14
- } from '@tanstack/react-query'
15
-
16
- import { NullSeamClientError, useSeamClient } from 'lib/seam/use-seam-client.js'
17
-
18
- export type UseSeamMutationVariables<T extends SeamHttpEndpointMutationPaths> =
19
- Parameters<SeamHttpEndpoints[T]>[0]
20
-
21
- export type UseSeamMutationResult<T extends SeamHttpEndpointMutationPaths> =
22
- UseMutationResult<
23
- MutationData<T>,
24
- MutationError<T>,
25
- UseSeamMutationVariables<T>
26
- >
27
-
28
- export function useSeamMutation<T extends SeamHttpEndpointMutationPaths>(
29
- endpointPath: T,
30
- options: Parameters<SeamHttpEndpoints[T]>[1] &
31
- MutationOptions<
32
- MutationData<T>,
33
- MutationError<T>,
34
- UseSeamMutationVariables<T>
35
- > = {}
36
- ): UseSeamMutationResult<T> {
37
- const { endpointClient: client } = useSeamClient()
38
- return useMutation({
39
- ...options,
40
- mutationFn: async (variables) => {
41
- if (client === null) throw new NullSeamClientError()
42
- // Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
43
- // Type assertion is needed here for performance reasons. The types are correct at runtime.
44
- const endpoint = client[endpointPath] as (...args: any) => Promise<any>
45
- return await endpoint(variables, options)
46
- },
47
- })
48
- }
49
-
50
- type MutationData<T extends SeamHttpEndpointMutationPaths> = Awaited<
51
- ReturnType<SeamHttpEndpoints[T]>
52
- >
53
-
54
- type MutationError<T extends SeamHttpEndpointMutationPaths> =
55
- | Error
56
- | SeamHttpApiError
57
- | SeamHttpInvalidInputError
58
- | (MutationData<T> extends ActionAttempt
59
- ?
60
- | SeamActionAttemptFailedError<MutationData<T>>
61
- | SeamActionAttemptTimeoutError<MutationData<T>>
62
- : never)
63
-
64
- type MutationOptions<X, Y, Z> = Omit<UseMutationOptions<X, Y, Z>, 'mutationFn'>
@@ -1,59 +0,0 @@
1
- import type {
2
- SeamHttpApiError,
3
- SeamHttpEndpointsWithoutWorkspace,
4
- SeamHttpEndpointWithoutWorkspaceQueryPaths,
5
- SeamHttpInvalidInputError,
6
- } from '@seamapi/http/connect'
7
- import {
8
- type QueryKey,
9
- useQuery,
10
- type UseQueryOptions,
11
- type UseQueryResult,
12
- } from '@tanstack/react-query'
13
-
14
- import { useSeamClient } from 'lib/seam/use-seam-client.js'
15
-
16
- export type UseSeamQueryWithoutWorkspaceParameters<
17
- T extends SeamHttpEndpointWithoutWorkspaceQueryPaths,
18
- > = Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[0]
19
-
20
- export type UseSeamQueryWithoutWorkspaceResult<
21
- T extends SeamHttpEndpointWithoutWorkspaceQueryPaths,
22
- > = UseQueryResult<QueryData<T>, QueryError>
23
-
24
- export function useSeamQueryWithoutWorkspace<
25
- T extends SeamHttpEndpointWithoutWorkspaceQueryPaths,
26
- >(
27
- endpointPath: T,
28
- parameters: UseSeamQueryWithoutWorkspaceParameters<T> = {},
29
- options: Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[1] &
30
- QueryOptions<QueryData<T>, QueryError> = {}
31
- ): UseSeamQueryWithoutWorkspaceResult<T> & { queryKey: QueryKey } {
32
- const { endpointClient: client, queryKeyPrefixes } = useSeamClient()
33
- const queryKey = [
34
- ...queryKeyPrefixes,
35
- ...endpointPath.split('/').filter((v) => v !== ''),
36
- parameters ?? {},
37
- ]
38
- const result = useQuery({
39
- enabled: client != null,
40
- ...options,
41
- queryKey,
42
- queryFn: async () => {
43
- if (client == null) return null
44
- // Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
45
- // Type assertion is needed here for performance reasons. The types are correct at runtime.
46
- const endpoint = client[endpointPath] as (...args: any) => Promise<any>
47
- return await endpoint(parameters, options)
48
- },
49
- })
50
- return { ...result, queryKey }
51
- }
52
-
53
- type QueryData<T extends SeamHttpEndpointWithoutWorkspaceQueryPaths> = Awaited<
54
- ReturnType<SeamHttpEndpointsWithoutWorkspace[T]>
55
- >
56
-
57
- type QueryError = Error | SeamHttpApiError | SeamHttpInvalidInputError
58
-
59
- type QueryOptions<X, Y> = Omit<UseQueryOptions<X, Y>, 'queryKey' | 'queryFn'>
@@ -1,66 +0,0 @@
1
- import type {
2
- SeamActionAttemptFailedError,
3
- SeamActionAttemptTimeoutError,
4
- SeamHttpApiError,
5
- SeamHttpEndpointQueryPaths,
6
- SeamHttpEndpoints,
7
- SeamHttpInvalidInputError,
8
- } from '@seamapi/http/connect'
9
- import type { ActionAttempt } from '@seamapi/types/connect'
10
- import {
11
- type QueryKey,
12
- useQuery,
13
- type UseQueryOptions,
14
- type UseQueryResult,
15
- } from '@tanstack/react-query'
16
-
17
- import { useSeamClient } from 'lib/seam/use-seam-client.js'
18
-
19
- export type UseSeamQueryParameters<T extends SeamHttpEndpointQueryPaths> =
20
- Parameters<SeamHttpEndpoints[T]>[0]
21
-
22
- export type UseSeamQueryResult<T extends SeamHttpEndpointQueryPaths> =
23
- UseQueryResult<QueryData<T>, QueryError<T>>
24
-
25
- export function useSeamQuery<T extends SeamHttpEndpointQueryPaths>(
26
- endpointPath: T,
27
- parameters: UseSeamQueryParameters<T> = {},
28
- options: Parameters<SeamHttpEndpoints[T]>[1] &
29
- QueryOptions<QueryData<T>, SeamHttpApiError> = {}
30
- ): UseSeamQueryResult<T> & { queryKey: QueryKey } {
31
- const { endpointClient: client, queryKeyPrefixes } = useSeamClient()
32
- const queryKey = [
33
- ...queryKeyPrefixes,
34
- ...endpointPath.split('/').filter((v) => v !== ''),
35
- parameters ?? {},
36
- ]
37
- const result = useQuery({
38
- enabled: client != null,
39
- ...options,
40
- queryKey,
41
- queryFn: async () => {
42
- if (client == null) return null
43
- // Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
44
- // Type assertion is needed here for performance reasons. The types are correct at runtime.
45
- const endpoint = client[endpointPath] as (...args: any) => Promise<any>
46
- return await endpoint(parameters, options)
47
- },
48
- })
49
- return { ...result, queryKey }
50
- }
51
-
52
- type QueryData<T extends SeamHttpEndpointQueryPaths> = Awaited<
53
- ReturnType<SeamHttpEndpoints[T]>
54
- >
55
-
56
- type QueryError<T extends SeamHttpEndpointQueryPaths> =
57
- | Error
58
- | SeamHttpApiError
59
- | SeamHttpInvalidInputError
60
- | (QueryData<T> extends ActionAttempt
61
- ?
62
- | SeamActionAttemptFailedError<QueryData<T>>
63
- | SeamActionAttemptTimeoutError<QueryData<T>>
64
- : never)
65
-
66
- type QueryOptions<X, Y> = Omit<UseQueryOptions<X, Y>, 'queryKey' | 'queryFn'>