@seamapi/react 4.9.0 → 4.10.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 +2 -2
- package/dist/elements.js +7924 -8203
- package/dist/elements.js.map +1 -1
- package/lib/seam/SeamProvider.d.ts +1 -1
- package/lib/seam/SeamProvider.js +2 -2
- package/lib/seam/SeamProvider.js.map +1 -1
- package/lib/seam/SeamQueryProvider.d.ts +9 -1
- package/lib/seam/SeamQueryProvider.js +58 -5
- package/lib/seam/SeamQueryProvider.js.map +1 -1
- 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/use-seam-client.d.ts +4 -1
- package/lib/seam/use-seam-client.js +74 -17
- package/lib/seam/use-seam-client.js.map +1 -1
- package/lib/seam/use-seam-mutation-without-workspace.d.ts +8 -0
- package/lib/seam/use-seam-mutation-without-workspace.js +17 -0
- package/lib/seam/use-seam-mutation-without-workspace.js.map +1 -0
- package/lib/seam/use-seam-query-without-workspace.d.ts +8 -0
- package/lib/seam/use-seam-query-without-workspace.js +23 -0
- package/lib/seam/use-seam-query-without-workspace.js.map +1 -0
- package/lib/seam/use-seam-query.js +6 -2
- package/lib/seam/use-seam-query.js.map +1 -1
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/version.js.map +1 -1
- package/package.json +2 -2
- package/src/lib/seam/SeamProvider.tsx +5 -1
- package/src/lib/seam/SeamQueryProvider.tsx +110 -5
- package/src/lib/seam/index.ts +2 -0
- package/src/lib/seam/use-seam-client.ts +129 -23
- package/src/lib/seam/use-seam-mutation-without-workspace.ts +53 -0
- package/src/lib/seam/use-seam-query-without-workspace.ts +53 -0
- package/src/lib/seam/use-seam-query.ts +6 -2
- package/src/lib/version.ts +1 -1
|
@@ -3,7 +3,11 @@ import type {
|
|
|
3
3
|
SeamHttpEndpoints,
|
|
4
4
|
SeamHttpOptionsWithClientSessionToken,
|
|
5
5
|
} from '@seamapi/http/connect'
|
|
6
|
-
import {
|
|
6
|
+
import {
|
|
7
|
+
QueryClient,
|
|
8
|
+
QueryClientContext,
|
|
9
|
+
QueryClientProvider,
|
|
10
|
+
} from '@tanstack/react-query'
|
|
7
11
|
import {
|
|
8
12
|
createContext,
|
|
9
13
|
type PropsWithChildren,
|
|
@@ -21,16 +25,21 @@ export interface SeamQueryContext {
|
|
|
21
25
|
publishableKey?: string | undefined
|
|
22
26
|
userIdentifierKey?: string | undefined
|
|
23
27
|
clientSessionToken?: string | undefined
|
|
28
|
+
consoleSessionToken?: string | undefined
|
|
29
|
+
workspaceId?: string | undefined
|
|
30
|
+
queryKeyPrefix?: string | undefined
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
export type SeamQueryProviderProps =
|
|
27
34
|
| SeamQueryProviderPropsWithClient
|
|
28
35
|
| SeamQueryProviderPropsWithPublishableKey
|
|
29
36
|
| SeamQueryProviderPropsWithClientSessionToken
|
|
37
|
+
| SeamQueryProviderPropsWithConsoleSessionToken
|
|
30
38
|
|
|
31
39
|
export interface SeamQueryProviderPropsWithClient
|
|
32
40
|
extends SeamQueryProviderBaseProps {
|
|
33
41
|
client: SeamHttp
|
|
42
|
+
queryKeyPrefix: string
|
|
34
43
|
}
|
|
35
44
|
|
|
36
45
|
export interface SeamQueryProviderPropsWithPublishableKey
|
|
@@ -46,6 +55,13 @@ export interface SeamQueryProviderPropsWithClientSessionToken
|
|
|
46
55
|
clientSessionToken: string
|
|
47
56
|
}
|
|
48
57
|
|
|
58
|
+
export interface SeamQueryProviderPropsWithConsoleSessionToken
|
|
59
|
+
extends SeamQueryProviderBaseProps,
|
|
60
|
+
SeamQueryProviderClientOptions {
|
|
61
|
+
consoleSessionToken: string
|
|
62
|
+
workspaceId?: string | undefined
|
|
63
|
+
}
|
|
64
|
+
|
|
49
65
|
interface SeamQueryProviderBaseProps extends PropsWithChildren {
|
|
50
66
|
queryClient?: QueryClient | undefined
|
|
51
67
|
onSessionUpdate?: (client: SeamHttp) => void
|
|
@@ -68,7 +84,8 @@ export function SeamQueryProvider({
|
|
|
68
84
|
if (
|
|
69
85
|
context.client == null &&
|
|
70
86
|
context.publishableKey == null &&
|
|
71
|
-
context.clientSessionToken == null
|
|
87
|
+
context.clientSessionToken == null &&
|
|
88
|
+
context.consoleSessionToken == null
|
|
72
89
|
) {
|
|
73
90
|
return defaultSeamQueryContextValue
|
|
74
91
|
}
|
|
@@ -78,18 +95,30 @@ export function SeamQueryProvider({
|
|
|
78
95
|
if (
|
|
79
96
|
value.client == null &&
|
|
80
97
|
value.publishableKey == null &&
|
|
81
|
-
value.clientSessionToken == null
|
|
98
|
+
value.clientSessionToken == null &&
|
|
99
|
+
value.consoleSessionToken == null
|
|
82
100
|
) {
|
|
83
101
|
throw new Error(
|
|
84
|
-
`Must provide either a Seam client, clientSessionToken, or
|
|
102
|
+
`Must provide either a Seam client, clientSessionToken, publishableKey or consoleSessionToken.`
|
|
85
103
|
)
|
|
86
104
|
}
|
|
87
105
|
|
|
88
106
|
const { Provider } = seamContext
|
|
107
|
+
const queryClientFromContext = useContext(QueryClientContext)
|
|
108
|
+
|
|
109
|
+
if (
|
|
110
|
+
queryClientFromContext != null &&
|
|
111
|
+
queryClient != null &&
|
|
112
|
+
queryClientFromContext !== queryClient
|
|
113
|
+
) {
|
|
114
|
+
throw new Error(
|
|
115
|
+
'The QueryClient passed into SeamQueryProvider is different from the one in the existing QueryClientContext. Omit the queryClient prop from SeamProvider or SeamQueryProvider to use the existing QueryClient provided by the QueryClientProvider.'
|
|
116
|
+
)
|
|
117
|
+
}
|
|
89
118
|
|
|
90
119
|
return (
|
|
91
120
|
<QueryClientProvider
|
|
92
|
-
client={
|
|
121
|
+
client={queryClientFromContext ?? queryClient ?? defaultQueryClient}
|
|
93
122
|
>
|
|
94
123
|
<Provider value={value}>
|
|
95
124
|
<Session onSessionUpdate={onSessionUpdate}>{children}</Session>
|
|
@@ -128,6 +157,11 @@ const createSeamQueryContextValue = (
|
|
|
128
157
|
options: SeamQueryProviderProps
|
|
129
158
|
): SeamQueryContext => {
|
|
130
159
|
if (isSeamQueryProviderPropsWithClient(options)) {
|
|
160
|
+
if (options.queryKeyPrefix == null) {
|
|
161
|
+
throw new InvalidSeamQueryProviderProps(
|
|
162
|
+
'The client prop must be used with a queryKeyPrefix prop.'
|
|
163
|
+
)
|
|
164
|
+
}
|
|
131
165
|
return {
|
|
132
166
|
...options,
|
|
133
167
|
endpointClient: null,
|
|
@@ -155,6 +189,17 @@ const createSeamQueryContextValue = (
|
|
|
155
189
|
}
|
|
156
190
|
}
|
|
157
191
|
|
|
192
|
+
if (isSeamQueryProviderPropsWithConsoleSessionToken(options)) {
|
|
193
|
+
const { consoleSessionToken, workspaceId, ...clientOptions } = options
|
|
194
|
+
return {
|
|
195
|
+
consoleSessionToken,
|
|
196
|
+
workspaceId,
|
|
197
|
+
clientOptions,
|
|
198
|
+
client: null,
|
|
199
|
+
endpointClient: null,
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
158
203
|
return { client: null, endpointClient: null }
|
|
159
204
|
}
|
|
160
205
|
|
|
@@ -207,6 +252,18 @@ const isSeamQueryProviderPropsWithPublishableKey = (
|
|
|
207
252
|
)
|
|
208
253
|
}
|
|
209
254
|
|
|
255
|
+
if ('consoleSessionToken' in props && props.consoleSessionToken != null) {
|
|
256
|
+
throw new InvalidSeamQueryProviderProps(
|
|
257
|
+
'The consoleSessionToken prop cannot be used with the publishableKey prop.'
|
|
258
|
+
)
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
if ('workspaceId' in props && props.workspaceId != null) {
|
|
262
|
+
throw new InvalidSeamQueryProviderProps(
|
|
263
|
+
'The workspaceId prop cannot be used with the publishableKey prop.'
|
|
264
|
+
)
|
|
265
|
+
}
|
|
266
|
+
|
|
210
267
|
return true
|
|
211
268
|
}
|
|
212
269
|
|
|
@@ -237,6 +294,54 @@ const isSeamQueryProviderPropsWithClientSessionToken = (
|
|
|
237
294
|
)
|
|
238
295
|
}
|
|
239
296
|
|
|
297
|
+
if ('consoleSessionToken' in props && props.consoleSessionToken != null) {
|
|
298
|
+
throw new InvalidSeamQueryProviderProps(
|
|
299
|
+
'The consoleSessionToken prop cannot be used with the clientSessionToken prop.'
|
|
300
|
+
)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
if ('workspaceId' in props && props.workspaceId != null) {
|
|
304
|
+
throw new InvalidSeamQueryProviderProps(
|
|
305
|
+
'The workspaceId prop cannot be used with the clientSessionToken prop.'
|
|
306
|
+
)
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return true
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const isSeamQueryProviderPropsWithConsoleSessionToken = (
|
|
313
|
+
props: SeamQueryProviderProps
|
|
314
|
+
): props is SeamQueryProviderPropsWithConsoleSessionToken &
|
|
315
|
+
SeamQueryProviderClientOptions => {
|
|
316
|
+
if (!('consoleSessionToken' in props)) return false
|
|
317
|
+
|
|
318
|
+
const { consoleSessionToken } = props
|
|
319
|
+
if (consoleSessionToken == null) return false
|
|
320
|
+
|
|
321
|
+
if ('client' in props && props.client != null) {
|
|
322
|
+
throw new InvalidSeamQueryProviderProps(
|
|
323
|
+
'The client prop cannot be used with the publishableKey prop.'
|
|
324
|
+
)
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
if ('clientSessionToken' in props && props.clientSessionToken != null) {
|
|
328
|
+
throw new InvalidSeamQueryProviderProps(
|
|
329
|
+
'The clientSessionToken prop cannot be used with the publishableKey prop.'
|
|
330
|
+
)
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
if ('publishableKey' in props && props.publishableKey != null) {
|
|
334
|
+
throw new InvalidSeamQueryProviderProps(
|
|
335
|
+
'The publishableKey prop cannot be used with the consoleSessionToken prop.'
|
|
336
|
+
)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
if ('userIdentifierKey' in props && props.userIdentifierKey != null) {
|
|
340
|
+
throw new InvalidSeamQueryProviderProps(
|
|
341
|
+
'The userIdentifierKey prop cannot be used with the consoleSessionToken prop.'
|
|
342
|
+
)
|
|
343
|
+
}
|
|
344
|
+
|
|
240
345
|
return true
|
|
241
346
|
}
|
|
242
347
|
|
package/src/lib/seam/index.ts
CHANGED
|
@@ -13,5 +13,7 @@ export * from './devices/use-devices.js'
|
|
|
13
13
|
export * from './SeamProvider.js'
|
|
14
14
|
export * from './use-seam-client.js'
|
|
15
15
|
export * from './use-seam-mutation.js'
|
|
16
|
+
export * from './use-seam-mutation-without-workspace.js'
|
|
16
17
|
export * from './use-seam-query.js'
|
|
17
18
|
export * from './use-seam-query-result.js'
|
|
19
|
+
export * from './use-seam-query-without-workspace.js'
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
SeamHttp,
|
|
3
|
+
SeamHttpEndpoints,
|
|
4
|
+
SeamHttpEndpointsWithoutWorkspace,
|
|
5
|
+
SeamHttpWithoutWorkspace,
|
|
6
|
+
} from '@seamapi/http/connect'
|
|
2
7
|
import { useQuery } from '@tanstack/react-query'
|
|
3
8
|
import { useEffect } from 'react'
|
|
4
9
|
import { v4 as uuidv4 } from 'uuid'
|
|
@@ -8,6 +13,9 @@ import { useSeamQueryContext } from './SeamQueryProvider.js'
|
|
|
8
13
|
export function useSeamClient(): {
|
|
9
14
|
client: SeamHttp | null
|
|
10
15
|
endpointClient: SeamHttpEndpoints | null
|
|
16
|
+
clientWithoutWorkspace: SeamHttpWithoutWorkspace | null
|
|
17
|
+
endpointClientWithoutWorkspace: SeamHttpEndpointsWithoutWorkspace | null
|
|
18
|
+
queryKeyPrefixes: string[]
|
|
11
19
|
isPending: boolean
|
|
12
20
|
isError: boolean
|
|
13
21
|
error: unknown
|
|
@@ -17,16 +25,23 @@ export function useSeamClient(): {
|
|
|
17
25
|
clientOptions,
|
|
18
26
|
publishableKey,
|
|
19
27
|
clientSessionToken,
|
|
28
|
+
consoleSessionToken,
|
|
29
|
+
workspaceId,
|
|
30
|
+
queryKeyPrefix,
|
|
20
31
|
...context
|
|
21
32
|
} = useSeamQueryContext()
|
|
22
33
|
const userIdentifierKey = useUserIdentifierKeyOrFingerprint(
|
|
23
34
|
clientSessionToken != null ? '' : context.userIdentifierKey
|
|
24
35
|
)
|
|
25
36
|
|
|
26
|
-
const { isPending, isError, error, data } = useQuery<
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
const { isPending, isError, error, data } = useQuery<{
|
|
38
|
+
client: SeamHttp | null
|
|
39
|
+
endpointClient: SeamHttpEndpoints | null
|
|
40
|
+
clientWithoutWorkspace: SeamHttpWithoutWorkspace | null
|
|
41
|
+
endpointClientWithoutWorkspace: SeamHttpEndpointsWithoutWorkspace | null
|
|
42
|
+
}>({
|
|
29
43
|
queryKey: [
|
|
44
|
+
...getQueryKeyPrefixes({ queryKeyPrefix }),
|
|
30
45
|
'client',
|
|
31
46
|
{
|
|
32
47
|
client,
|
|
@@ -38,41 +53,94 @@ export function useSeamClient(): {
|
|
|
38
53
|
],
|
|
39
54
|
queryFn: async () => {
|
|
40
55
|
if (client != null)
|
|
41
|
-
return
|
|
56
|
+
return {
|
|
57
|
+
client,
|
|
58
|
+
endpointClient: SeamHttpEndpoints.fromClient(client.client),
|
|
59
|
+
clientWithoutWorkspace: null,
|
|
60
|
+
endpointClientWithoutWorkspace: null,
|
|
61
|
+
}
|
|
42
62
|
|
|
43
63
|
if (clientSessionToken != null) {
|
|
44
|
-
const
|
|
64
|
+
const seam = SeamHttp.fromClientSessionToken(
|
|
45
65
|
clientSessionToken,
|
|
46
66
|
clientOptions
|
|
47
67
|
)
|
|
48
68
|
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
SeamHttpEndpoints.fromClient(
|
|
52
|
-
|
|
69
|
+
return {
|
|
70
|
+
client: seam,
|
|
71
|
+
endpointClient: SeamHttpEndpoints.fromClient(seam.client),
|
|
72
|
+
clientWithoutWorkspace: null,
|
|
73
|
+
endpointClientWithoutWorkspace: null,
|
|
74
|
+
}
|
|
53
75
|
}
|
|
54
76
|
|
|
55
|
-
if (publishableKey
|
|
56
|
-
|
|
57
|
-
|
|
77
|
+
if (publishableKey != null) {
|
|
78
|
+
const seam = await SeamHttp.fromPublishableKey(
|
|
79
|
+
publishableKey,
|
|
80
|
+
userIdentifierKey,
|
|
81
|
+
clientOptions
|
|
58
82
|
)
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
client: seam,
|
|
86
|
+
endpointClient: SeamHttpEndpoints.fromClient(seam.client),
|
|
87
|
+
clientWithoutWorkspace: null,
|
|
88
|
+
endpointClientWithoutWorkspace: null,
|
|
89
|
+
}
|
|
59
90
|
}
|
|
60
91
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
92
|
+
if (consoleSessionToken != null) {
|
|
93
|
+
const clientWithoutWorkspace =
|
|
94
|
+
SeamHttpWithoutWorkspace.fromConsoleSessionToken(consoleSessionToken)
|
|
95
|
+
|
|
96
|
+
const endpointClientWithoutWorkspace =
|
|
97
|
+
SeamHttpEndpointsWithoutWorkspace.fromClient(
|
|
98
|
+
clientWithoutWorkspace.client
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
if (workspaceId == null) {
|
|
102
|
+
return {
|
|
103
|
+
client: null,
|
|
104
|
+
endpointClient: null,
|
|
105
|
+
clientWithoutWorkspace,
|
|
106
|
+
endpointClientWithoutWorkspace,
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
const seam = SeamHttp.fromConsoleSessionToken(
|
|
111
|
+
consoleSessionToken,
|
|
112
|
+
workspaceId,
|
|
113
|
+
clientOptions
|
|
114
|
+
)
|
|
115
|
+
|
|
116
|
+
return {
|
|
117
|
+
client: seam,
|
|
118
|
+
endpointClient: SeamHttpEndpoints.fromClient(seam.client),
|
|
119
|
+
clientWithoutWorkspace,
|
|
120
|
+
endpointClientWithoutWorkspace,
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
throw new Error(
|
|
125
|
+
'Missing either a client, publishableKey, clientSessionToken, or consoleSessionToken.'
|
|
65
126
|
)
|
|
66
|
-
return [
|
|
67
|
-
publishableKeyClient,
|
|
68
|
-
SeamHttpEndpoints.fromClient(publishableKeyClient.client),
|
|
69
|
-
]
|
|
70
127
|
},
|
|
71
128
|
})
|
|
72
129
|
|
|
73
130
|
return {
|
|
74
|
-
client: data?.
|
|
75
|
-
endpointClient: data?.
|
|
131
|
+
client: data?.client ?? null,
|
|
132
|
+
endpointClient: data?.endpointClient ?? null,
|
|
133
|
+
clientWithoutWorkspace: data?.clientWithoutWorkspace ?? null,
|
|
134
|
+
endpointClientWithoutWorkspace:
|
|
135
|
+
data?.endpointClientWithoutWorkspace ?? null,
|
|
136
|
+
queryKeyPrefixes: getQueryKeyPrefixes({
|
|
137
|
+
queryKeyPrefix,
|
|
138
|
+
userIdentifierKey,
|
|
139
|
+
publishableKey,
|
|
140
|
+
clientSessionToken,
|
|
141
|
+
consoleSessionToken,
|
|
142
|
+
workspaceId,
|
|
143
|
+
}),
|
|
76
144
|
isPending,
|
|
77
145
|
isError,
|
|
78
146
|
error,
|
|
@@ -117,3 +185,41 @@ This is not recommended because the client session is now bound to this machine
|
|
|
117
185
|
|
|
118
186
|
return fingerprint
|
|
119
187
|
}
|
|
188
|
+
|
|
189
|
+
const getQueryKeyPrefixes = ({
|
|
190
|
+
queryKeyPrefix,
|
|
191
|
+
userIdentifierKey,
|
|
192
|
+
publishableKey,
|
|
193
|
+
clientSessionToken,
|
|
194
|
+
consoleSessionToken,
|
|
195
|
+
workspaceId,
|
|
196
|
+
}: {
|
|
197
|
+
queryKeyPrefix: string | undefined
|
|
198
|
+
userIdentifierKey?: string
|
|
199
|
+
publishableKey?: string | undefined
|
|
200
|
+
clientSessionToken?: string | undefined
|
|
201
|
+
consoleSessionToken?: string | undefined
|
|
202
|
+
workspaceId?: string | undefined
|
|
203
|
+
}): string[] => {
|
|
204
|
+
const seamPrefix = 'seam'
|
|
205
|
+
|
|
206
|
+
if (queryKeyPrefix != null) return [seamPrefix, queryKeyPrefix]
|
|
207
|
+
|
|
208
|
+
if (clientSessionToken != null) {
|
|
209
|
+
return [seamPrefix, clientSessionToken]
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
if (publishableKey != null && userIdentifierKey != null) {
|
|
213
|
+
return [seamPrefix, publishableKey, userIdentifierKey]
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
if (consoleSessionToken != null) {
|
|
217
|
+
if (workspaceId != null) {
|
|
218
|
+
return [seamPrefix, consoleSessionToken, workspaceId]
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
return [seamPrefix, consoleSessionToken, 'without_workspace']
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
return [seamPrefix]
|
|
225
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SeamHttpApiError,
|
|
3
|
+
SeamHttpEndpointsWithoutWorkspace,
|
|
4
|
+
SeamHttpEndpointWithoutWorkspaceMutationPaths,
|
|
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 UseSeamMutationWithoutWorkspaceVariables<
|
|
15
|
+
T extends SeamHttpEndpointWithoutWorkspaceMutationPaths,
|
|
16
|
+
> = Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[0]
|
|
17
|
+
|
|
18
|
+
export type UseSeamMutationWithoutWorkspaceResult<
|
|
19
|
+
T extends SeamHttpEndpointWithoutWorkspaceMutationPaths,
|
|
20
|
+
> = UseMutationResult<
|
|
21
|
+
MutationData<T>,
|
|
22
|
+
SeamHttpApiError,
|
|
23
|
+
UseSeamMutationWithoutWorkspaceVariables<T>
|
|
24
|
+
>
|
|
25
|
+
|
|
26
|
+
export function UseSeamMutationWithoutWorkspace<
|
|
27
|
+
T extends SeamHttpEndpointWithoutWorkspaceMutationPaths,
|
|
28
|
+
>(
|
|
29
|
+
endpointPath: T,
|
|
30
|
+
options: Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[1] &
|
|
31
|
+
MutationOptions<
|
|
32
|
+
MutationData<T>,
|
|
33
|
+
SeamHttpApiError,
|
|
34
|
+
UseSeamMutationWithoutWorkspaceVariables<T>
|
|
35
|
+
> = {}
|
|
36
|
+
): UseSeamMutationWithoutWorkspaceResult<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 SeamHttpEndpointWithoutWorkspaceMutationPaths> =
|
|
51
|
+
Awaited<ReturnType<SeamHttpEndpointsWithoutWorkspace[T]>>
|
|
52
|
+
|
|
53
|
+
type MutationOptions<X, Y, Z> = Omit<UseMutationOptions<X, Y, Z>, 'mutationFn'>
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SeamHttpApiError,
|
|
3
|
+
SeamHttpEndpointsWithoutWorkspace,
|
|
4
|
+
SeamHttpEndpointWithoutWorkspaceQueryPaths,
|
|
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 UseSeamQueryWithoutWorkspaceParameters<
|
|
15
|
+
T extends SeamHttpEndpointWithoutWorkspaceQueryPaths,
|
|
16
|
+
> = Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[0]
|
|
17
|
+
|
|
18
|
+
export type UseSeamQueryWithoutWorkspaceResult<
|
|
19
|
+
T extends SeamHttpEndpointWithoutWorkspaceQueryPaths,
|
|
20
|
+
> = UseQueryResult<QueryData<T>, SeamHttpApiError>
|
|
21
|
+
|
|
22
|
+
export function useSeamQueryWithoutWorkspace<
|
|
23
|
+
T extends SeamHttpEndpointWithoutWorkspaceQueryPaths,
|
|
24
|
+
>(
|
|
25
|
+
endpointPath: T,
|
|
26
|
+
parameters?: UseSeamQueryWithoutWorkspaceParameters<T>,
|
|
27
|
+
options: Parameters<SeamHttpEndpointsWithoutWorkspace[T]>[1] &
|
|
28
|
+
QueryOptions<QueryData<T>, SeamHttpApiError> = {}
|
|
29
|
+
): UseSeamQueryWithoutWorkspaceResult<T> {
|
|
30
|
+
const { endpointClient: client, queryKeyPrefixes } = useSeamClient()
|
|
31
|
+
return useQuery({
|
|
32
|
+
enabled: client != null,
|
|
33
|
+
...options,
|
|
34
|
+
queryKey: [
|
|
35
|
+
...queryKeyPrefixes,
|
|
36
|
+
...endpointPath.split('/').filter((v) => v !== ''),
|
|
37
|
+
parameters,
|
|
38
|
+
],
|
|
39
|
+
queryFn: async () => {
|
|
40
|
+
if (client == null) return null
|
|
41
|
+
// Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
|
|
42
|
+
// Type assertion is needed here for performance reasons. The types are correct at runtime.
|
|
43
|
+
const endpoint = client[endpointPath] as (...args: any) => Promise<any>
|
|
44
|
+
return await endpoint(parameters, options)
|
|
45
|
+
},
|
|
46
|
+
})
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
type QueryData<T extends SeamHttpEndpointWithoutWorkspaceQueryPaths> = Awaited<
|
|
50
|
+
ReturnType<SeamHttpEndpointsWithoutWorkspace[T]>
|
|
51
|
+
>
|
|
52
|
+
|
|
53
|
+
type QueryOptions<X, Y> = Omit<UseQueryOptions<X, Y>, 'queryKey' | 'queryFn'>
|
|
@@ -23,11 +23,15 @@ export function useSeamQuery<T extends SeamHttpEndpointQueryPaths>(
|
|
|
23
23
|
options: Parameters<SeamHttpEndpoints[T]>[1] &
|
|
24
24
|
QueryOptions<QueryData<T>, SeamHttpApiError> = {}
|
|
25
25
|
): UseSeamQueryResult<T> {
|
|
26
|
-
const { endpointClient: client } = useSeamClient()
|
|
26
|
+
const { endpointClient: client, queryKeyPrefixes } = useSeamClient()
|
|
27
27
|
return useQuery({
|
|
28
28
|
enabled: client != null,
|
|
29
29
|
...options,
|
|
30
|
-
queryKey: [
|
|
30
|
+
queryKey: [
|
|
31
|
+
...queryKeyPrefixes,
|
|
32
|
+
...endpointPath.split('/').filter((v) => v !== ''),
|
|
33
|
+
parameters,
|
|
34
|
+
],
|
|
31
35
|
queryFn: async () => {
|
|
32
36
|
if (client == null) return null
|
|
33
37
|
// Using @ts-expect-error over any is preferred, but not possible here because TypeScript will run out of memory.
|
package/src/lib/version.ts
CHANGED