Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,15 @@ function useSubmitCreateAccessCode(params: {

export function useResponseErrors(): {
responseErrors: ResponseErrors | null
handleResponseError: (error: SeamHttpApiError) => void
handleResponseError: (error: SeamHttpApiError | Error) => void
resetResponseErrors: () => void
} {
const [responseErrors, setResponseErrors] = useState<Record<
string,
string | undefined
> | null>(null)

const handleResponseError = (error: SeamHttpApiError): void => {
const handleResponseError = (error: SeamHttpApiError | Error): void => {
if (isSeamHttpInvalidInputError(error)) {
const errors = shake({
code: error.getValidationErrorMessages('code')[0],
Expand Down
18 changes: 16 additions & 2 deletions src/lib/seam/use-seam-infinite-query.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import type {
SeamActionAttemptFailedError,
SeamActionAttemptTimeoutError,
SeamHttpApiError,
SeamHttpEndpointPaginatedQueryPaths,
SeamHttpEndpoints,
SeamHttpInvalidInputError,
SeamHttpRequest,
SeamPageCursor,
} from '@seamapi/http/connect'
import type { ActionAttempt } from '@seamapi/types/connect'
import {
useInfiniteQuery,
type UseInfiniteQueryOptions,
Expand All @@ -19,15 +23,15 @@ export type UseSeamInfiniteQueryParameters<

export type UseSeamInfiniteQueryResult<
T extends SeamHttpEndpointPaginatedQueryPaths,
> = UseInfiniteQueryResult<QueryData<T>, SeamHttpApiError>
> = UseInfiniteQueryResult<QueryData<T>, QueryError<T>>

export function useSeamInfiniteQuery<
T extends SeamHttpEndpointPaginatedQueryPaths,
>(
endpointPath: T,
parameters?: UseSeamInfiniteQueryParameters<T>,
options: Parameters<SeamHttpEndpoints[T]>[1] &
QueryOptions<QueryData<T>, SeamHttpApiError> = {}
QueryOptions<QueryData<T>, QueryError<T>> = {}
): UseSeamInfiniteQueryResult<T> {
const { endpointClient: client, queryKeyPrefixes } = useSeamClient()
return useInfiniteQuery({
Expand Down Expand Up @@ -75,6 +79,16 @@ interface QueryData<T extends SeamHttpEndpointPaginatedQueryPaths> {
nextPageCursor: SeamPageCursor | null
}

type QueryError<T extends SeamHttpEndpointPaginatedQueryPaths> =
| Error
| SeamHttpApiError
| SeamHttpInvalidInputError
| (QueryData<T>['data'] extends ActionAttempt
?
| SeamActionAttemptFailedError<QueryData<T>['data']>
| SeamActionAttemptTimeoutError<QueryData<T>['data']>
: never)

type QueryOptions<X, Y> = Omit<
UseInfiniteQueryOptions<X, Y>,
'queryKey' | 'queryFn' | 'initialPageParam' | 'getNextPageParam'
Expand Down
7 changes: 5 additions & 2 deletions src/lib/seam/use-seam-mutation-without-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
SeamHttpApiError,
SeamHttpEndpointsWithoutWorkspace,
SeamHttpEndpointWithoutWorkspaceMutationPaths,
SeamHttpInvalidInputError,
} from '@seamapi/http/connect'
import {
useMutation,
Expand All @@ -19,7 +20,7 @@ export type UseSeamMutationWithoutWorkspaceResult<
T extends SeamHttpEndpointWithoutWorkspaceMutationPaths,
> = UseMutationResult<
MutationData<T>,
SeamHttpApiError,
MutationError,
UseSeamMutationWithoutWorkspaceVariables<T>
>

Expand All @@ -30,7 +31,7 @@ export function useSeamMutationWithoutWorkspace<
options: Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[1] &
MutationOptions<
MutationData<T>,
SeamHttpApiError,
MutationError,
UseSeamMutationWithoutWorkspaceVariables<T>
> = {}
): UseSeamMutationWithoutWorkspaceResult<T> {
Expand All @@ -50,4 +51,6 @@ export function useSeamMutationWithoutWorkspace<
type MutationData<T extends SeamHttpEndpointWithoutWorkspaceMutationPaths> =
Awaited<ReturnType<SeamHttpEndpointsWithoutWorkspace[T]>>

type MutationError = Error | SeamHttpApiError | SeamHttpInvalidInputError

type MutationOptions<X, Y, Z> = Omit<UseMutationOptions<X, Y, Z>, 'mutationFn'>
18 changes: 16 additions & 2 deletions src/lib/seam/use-seam-mutation.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import type {
SeamActionAttemptFailedError,
SeamActionAttemptTimeoutError,
SeamHttpApiError,
SeamHttpEndpointMutationPaths,
SeamHttpEndpoints,
SeamHttpInvalidInputError,
} from '@seamapi/http/connect'
import type { ActionAttempt } from '@seamapi/types/connect'
import {
useMutation,
type UseMutationOptions,
Expand All @@ -17,7 +21,7 @@ export type UseSeamMutationVariables<T extends SeamHttpEndpointMutationPaths> =
export type UseSeamMutationResult<T extends SeamHttpEndpointMutationPaths> =
UseMutationResult<
MutationData<T>,
SeamHttpApiError,
MutationError<T>,
UseSeamMutationVariables<T>
>

Expand All @@ -26,7 +30,7 @@ export function useSeamMutation<T extends SeamHttpEndpointMutationPaths>(
options: Parameters<SeamHttpEndpoints[T]>[1] &
MutationOptions<
MutationData<T>,
SeamHttpApiError,
MutationError<T>,
UseSeamMutationVariables<T>
> = {}
): UseSeamMutationResult<T> {
Expand All @@ -47,4 +51,14 @@ type MutationData<T extends SeamHttpEndpointMutationPaths> = Awaited<
ReturnType<SeamHttpEndpoints[T]>
>

type MutationError<T extends SeamHttpEndpointMutationPaths> =
| Error
| SeamHttpApiError
| SeamHttpInvalidInputError
| (MutationData<T> extends ActionAttempt
?
| SeamActionAttemptFailedError<MutationData<T>>
| SeamActionAttemptTimeoutError<MutationData<T>>
: never)

type MutationOptions<X, Y, Z> = Omit<UseMutationOptions<X, Y, Z>, 'mutationFn'>
7 changes: 5 additions & 2 deletions src/lib/seam/use-seam-query-without-workspace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import type {
SeamHttpApiError,
SeamHttpEndpointsWithoutWorkspace,
SeamHttpEndpointWithoutWorkspaceQueryPaths,
SeamHttpInvalidInputError,
} from '@seamapi/http/connect'
import {
useQuery,
Expand All @@ -17,15 +18,15 @@ export type UseSeamQueryWithoutWorkspaceParameters<

export type UseSeamQueryWithoutWorkspaceResult<
T extends SeamHttpEndpointWithoutWorkspaceQueryPaths,
> = UseQueryResult<QueryData<T>, SeamHttpApiError>
> = UseQueryResult<QueryData<T>, QueryError>

export function useSeamQueryWithoutWorkspace<
T extends SeamHttpEndpointWithoutWorkspaceQueryPaths,
>(
endpointPath: T,
parameters?: UseSeamQueryWithoutWorkspaceParameters<T>,
options: Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[1] &
QueryOptions<QueryData<T>, SeamHttpApiError> = {}
QueryOptions<QueryData<T>, QueryError> = {}
): UseSeamQueryWithoutWorkspaceResult<T> {
const { endpointClient: client, queryKeyPrefixes } = useSeamClient()
return useQuery({
Expand All @@ -50,4 +51,6 @@ type QueryData<T extends SeamHttpEndpointWithoutWorkspaceQueryPaths> = Awaited<
ReturnType<SeamHttpEndpointsWithoutWorkspace[T]>
>

type QueryError = Error | SeamHttpApiError | SeamHttpInvalidInputError

type QueryOptions<X, Y> = Omit<UseQueryOptions<X, Y>, 'queryKey' | 'queryFn'>
16 changes: 15 additions & 1 deletion src/lib/seam/use-seam-query.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import type {
SeamActionAttemptFailedError,
SeamActionAttemptTimeoutError,
SeamHttpApiError,
SeamHttpEndpointQueryPaths,
SeamHttpEndpoints,
SeamHttpInvalidInputError,
} from '@seamapi/http/connect'
import type { ActionAttempt } from '@seamapi/types/connect'
import {
useQuery,
type UseQueryOptions,
Expand All @@ -15,7 +19,7 @@ export type UseSeamQueryParameters<T extends SeamHttpEndpointQueryPaths> =
Parameters<SeamHttpEndpoints[T]>[0]

export type UseSeamQueryResult<T extends SeamHttpEndpointQueryPaths> =
UseQueryResult<QueryData<T>, SeamHttpApiError>
UseQueryResult<QueryData<T>, QueryError<T>>

export function useSeamQuery<T extends SeamHttpEndpointQueryPaths>(
endpointPath: T,
Expand Down Expand Up @@ -46,4 +50,14 @@ type QueryData<T extends SeamHttpEndpointQueryPaths> = Awaited<
ReturnType<SeamHttpEndpoints[T]>
>

type QueryError<T extends SeamHttpEndpointQueryPaths> =
| Error
| SeamHttpApiError
| SeamHttpInvalidInputError
| (QueryData<T> extends ActionAttempt
?
| SeamActionAttemptFailedError<QueryData<T>>
| SeamActionAttemptTimeoutError<QueryData<T>>
: never)

type QueryOptions<X, Y> = Omit<UseQueryOptions<X, Y>, 'queryKey' | 'queryFn'>
Loading