1
- import type { NewProject , UpdateProject , ViewProject } from '$features/projects/models' ;
1
+ import type { ClientConfiguration , NewProject , UpdateProject , ViewProject } from '$features/projects/models' ;
2
2
import type { WebSocketMessageValue } from '$features/websockets/models' ;
3
3
4
4
import { accessToken } from '$features/auth/index.svelte' ;
5
+ import { ValueFromBody } from '$features/shared/models' ;
5
6
import { type FetchClientResponse , type ProblemDetails , useFetchClient } from '@exceptionless/fetchclient' ;
6
7
import { createMutation , createQuery , QueryClient , useQueryClient } from '@tanstack/svelte-query' ;
7
8
8
-
9
9
export async function invalidateProjectQueries ( queryClient : QueryClient , message : WebSocketMessageValue < 'ProjectChanged' > ) {
10
10
const { id, organization_id } = message ;
11
11
if ( id ) {
@@ -23,15 +23,27 @@ export async function invalidateProjectQueries(queryClient: QueryClient, message
23
23
24
24
// TODO: Do we need to scope these all by organization?
25
25
export const queryKeys = {
26
+ config : ( id : string | undefined ) => [ ...queryKeys . id ( id ) , 'config' ] as const ,
27
+ deleteConfig : ( id : string | undefined ) => [ ...queryKeys . id ( id ) , 'delete-config' ] as const ,
26
28
deleteProject : ( ids : string [ ] | undefined ) => [ ...queryKeys . ids ( ids ) , 'delete' ] as const ,
27
29
deletePromotedTab : ( id : string | undefined ) => [ ...queryKeys . id ( id ) , 'demote-tab' ] as const ,
28
30
id : ( id : string | undefined ) => [ ...queryKeys . type , id ] as const ,
29
31
ids : ( ids : string [ ] | undefined ) => [ ...queryKeys . type , ...( ids ?? [ ] ) ] as const ,
30
32
organization : ( id : string | undefined ) => [ ...queryKeys . type , 'organization' , id ] as const ,
33
+ postConfig : ( id : string | undefined ) => [ ...queryKeys . id ( id ) , 'post-config' ] as const ,
31
34
postPromotedTab : ( id : string | undefined ) => [ ...queryKeys . id ( id ) , 'promote-tab' ] as const ,
32
35
resetData : ( id : string | undefined ) => [ ...queryKeys . id ( id ) , 'reset-data' ] as const ,
33
36
type : [ 'Project' ] as const
34
37
} ;
38
+ export interface DeleteConfigParams {
39
+ key : string ;
40
+ }
41
+
42
+ export interface DeleteConfigRequest {
43
+ route : {
44
+ id : string | undefined ;
45
+ } ;
46
+ }
35
47
36
48
export interface DeleteProjectRequest {
37
49
route : {
@@ -64,6 +76,12 @@ export interface GetOrganizationProjectsRequest {
64
76
} ;
65
77
}
66
78
79
+ export interface GetProjectConfigRequest {
80
+ route : {
81
+ id : string | undefined ;
82
+ } ;
83
+ }
84
+
67
85
export interface GetProjectRequest {
68
86
route : {
69
87
id : string | undefined ;
@@ -72,8 +90,15 @@ export interface GetProjectRequest {
72
90
73
91
export type GetProjectsMode = 'stats' | null ;
74
92
75
- export interface GetProjectsParams {
76
- filter ?: string ;
93
+ export interface PostConfigParams {
94
+ key : string ;
95
+ value : string ;
96
+ }
97
+
98
+ export interface PostConfigRequest {
99
+ route : {
100
+ id : string | undefined ;
101
+ } ;
77
102
}
78
103
79
104
export interface PostPromotedTabParams {
@@ -85,6 +110,7 @@ export interface PostPromotedTabRequest {
85
110
id : string | undefined ;
86
111
} ;
87
112
}
113
+
88
114
export interface ResetDataRequest {
89
115
route : {
90
116
id : string ;
@@ -97,7 +123,6 @@ export interface UpdateProjectRequest {
97
123
} ;
98
124
}
99
125
100
-
101
126
export function deleteProject ( request : DeleteProjectRequest ) {
102
127
const queryClient = useQueryClient ( ) ;
103
128
@@ -121,6 +146,26 @@ export function deleteProject(request: DeleteProjectRequest) {
121
146
} ) ) ;
122
147
}
123
148
149
+ export function deleteProjectConfig ( request : DeleteConfigRequest ) {
150
+ const queryClient = useQueryClient ( ) ;
151
+
152
+ return createMutation < boolean , ProblemDetails , DeleteConfigParams > ( ( ) => ( {
153
+ enabled : ( ) => ! ! accessToken . current ,
154
+ mutationFn : async ( params : DeleteConfigParams ) => {
155
+ const client = useFetchClient ( ) ;
156
+ const response = await client . delete ( `projects/${ request . route . id } /config` , {
157
+ params : { key : params . key }
158
+ } ) ;
159
+
160
+ return response . ok ;
161
+ } ,
162
+ mutationKey : queryKeys . deleteConfig ( request . route . id ) ,
163
+ onSuccess : ( ) => {
164
+ queryClient . invalidateQueries ( { queryKey : queryKeys . config ( request . route . id ) } ) ;
165
+ }
166
+ } ) ) ;
167
+ }
168
+
124
169
export function deletePromotedTab ( request : DeletePromotedTabRequest ) {
125
170
const queryClient = useQueryClient ( ) ;
126
171
return createMutation < boolean , ProblemDetails , DeletePromotedTabParams > ( ( ) => ( {
@@ -176,6 +221,21 @@ export function getOrganizationProjectsQuery(request: GetOrganizationProjectsReq
176
221
} ) ) ;
177
222
}
178
223
224
+ export function getProjectConfig ( request : GetProjectConfigRequest ) {
225
+ return createQuery < ClientConfiguration , ProblemDetails > ( ( ) => ( {
226
+ enabled : ( ) => ! ! accessToken . current && ! ! request . route . id ,
227
+ queryFn : async ( { signal } : { signal : AbortSignal } ) => {
228
+ const client = useFetchClient ( ) ;
229
+ const response = await client . getJSON < ClientConfiguration > ( `projects/${ request . route . id } /config` , {
230
+ signal
231
+ } ) ;
232
+
233
+ return response . data ! ;
234
+ } ,
235
+ queryKey : queryKeys . config ( request . route . id )
236
+ } ) ) ;
237
+ }
238
+
179
239
export function getProjectQuery ( request : GetProjectRequest ) {
180
240
return createQuery < ViewProject , ProblemDetails > ( ( ) => ( {
181
241
enabled : ( ) => ! ! accessToken . current && ! ! request . route . id ,
@@ -190,6 +250,7 @@ export function getProjectQuery(request: GetProjectRequest) {
190
250
queryKey : queryKeys . id ( request . route . id )
191
251
} ) ) ;
192
252
}
253
+
193
254
export function postProject ( ) {
194
255
const queryClient = useQueryClient ( ) ;
195
256
@@ -206,6 +267,26 @@ export function postProject() {
206
267
} ) ) ;
207
268
}
208
269
270
+ export function postProjectConfig ( request : PostConfigRequest ) {
271
+ const queryClient = useQueryClient ( ) ;
272
+
273
+ return createMutation < boolean , ProblemDetails , PostConfigParams > ( ( ) => ( {
274
+ enabled : ( ) => ! ! accessToken . current ,
275
+ mutationFn : async ( params : PostConfigParams ) => {
276
+ const client = useFetchClient ( ) ;
277
+ const response = await client . post ( `projects/${ request . route . id } /config` , new ValueFromBody ( params . value ) , {
278
+ params : { key : params . key }
279
+ } ) ;
280
+
281
+ return response . ok ;
282
+ } ,
283
+ mutationKey : queryKeys . postConfig ( request . route . id ) ,
284
+ onSuccess : ( ) => {
285
+ queryClient . invalidateQueries ( { queryKey : queryKeys . config ( request . route . id ) } ) ;
286
+ }
287
+ } ) ) ;
288
+ }
289
+
209
290
export function postPromotedTab ( request : PostPromotedTabRequest ) {
210
291
const queryClient = useQueryClient ( ) ;
211
292
return createMutation < boolean , ProblemDetails , PostPromotedTabParams > ( ( ) => ( {
0 commit comments