@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.
- package/README.md +2 -17
- package/dist/elements.js +9445 -9053
- package/dist/elements.js.map +1 -1
- package/dist/index.css +1 -0
- package/dist/index.css.map +1 -1
- package/dist/index.min.css +1 -1
- package/dist/index.min.css.map +1 -1
- package/index.d.ts +1 -0
- package/index.js +1 -0
- package/index.js.map +1 -1
- package/lib/index.d.ts +0 -1
- package/lib/index.js +0 -1
- package/lib/index.js.map +1 -1
- package/lib/seam/SeamProvider.d.ts +1 -1
- package/lib/seam/SeamProvider.js +1 -1
- package/lib/seam/SeamProvider.js.map +1 -1
- package/lib/seam/access-codes/use-access-code.js +1 -1
- package/lib/seam/access-codes/use-access-code.js.map +1 -1
- package/lib/seam/access-codes/use-access-codes.js +1 -1
- package/lib/seam/access-codes/use-access-codes.js.map +1 -1
- package/lib/seam/access-codes/use-create-access-code.d.ts +1 -1
- package/lib/seam/access-codes/use-create-access-code.js +1 -1
- package/lib/seam/access-codes/use-create-access-code.js.map +1 -1
- package/lib/seam/access-codes/use-delete-access-code.js +1 -1
- package/lib/seam/access-codes/use-delete-access-code.js.map +1 -1
- package/lib/seam/access-codes/use-generate-access-code-code.js +1 -1
- package/lib/seam/access-codes/use-generate-access-code-code.js.map +1 -1
- package/lib/seam/access-codes/use-update-access-code.js +1 -1
- package/lib/seam/access-codes/use-update-access-code.js.map +1 -1
- package/lib/seam/client-sessions/use-client-session.js +1 -1
- package/lib/seam/client-sessions/use-client-session.js.map +1 -1
- package/lib/seam/components/DeviceDetails/LockDeviceDetails.js +2 -23
- package/lib/seam/components/DeviceDetails/LockDeviceDetails.js.map +1 -1
- package/lib/seam/components/DeviceDetails/LockDeviceLockButtons.d.ts +11 -0
- package/lib/seam/components/DeviceDetails/LockDeviceLockButtons.js +68 -0
- package/lib/seam/components/DeviceDetails/LockDeviceLockButtons.js.map +1 -0
- package/lib/seam/components/SupportedDeviceTable/use-device-model.js +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-device-model.js.map +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-device-models.js +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-device-models.js.map +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-manufacturer.js +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-manufacturer.js.map +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-manufacturers.js +1 -1
- package/lib/seam/components/SupportedDeviceTable/use-manufacturers.js.map +1 -1
- package/lib/seam/connect-webviews/use-create-connect-webview.js +1 -1
- package/lib/seam/connect-webviews/use-create-connect-webview.js.map +1 -1
- package/lib/seam/connected-accounts/use-connected-account.js +1 -1
- package/lib/seam/connected-accounts/use-connected-account.js.map +1 -1
- package/lib/seam/devices/use-device-providers.js +1 -1
- package/lib/seam/devices/use-device-providers.js.map +1 -1
- package/lib/seam/devices/use-device.js +1 -1
- package/lib/seam/devices/use-device.js.map +1 -1
- package/lib/seam/devices/use-devices.js +1 -1
- package/lib/seam/devices/use-devices.js.map +1 -1
- package/lib/seam/devices/use-update-device-name.js +1 -1
- package/lib/seam/devices/use-update-device-name.js.map +1 -1
- package/lib/seam/events/use-events.js +1 -1
- package/lib/seam/events/use-events.js.map +1 -1
- package/lib/seam/index.d.ts +0 -6
- package/lib/seam/index.js +0 -6
- package/lib/seam/index.js.map +1 -1
- package/lib/seam/locks/use-lock-door.d.ts +17 -0
- package/lib/seam/locks/use-lock-door.js +60 -0
- package/lib/seam/locks/use-lock-door.js.map +1 -0
- package/lib/seam/locks/use-toggle-lock.js +1 -1
- package/lib/seam/locks/use-toggle-lock.js.map +1 -1
- package/lib/seam/locks/use-unlock-door.d.ts +17 -0
- package/lib/seam/locks/use-unlock-door.js +60 -0
- package/lib/seam/locks/use-unlock-door.js.map +1 -0
- package/lib/seam/noise-sensors/use-noise-thresholds.js +1 -1
- package/lib/seam/noise-sensors/use-noise-thresholds.js.map +1 -1
- package/lib/seam/thermostats/use-cool-thermostat.js +1 -1
- package/lib/seam/thermostats/use-cool-thermostat.js.map +1 -1
- package/lib/seam/thermostats/use-create-thermostat-climate-preset.js +1 -1
- package/lib/seam/thermostats/use-create-thermostat-climate-preset.js.map +1 -1
- package/lib/seam/thermostats/use-delete-thermostat-climate-preset.js +1 -1
- package/lib/seam/thermostats/use-delete-thermostat-climate-preset.js.map +1 -1
- package/lib/seam/thermostats/use-heat-cool-thermostat.js +1 -1
- package/lib/seam/thermostats/use-heat-cool-thermostat.js.map +1 -1
- package/lib/seam/thermostats/use-heat-thermostat.js +1 -1
- package/lib/seam/thermostats/use-heat-thermostat.js.map +1 -1
- package/lib/seam/thermostats/use-set-thermostat-fan-mode.js +1 -1
- package/lib/seam/thermostats/use-set-thermostat-fan-mode.js.map +1 -1
- package/lib/seam/thermostats/use-set-thermostat-off.js +1 -1
- package/lib/seam/thermostats/use-set-thermostat-off.js.map +1 -1
- package/lib/seam/thermostats/use-update-thermostat-climate-preset.js +1 -1
- package/lib/seam/thermostats/use-update-thermostat-climate-preset.js.map +1 -1
- package/lib/telemetry/hooks.js +1 -1
- 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 +5 -5
- package/src/index.ts +1 -0
- package/src/lib/index.ts +0 -1
- package/src/lib/seam/SeamProvider.tsx +4 -4
- package/src/lib/seam/access-codes/use-access-code.ts +1 -1
- package/src/lib/seam/access-codes/use-access-codes.ts +1 -1
- package/src/lib/seam/access-codes/use-create-access-code.ts +2 -3
- package/src/lib/seam/access-codes/use-delete-access-code.ts +1 -2
- package/src/lib/seam/access-codes/use-generate-access-code-code.ts +1 -2
- package/src/lib/seam/access-codes/use-update-access-code.ts +1 -2
- package/src/lib/seam/client-sessions/use-client-session.ts +1 -1
- package/src/lib/seam/components/DeviceDetails/LockDeviceDetails.tsx +7 -43
- package/src/lib/seam/components/DeviceDetails/LockDeviceLockButtons.tsx +137 -0
- package/src/lib/seam/components/SupportedDeviceTable/use-device-model.ts +1 -1
- package/src/lib/seam/components/SupportedDeviceTable/use-device-models.ts +1 -1
- package/src/lib/seam/components/SupportedDeviceTable/use-manufacturer.ts +1 -1
- package/src/lib/seam/components/SupportedDeviceTable/use-manufacturers.ts +1 -1
- package/src/lib/seam/connect-webviews/use-create-connect-webview.ts +1 -1
- package/src/lib/seam/connected-accounts/use-connected-account.ts +1 -1
- package/src/lib/seam/devices/use-device-providers.ts +1 -1
- package/src/lib/seam/devices/use-device.ts +1 -1
- package/src/lib/seam/devices/use-devices.ts +1 -1
- package/src/lib/seam/devices/use-update-device-name.ts +1 -2
- package/src/lib/seam/events/use-events.ts +1 -1
- package/src/lib/seam/index.ts +0 -6
- package/src/lib/seam/locks/use-lock-door.ts +101 -0
- package/src/lib/seam/locks/use-toggle-lock.ts +1 -2
- package/src/lib/seam/locks/use-unlock-door.ts +104 -0
- package/src/lib/seam/noise-sensors/use-noise-thresholds.ts +1 -1
- package/src/lib/seam/thermostats/use-cool-thermostat.ts +1 -1
- package/src/lib/seam/thermostats/use-create-thermostat-climate-preset.ts +1 -1
- package/src/lib/seam/thermostats/use-delete-thermostat-climate-preset.ts +1 -1
- package/src/lib/seam/thermostats/use-heat-cool-thermostat.ts +1 -1
- package/src/lib/seam/thermostats/use-heat-thermostat.ts +1 -1
- package/src/lib/seam/thermostats/use-set-thermostat-fan-mode.ts +1 -2
- package/src/lib/seam/thermostats/use-set-thermostat-off.ts +1 -2
- package/src/lib/seam/thermostats/use-update-thermostat-climate-preset.ts +1 -1
- package/src/lib/telemetry/hooks.ts +1 -1
- package/src/lib/version.ts +1 -1
- package/src/styles/_device-details.scss +1 -0
- package/lib/seam/SeamQueryProvider.d.ts +0 -40
- package/lib/seam/SeamQueryProvider.js +0 -180
- package/lib/seam/SeamQueryProvider.js.map +0 -1
- package/lib/seam/use-seam-client.d.ts +0 -14
- package/lib/seam/use-seam-client.js +0 -134
- package/lib/seam/use-seam-client.js.map +0 -1
- package/lib/seam/use-seam-infinite-query.d.ts +0 -15
- package/lib/seam/use-seam-infinite-query.js +0 -47
- package/lib/seam/use-seam-infinite-query.js.map +0 -1
- package/lib/seam/use-seam-mutation-without-workspace.d.ts +0 -9
- package/lib/seam/use-seam-mutation-without-workspace.js +0 -17
- package/lib/seam/use-seam-mutation-without-workspace.js.map +0 -1
- package/lib/seam/use-seam-mutation.d.ts +0 -10
- package/lib/seam/use-seam-mutation.js +0 -17
- package/lib/seam/use-seam-mutation.js.map +0 -1
- package/lib/seam/use-seam-query-without-workspace.d.ts +0 -11
- package/lib/seam/use-seam-query-without-workspace.js +0 -25
- package/lib/seam/use-seam-query-without-workspace.js.map +0 -1
- package/lib/seam/use-seam-query.d.ts +0 -12
- package/lib/seam/use-seam-query.js +0 -25
- package/lib/seam/use-seam-query.js.map +0 -1
- package/src/lib/seam/SeamQueryProvider.tsx +0 -356
- package/src/lib/seam/use-seam-client.ts +0 -225
- package/src/lib/seam/use-seam-infinite-query.ts +0 -103
- package/src/lib/seam/use-seam-mutation-without-workspace.ts +0 -56
- package/src/lib/seam/use-seam-mutation.ts +0 -64
- package/src/lib/seam/use-seam-query-without-workspace.ts +0 -59
- 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'>
|