@startsimpli/hooks 0.4.32 → 0.4.33
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/package.json +1 -1
- package/src/index.ts +1 -0
- package/src/useVault.ts +22 -7
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/useVault.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
1
|
+
import { useMutation, useQueries, useQuery, useQueryClient } from '@tanstack/react-query'
|
|
2
2
|
import type {
|
|
3
3
|
VaultAccessKeyInput,
|
|
4
4
|
VaultApi,
|
|
5
|
+
VaultEnvironment,
|
|
5
6
|
VaultEnvironmentInput,
|
|
6
7
|
VaultListParams,
|
|
7
8
|
VaultProjectInput,
|
|
@@ -182,19 +183,33 @@ export function useAccessKeys(api: VaultApi, slug: string, params?: VaultListPar
|
|
|
182
183
|
})
|
|
183
184
|
}
|
|
184
185
|
|
|
185
|
-
|
|
186
|
+
/** Access keys across every environment, for the top-level Access Keys page
|
|
187
|
+
* (startsim access-keys relocation) — the API only lists per-environment, so
|
|
188
|
+
* this fans out one query per env and lets the caller flatten the results. */
|
|
189
|
+
export function useAllAccessKeys(api: VaultApi, envs: Pick<VaultEnvironment, 'slug'>[]) {
|
|
190
|
+
return useQueries({
|
|
191
|
+
queries: envs.map((env) => ({
|
|
192
|
+
queryKey: accessKeysKey(env.slug),
|
|
193
|
+
queryFn: () => api.listAccessKeys(env.slug),
|
|
194
|
+
enabled: !!env.slug,
|
|
195
|
+
})),
|
|
196
|
+
})
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
export function useCreateAccessKey(api: VaultApi) {
|
|
186
200
|
const qc = useQueryClient()
|
|
187
201
|
return useMutation({
|
|
188
|
-
mutationFn: (data:
|
|
189
|
-
|
|
202
|
+
mutationFn: ({ slug, data }: { slug: string; data: VaultAccessKeyInput }) =>
|
|
203
|
+
api.createAccessKey(slug, data),
|
|
204
|
+
onSuccess: (_, { slug }) => qc.invalidateQueries({ queryKey: accessKeysKey(slug) }),
|
|
190
205
|
})
|
|
191
206
|
}
|
|
192
207
|
|
|
193
|
-
export function useDeleteAccessKey(api: VaultApi
|
|
208
|
+
export function useDeleteAccessKey(api: VaultApi) {
|
|
194
209
|
const qc = useQueryClient()
|
|
195
210
|
return useMutation({
|
|
196
|
-
mutationFn: (id: string) => api.deleteAccessKey(slug, id),
|
|
197
|
-
onSuccess: () => qc.invalidateQueries({ queryKey: accessKeysKey(slug) }),
|
|
211
|
+
mutationFn: ({ slug, id }: { slug: string; id: string }) => api.deleteAccessKey(slug, id),
|
|
212
|
+
onSuccess: (_, { slug }) => qc.invalidateQueries({ queryKey: accessKeysKey(slug) }),
|
|
198
213
|
})
|
|
199
214
|
}
|
|
200
215
|
|