@startsimpli/hooks 0.4.45 → 0.4.47
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 +3 -3
- package/src/__tests__/useVault.test.ts +20 -0
- package/src/index.ts +3 -0
- package/src/useVault.ts +24 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@startsimpli/hooks",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.47",
|
|
4
4
|
"description": "Shared React hooks for StartSimpli apps",
|
|
5
5
|
"main": "./src/index.ts",
|
|
6
6
|
"types": "./src/index.ts",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@tanstack/react-query": ">=5.0.0",
|
|
24
24
|
"react": ">=18.0.0",
|
|
25
25
|
"react-native": ">=0.74.0",
|
|
26
|
-
"@startsimpli/api": "^0.5.
|
|
26
|
+
"@startsimpli/api": "^0.5.69"
|
|
27
27
|
},
|
|
28
28
|
"peerDependenciesMeta": {
|
|
29
29
|
"@tanstack/react-query": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"tsup": "^8.5.1",
|
|
47
47
|
"typescript": "^6.0.3",
|
|
48
48
|
"vitest": "^4.1.5",
|
|
49
|
-
"@startsimpli/api": "0.5.
|
|
49
|
+
"@startsimpli/api": "0.5.69"
|
|
50
50
|
},
|
|
51
51
|
"scripts": {
|
|
52
52
|
"build": "tsup",
|
|
@@ -4,7 +4,9 @@ import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
|
|
|
4
4
|
import React from 'react'
|
|
5
5
|
import {
|
|
6
6
|
useAssignEnvironmentProject,
|
|
7
|
+
useCreateAccountKey,
|
|
7
8
|
useCreateSecret,
|
|
9
|
+
useRevokeAccountKey,
|
|
8
10
|
useDeleteProject,
|
|
9
11
|
useDeleteSecret,
|
|
10
12
|
useLinkSharedKey,
|
|
@@ -196,3 +198,21 @@ describe('projects + global keys hooks (startsim-oftw, startsim-1m4g)', () => {
|
|
|
196
198
|
)
|
|
197
199
|
})
|
|
198
200
|
})
|
|
201
|
+
|
|
202
|
+
describe('account (CLI) keys', () => {
|
|
203
|
+
it('create and revoke both refresh the account-keys list', async () => {
|
|
204
|
+
const qc = mkClient()
|
|
205
|
+
const calls = trackInvalidations(qc)
|
|
206
|
+
const api = {
|
|
207
|
+
createAccountKey: vi.fn().mockResolvedValue({ id: '1', key: 'RAW' }),
|
|
208
|
+
revokeAccountKey: vi.fn().mockResolvedValue({}),
|
|
209
|
+
} as unknown as VaultApi
|
|
210
|
+
|
|
211
|
+
const create = renderHook(() => useCreateAccountKey(api), { wrapper: wrap(qc) })
|
|
212
|
+
await act(async () => { await create.result.current.mutateAsync({ name: 'laptop' }) })
|
|
213
|
+
const revoke = renderHook(() => useRevokeAccountKey(api), { wrapper: wrap(qc) })
|
|
214
|
+
await act(async () => { await revoke.result.current.mutateAsync('1') })
|
|
215
|
+
|
|
216
|
+
expect(calls.filter((k) => k.join('/') === 'vault/account-keys')).toHaveLength(2)
|
|
217
|
+
})
|
|
218
|
+
})
|
package/src/index.ts
CHANGED
package/src/useVault.ts
CHANGED
|
@@ -321,3 +321,27 @@ export function useAuditLog(api: VaultApi, slug: string, params?: VaultListParam
|
|
|
321
321
|
enabled: !!slug,
|
|
322
322
|
})
|
|
323
323
|
}
|
|
324
|
+
|
|
325
|
+
// --- Account (CLI) keys ---
|
|
326
|
+
const ACCOUNT_KEYS_KEY = ['vault', 'account-keys'] as const
|
|
327
|
+
|
|
328
|
+
export function useAccountKeys(api: VaultApi) {
|
|
329
|
+
return useQuery({ queryKey: ACCOUNT_KEYS_KEY, queryFn: () => api.listAccountKeys() })
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
/** The raw key comes back once in the mutation result. */
|
|
333
|
+
export function useCreateAccountKey(api: VaultApi) {
|
|
334
|
+
const qc = useQueryClient()
|
|
335
|
+
return useMutation({
|
|
336
|
+
mutationFn: (data: { name: string }) => api.createAccountKey(data),
|
|
337
|
+
onSuccess: () => qc.invalidateQueries({ queryKey: ACCOUNT_KEYS_KEY }),
|
|
338
|
+
})
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
export function useRevokeAccountKey(api: VaultApi) {
|
|
342
|
+
const qc = useQueryClient()
|
|
343
|
+
return useMutation({
|
|
344
|
+
mutationFn: (id: string) => api.revokeAccountKey(id),
|
|
345
|
+
onSuccess: () => qc.invalidateQueries({ queryKey: ACCOUNT_KEYS_KEY }),
|
|
346
|
+
})
|
|
347
|
+
}
|